|
|
|
var express = require('express');
|
|
|
|
var router = express.Router();
|
|
|
|
var Mock = require("mockjs")
|
|
|
|
var util=require('../../public/javascripts/util')
|
|
|
|
var moment = require('moment')
|
|
|
|
var multipart = require('connect-multiparty');
|
|
|
|
var multipartMiddleware = multipart();
|
|
|
|
var mock=require('../../public/javascripts/mock')
|
|
|
|
|
|
|
|
function groupJson(message,req, res, next){
|
|
|
|
var data=Mock.mock({...mock.ok(message),...{
|
|
|
|
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={
|
|
|
|
id:i,
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}})
|
|
|
|
return res.json(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
//项目分组信息
|
|
|
|
router.get('/project/group',function(req, res, next) {
|
|
|
|
return groupJson('获取项目分组信息成功',req,res,next)
|
|
|
|
})
|
|
|
|
|
|
|
|
//添加分组
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return res.json(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
//项目列表数据
|
|
|
|
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}添加成功`))
|
|
|
|
return res.json(data)
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports=router
|