blob: d8f5b09984bce7485e95f6405c5be72e57ae20a3 [file] [log] [blame]
huibing.xie1f1606f2018-08-20 15:46:55 +08001// import Mock from 'mockjs'
2import { param2Obj } from '@/utils'
3
huibing.xie84425172018-08-28 19:41:13 +08004const typeList = [{
5 'id': '1',
6 'code': 'sex',
7 'name': '性别'
8},
9{
10 'id': '2',
11 'code': 'zzmm',
12 'name': '政治面貌'
13}]
14const dicList = [{
huibing.xie1f1606f2018-08-20 15:46:55 +080015 'id': '1',
huibing.xiec95b6a22018-08-29 14:15:43 +080016 'type': 'classCode',
huibing.xie1f1606f2018-08-20 15:46:55 +080017 'name': '院系'
18},
19{
20 'id': '2',
huibing.xiec95b6a22018-08-29 14:15:43 +080021 'type': 'classCode',
huibing.xie1f1606f2018-08-20 15:46:55 +080022 'name': '部门'
23},
24{
25 'id': '3',
26 'type': 'gjzybz',
27 'name': '文学'
28},
29{
30 'id': '4',
31 'type': 'gjzybz',
32 'name': '物理'
33},
34{
35 'id': '5',
36 'type': 'gjzybz',
37 'name': '数学'
38},
39{
40 'id': '6',
41 'type': 'nj',
42 'name': '2017'
43},
44{
45 'id': '7',
46 'type': 'nj',
47 'name': '2018'
48},
49{
50 'id': '8',
51 'type': 'nj',
52 'name': '2019'
53},
54{
55 'id': '9',
56 'type': 'zzmm',
huibing.xie84425172018-08-28 19:41:13 +080057 'code': 'dy',
huibing.xie1f1606f2018-08-20 15:46:55 +080058 'name': '党员'
59},
60{
61 'id': '10',
62 'type': 'zzmm',
huibing.xie84425172018-08-28 19:41:13 +080063 'code': 'qz',
huibing.xie1f1606f2018-08-20 15:46:55 +080064 'name': '群众'
65},
66{
67 'id': '11',
huibing.xie84425172018-08-28 19:41:13 +080068 'type': 'sex',
69 'code': 'male',
huibing.xie1f1606f2018-08-20 15:46:55 +080070 'name': '男'
71},
72{
73 'id': '12',
huibing.xie84425172018-08-28 19:41:13 +080074 'type': 'sex',
75 'code': 'female',
huibing.xie1f1606f2018-08-20 15:46:55 +080076 'name': '女'
77},
78{
79 'id': '13',
80 'type': 'xswz',
81 'name': '置顶'
82},
83{
84 'id': '14',
85 'type': 'xswz',
86 'name': '其他'
87},
88{
89 'id': '15',
90 'type': 'gglx',
91 'name': '离校公告'
92},
93{
94 'id': '16',
95 'type': 'jszlx',
96 'name': '所有人'
97},
98{
99 'id': '17',
100 'type': 'jszlx',
101 'name': '所有学生'
102},
103{
104 'id': '18',
105 'type': 'jszlx',
106 'name': '所有教职工'
huibing.xief40b2b92018-08-22 17:12:47 +0800107},
108{
109 'id': '19',
110 'type': 'xslb',
111 'name': '本专科生'
112},
113{
114 'id': '20',
115 'type': 'xslb',
116 'name': '研究生'
Horacecc758592018-08-23 17:40:39 +0800117},
118{
119 'id': '21',
120 'type': 'scope',
121 'name': '辅导员范围'
122},
123{
124 'id': '22',
125 'type': 'defaultAuditStatus',
126 'name': '待审核'
127},
128{
129 'id': '23',
130 'type': 'defaultAuditStatus',
131 'name': '审核通过'
132},
133{
134 'id': '24',
135 'type': 'defaultAuditStatus',
136 'name': '审核不通过'
137},
138{
139 'id': '25',
140 'type': 'auditType',
141 'name': '手动'
142},
143{
144 'id': '26',
145 'type': 'auditType',
146 'name': '自动'
147},
148{
149 'id': '27',
150 'type': 'scope',
151 'name': '全校范围'
152},
153{
154 'id': '28',
155 'type': 'scope',
156 'name': '院系范围'
huibing.xie1f1606f2018-08-20 15:46:55 +0800157}]
158
159export default{
huibing.xie84425172018-08-28 19:41:13 +0800160 getPage: config => {
161 const { name, pageIndex = 1, pageSize = 20 } = param2Obj(config.url)
162 const mockList = typeList.filter(item => {
163 if (name && item.name !== name && item.code !== name) return false
164 return true
165 })
166
167 const pageList = mockList.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1))
168 return {
169 items: pageList,
170 recordCount: mockList.length,
171 code: 200
172 }
173 },
huibing.xie1f1606f2018-08-20 15:46:55 +0800174 getDicList: config => {
huibing.xie99536f52018-08-29 14:30:32 +0800175 let type = ''
176 if (config.dicType) {
177 type = config.dicType
huibing.xiec95b6a22018-08-29 14:15:43 +0800178 } else {
huibing.xie99536f52018-08-29 14:30:32 +0800179 const { dicType } = param2Obj(config.url)
180 type = dicType
huibing.xiec95b6a22018-08-29 14:15:43 +0800181 }
huibing.xie84425172018-08-28 19:41:13 +0800182 const mockList = dicList.filter(item => {
huibing.xie99536f52018-08-29 14:30:32 +0800183 if (type && item.type !== type) return false
huibing.xie1f1606f2018-08-20 15:46:55 +0800184 return true
185 })
186
187 return {
188 items: mockList,
189 code: 200
190 }
huibing.xie84425172018-08-28 19:41:13 +0800191 },
192 getType: config => {
193 const { id } = param2Obj(config.url)
194 const mockList = typeList.filter(item => item.id + '' === id + '')
195 return {
196 data: mockList.length > 0 ? mockList[0] : null,
197 code: 200
198 }
199 },
200 createType: config => {
201 const type = JSON.parse(config.body)
202 if (!type.id) {
203 type.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
204 typeList.unshift(type)
205 } else {
206 for (let i = 0; i < typeList.length; i++) {
207 if (typeList[i].id + '' === type.id + '') {
208 typeList.splice(i, 1, type)
209 break
210 }
211 }
212 }
213 return {
214 item: type,
215 code: 200
216 }
217 },
218 deleteType: config => {
219 const type = JSON.parse(config.body)
220 let index = -1
221 for (let i = 0; i < typeList.length; i++) {
222 if (typeList[i].id + '' === type.id + '') {
223 index = i
224 break
225 }
226 }
227 if (index > -1) {
228 typeList.splice(index, 1)
229 }
230 return {
231 code: 200
232 }
233 },
234 getDic: config => {
235 const { id } = param2Obj(config.url)
236 const mockList = dicList.filter(item => item.id + '' === id + '')
237 return {
238 data: mockList.length > 0 ? mockList[0] : null,
239 code: 200
240 }
241 },
242 createDic: config => {
243 const dic = JSON.parse(config.body)
244 if (!dic.id) {
245 dic.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
246 dicList.unshift(dic)
247 } else {
248 for (let i = 0; i < dicList.length; i++) {
249 if (dicList[i].id + '' === dic.id + '') {
250 dicList.splice(i, 1, dic)
251 break
252 }
253 }
254 }
255 return {
256 item: dic,
257 code: 200
258 }
259 },
260 deleteDic: config => {
261 const dic = JSON.parse(config.body)
262 let index = -1
263 for (let i = 0; i < dicList.length; i++) {
264 if (dicList[i].id + '' === dic.id + '') {
265 index = i
266 break
267 }
268 }
269 if (index > -1) {
270 dicList.splice(index, 1)
271 }
272 return {
273 code: 200
274 }
huibing.xie1f1606f2018-08-20 15:46:55 +0800275 }
276}