huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 1 | import Mock from 'mockjs' |
| 2 | import { param2Obj } from '@/utils' |
| 3 | |
| 4 | const rostersyncinterfaceList = Mock.mock({ |
| 5 | 'list|50': [{ |
| 6 | 'id': '@increment', |
huibing.xie | c95b6a2 | 2018-08-29 14:15:43 +0800 | [diff] [blame^] | 7 | 'code': '@word(4)', |
| 8 | 'name': '@cword(6, 15)', |
| 9 | 'sql': '@word(15)', |
| 10 | 'sort': '@word(15)' |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 11 | }] |
| 12 | }).list |
| 13 | |
| 14 | export default{ |
huibing.xie | c95b6a2 | 2018-08-29 14:15:43 +0800 | [diff] [blame^] | 15 | getPage: config => { |
| 16 | const { code, name, sql, sort, pageIndex = 1, pageSize = 20 } = param2Obj(config.url) |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 17 | const mockList = rostersyncinterfaceList.filter(item => { |
huibing.xie | c95b6a2 | 2018-08-29 14:15:43 +0800 | [diff] [blame^] | 18 | if (code && item.code !== code) return false |
| 19 | if (name && item.name !== name) return false |
| 20 | if (sql && item.sql !== sql) return false |
| 21 | if (sort && item.sort !== sort) return false |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 22 | return true |
| 23 | }) |
| 24 | |
| 25 | const pageList = mockList.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)) |
| 26 | return { |
| 27 | items: pageList, |
| 28 | recordCount: mockList.length, |
| 29 | code: 200 |
| 30 | } |
| 31 | }, |
huibing.xie | c95b6a2 | 2018-08-29 14:15:43 +0800 | [diff] [blame^] | 32 | getList: config => { |
| 33 | return { |
| 34 | items: rostersyncinterfaceList, |
| 35 | code: 200 |
| 36 | } |
| 37 | }, |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 38 | getItem: config => { |
| 39 | const { id } = param2Obj(config.url) |
| 40 | const mockList = rostersyncinterfaceList.filter(item => item.id + '' === id + '') |
| 41 | return { |
| 42 | data: mockList.length > 0 ? mockList[0] : null, |
| 43 | code: 200 |
| 44 | } |
| 45 | }, |
| 46 | createData: config => { |
| 47 | const rostersyncinterface = JSON.parse(config.body) |
| 48 | if (!rostersyncinterface.id) { |
| 49 | rostersyncinterface.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id |
| 50 | rostersyncinterfaceList.unshift(rostersyncinterface) |
| 51 | } else { |
| 52 | for (let i = 0; i < rostersyncinterfaceList.length; i++) { |
| 53 | if (rostersyncinterfaceList[i].id + '' === rostersyncinterface.id + '') { |
| 54 | rostersyncinterfaceList.splice(i, 1, rostersyncinterface) |
| 55 | break |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | return { |
| 60 | item: rostersyncinterface, |
| 61 | code: 200 |
| 62 | } |
| 63 | }, |
| 64 | deleteData: config => { |
| 65 | const rostersyncinterface = JSON.parse(config.body) |
| 66 | let index = -1 |
| 67 | for (let i = 0; i < rostersyncinterfaceList.length; i++) { |
| 68 | if (rostersyncinterfaceList[i].id + '' === rostersyncinterface.id + '') { |
| 69 | index = i |
| 70 | break |
| 71 | } |
| 72 | } |
| 73 | if (index > -1) { |
| 74 | rostersyncinterfaceList.splice(index, 1) |
| 75 | } |
| 76 | return { |
| 77 | code: 200 |
| 78 | } |
| 79 | } |
| 80 | } |