2024-10-15 15:37:50 +08:00
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
import piniaPersistConfig from '@/stores/helper/persist'
|
|
|
|
|
import { DICT_STORE_KEY } from '@/stores/constant'
|
|
|
|
|
// 模拟数据
|
|
|
|
|
import dictData from '@/api/system/dictData'
|
|
|
|
|
|
2024-11-04 18:43:24 +08:00
|
|
|
//import { getDictList } from '@/api/user/login.ts'
|
|
|
|
|
//const dictData = getDictList
|
|
|
|
|
|
2024-10-15 15:37:50 +08:00
|
|
|
export const useDictStore = defineStore({
|
|
|
|
|
id: DICT_STORE_KEY,
|
|
|
|
|
state: () => ({
|
|
|
|
|
dictData,
|
|
|
|
|
}),
|
|
|
|
|
getters: {},
|
|
|
|
|
actions: {
|
|
|
|
|
// 获取字典数据数组,如果为空则返回空数组
|
|
|
|
|
getDictData(code: string) {
|
|
|
|
|
const dict = this.dictData.find(item => item.code === code )
|
|
|
|
|
return dict?.children || []
|
|
|
|
|
},
|
|
|
|
|
// 初始化获取全部字典数据并缓存
|
|
|
|
|
},
|
|
|
|
|
persist: piniaPersistConfig(DICT_STORE_KEY),
|
|
|
|
|
})
|