feat: 封装数据字典

This commit is contained in:
xlsea
2024-09-04 09:11:04 +08:00
parent 0130688265
commit 3d426fb8e1
20 changed files with 421 additions and 24 deletions

View File

@ -0,0 +1,35 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
export const useDictStore = defineStore('dict', () => {
const dictData = ref<{ [key: string]: Array<Api.System.DictData> }>({});
const getDict = (key: string) => {
return dictData.value[key];
};
const setDict = (key: string, dict: Array<Api.System.DictData>) => {
dictData.value[key] = dict;
};
const removeDict = (key: string) => {
if (key in dictData.value) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete dictData.value[key];
}
};
const cleanDict = () => {
dictData.value = {};
};
return {
dictData,
getDict,
setDict,
removeDict,
cleanDict
};
});
export default useDictStore;