You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
riskcloudmock/routes/main/project.js

88 lines
2.8 KiB

4 years ago
var express = require('express');
var router = express.Router();
var Mock = require("mockjs")
var util=require('../../public/javascripts/util')
var moment = require('moment')
4 years ago
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
var mock=require('../../public/javascripts/mock')
4 years ago
4 years ago
function groupJson(message,req, res, next){
var data=Mock.mock({...mock.ok(message),...{
4 years ago
body: {
total:0,
"groupCount|1-20": 0,
group:function (){
let arr=[]
let names=[]
for(let i=0;i<this.groupCount;i++){
let obj
do{
obj={
4 years ago
id:i,
4 years ago
name: Mock.mock('@first'),
count:Mock.Random.natural(1,100)
}
}while (names.includes(obj.name))
names.push(obj.name)
arr.push(obj)
this.total+=obj.count
}
return arr
}
}
}})
4 years ago
return res.json(data)
4 years ago
}
//项目分组信息
router.get('/project/group',function(req, res, next) {
return groupJson('获取项目分组信息成功',req,res,next)
4 years ago
})
4 years ago
//添加分组
router.post('/project/group',multipartMiddleware,function(req, res, next) {
return groupJson(`添加项目分组${req.body.name}成功`,req,res,next)
})
//分组重命名
router.patch('/project/group/:name',multipartMiddleware,function(req, res, next) {
return groupJson(`项目分组${req.params.name}重命名为${req.body.name}`,req,res,next)
})
//删除分组
router.delete('/project/group/:name',multipartMiddleware,function(req, res, next) {
return groupJson(`项目分组${req.params.name}删除成功`,req,res,next)
})
function projectJson(message,req, res){
var data=mock.page(req,message,{
projectName:/[a-zA-Z0-9]{3,6}/,
templateName:/(GB|国际标准)模板/,
createUser:Mock.mock('@first'),
createTime:function (){
return moment(Date.now()-Mock.Random.natural(3600,36000)*1000).format(util.dateFormat)
},
lastModifyUser:Mock.mock('@first'),
lastModifyTime:function (){
return moment(moment(this.createTime,util.dateFormat).toDate().getTime()+Mock.Random.natural(1,3600)*1000).format(util.dateFormat)
4 years ago
}
})
return res.json(data)
}
4 years ago
4 years ago
//项目列表数据
router.get('/project',function(req, res, next) {
return projectJson('获取项目列表信息成功',req,res,next)
})
//添加项目
router.post('/project',multipartMiddleware,function(req, res, next) {
var data=Mock.mock(mock.ok(`项目${req.body.projectName}添加成功`))
4 years ago
return res.json(data)
4 years ago
})
module.exports=router