Răsfoiți Sursa

perf(views): 修复“选择网关参数”步骤选择参数提交异常问题

wangshun 1 lună în urmă
părinte
comite
6abf66ff80
1 a modificat fișierele cu 13 adăugiri și 29 ștergeri
  1. 13 29
      src/views/create-device/GatewayParameters.vue

+ 13 - 29
src/views/create-device/GatewayParameters.vue

@@ -344,7 +344,7 @@ const postGatewayLinkProtocolList = (linkId: number, id: number, monitorType: st
         fuzzyQuery('monitor');
 
         monitorAssociationGatewayList.value.forEach((item) => {
-          if (id === item.gatewayId) {
+          if (id === item.gatewayId && linkId === item.linkId) {
             monitorEquipmentLsit.value.push(item.id);
             monitorChooselistEquipment.value.push(item);
           }
@@ -369,7 +369,7 @@ const postGatewayLinkProtocolList = (linkId: number, id: number, monitorType: st
         fuzzyQuery('control');
 
         controlAssociationGatewayList.value.forEach((item) => {
-          if (id === item.gatewayId) {
+          if (id === item.gatewayId && linkId === item.linkId) {
             controlEquipmentLsit.value.push(item.id);
             controlChooselistEquipment.value.push(item);
           }
@@ -410,31 +410,18 @@ const handleOk = () => {
 
 // 合并逻辑
 const mergeArrays = (a: ListEquipmentParametersItem[], b: ListEquipmentParametersItem[]) => {
-  const gateways = new Map<number, ListEquipmentParametersItem[]>();
-
-  a.forEach((item) => {
-    const gatewayId = item.gatewayId;
-    if (!gateways.has(gatewayId)) {
-      gateways.set(gatewayId, []);
-    }
-    gateways.get(gatewayId)?.push(item);
-  });
-
-  const bGroups = new Map<number, ListEquipmentParametersItem[]>();
-  b.forEach((item) => {
-    const gatewayId = item.gatewayId;
-    if (!bGroups.has(gatewayId)) {
-      bGroups.set(gatewayId, []);
-    }
-    bGroups.get(gatewayId)?.push(item);
-  });
-
-  bGroups.forEach((value, key) => {
-    gateways.set(key, value);
-  });
+  // 找出b中所有的gatewayId和linkId组合
+  const bCombinations = new Set(b.map((item) => `${item.gatewayId}-${item.linkId}`));
+
+  // 处理后的数组
+  const result = [
+    // 保留b中存在的项(gatewayId和linkId匹配的)
+    ...b,
+    // 保留a中gatewayId和linkId不在b中的项
+    ...a.filter((item) => !bCombinations.has(`${item.gatewayId}-${item.linkId}`)),
+  ];
 
-  // 合并所有分组并按原顺序展开
-  return Array.from(gateways.values()).flat();
+  return result;
 };
 
 const deleteAll = () => {
@@ -797,7 +784,6 @@ const useUniqueArray = (data: ListEquipmentParametersItem[]) => {
 };
 
 const addAutomaticMatching = () => {
-  console.log(paramValueListAutomaticData.value);
   paramValueListAutomaticData.value.forEach((item) => {
     const { gatewayParamCode, gatewayParamName, platformParamCode, platformParamName, id, unit } = item;
     if (item.readWriteTypeCode === 'read_only') {
@@ -837,8 +823,6 @@ const addAutomaticMatching = () => {
     }
   });
 
-  console.log(monitorChooselistEquipment.value);
-
   monitorChooselistEquipment.value = useUniqueArray(monitorChooselistEquipment.value);
   controlChooselistEquipment.value = useUniqueArray(controlChooselistEquipment.value);