Bläddra i källkod

feat: 添加 uniqById 函数以按 ID 去重,优化物品列表数据处理

xieyong 2 dagar sedan
förälder
incheckning
9502ec1a08
2 ändrade filer med 16 tillägg och 2 borttagningar
  1. 13 0
      src/utils/util.js
  2. 3 2
      src/views/bpm/outgoingManagement/outbound.vue

+ 13 - 0
src/utils/util.js

@@ -152,6 +152,19 @@ export function getSummaries(param, key, unit) {
   return sums;
 }
 
+// 按 id 去重,保留首次出现的项(用于 v-for :key="item.id" 的列表)
+// 后端返回重复 id 时会导致 Vue 报 "Duplicate keys detected" 并造成选中态/回显错乱
+export function uniqById(list) {
+  if (!Array.isArray(list)) return [];
+  const map = new Map();
+  list.forEach((item) => {
+    if (item && item.id != null && !map.has(item.id)) {
+      map.set(item.id, item);
+    }
+  });
+  return Array.from(map.values());
+}
+
 //随机id
 export function generateRandomString(num = 5) {
   let result = '';

+ 3 - 2
src/views/bpm/outgoingManagement/outbound.vue

@@ -417,6 +417,7 @@
   import { mapGetters } from 'vuex';
   import { parameterGetByCode } from '@/api/main/index.js';
   import tableColumnsMixin from '@/mixins/tableColumnsMixin';
+  import { uniqById } from '@/utils/util.js';
 
   export default {
     mixins: [tableColumnsMixin],
@@ -849,7 +850,7 @@
       // 获取物品列表
       async getListItems() {
         const { data } = await getTreeByGroup({});
-        this.goodsLists = data;
+        this.goodsLists = uniqById(data);
       },
       // 打开单据来源弹窗
       openDocumentSourceDialog() {
@@ -1108,7 +1109,7 @@
             size: 9999,
             page: 1
           });
-          this.llrLsit = res.list;
+          this.llrLsit = uniqById(res.list);
           resolve();
         });
       },