فهرست منبع

Merge branch 'main-fix' into 'dev'

Main fix

See merge request skyeye/skyeye_frontend/skyeye-admin!42
航飞 楼 1 سال پیش
والد
کامیت
e23fc01636
1فایلهای تغییر یافته به همراه29 افزوده شده و 29 حذف شده
  1. 29 29
      src/views/datamanager/alertformdata/hooks/useWorkLocation.ts

+ 29 - 29
src/views/datamanager/alertformdata/hooks/useWorkLocation.ts

@@ -1,49 +1,49 @@
 import { ref } from 'vue';
-import { getWorkLocationList } from '@/api/datamanagement/alert'
+import { getWorkLocationList } from '@/api/datamanagement/alert';
 
 type Location = {
-  value: number,
-  label: string,
+  value: number;
+  label: string;
   children: {
-    value: number,
-    label: string
-  }[]
-}
+    value: number;
+    label: string;
+  }[];
+};
 
 export function useWorkLocation() {
   const locationOptions = ref<Location[]>([]);
 
   const getLocationOptions = () => {
     getWorkLocationList().then((res) => {
-      locationOptions.value = res?.map((item) => {
-        const newChildren = item.workspaceList?.map(x => {
-          return { value: x.workspaceId, label: x.workspaceName }
-        }) || []
-        return {
-          value: item.workshopId,
-          label: item.workshopName,
-          children: newChildren
-        }
-      }) || []
-    })
+      locationOptions.value =
+        res?.map((item) => {
+          const newChildren =
+            item.workspaceList?.map((x) => {
+              return { value: x.workspaceId, label: x.workspaceName };
+            }) || [];
+          return {
+            value: item.workshopId,
+            label: item.workshopName,
+            children: newChildren,
+          };
+        }) || [];
+    });
   };
 
-  // 根据workshopId + workspaceId 指定表格显示 地点 label
   const getNameByWorkid = (workshopId, workspaceId, array) => {
-    if (workshopId < 0 || workshopId > array.length) return '-';
-    const obj = array[workshopId - 1];
-
-    if (!obj.children || !Array.isArray(obj.children)) return '-';
-    if (workspaceId < 0) return '-';
-    if (obj.children) {
-      const subObj = obj.children.find(subobj => subobj.value === workspaceId);
-      return obj.label + ' - ' + subObj?.label;
+    const shop = array.find((item) => item.value === workshopId);
+    if (!shop) {
+      return '-';
     }
+
+    if (!shop.children || !Array.isArray(shop.children)) return '-';
+    const space = shop.children.find((item) => item.value === workspaceId);
+    return shop.label + ' - ' + space?.label;
   };
 
   return {
     locationOptions,
     getLocationOptions,
-    getNameByWorkid
-  }
+    getNameByWorkid,
+  };
 }