Mock數據模擬接口


// 引入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);

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM