// 引入mockjs const Mock = require('mockjs'); // 获取 mock.Random 对象 const Random = Mock.Random; // mock一组数据 const produceNewsData = function(req) { let item = JSON.parse(req.body) let articles = []; for (let i = 0; i < 100; i++) { let newArticleObject = { title: Random.csentence(5, 30), // Random.csentence( min,max) thumbnail_pic_s: Random.dataImage('300x250', 'mock的图片'), // Random.dataImage( size, text ) 生成一段随机的 Base64 图片编码 author_name: Random.cname(), // Random.cname() 随机生成一个常见的中文姓名 date: Random.date() + ' ' + Random.time() // Random.date()指示生成的日期字符串的格式,默认为yyyy-MM-dd;Random.time() 返回一个随机的时间字符串 } articles.push(newArticleObject) } return { datalist: articles } } const loginData = function (req) { const {username} = JSON.parse(req.body) if(username=='xmyfsj'){ return { result: 200, data: { uid:Random.id(), type: 1, username:username, expire_in: "63666", token: Random.guid(), logintime: Random.now() } } }else{ return { result: 0, data: { uid:Random.id(), type: 1, username:username, expire_in: "63666", token: Random.guid(), logintime: Random.now() } } } } //Mock.mock(url, post/get 返回的数据) Mock.mock('/api/news/index', 'post', produceNewsData); Mock.mock("/api/news/index", "get", (options) =>{ // 最佳实践,将请求和参数都打印出来,以便调试A let item=JSON.parse(options.body) let articles = []; for (let i = 0; i < 20; i++) { let newArticleObject = { title: Random.csentence(5, 30), // Random.csentence( min, max ) thumbnail_pic_s: Random.dataImage('300x250', 'mock的图片'), // Random.dataImage( size, text ) 生成一段随机的 Base64 图片编码 author_name: Random.cname(), // Random.cname() 随机生成一个常见的中文姓名 date: Random.date() + ' ' + Random.time() // Random.date()指示生成的日期字符串的格式,默认为yyyy-MM-dd;Random.time() 返回一个随机的时间字符串 } articles.push(newArticleObject) } return { result: 0, data: { datalist: articles, total: 240, product_type:item.product_type } } }); Mock.mock('/api/news/login', 'post', loginData); const menu=function (req) { let menulist=[ { "moduleId": 1363258, "parentId": 1363257, "moduleName": "供应商管理", "moduleCode": "supplier(basp)", "moduleIcon": "", "sort": 2, "badge": 0, "parent": null, "hidden": "N", "helpUrl": null, "childModules": [{ "childModules": [], "moduleCode": "supplierPool", "moduleDesc": "供应商池", "moduleId": "20204", "moduleName": "供应商池", "parentId": "202", "sort": 1 }, { "childModules": [], "moduleCode": "qualificationManager", "moduleDesc": "自营资质管理", "moduleId": "2020203", "moduleName": "自营资质管理", "parentId": "202", "sort": 4 }, { "childModules": [], "moduleCode": "pointsManager", "moduleDesc": "积分管理", "moduleId": "2020204", "moduleName": "积分管理", "parentId": "202", "sort": 5 }, { "childModules": [], "moduleCode": "supplierPaydaysM", "moduleDesc": "账期维护", "moduleId": "2017091200", "moduleName": "账期维护", "parentId": "202", "sort": 19 }, { "childModules": [], "moduleCode": "supplierAppInfo", "moduleDesc": "APP信息维护", "moduleId": "20202", "moduleName": "APP信息维护", "parentId": "202", "sort": 20 }, { "childModules": [], "moduleCode": "capacityPurchase", "moduleDesc": "运力采购", "moduleId": "201809051753", "moduleName": "运力采购", "parentId": "202", "sort": 21 }, { "childModules": [], "helpUrl": "", "moduleCode": "supplierSettlementConfiguration", "moduleDesc": "供应商自动结算配置", "moduleId": "201904150001", "moduleName": "供应商自动结算配置", "parentId": "202", "sort": 22 }, { "childModules": [], "moduleCode": "purchaseRateConfig", "moduleDesc": "采购比例配置", "moduleId": "20191104", "moduleName": "采购比例配置", "parentId": "202", "sort": 23 }, { "childModules": [], "moduleCode": "purchaseStaffConfig", "moduleDesc": "采购人员配置", "moduleId": "20191105", "moduleName": "采购人员配置", "parentId": "202", "sort": 24 }] }, { "moduleId": 1363262, "parentId": 1363257, "moduleName": "模板管理", "moduleCode": "systemManage(basp)", "moduleIcon": "", "sort": 2, "badge": 0, "parent": null, "hidden": "N", "helpUrl": null, "childModules": [ { "moduleId": 1363265, "parentId": 1363262, "moduleName": "资源管理", "moduleCode": "resourceManage", "moduleIcon": "", "sort": 2, "badge": 0, "parent": null, "hidden": "N", "helpUrl": null, "childModules": [] },{ "moduleId": 1363264, "parentId": 1363262, "moduleName": "模块管理", "moduleCode": "moduleManage", "moduleIcon": "", "sort": 2, "badge": 0, "parent": null, "hidden": "N", "helpUrl": null, "childModules": [] }, { "moduleId": 1363263, "parentId": 1363262, "moduleName": "角色管理", "moduleCode": "roleManage", "moduleIcon": "", "sort": 2, "badge": 0, "parent": null, "hidden": "N", "helpUrl": null, "childModules": [] }, { "moduleId": 1363266, "parentId": 1363262, "moduleName": "数据组管理", "moduleCode": "datagroupManage", "moduleIcon": "", "sort": 2, "badge": 0, "parent": null, "hidden": "N", "helpUrl": null, "childModules": [] }, { "moduleId": 1363260, "parentId": 1363258, "moduleName": "账号分配管理", "moduleCode": "accountAssignManage", "moduleIcon": "", "sort": 2, "badge": 0, "parent": null, "hidden": "N", "helpUrl": null, "childModules": [] }, { "moduleId": 1363261, "parentId": 1363258, "moduleName": "账号数据组管理", "moduleCode": "accountDataGroupManage", "moduleIcon": "", "sort": 2, "badge": 0, "parent": null, "hidden": "N", "helpUrl": null, "childModules": [] }, { "moduleId": 1363259, "parentId": 1363258, "moduleName": "子账号管理", "moduleCode": "leafAccountManage", "moduleIcon": "", "sort": 2, "badge": 0, "parent": null, "hidden": "N", "helpUrl": null, "childModules": [] }, { "moduleId": 1363262, "parentId": 1363258, "moduleName": "数据字典", "moduleCode": "dataDictionary", "moduleIcon": "", "sort": 2, "badge": 0, "parent": null, "hidden": "N", "helpUrl": null, "childModules": [] }, { "moduleId": 1363269, "parentId": 1363258, "moduleName": "数据Mock", "moduleCode": "dataMock", "moduleIcon": "", "sort": 2, "badge": 0, "parent": null, "hidden": "N", "helpUrl": null, "childModules": [] }] } ]; return menulist; } Mock.mock('/api/menu/list', 'get', menu); const superlier_data=function (req) { let dataList={ "datas": [{ "administrativeCode": "370200", "areaName": "鲁晋分拨区", "billingHuman": "", "businessType": "2,1", "businessTypeName": "发货和提货", "businessTypeStr": "发货,提货", "checkMethod": "01", "checkMethodStr": "月结", "companyNature": "", "companyNatureStr": "", "dataSource": 1, "deptCode": "532R", "deptId": "2671", "deptName": "青岛流亭航空站点", "getBillHuman": "", "greateEmp": "SAP", "greateTime": "2019-04-10T14:22:00", "id": "10000618505", "isdelete": 0, "legalRepresentative": "", "modifyEmp": "JOB", "modifyTime": "2019-11-22T15:31:00", "path": "http://shiva-trtms-air-p.sit.sf-express.com/air/download/downloadATPFile.pub?picPath=", "registerFund": "", "serviceItemGet": "", "serviceItemOtherGet": "", "serviceItemOtherSend": "", "serviceItemSend": "", "settleAccountsHuman": "", "spsiAddress": "山东省青岛市市南区福州南路60号1栋5层", "state": 2, "stateStr": "备用", "supplierCode": "1000847830", "supplierName": "山东薛航物流有限公司", "supplierProp": "TS01", "supplierType": "TM01", "tel": "", "transportType": "2", "transportTypeStr": "散航班", "typeStr": "" }, { "administrativeCode": "320100", "areaName": "苏沪分拨区", "billingHuman": "", "businessType": "2,1", "businessTypeName": "发货和提货", "businessTypeStr": "发货,提货", "checkMethod": "01", "checkMethodStr": "月结", "companyNature": "", "companyNatureStr": "", "dataSource": 1, "deptCode": "025RH", "deptId": "10209879212957", "deptName": "南京禄口重货快运集散点", "getBillHuman": "", "greateEmp": "SAP", "greateTime": "2018-07-16T15:51:00", "id": "10000618485", "isdelete": 0, "legalRepresentative": "", "modifyEmp": "JOB", "modifyTime": "2019-11-22T15:31:00", "path": "http://shiva-trtms-air-p.sit.sf-express.com/air/download/downloadATPFile.pub?picPath=", "registerFund": "", "serviceItemGet": "", "serviceItemOtherGet": "", "serviceItemOtherSend": "", "serviceItemSend": "", "settleAccountsHuman": "", "spsiAddress": "1279号 上海市浦东新区机场镇航城路1279号", "state": 2, "stateStr": "备用", "supplierCode": "1000002561", "supplierName": "中国货运航空有限公司", "supplierProp": "TS01", "supplierType": "TM02,TM01", "tel": "15002529957", "transportType": "1,2", "transportTypeStr": "全货机,散航班", "typeStr": "" }, { "administrativeCode": "320102", "areaName": "苏沪分拨区", "billingHuman": "", "businessType": "2,1", "businessTypeName": "发货和提货", "businessTypeStr": "发货,提货", "checkMethod": "01", "checkMethodStr": "月结", "companyNature": "", "companyNatureStr": "", "dataSource": 1, "deptCode": "025RH", "deptId": "10209879212957", "deptName": "南京禄口重货快运集散点", "getBillHuman": "", "greateEmp": "SAP", "greateTime": "2018-07-16T15:51:00", "id": "10000618485", "isdelete": 0, "legalRepresentative": "", "modifyEmp": "JOB", "modifyTime": "2019-11-22T15:31:00", "path": "http://shiva-trtms-air-p.sit.sf-express.com/air/download/downloadATPFile.pub?picPath=", "registerFund": "", "serviceItemGet": "", "serviceItemOtherGet": "", "serviceItemOtherSend": "", "serviceItemSend": "", "settleAccountsHuman": "", "spsiAddress": "1279号 上海市浦东新区机场镇航城路1279号", "state": 2, "stateStr": "备用", "supplierCode": "1000002561", "supplierName": "中国货运航空有限公司", "supplierProp": "TS01", "supplierType": "TM02,TM01", "tel": "15002529957", "transportType": "1,2", "transportTypeStr": "全货机,散航班", "typeStr": "" }], "total": 60 } return dataList; } Mock.mock('/api/supplierPool/list', 'get', superlier_data);