blob: 2c4d8f38592195a81fcd5db7418874485db6a48c [file] [log] [blame]
import Mock from 'mockjs'
import { param2Obj, parseTime } from '@/utils'
const newspublishList = Mock.mock({
'list|26': [{
'id': '@increment',
'ggbt': '@cword(6, 15)',
'gglx': '离校公告',
'jszlx|1': ['所有学生', '所有人', '所有教职工'],
'sfky|1': ['可用', '不可用'],
'fbqssj': '2018-06-28',
'fbjssj': '2018-06-28',
'xswz|1': ['其它', '置顶'],
'jlckzt': '需要',
'djs': '@integer(60, 100)',
'fbr': 'admin',
'fbrq': '2018-08-08'
}]
}).list
export default{
getList: config => {
const { ggbt, fbqssj, fbjssj, sfky, xswz, jlckzt, pageIndex = 1, pageSize = 20 } = param2Obj(config.url)
const mockList = newspublishList.filter(item => {
if (ggbt && item.ggbt !== ggbt) return false
if (fbqssj && item.fbqssj !== fbqssj) return false
if (fbjssj && item.fbjssj !== fbjssj) return false
if (sfky && item.sfky !== sfky) return false
if (xswz && item.xswz !== xswz) return false
if (jlckzt && item.jlckzt !== jlckzt) 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 = newspublishList.filter(item => item.id + '' === id + '')
return {
data: mockList.length > 0 ? mockList[0] : null,
code: 200
}
},
createData: config => {
const newspublish = JSON.parse(config.body)
newspublish.cjsj = parseTime(new Date(), '{y}-{m}-{d}')
if (!newspublish.id) {
newspublish.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
newspublishList.unshift(newspublish)
} else {
for (let i = 0; i < newspublishList.length; i++) {
if (newspublishList[i].id + '' === newspublish.id + '') {
newspublishList.splice(i, 1, newspublish)
break
}
}
}
return {
item: newspublish,
code: 200
}
},
deleteData: config => {
const newspublish = JSON.parse(config.body)
let index = -1
for (let i = 0; i < newspublishList.length; i++) {
if (newspublishList[i].id + '' === newspublish.id + '') {
index = i
break
}
}
if (index > -1) {
newspublishList.splice(index, 1)
}
return {
code: 200
}
}
}