UNPKG

isun

Version:

快速创建vue项目

125 lines (106 loc) 4.4 kB
import Mock from 'mockjs' import { builder, getBody, PageBuilder } from '../util' import { userTotal, userInfo } from '../entity' import { sortBy } from 'lodash' const regionList = [ '迪庆藏族自治州', '怒江傈僳族自治州', '丽江市', '大理白族自治州', '保山市', '德宏傣族景颇族自治州', '临沧市', '普洱市', '西双版纳傣族自治州', '玉溪市', '楚雄彝族自治州', '昆明市', '红河哈尼族彝族自治州', '文山壮族苗族自治州', '曲靖市', '昭通市' ] const adcdList = [ '533400', '533300', '530700', '532900', '530500', '533100', '530900', '530800', '532800', '530400', '532300', '530100', '532500', '532600', '530300', '530600' ] const userTotaldo = Mock.mock({ 'data|16': [ { ...userTotal, 'id|+1': 0, title: '节点' + '@ctitle(3,12)', 'region|+1': regionList, // 地区 'adcd|+1': adcdList, // 地区编码 regionUserNum: '@integer(1,1000)' // 用户数 } ] }) const userTotalInfo = (options) => { return builder(userTotaldo.data) } const consensusList = [[0, 1], [1, 3, 4], [0, 1, 2, 3, 4]] const consensusItemsTitleList = [['合约0', '合约1'], ['合约1', '合约3', '合约4'], ['合约0', '合约1', '合约2', '合约3', '合约4']] const userInfodo = Mock.mock({ 'data|100': [ { ...userInfo, 'id|+1': 0, logo: '@image("200x100")', // 图标 longitude: '@float(102,103.1-10)', // 经度 latitude: '@float(24,26.1-10)', // 纬度 regDate: '@datetime("yyyy-MM-dd HH:mm:ss")', // 注册时间 addDate: '@datetime("yyyy-MM-dd HH:mm:ss")', // 上链时间 userType: '@integer(0,2)', // 用户类型 关联字典表 userType 注意:这里字典表中的类型为string型,mock自动生成int型 allianceUsersType: '@integer(0,4)', // 联盟用户类型 关联字典表 allianceUsers 注意:这里字典表中的类型为string型,mock自动生成int型 'adcd|+1': adcdList, // 6位行政区划编码 belongNodeName: '节点' + '@ctitle(2,10)', // 隶属节点名 belongNodeId: '@integer(0,5)', // 隶属节点ID 模拟绑定第一个节点 title: '用户' + '@ctitle(3,12)', // 公司名称 upperChainData: '@integer(1,1000)', // 上链条数据 'consensusItems|+1': consensusList, // 履行共识项 'consensusItemsTitle|+1': consensusItemsTitleList, // 履行共识项 名称 status: '@integer(0,1)', // 状态 1上线 0下线 level: '@integer(0,1)' // 用户级别 0普通用户 1高级认证 } ] }) const userInfoList = (options) => { const body = getBody(options) const { current, size, title, allianceUsersType, userType, belongNodeId, consensusItems } = body let _data = userInfodo.data if (title !== '' && title !== null && title !== undefined) { _data = sortBy(_data.filter((d) => d.title.includes(title)), (d) => d.sortNo) } if (allianceUsersType !== '' && allianceUsersType !== null && allianceUsersType !== undefined) { _data = sortBy(_data.filter((d) => d.allianceUsersType === allianceUsersType), (d) => d.sortNo) } if (userType !== '' && userType !== null && userType !== undefined) { _data = sortBy(_data.filter((d) => d.userType === userType), (d) => d.sortNo) } if (belongNodeId !== '' && belongNodeId !== null && belongNodeId.length > 0 && belongNodeId !== undefined) { _data = sortBy(_data.filter((d) => JSON.stringify(belongNodeId).includes(d.belongNodeId)), (d) => d.sortNo) } if (consensusItems !== '' && consensusItems !== null && consensusItems !== [] && consensusItems !== undefined) { consensusItems.forEach(item => { _data = sortBy(_data.filter((d) => d.consensusItems.includes(item)), (d) => d.sortNo) }) } return PageBuilder(_data, current, size) } Mock.mock(/\/api\/user\/total/, 'post', userTotalInfo) Mock.mock(/\/api\/user\/list/, 'post', userInfoList)