UNPKG

isun

Version:

快速创建vue项目

122 lines (114 loc) 5.08 kB
import Mock from 'mockjs' import { builder, getBody, PageBuilder } from '../util' import { chain, chainRelation } from '../entity' import { sortBy } from 'lodash' const ruleIdList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] const chainList = Mock.mock({ 'data|1000': [ { ...chain, 'id|+1': 0, // 数据链Id contractId: '@integer(0,100)', // 合约Id 'seq|+1': 0, // 区块序号(用于区块高度查询) userName: '用户名' + '@ctitle(3,12)', // 上链用户名称 dataLinkCode: 0, // 数据链码 'ruleValue|10': [// 根据ruleList显示的内容 { 'ruleId|+1': ruleIdList, value: '显示值-' + '@ctitle(3,6)' } ], ciphertext: '密文' + '@ctitle(3,12)' // 密文 } ] }) const ruleTypeList = ['字符串', '整数', '#jpg', '#png', 'zip'] const chainRelationList = Mock.mock({ 'data|1-7': [ { 'generation|1-4': [ { ...chainRelation[0].generation[0], 'contractId|+1': 0, // 合约Id contractName: '合约' + '@ctitle(3,12)', // 合约名称 releaseAvatar: '@image("200x100", "#00405d", "#FFF", "pic")', // 合约发布方头像 releaseName: '合约发布方名称', // 合约发布方名称 'ruleList|1-6': // 合约规则 string型,前端自动编写规则 [ { 'id|+1': ruleIdList, // 规则Id title: '标题' + '@ctitle(0,5)', // 名称 'type|+1': ruleTypeList, // 类型 length: '@integer(0,100)', // 字段长度/ 允许资料数量 checkRule: '', // 校验规则 (正则) 'isNot|1': true, // 是否可以为空 desc: '描述' + '@ctitle(0,30)', // 字段描述 'isCheck|1': true // 是否需要节点审核 } ], // 合约规则(关联合约规则表) 'chainList|10': [ // 链表列表 (关联链表) { ...chain, 'id|+1': 0, // 数据链Id contractId: '@integer(0,1)', // 合约Id 'seq|+1': 0, // 区块序号(用于区块高度查询) userName: '用户名' + '@ctitle(3,12)', // 上链用户名称 dataLinkCode: 0, // 数据链码 'ruleValue|10': [// 根据ruleList显示的内容 { 'ruleId|+1': ruleIdList, value: '显示值-' + '@ctitle(3,6)' } ], ciphertext: '密文' + '@ctitle(3,12)' // 密文 } ] } ] } ] }) const search = (options) => { const body = getBody(options) const { current, size, contractId, userName, ciphertext, seq } = body // seq, userName, dataLinkCode, keyWord let _data = chainList.data if (contractId !== '' && contractId !== null && contractId !== undefined) { _data = sortBy(_data.filter((d) => d.contractId === contractId), (d) => d.seq) } else { return PageBuilder(_data, current, size, '合约ID不能为空', 400) } if (userName !== '' && userName !== null && userName !== undefined) { _data = sortBy(_data.filter((d) => d.userName.includes(userName)), (d) => d.seq) } if (ciphertext !== '' && ciphertext !== null && ciphertext !== undefined) { _data = sortBy(_data.filter((d) => d.ciphertext.includes(ciphertext)), (d) => d.seq) } _data = _data.map((item, index) => { return { ...item, seq: index + 1 } }) if (seq !== '' && seq !== null && seq !== undefined && seq !== [] && seq !== [0, 0]) { if (seq[0] === 0 && seq[1] === 1) { } else { const _dataA = _data.slice(seq[0], seq[1]) return PageBuilder(_dataA, current, size) } } return PageBuilder(_data, current, size) } const relation = (options) => { const body = getBody(options) const { id } = body const _data = chainRelationList.data if (id !== '' && id !== null && id !== undefined) { } else { return builder(_data, '链ID不能为空', 400) } return builder(_data) } Mock.mock(/\/api\/chain\/search/, 'post', search) Mock.mock(/\/api\/chain\/relation/, 'post', relation)