diff --git a/app.js b/app.js index c588cc2..c52c152 100644 --- a/app.js +++ b/app.js @@ -9,6 +9,7 @@ var accountRouter = require('./routes/account') var mainRouter=require('./routes/main/main') var projectRouter=require('./routes/main/project') var dataRouter=require('./routes/main/data') +var projectDetailRouter=require('./routes/project/project') const server = require("inspector"); var app = express(); @@ -30,6 +31,7 @@ app.use(cors({ app.use('/', indexRouter); app.use('/api/account',accountRouter) app.use('/api/main',mainRouter,projectRouter,dataRouter) +app.use('/api/project',projectDetailRouter) // catch 404 and forward to error handler app.use(function(req, res, next) { diff --git a/routes/main/data.js b/routes/main/data.js index bc891cf..baab413 100644 --- a/routes/main/data.js +++ b/routes/main/data.js @@ -53,17 +53,29 @@ router.get('/data',function(req, res, next) { }) router.post('/data',multipartMiddleware,function(req, res, next){ - if(req.body.type==='import') { - var data = Mock.mock(mock.ok(`基础数据导入成功`)) - return res.json(data) - }else{ - var data=Mock.mock(mock.ok('基础数据添加成功')) - return res.json(data) + let data + const type=req.body.type + console.info(`type=${type}`) + switch (req.body.type){ + case 'import': + data = mock.ok(`基础数据导入成功`) + break + case 'addEmpty': + data=mock.ok('基础数据插入空白行成功') + break + case 'copy': + data=mock.ok('基础数据复制行数据成功') + break } + return res.json(data) }) router.delete('/data',multipartMiddleware,function(req, res, next){ + return res.json(mock.ok('基础数据删除成功')) +}) +router.patch('/data',multipartMiddleware,function(req, res, next){ + return res.json(mock.ok('基础数据位置更新成功')) }) module.exports=router \ No newline at end of file diff --git a/routes/project/project.js b/routes/project/project.js new file mode 100644 index 0000000..99ee96c --- /dev/null +++ b/routes/project/project.js @@ -0,0 +1,42 @@ +var express = require('express'); +var router = express.Router(); +var mock = require('../../public/javascripts/mock') +var Mock = require("mockjs") + +router.get('/menu', function (req, res, next) { + res.json({ + ...mock.ok('菜单获取成功'), + ...Mock.mock({ + body: { + menus: function () { + let menus = [] + let config = [{name: '项目基本信息', childMenu: [{name: '一般信息'}, {name: '团队成员'}, {name: '会议信息'}]} + ,{name: '项目准备', childMenu: [{name: 'HAZOP节点划分'}, {name: 'HAZOP节点复用'}, {name: 'SIF节点划分'}, {name: '矩阵选择'}]} + ,{name: 'HAZOP分析', childMenu: [{name: 'HAZOP分析'}, {name: 'HAZOP所有'}]} + ,{name:'LOPA定级', childMenu: [{name:'LOPA'},{name:'LOPA表单'},{name:'LOPA所有节点'}]} + ,{name:'SIL验算', childMenu: [{name:'SIL验算'},{name:'SIL验算[Nodes]'},{name:'SIL验算-总'}]}] + config.forEach((item, index) => { + let menu = { + menuId: `a${index}`, + menuName: item.name, + isOpen: Mock.Random.boolean() + } + let childMenu = [] + item.childMenu.forEach((item, index) => { + childMenu.push({ + menuId: index, + menuName: item.name, + isSelected: false + }) + }) + menu.childMenu = childMenu + menus.push(menu) + }) + return menus + } + } + }) + }) +}) + +module.exports = router \ No newline at end of file