ソースを参照

perf(views): 优化实时监测页面设备分组及其列表的获取

1. 过滤掉没有二级分组的一级分组
wangcong 4 日 前
コミット
2dfccfd207
1 ファイル変更35 行追加33 行削除
  1. 35 33
      src/views/real-time-monitor/RealTimeMonitor.vue

+ 35 - 33
src/views/real-time-monitor/RealTimeMonitor.vue

@@ -69,39 +69,41 @@ const transformGroupsAndDevices = (groups: DeviceGroupItem[], devices: AllDevice
   });
 
   // 转换顶级分组
-  return groups.map((group) => {
-    // 转换当前组
-    const transformed: DeviceGroupTree = {
-      ...group,
-      label: group.groupName,
-      children: [],
-    };
-
-    // 转换子分组(二级分组),并过滤掉没有设备的分组
-    if (group.deviceGroupChilds && group.deviceGroupChilds.length > 0) {
-      transformed.children = group.deviceGroupChilds
-        .map((child) => {
-          const transformedChild: DeviceGroupTreeChild = {
-            ...child,
-            label: child.groupName,
-            children: [],
-          };
-
-          // 查找并添加属于这个二级分组的设备
-          const childDevices = deviceMap.get(child.id) || [];
-
-          transformedChild.children = childDevices.map((device) => ({
-            ...device,
-            label: device.deviceName,
-          }));
-
-          return transformedChild;
-        })
-        .filter((child) => child.children.length > 0); // 过滤掉没有设备的二级分组
-    }
-
-    return transformed;
-  });
+  return groups
+    .map((group) => {
+      // 转换当前组
+      const transformed: DeviceGroupTree = {
+        ...group,
+        label: group.groupName,
+        children: [],
+      };
+
+      // 转换子分组(二级分组),并过滤掉没有设备的分组
+      if (group.deviceGroupChilds && group.deviceGroupChilds.length > 0) {
+        transformed.children = group.deviceGroupChilds
+          .map((child) => {
+            const transformedChild: DeviceGroupTreeChild = {
+              ...child,
+              label: child.groupName,
+              children: [],
+            };
+
+            // 查找并添加属于这个二级分组的设备
+            const childDevices = deviceMap.get(child.id) || [];
+
+            transformedChild.children = childDevices.map((device) => ({
+              ...device,
+              label: device.deviceName,
+            }));
+
+            return transformedChild;
+          })
+          .filter((child) => child.children.length > 0); // 过滤掉没有设备的二级分组
+      }
+
+      return transformed;
+    })
+    .filter((parent) => parent.children.length > 0); // 过滤掉没有二级分组的一级分组
 };
 
 const checkModuleInfo = () => {