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