Przeglądaj źródła

dictLoading修改方式修改

lucw 8 miesięcy temu
rodzic
commit
9d9d5516e1
1 zmienionych plików z 10 dodań i 4 usunięć
  1. 10 4
      src/store/modules/dict.js

+ 10 - 4
src/store/modules/dict.js

@@ -21,6 +21,12 @@ const mutations = {
   //根据字典code 添加字典
   ADD_DICT: (state, { code, dict }) => {
     Vue.set(state, code, dict);
+  },
+  dictLoadingAdd: (state, code) => {
+    state.dictLoading.push(code);
+  },
+  dictLoadingRemove: (state, code) => {
+    state.dictLoading = state.dictLoading.filter((item) => item !== code);
   }
 };
 
@@ -31,7 +37,7 @@ const actions = {
     // 如果字典正在加载中,则不重复请求
     if (state.dictLoading.includes(code)) return;
 
-    state.dictLoading.push(code);
+    commit('dictLoadingAdd', code);
 
     if (state[code]?.length) return state[code];
 
@@ -50,14 +56,14 @@ const actions = {
             };
           })
         });
-        state.dictLoading = state.dictLoading.filter((item) => item !== code);
+        commit('dictLoadingRemove', code);
         return res.data;
       }
 
-      state.dictLoading = state.dictLoading.filter((item) => item !== code);
+      commit('dictLoadingRemove', code);
       return [];
     } catch (error) {
-      state.dictLoading = state.dictLoading.filter((item) => item !== code);
+      commit('dictLoadingRemove', code);
       return [];
     }
   },