var express = require('express'); var router = express.Router(); var Mock = require("mockjs") var moment = require("moment") var mock=require('../../public/javascripts/mock') var util=require('../../public/javascripts/util') const multipart = require("connect-multiparty"); var multipartMiddleware = multipart(); function base(req,message){ return mock.page(req,message,{ number:/\d{2}[A-Z]{2}\d{4}/, type:/阀门(Valve)/, name:/[A-Z]{4}-Series/, model:/[A-Z]{2}\d{3}[A-Z]{2}\d{2}/, manufacturer:/[A-Z]/, 'sd|100-999':0, 'su|100-999':0, 'dd|100-999':0, 'du|100-999':0, sff:function () { return `${Mock.Random.natural(0,100)}%` }, dataSources:'Exida Certification', framework:/[A-Z]/, 'tsd|0-10':0, 'mttr|1-10':0, 'ti':'', 'ctr|0-10':0, 'lt|0-10':0, htf:'', silLevel:function (){ return `${Mock.Random.natural(1,10)}%` }, route:function () { return `Route H${Mock.Random.natural(1,10)}` }, createUser:function () { return Mock.Random.first() }, note:'', createTime:function (){ return moment(Date.now()-Mock.Random.natural(3600,36000)*1000).format(util.dateFormat) } }) } router.get('/data',function(req, res, next) { var data=base(req,'基础数据获取成功') res.json(data) }) router.post('/data',multipartMiddleware,function(req, res, next){ 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