瀏覽代碼

场景管理排序fix

zhudie 2 年之前
父節點
當前提交
3b9b75c962

+ 2 - 2
src/views/system-config/scene-manage/SceneManage.vue

@@ -373,7 +373,7 @@
       const parentIndex = row.parent.children!.findIndex((item) => item.id === row.id);
       if (parentIndex > 0) {
         const previousRow = row.parent.children![parentIndex - 1];
-        const targetParent = getParent(tableData.value, previousRow.parent.id);
+        const targetParent = getParent(tableData.value, previousRow.parent.code);
         // 进行交换位置
         targetParent.children!.splice(parentIndex - 1, 2, row, previousRow);
       }
@@ -399,7 +399,7 @@
       const parentIndex = row.parent.children!.findIndex((item) => item.id === row.id);
       if (parentIndex < row.parent.children?.length - 1) {
         const behindRow = row.parent.children![parentIndex + 1];
-        const targetParent = getParent(tableData.value, behindRow.parent.id);
+        const targetParent = getParent(tableData.value, behindRow.parent.code);
         // 进行交换位置
         targetParent.children!.splice(parentIndex, 2, behindRow, row);
       }

+ 13 - 6
src/views/system-config/scene-manage/use-method.tsx

@@ -151,21 +151,28 @@ export const findItemLevel = (data, targetId, targetName, currentLevel = 0) => {
 
 
 //得到parent
-export const getParent = (data:DataSourceUser[], targetId:number) => {
-  let parentNode = {} as DataSourceUser
+export const getParent = (data:DataSourceUser[], targetCode:string) => {
+
+  
+  
+  //let parentNode = {} as DataSourceUser
   for (let i = 0; i < data.length; i++) {
     const item = data[i];
 
-    if (item.id === targetId ) {
-      parentNode = item
+    if (item.code === targetCode ) {
+      // parentNode = item
+      return item
     }
 
     if (item.children && item.children.length > 0) {
-       getParent(item.children, targetId);
+      const foundItem = getParent(item.children, targetCode);
+      if(foundItem){
+        return foundItem
+      }
     }
   }
 
-  return parentNode;
+  return null;
 };
 
 //删除行