Files
admin-sjzx/src/stores/dictData.ts

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-02-19 13:44:32 +08:00
import { defineStore } from 'pinia'
import { DICT_DATA } from '@/stores/constant/cacheKey'
2024-06-05 14:34:23 +08:00
import type { DictData } from '@/stores/interface/index'
2024-02-19 13:44:32 +08:00
import { reactive } from 'vue'
2024-08-22 15:59:15 +08:00
import { useAdminInfo } from '@/stores/adminInfo'
const adminInfo = useAdminInfo()
2024-02-19 13:44:32 +08:00
export const useDictData = defineStore(
'dictData',
() => {
const state: DictData = reactive({
basic: [],
2024-03-07 19:02:49 +08:00
area: [],
2024-06-05 15:08:24 +08:00
areaTree: [],
userList: []
2024-02-19 13:44:32 +08:00
// 其他接口获取的字典,比如区域
})
const getBasicData = (code: string, arr?: string[]) => {
let list = []
list = state.basic.filter(item => item.code === code)[0]?.children || []
if (arr) {
list = list.filter(item => !arr.includes(item.code))
}
return list
}
2024-03-27 20:29:51 +08:00
const areaSelect = () => {
let list = state.areaTree.filter(item => item.id == state.area[0]?.area)
return list.length == 0 ? state.areaTree : list
2024-03-07 19:02:49 +08:00
}
2024-06-05 14:34:23 +08:00
const statusSelect = () => {
2024-08-22 15:59:15 +08:00
if (adminInfo.deptLevel == 2) {
return [
{ name: '审批中', id: 1 },
{ name: '审批通过', id: 2 }
]
} else {
return [
{ name: '待提交审批', id: 0 },
{ name: '审批中', id: 1 },
{ name: '审批通过', id: 2 },
{ name: '审批不通过', id: 3 },
{ name: '已取消', id: 4 }
]
}
2024-06-05 14:34:23 +08:00
}
2024-02-19 13:44:32 +08:00
return {
state,
2024-03-07 19:02:49 +08:00
getBasicData,
2024-06-05 14:34:23 +08:00
areaSelect,
statusSelect
2024-02-19 13:44:32 +08:00
}
},
{
persist: {
key: DICT_DATA
}
}
)