2
0

增加字典数据界面

This commit is contained in:
lai
2024-12-30 16:46:12 +08:00
parent 0a1f0d94d8
commit 3e2d8faf5e
12 changed files with 1027 additions and 45 deletions

View File

@@ -0,0 +1,62 @@
import { defineStore } from 'pinia';
/**字典参数类型 */
type DictStore = {
/**字典数据 */
dicts: Map<string, DictType[]>;
};
const useDictStore = defineStore('dict', {
state: (): DictStore => ({
dicts: new Map(),
}),
actions: {
/**清空字典 */
clearDict() {
this.dicts.clear();
},
/**删除字典 */
removeDict(key: string) {
if (!key) return;
return this.dicts.delete(key);
},
/**
* 处理字典数据对象用于回显标签
* @param data 字典数据项
* @returns
*/
parseDataDict(data: Record<string, any>) {
return [
{
label: data.dictLabel,
value: data.dictValue,
tagType: data.tagType,
tagClass: data.tagClass,
},
];
},
/**获取字典 */
async getDict(key: string) {
if (!key) return [];
let disct = this.dicts.get(key);
if (disct === undefined || disct.length === 0) {
const res = await getDictDataType(key);
if (!res.error && Array.isArray(res.data)) {
const dictData: DictType[] = res.data.map((d:any) => ({
label: d.dictLabel,
value: d.dictValue,
tagType: d.tagType,
tagClass: d.tagClass,
}));
this.dicts.set(key, dictData);
disct = dictData;
} else {
disct = [];
}
}
return disct;
},
},
});
export default useDictStore;