数据字典
diff --git a/leave-school-vue/src/mock/dictionary.js b/leave-school-vue/src/mock/dictionary.js
index da85881..10aa7c3 100644
--- a/leave-school-vue/src/mock/dictionary.js
+++ b/leave-school-vue/src/mock/dictionary.js
@@ -1,7 +1,17 @@
// import Mock from 'mockjs'
import { param2Obj } from '@/utils'
-const deptList = [{
+const typeList = [{
+ 'id': '1',
+ 'code': 'sex',
+ 'name': '性别'
+},
+{
+ 'id': '2',
+ 'code': 'zzmm',
+ 'name': '政治面貌'
+}]
+const dicList = [{
'id': '1',
'type': 'lbm',
'name': '院系'
@@ -44,21 +54,25 @@
{
'id': '9',
'type': 'zzmm',
+ 'code': 'dy',
'name': '党员'
},
{
'id': '10',
'type': 'zzmm',
+ 'code': 'qz',
'name': '群众'
},
{
'id': '11',
- 'type': 'xb',
+ 'type': 'sex',
+ 'code': 'male',
'name': '男'
},
{
'id': '12',
- 'type': 'xb',
+ 'type': 'sex',
+ 'code': 'female',
'name': '女'
},
{
@@ -143,9 +157,23 @@
}]
export default{
+ getPage: config => {
+ const { name, pageIndex = 1, pageSize = 20 } = param2Obj(config.url)
+ const mockList = typeList.filter(item => {
+ if (name && item.name !== name && item.code !== name) 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
+ }
+ },
getDicList: config => {
const { type } = param2Obj(config.url)
- const mockList = deptList.filter(item => {
+ const mockList = dicList.filter(item => {
if (type && item.type !== type) return false
return true
})
@@ -154,5 +182,89 @@
items: mockList,
code: 200
}
+ },
+ getType: config => {
+ const { id } = param2Obj(config.url)
+ const mockList = typeList.filter(item => item.id + '' === id + '')
+ return {
+ data: mockList.length > 0 ? mockList[0] : null,
+ code: 200
+ }
+ },
+ createType: config => {
+ const type = JSON.parse(config.body)
+ if (!type.id) {
+ type.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
+ typeList.unshift(type)
+ } else {
+ for (let i = 0; i < typeList.length; i++) {
+ if (typeList[i].id + '' === type.id + '') {
+ typeList.splice(i, 1, type)
+ break
+ }
+ }
+ }
+ return {
+ item: type,
+ code: 200
+ }
+ },
+ deleteType: config => {
+ const type = JSON.parse(config.body)
+ let index = -1
+ for (let i = 0; i < typeList.length; i++) {
+ if (typeList[i].id + '' === type.id + '') {
+ index = i
+ break
+ }
+ }
+ if (index > -1) {
+ typeList.splice(index, 1)
+ }
+ return {
+ code: 200
+ }
+ },
+ getDic: config => {
+ const { id } = param2Obj(config.url)
+ const mockList = dicList.filter(item => item.id + '' === id + '')
+ return {
+ data: mockList.length > 0 ? mockList[0] : null,
+ code: 200
+ }
+ },
+ createDic: config => {
+ const dic = JSON.parse(config.body)
+ if (!dic.id) {
+ dic.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
+ dicList.unshift(dic)
+ } else {
+ for (let i = 0; i < dicList.length; i++) {
+ if (dicList[i].id + '' === dic.id + '') {
+ dicList.splice(i, 1, dic)
+ break
+ }
+ }
+ }
+ return {
+ item: dic,
+ code: 200
+ }
+ },
+ deleteDic: config => {
+ const dic = JSON.parse(config.body)
+ let index = -1
+ for (let i = 0; i < dicList.length; i++) {
+ if (dicList[i].id + '' === dic.id + '') {
+ index = i
+ break
+ }
+ }
+ if (index > -1) {
+ dicList.splice(index, 1)
+ }
+ return {
+ code: 200
+ }
}
}