blob: 0ce4f87cb8ea0df4d927b78af330ad65575ec679 [file] [log] [blame]
import Mock from 'mockjs'
import { param2Obj, parseTime } from '@/utils'
const deptList = Mock.mock({
'list|26': [{
'id': '@increment',
'dwdm': '000@id',
'dwmc|1': ['教育学院', '经管学院', '人文学院', '数学学院', '计算机学院', '电子学院', '电气学院', '生命科学院'],
'dwjc': '@cword(3, 5)',
'dwywmc': '@word(6, 10)',
'sfqy|1': ['启用', '未启用'],
'sfqycode|1': ['1', '0'],
'lbm|1': ['院系', '部门'],
'lbmid|1': ['1', '2'],
'cjsj': '@Date'
}]
}).list
export default{
getList: config => {
const { dwdm, dwmc, sfqy, lbm, pageIndex = 1, pageSize = 20 } = param2Obj(config.url)
const mockList = deptList.filter(item => {
if (dwdm && item.dwdm !== dwdm) return false
if (dwmc && item.dwmc !== dwmc) return false
if (sfqy && item.sfqycode !== sfqy) return false
if (lbm && item.lbmid !== lbm) return false
return true
})
const pageList = mockList.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1))
return {
items: pageList,
recordCount: mockList.length,
code: 200
}
},
getAllList: config => {
return {
items: deptList,
code: 200
}
},
getItem: config => {
const { id } = param2Obj(config.url)
const mockList = deptList.filter(item => item.id + '' === id + '')
return {
data: mockList.length > 0 ? mockList[0] : null,
code: 200
}
},
createData: config => {
const dept = JSON.parse(config.body)
dept.cjsj = parseTime(new Date(), '{y}-{m}-{d}')
if (!dept.id) {
dept.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
deptList.unshift(dept)
} else {
for (let i = 0; i < deptList.length; i++) {
if (deptList[i].id + '' === dept.id + '') {
deptList.splice(i, 1, dept)
break
}
}
}
return {
item: dept,
code: 200
}
},
deleteData: config => {
const dept = JSON.parse(config.body)
let index = -1
for (let i = 0; i < deptList.length; i++) {
if (deptList[i].id + '' === dept.id + '') {
index = i
break
}
}
if (index > -1) {
deptList.splice(index, 1)
}
return {
code: 200
}
}
}