blob: 5eecdd2362508eae8cb2537832ae34501fcae6d4 [file] [log] [blame]
import Mock from 'mockjs'
import { param2Obj, parseTime } from '@/utils'
import dic from './dictionary'
const deptList = Mock.mock({
'list|26': [{
'id': '@increment',
'code': '000@id',
'name|1': ['教育学院', '经管学院', '人文学院', '数学学院', '计算机学院', '电子学院', '电气学院', '生命科学院'],
'abbreviation': '@cword(3, 5)',
'enName': '@word(6, 10)',
'enable|1': ['启用', '未启用'],
'classCode|1': ['院系', '部门'],
'createDate': '@Date'
}]
}).list
export default{
getPage: config => {
const { code, name, enable, classCode, pageIndex = 1, pageSize = 20 } = param2Obj(config.url)
const mockList = deptList.filter(item => {
if (code && item.code !== code) return false
if (name && item.name !== name) return false
if (enable && item.enable !== enable) return false
if (classCode && item.classCode !== classCode) return false
return true
})
const pageList = mockList.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1))
return {
classCodeList: dic.getDicList({ dicType: 'classCode' }).items,
items: pageList,
recordCount: mockList.length,
code: 200
}
},
getDeptList: config => {
const mockList = deptList.filter(item => item.classCode === '院系')
return {
items: mockList,
code: 200
}
},
getSectionList: config => {
const mockList = deptList.filter(item => item.classCode === '部门')
return {
items: mockList,
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
}
}
}