Procházet zdrojové kódy

fix: 修改地点返回数据格式与转换方法,适应二级菜单多个数据情况

bxy před 1 rokem
rodič
revize
29317322a6

+ 12 - 16
src/views/datamanager/alertformdata/hooks/useWorkLocation.ts

@@ -4,12 +4,10 @@ import { getWorkLocationList } from '@/api/datamanagement/alert'
 type Location = {
   value: number,
   label: string,
-  children: [
-    {
-      value: number,
-      label: string
-    }
-  ]
+  children: {
+    value: number,
+    label: string
+  }[]
 }
 
 export function useWorkLocation() {
@@ -17,18 +15,16 @@ export function useWorkLocation() {
 
   const getLocationOptions = () => {
     getWorkLocationList().then((res) => {
-      res.forEach((item) => {
-        locationOptions.value.push({
+      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: [
-            {
-              value: item.workspaceList[0].workspaceId,
-              label: item.workspaceList[0].workspaceName
-            }
-          ]
-        })
-      })
+          children: newChildren
+        }
+      }) || []
     })
   };