|
|
@@ -4,9 +4,11 @@ import { mapValues } from 'lodash';
|
|
|
|
|
|
const useBsDict = class {
|
|
|
dicts = {};
|
|
|
+ dictMap = null;
|
|
|
|
|
|
constructor() {
|
|
|
this.dicts = reactive({});
|
|
|
+ this.dictMap = null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -15,6 +17,7 @@ const useBsDict = class {
|
|
|
const dictStr = localStorage.getItem('dicts');
|
|
|
if (dictStr) {
|
|
|
this.dicts = JSON.parse(dictStr);
|
|
|
+ this.dictMap = new Map(Object.entries(this.dicts));
|
|
|
} else {
|
|
|
await this.fetchDictData();
|
|
|
}
|
|
|
@@ -43,7 +46,7 @@ const useBsDict = class {
|
|
|
}
|
|
|
|
|
|
getDictItem(dictCode, dictValue) {
|
|
|
- return this.dicts[dictCode].find(v => v.value === dictValue);
|
|
|
+ return this.dictMap.get(dictCode).find(v => v.value === dictValue);
|
|
|
}
|
|
|
|
|
|
// 参数归一化
|
|
|
@@ -62,9 +65,14 @@ const useBsDict = class {
|
|
|
const res = await dictApi.getDictAll();
|
|
|
if (res?.code === 0) {
|
|
|
this.dicts = this.normalizeDictNames(res.data);
|
|
|
+ this.dictMap = new Map(Object.entries(this.dicts));
|
|
|
localStorage.setItem('dicts', JSON.stringify(this.dicts));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ getDictList(code) {
|
|
|
+ return this.dictMap.get(code);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
export default new useBsDict();
|