huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 1 | // import Mock from 'mockjs' |
| 2 | import { param2Obj } from '@/utils' |
| 3 | |
huibing.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame] | 4 | const typeList = [{ |
| 5 | 'id': '1', |
| 6 | 'code': 'sex', |
| 7 | 'name': '性别' |
| 8 | }, |
| 9 | { |
| 10 | 'id': '2', |
| 11 | 'code': 'zzmm', |
| 12 | 'name': '政治面貌' |
| 13 | }] |
| 14 | const dicList = [{ |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 15 | 'id': '1', |
huibing.xie | c95b6a2 | 2018-08-29 14:15:43 +0800 | [diff] [blame^] | 16 | 'type': 'classCode', |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 17 | 'name': '院系' |
| 18 | }, |
| 19 | { |
| 20 | 'id': '2', |
huibing.xie | c95b6a2 | 2018-08-29 14:15:43 +0800 | [diff] [blame^] | 21 | 'type': 'classCode', |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 22 | '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.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame] | 57 | 'code': 'dy', |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 58 | 'name': '党员' |
| 59 | }, |
| 60 | { |
| 61 | 'id': '10', |
| 62 | 'type': 'zzmm', |
huibing.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame] | 63 | 'code': 'qz', |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 64 | 'name': '群众' |
| 65 | }, |
| 66 | { |
| 67 | 'id': '11', |
huibing.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame] | 68 | 'type': 'sex', |
| 69 | 'code': 'male', |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 70 | 'name': '男' |
| 71 | }, |
| 72 | { |
| 73 | 'id': '12', |
huibing.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame] | 74 | 'type': 'sex', |
| 75 | 'code': 'female', |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 76 | '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.xie | f40b2b9 | 2018-08-22 17:12:47 +0800 | [diff] [blame] | 107 | }, |
| 108 | { |
| 109 | 'id': '19', |
| 110 | 'type': 'xslb', |
| 111 | 'name': '本专科生' |
| 112 | }, |
| 113 | { |
| 114 | 'id': '20', |
| 115 | 'type': 'xslb', |
| 116 | 'name': '研究生' |
Horace | cc75859 | 2018-08-23 17:40:39 +0800 | [diff] [blame] | 117 | }, |
| 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.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 157 | }] |
| 158 | |
| 159 | export default{ |
huibing.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame] | 160 | 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.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 174 | getDicList: config => { |
huibing.xie | c95b6a2 | 2018-08-29 14:15:43 +0800 | [diff] [blame^] | 175 | let dictype = '' |
| 176 | if (config.type) { |
| 177 | dictype = config.type |
| 178 | } else { |
| 179 | const { type } = param2Obj(config.url) |
| 180 | dictype = type |
| 181 | } |
huibing.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame] | 182 | const mockList = dicList.filter(item => { |
huibing.xie | c95b6a2 | 2018-08-29 14:15:43 +0800 | [diff] [blame^] | 183 | if (dictype && item.type !== dictype) return false |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 184 | return true |
| 185 | }) |
| 186 | |
| 187 | return { |
| 188 | items: mockList, |
| 189 | code: 200 |
| 190 | } |
huibing.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame] | 191 | }, |
| 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.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 275 | } |
| 276 | } |