| import Mock from 'mockjs' |
| import { param2Obj } from '@/utils' |
| |
| const recordList = Mock.mock({ |
| 'list|26': [{ |
| 'id': '@increment', |
| 'xh': '@word(5)', |
| 'xm': '@cword(2, 3)', |
| 'yx': '@cword(6, 15)', |
| 'zy': '@cword(6, 15)', |
| 'bj': '@cword(6, 15)', |
| 'xslb': '@cword(3, 5)', |
| 'sfzylx|1': ['准予', '不准予'], |
| 'shjllist|4': [{ |
| 'shhj': '@cword(6, 8)', |
| 'shzt|1': ['通过', '不通过'], |
| 'shyj|3': [{ |
| 'shzt|1': ['通过', '不通过'], |
| 'shsj': '@datetime', |
| 'shr': '@cword(2, 3)', |
| 'shyj': '@cword(6, 10)' |
| }] |
| }], |
| 'blbmlist': [{ |
| 'bmmc': '后勤处', |
| 'shjg|1': ['—', '×', '√'] |
| }, |
| { |
| 'bmmc': '财务处', |
| 'shjg|1': ['—', '×', '√'] |
| }, |
| { |
| 'bmmc': '学生处', |
| 'shjg|1': ['—', '×', '√'] |
| }, |
| { |
| 'bmmc': '图书馆', |
| 'shjg|1': ['—', '×', '√'] |
| }] |
| }] |
| }).list |
| |
| export default{ |
| getList: config => { |
| const { pcmc, xh, xm, sfzylx, yx, zy, bj, xslb, pageIndex = 1, pageSize = 20 } = param2Obj(config.url) |
| const mockList = recordList.filter(item => { |
| if (pcmc && item.pcmc + '' !== pcmc + '') return false |
| if (xh && item.xh !== xh) return false |
| if (xm && item.xm !== xm) return false |
| if (sfzylx && item.sfzylx !== sfzylx) return false |
| if (yx && item.yx !== yx) return false |
| if (zy && item.zy !== zy) return false |
| if (bj && item.bj !== bj) return false |
| if (xslb && item.xslb !== xslb) return false |
| return true |
| }) |
| |
| const pageList = mockList.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)) |
| return { |
| items: pageList, |
| recordCount: mockList.length, |
| code: 200 |
| } |
| }, |
| getAllList: config => { |
| return { |
| items: recordList, |
| code: 200 |
| } |
| }, |
| getItem: config => { |
| const { id } = param2Obj(config.url) |
| const mockList = recordList.filter(item => item.id + '' === id + '') |
| return { |
| data: mockList.length > 0 ? mockList[0] : null, |
| code: 200 |
| } |
| }, |
| createData: config => { |
| const record = JSON.parse(config.body) |
| if (!record.id) { |
| record.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id |
| recordList.unshift(record) |
| } else { |
| for (let i = 0; i < recordList.length; i++) { |
| if (recordList[i].id + '' === record.id + '') { |
| recordList.splice(i, 1, record) |
| break |
| } |
| } |
| } |
| return { |
| item: record, |
| code: 200 |
| } |
| }, |
| deleteData: config => { |
| const record = JSON.parse(config.body) |
| let index = -1 |
| for (let i = 0; i < recordList.length; i++) { |
| if (recordList[i].id + '' === record.id + '') { |
| index = i |
| break |
| } |
| } |
| if (index > -1) { |
| recordList.splice(index, 1) |
| } |
| return { |
| code: 200 |
| } |
| } |
| } |