From e3e81dd456e1388d0a133ad1581311fd154cc604 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Wed, 14 Oct 2020 06:48:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9F=BA=E7=A1=80=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 3 +- public/javascripts/mock.js | 40 ++++++++++++++++++++++ routes/account.js | 18 ++++++---- routes/main/data.js | 69 ++++++++++++++++++++++++++++++++++++++ routes/main/main.js | 8 ++--- routes/main/project.js | 57 +++++++++---------------------- 6 files changed, 141 insertions(+), 54 deletions(-) create mode 100644 public/javascripts/mock.js create mode 100644 routes/main/data.js diff --git a/app.js b/app.js index c1046b7..c588cc2 100644 --- a/app.js +++ b/app.js @@ -8,6 +8,7 @@ var indexRouter = require('./routes/index'); var accountRouter = require('./routes/account') var mainRouter=require('./routes/main/main') var projectRouter=require('./routes/main/project') +var dataRouter=require('./routes/main/data') const server = require("inspector"); var app = express(); @@ -28,7 +29,7 @@ app.use(cors({ })) app.use('/', indexRouter); app.use('/api/account',accountRouter) -app.use('/api/main',mainRouter,projectRouter) +app.use('/api/main',mainRouter,projectRouter,dataRouter) // catch 404 and forward to error handler app.use(function(req, res, next) { diff --git a/public/javascripts/mock.js b/public/javascripts/mock.js new file mode 100644 index 0000000..ee5bc39 --- /dev/null +++ b/public/javascripts/mock.js @@ -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