| import Mock from 'mockjs' |
| import { param2Obj, parseTime } from '@/utils' |
| |
| const userList = Mock.mock({ |
| 'list|26': [{ |
| 'id': '@increment', |
| 'rownum': '@id', |
| 'ghxh': '@id', |
| 'xm': '000@id', |
| 'zhlb|1': ['教职工', '学生', '其他'], |
| 'xb|1': ['男', '女'], |
| 'zt|1': ['启用', '停用'], |
| 'yx': '@cword(3, 5)', |
| 'xybm': '@word(6, 10)', |
| 'gzdw': '@word(6, 10)', |
| 'sj': '@cword(3, 5)', |
| 'wx': '@cword(3, 5)', |
| 'qq': '@cword(3, 5)' |
| }] |
| }).list |
| |
| const zhlbList = Mock.mock( |
| [{ |
| 'value': 'teacher', |
| 'label': '教职工' |
| }, |
| { |
| 'value': 'student', |
| 'label': '学生' |
| }, |
| { |
| 'value': 'other', |
| 'label': '其他' |
| }] |
| ) |
| |
| const xbList = Mock.mock( |
| [{ |
| 'value': 'male', |
| 'label': '男' |
| }, |
| { |
| 'value': 'female', |
| 'label': '女' |
| }] |
| ) |
| const ztList = Mock.mock( |
| [{ |
| 'value': 'on', |
| 'label': '启用' |
| }, |
| { |
| 'value': 'off', |
| 'label': '停用' |
| }] |
| ) |
| export default{ |
| getPage: config => { |
| const { zhlb, ghxhxm, pageIndex = 1, pageSize = 20 } = param2Obj(config.url) |
| const mockList = userList.filter(item => { |
| if (zhlb && item.zhlb !== zhlb) return false |
| if (ghxhxm && item.ghxh + '' !== ghxhxm + '' && item.xm + '' !== ghxhxm + '') return false |
| return true |
| }) |
| |
| const pageList = mockList.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)) |
| return { |
| xbList: xbList, |
| ztList: ztList, |
| zhlbList: zhlbList, |
| items: pageList, |
| recordCount: mockList.length, |
| code: 200 |
| } |
| }, |
| getItem: config => { |
| const { id } = param2Obj(config.url) |
| const mockList = userList.filter(item => item.id + '' === id + '') |
| return { |
| data: mockList.length > 0 ? mockList[0] : null, |
| code: 200 |
| } |
| }, |
| createData: config => { |
| const user = JSON.parse(config.body) |
| user.cjsj = parseTime(new Date(), '{y}-{m}-{d}') |
| if (!user.id) { |
| user.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id |
| userList.unshift(user) |
| } else { |
| for (let i = 0; i < userList.length; i++) { |
| if (userList[i].id + '' === user.id + '') { |
| userList.splice(i, 1, user) |
| break |
| } |
| } |
| } |
| return { |
| item: user, |
| code: 200 |
| } |
| }, |
| deleteData: config => { |
| const user = JSON.parse(config.body) |
| let index = -1 |
| for (let i = 0; i < userList.length; i++) { |
| if (userList[i].id + '' === user.id + '') { |
| index = i |
| break |
| } |
| } |
| if (index > -1) { |
| userList.splice(index, 1) |
| } |
| return { |
| code: 200 |
| } |
| } |
| } |