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