|
|
@@ -12,7 +12,10 @@ import { getByCode } from '@/api/system/dictionary-data';
|
|
|
// // }
|
|
|
// };
|
|
|
|
|
|
-const state = {};
|
|
|
+const state = {
|
|
|
+ // 加载中的字典项
|
|
|
+ dictLoading: []
|
|
|
+};
|
|
|
|
|
|
const mutations = {
|
|
|
//根据字典code 添加字典
|
|
|
@@ -25,46 +28,38 @@ const actions = {
|
|
|
// 根据字典enumName请求字典 已获取的不做重复请求
|
|
|
async requestDict({ commit, state }, enumName) {
|
|
|
const code = dictEnum[enumName];
|
|
|
+ // 如果字典正在加载中,则不重复请求
|
|
|
+ if (state.dictLoading.includes(code)) return;
|
|
|
+
|
|
|
+ state.dictLoading.push(code);
|
|
|
|
|
|
if (state[code]?.length) return state[code];
|
|
|
- let res;
|
|
|
- // if (otherDictConfig[dictEnum[enumName]]) {
|
|
|
- // const config = otherDictConfig[dictEnum[enumName]];
|
|
|
- // console.log(config);
|
|
|
- // //非枚举定义
|
|
|
- // res = await config.request();
|
|
|
- // if (res?.code == 0) {
|
|
|
- // let list = config.resKey ? res.data[config.resKey] : res.data;
|
|
|
- // commit('ADD_DICT', {
|
|
|
- // code,
|
|
|
- // dict: list.map((item) => ({
|
|
|
- // ...item,
|
|
|
- // dictCode: item[config.dictCode],
|
|
|
- // dictValue: item[config.dictValue]
|
|
|
- // }))
|
|
|
- // });
|
|
|
- // return res.list;
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- res = await getByCode(code);
|
|
|
- if (res?.code == 0) {
|
|
|
- const isNumber = numberList.includes(code);
|
|
|
- commit('ADD_DICT', {
|
|
|
- code,
|
|
|
- dict: res.data.map((item) => {
|
|
|
- const arr = Object.entries(item)[0] || [];
|
|
|
|
|
|
- return {
|
|
|
- dictCode: isNumber ? Number(arr[0]) : arr[0],
|
|
|
- dictValue: arr[1]
|
|
|
- };
|
|
|
- })
|
|
|
- });
|
|
|
- return res.data;
|
|
|
- }
|
|
|
- // }
|
|
|
+ try {
|
|
|
+ let res = await getByCode(code);
|
|
|
+ if (res?.code == 0) {
|
|
|
+ const isNumber = numberList.includes(code);
|
|
|
+ commit('ADD_DICT', {
|
|
|
+ code,
|
|
|
+ dict: res.data.map((item) => {
|
|
|
+ const arr = Object.entries(item)[0] || [];
|
|
|
|
|
|
- return [];
|
|
|
+ return {
|
|
|
+ dictCode: isNumber ? Number(arr[0]) : arr[0],
|
|
|
+ dictValue: arr[1]
|
|
|
+ };
|
|
|
+ })
|
|
|
+ });
|
|
|
+ state.dictLoading = state.dictLoading.filter((item) => item !== code);
|
|
|
+ return res.data;
|
|
|
+ }
|
|
|
+
|
|
|
+ state.dictLoading = state.dictLoading.filter((item) => item !== code);
|
|
|
+ return [];
|
|
|
+ } catch (error) {
|
|
|
+ state.dictLoading = state.dictLoading.filter((item) => item !== code);
|
|
|
+ return [];
|
|
|
+ }
|
|
|
},
|
|
|
// 更新字典
|
|
|
async reloadRequestDict({ commit }, enumName) {
|