Ver Fonte

fix:菜单管理bug 修复

liujiejie há 1 ano atrás
pai
commit
5a5a51d891

+ 62 - 15
src/views/system/menuMag/components/editDialog.vue

@@ -122,6 +122,7 @@ export default {
     };
   },
   created() {
+    console.log(this.checkId, "checkid");
     this.menuOptions[0].children.push(...this.tableData);
     if (this.title === "编辑" && this.activeName === "2") {
       this.menuForm = {
@@ -133,29 +134,67 @@ export default {
         permissionShow: this.row.permissionShow,
       };
     } else if (this.title === "新增" && this.activeName === "2") {
-      this.menuForm.parentId = this.row.permissionId;
+      this.menuForm.parentId = this.checkId;
+    } else {
+      this.menuForm.parentId = 0;
     }
   },
   watch: {
-    checkId(newVale, oldVal) {
-      if (newVale) {
-        console.log(newVale, "newVale");
-        if (this.title === "编辑" && this.activeName === "2") {
-          this.menuForm = {
-            parentId: this.row.parentId,
-            pname: this.row.permissionName,
-            purl: this.row.permissionUrl,
-            pstat: this.row.permissionState,
-            pcode: this.row.permissionCode,
-            permissionShow: this.row.permissionShow,
-          };
-        } else if (this.title === "新增" && this.activeName === "2") {
-          this.menuForm.parentId = this.row.permissionId;
+    row: {
+      handler(newVal) {
+        if (newVal) {
+          console.log(newVal, "newRowValue");
+          if (this.title === "编辑" && this.activeName === "2") {
+            this.menuForm = {
+              parentId: newVal.parentId,
+              pname: newVal.permissionName,
+              purl: newVal.permissionUrl,
+              pstat: newVal.permissionState,
+              pcode: newVal.permissionCode,
+              permissionShow: newVal.permissionShow,
+            };
+          } else if (this.title === "新增" && this.activeName === "2") {
+            this.menuForm.parentId = this.checkId;
+          } else {
+            this.menuForm.parentId = 0;
+          }
         }
+      },
+      immediate: true,
+      deep: true,
+    },
+    checkId(newVal) {
+      if (newVal !== null && newVal !== undefined) {
+        console.log(newVal, "checkId");
+        this.menuForm.parentId = newVal;
       }
     },
+    tableData: {
+      handler(newData) {
+        this.$nextTick(() => {
+          console.log("gengxin");
+          this.setExpandAll(this.defaultExpandAll);
+        });
+      },
+      immediate: true,
+      deep: true,
+    },
   },
+
   methods: {
+    setExpandAll(expand) {
+      const table = this.$refs.table;
+      if (table) {
+        this.tableData.forEach((row) => {
+          table.toggleRowExpansion(row, expand);
+          if (row.children) {
+            row.children.forEach((child) => {
+              table.toggleRowExpansion(child, expand);
+            });
+          }
+        });
+      }
+    },
     /** 转换菜单数据结构 */
     normalizer(node) {
       if (node.children && !node.children.length) {
@@ -221,6 +260,14 @@ export default {
     },
     cancel() {
       this.$refs["addUserForm"].resetFields();
+      this.menuForm = {
+        parentId: null,
+        pname: null,
+        purl: null,
+        pstat: null,
+        pcode: null,
+        permissionShow: null,
+      };
     },
   },
 };

+ 18 - 5
src/views/system/menuMag/index.vue

@@ -123,7 +123,19 @@
     </div>
 
     <!-- 新增编辑弹出层 -->
-    <el-dialog :title="title" :visible.sync="unusualdialog" width="500px">
+    <el-dialog
+      :title="title"
+      :visible.sync="unusualdialog"
+      width="500px"
+      @close="
+        () => {
+          this.$refs.addMenu.cancel();
+          this.loadingView = false;
+          this.unusualdialog = false;
+          this.checkId = null;
+        }
+      "
+    >
       <div v-loading="loadingView" class="views">
         <el-tabs type="border-card" class="tabs" v-model="activeName">
           <el-tab-pane label="目录" name="1"
@@ -154,7 +166,7 @@
                 this.$refs.addMenu.cancel();
                 this.loadingView = false;
                 this.unusualdialog = false;
-                this.checkId = '';
+                this.checkId = null;
               }
             "
             size="small"
@@ -253,12 +265,12 @@ export default {
     editAuthMenu() {
       if (this.activeName === "1") {
         this.$refs.addList.submit();
-        this.checkId = "";
+        this.checkId = null;
         //目录
       } else {
         //菜单
         this.$refs.addMenu.submit();
-        this.checkId = "";
+        this.checkId = null;
       }
     },
     updateList() {
@@ -279,12 +291,13 @@ export default {
     compile(row) {
       this.unusualdialog = true;
       this.activeName = "2";
-      this.checkId = row.permissionId;
+      this.checkId = row.parentId;
       this.row = row;
       this.title = "编辑";
     },
     // 新增子级
     newcomer(row) {
+      console.log(row.parentId);
       this.unusualdialog = true;
       this.checkId = row.permissionId;
       this.activeName = "2";