Jelajahi Sumber

字典getDictValue和requestDict方法优化自动获取,防止重复触发。批记录-字段修改

lucw 8 bulan lalu
induk
melakukan
b61536766e

+ 15 - 0
src/store/getters.js

@@ -2,6 +2,8 @@
  * vuex getter
  */
 import dictEnum from '@/enum/dict';
+import store from './index';
+
 export default {
   user: (state) => state.user,
   theme: (state) => state.theme,
@@ -18,11 +20,24 @@ export default {
       return item.dictCode === dictCode + '';
     });
 
+    if (!obj) {
+      // 提交dict模块下的actions的requestDict
+      store.dispatch('dict/requestDict', enumName);
+      return '';
+    }
+
     return obj && obj.dictValue;
   },
   // 根据字典enumName 获取字典列表 label value 格式
   getDictListByName: (sate) => (enumName) => {
     const dList = sate.dict[dictEnum[enumName]] || [];
+
+    if (!dList.length) {
+      // 提交dict模块下的actions的requestDict
+      store.dispatch('dict/requestDict', enumName);
+      return '';
+    }
+
     return dList.map((i) => {
       return {
         ...i,

+ 40 - 39
src/store/modules/dict.js

@@ -12,62 +12,63 @@ import { getByCode } from '@/api/system/dictionary-data';
 //   //   }
 // };
 
-const state = {};
+const state = {
+  // 加载中的字典项
+  dictLoading: []
+};
 
 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);
   }
 };
 
 const actions = {
   // 根据字典enumName请求字典 已获取的不做重复请求
-  async requestDict ({ commit, state }, enumName) {
+  async requestDict({ commit, state }, enumName) {
     const code = dictEnum[enumName];
+    // 如果字典正在加载中,则不重复请求
+    if (state.dictLoading.includes(code)) return;
+
+    commit('dictLoadingAdd', 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]
+            };
+          })
+        });
+        commit('dictLoadingRemove', code);
+        return res.data;
+      }
+
+      commit('dictLoadingRemove', code);
+      return [];
+    } catch (error) {
+      commit('dictLoadingRemove', code);
+      return [];
+    }
   },
   // 更新字典
-  async reloadRequestDict ({ commit }, enumName) {
+  async reloadRequestDict({ commit }, enumName) {
     const code = dictEnum[enumName];
     const res = await getByCode(code);
     const isNumber = numberList.includes(code);

+ 8 - 0
src/views/batchRecord/components/tables/craftFilesTable.vue

@@ -82,6 +82,14 @@
               return cellValue && cellValue[0]?.name;
             }
           },
+          {
+            prop: 'produceTaskName',
+            label: '工序名称',
+            align: 'center',
+            slot: 'produceTaskName',
+            showOverflowTooltip: true,
+            minWidth: 200
+          },
           {
             prop: 'version',
             label: '版本',

+ 3 - 29
src/views/batchRecord/components/tables/workOrderTable.vue

@@ -64,37 +64,11 @@
             slot: 'code'
           },
           {
-            prop: 'scheduleStatus',
+            prop: 'taskName',
             label: '工序进度',
             align: 'center',
-            formatter: (row) => {
-              switch (row.scheduleStatus) {
-                case 10:
-                  return '待排产';
-                case 20:
-                  return '待发布';
-                case 30:
-                  return '发布失败';
-                case 40:
-                  return '待生产';
-                case 50:
-                  return '生产中';
-                case 60:
-                  return '已完成';
-                case 70:
-                  return '已延期';
-                case 80:
-                  return '待下达';
-                case 90:
-                  return '已暂停';
-                case 100:
-                  return '已终止';
-                case 110:
-                  return '已委外';
-                default:
-                  return '';
-              }
-            }
+            showOverflowTooltip: true,
+            minWidth: 150
           },
           {
             prop: 'planStartTime',

+ 5 - 5
src/views/home/index.vue

@@ -138,32 +138,32 @@
         arr: [
           {
             name: '生产总数',
-            num: '188',
+            num: '',
             imgUrl: require('../../assets/Group1.png'),
             unit: ''
           },
           {
             name: '待生产数量',
-            num: '188',
+            num: '',
             imgUrl: require('../../assets/Group2.png'),
             unit: ''
           },
           {
             name: '已完成数量',
-            num: '188',
+            num: '',
             imgUrl: require('../../assets/Group3.png'),
             unit: ''
           },
           {
             name: '生产中数量',
-            num: '188',
+            num: '',
             imgUrl: require('../../assets/Group4.png'),
             unit: '',
             color: '#f97876'
           },
           {
             name: '已延期',
-            num: '188',
+            num: '',
             imgUrl: require('../../assets/Group2.png'),
             unit: ''
           }