blob: eb46aa18da2fa25ea63ead5787249a45e922d829 [file] [log] [blame]
import Mock from 'mockjs'
import { param2Obj } from '@/utils'
const rostersyncinterfaceList = Mock.mock({
'list|50': [{
'id': '@increment',
'code': '@word(4)',
'name': '@cword(6, 15)',
'sql': '@word(15)',
'sort': '@word(15)'
}]
}).list
export default{
getPage: config => {
const { code, name, sql, sort, pageIndex = 1, pageSize = 20 } = param2Obj(config.url)
const mockList = rostersyncinterfaceList.filter(item => {
if (code && item.code !== code) return false
if (name && item.name !== name) return false
if (sql && item.sql !== sql) return false
if (sort && item.sort !== sort) 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
}
},
getList: config => {
return {
items: rostersyncinterfaceList,
code: 200
}
},
getItem: config => {
const { id } = param2Obj(config.url)
const mockList = rostersyncinterfaceList.filter(item => item.id + '' === id + '')
return {
data: mockList.length > 0 ? mockList[0] : null,
code: 200
}
},
createData: config => {
const rostersyncinterface = JSON.parse(config.body)
if (!rostersyncinterface.id) {
rostersyncinterface.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
rostersyncinterfaceList.unshift(rostersyncinterface)
} else {
for (let i = 0; i < rostersyncinterfaceList.length; i++) {
if (rostersyncinterfaceList[i].id + '' === rostersyncinterface.id + '') {
rostersyncinterfaceList.splice(i, 1, rostersyncinterface)
break
}
}
}
return {
item: rostersyncinterface,
code: 200
}
},
deleteData: config => {
const rostersyncinterface = JSON.parse(config.body)
let index = -1
for (let i = 0; i < rostersyncinterfaceList.length; i++) {
if (rostersyncinterfaceList[i].id + '' === rostersyncinterface.id + '') {
index = i
break
}
}
if (index > -1) {
rostersyncinterfaceList.splice(index, 1)
}
return {
code: 200
}
}
}