parent
2c55cb3a18
commit
e3e81dd456
@ -0,0 +1,40 @@ |
||||
var Mock = require("mockjs") |
||||
module.exports={ |
||||
//模拟基础数据
|
||||
ok:function (message){ |
||||
return { |
||||
code:200, |
||||
message:message, |
||||
result:'OK' |
||||
} |
||||
}, |
||||
error:function (message){ |
||||
return { |
||||
code:200, |
||||
message:message, |
||||
result:'FAIL' |
||||
} |
||||
}, |
||||
//模拟分页数据
|
||||
page:function (req,message,obj){ |
||||
return Mock.mock({...this.ok(message),...{ |
||||
body:{ |
||||
'totalCount|10-100':0, |
||||
pageSize:req.query.pageSize, |
||||
totalPage:function (){ |
||||
return Math.ceil(this.totalCount/this.pageSize) |
||||
}, |
||||
currentPage:function (){ |
||||
return Mock.Random.natural(1,this.totalPage) |
||||
}, |
||||
data:function (){ |
||||
let arr=[] |
||||
for(let i=0;i<this.pageSize;i++){ |
||||
arr.push(Mock.mock(obj)) |
||||
} |
||||
return arr |
||||
} |
||||
} |
||||
}}) |
||||
} |
||||
} |
@ -0,0 +1,69 @@ |
||||
|
||||
|
||||
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){ |
||||
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) |
||||
} |
||||
}) |
||||
|
||||
router.delete('/data',multipartMiddleware,function(req, res, next){ |
||||
|
||||
}) |
||||
|
||||
module.exports=router |
Loading…
Reference in new issue