var express = require('express'); var router = express.Router(); var mock = require('../../public/javascripts/mock') var Mock = require("mockjs") var multipart = require('connect-multiparty'); var multipartMiddleware = multipart(); var moment = require("moment") var util=require("../../public/javascripts/util") var route=require('../../public/javascripts/route') //获取HAZOP节点划分 router.get('/hdivide', function (req, res, next) { var data=mock.page(req,'获取HAOZP节点划分成功',{ //节点 node:()=>Mock.Random.word(), //节点编号 nodeId:/Node\d{3}/, //节点描述 nodeDesc:()=>Mock.Random.sentence(3, 5), //节点PID号 nodePid:/PID\d{3}/ }) res.json(data) }) router.get('/hdivide/node', function (req, res, next) { var data=mock.page(req,'获取HAOZP节点划分成功',{ //节点 node:()=>Mock.Random.word(), }) res.json(data) }) route.addContextMenu(router,'hdivide','HAZOP节点划分') //获取节点复用 router.get('/hreuse', function (req, res, next) { var data=mock.page(req,'获取HAZOP节点复用成功',{ //节点 node:()=>Mock.Random.word(), //偏差 deviation:()=>Mock.Random.sentence(1, 3), //偏差描述 deviationDesc:()=>Mock.Random.sentence(3, 5) }) res.json(data) }) route.addContextMenu(router,'hreuse','HAZOP节点复用') //SIF节点划分 router.get('/sdivide', function (req, res, next) { var data=mock.page(req,'获取SIF节点划分成功',{ //SIF名称 name:()=>Mock.Random.name(), //SIF编号 id:/SIF\d{3}/, //SIF描述 desc:()=>Mock.Random.sentence(3, 5), //SIF连带动作 action:()=>Mock.Random.word(), //需求模式 demandModel:()=>Mock.Random.integer(1,3), //SIL等级要求 level:()=>Mock.Random.integer(1,10), //触发机构 impactMmechanism:()=>Mock.Random.word(), //后果描述 consequence:()=>Mock.Random.sentence(3, 5), //安全状态 status:()=>Mock.Random.word(), //安全失效等级 loseEfficacy:()=>Mock.Random.integer(1,10), //PID号 pid:/PID\d{3}/, //备注 note:()=>Mock.Random.sentence(3, 5) }) res.json(data) }) route.addContextMenu(router,'sdivide','SIF节点划分') router.get('/matrix', function (req, res, next) { var data=Mock.mock({ ...mock.ok('获取矩阵列表成功'), ...{ "body|1-10":[{ id:()=>Mock.Random.natural(1,1000), name:function (){ return `matrix${this.id}` }, "useProjectId|0-2":[/\d{3}/] }] } }) res.json(data) }) router.get('/matrix/:id', function (req, res, next) { var data=Mock.mock({ ...mock.ok('获取矩阵详情成功'), ...{ body:{ id:()=>Mock.Random.natural(1,1000), "useProjectId|0-2":[/\d{3}/], info:{ name:`matrix${Mock.Random.natural(5,8)}`, desc:`matrix${Mock.Random.natural(5,8)}`, x:()=>Mock.Random.natural(5,8), y:()=>Mock.Random.natural(5,8), explain:()=>Mock.Random.sentence(3, 5) }, severity:function (){ const severity=[] for(let i in Array.from(new Array(this.info.y).keys())){ severity.push({ //等级 level:Mock.Random.natural(1,9), //严重程度 severity:Mock.Random.natural(1,9), //人员 personnel:Mock.Random.word(), //财产 property:Mock.Random.word(), //环境 environment:Mock.Random.word(), //声誉 prestige:Mock.Random.word() }) } return severity }, possibility:function (){ const possibility=[] for(let i in Array.from(new Array(this.info.x).keys())){ possibility.push({ //等级 level:Mock.Random.natural(1,this.info.x), //概率值 probability:Mock.Random.natural(1,100)/100, //描述 desc:Mock.Random.sentence(3, 5) }) } return possibility }, 'level|3-5':[{ //Code code:/\d{1}/, //颜色 color:()=>Mock.Random.color(), //描述 desc:()=>Mock.Random.sentence(3, 5), //风险等级 level:/\d{1}/, //应采取措施 measure:()=>Mock.Random.sentence(3, 5), //实施期限 date:()=>Mock.Random.sentence(3, 5), //备注 note:()=>Mock.Random.sentence(3, 5) }], matrix:function (){ const matrix=[] for(let i in Array.from(new Array(this.info.y).keys())){ const child=[] for(let j in Array.from(new Array(this.info.x).keys())){ child.push(this.level[Mock.Random.natural(0,this.level.length-1)]) } matrix.push(child) } return matrix } } } }) res.json(data) }) module.exports=router