Ver código fonte

修改目录和菜单编辑状态

liujiejie 1 ano atrás
pai
commit
8b2cacaada

+ 52 - 72
src/views/system/menuMag/components/editDialog.vue

@@ -91,6 +91,7 @@ export default {
   },
   data() {
     return {
+      name: "",
       menuForm: {
         parentId: null,
         pname: null,
@@ -105,9 +106,7 @@ export default {
           message: "请选择",
           trigger: "change",
         },
-        pcode: [
-          { required: true, message: "请填写菜单菜单标识", trigger: "blur" },
-        ],
+        pcode: [{ required: true, message: "请填写菜单标识", trigger: "blur" }],
         pname: [{ required: true, message: "请填写菜单名称", trigger: "blur" }],
         purl: [{ required: true, message: "请填写路由地址", trigger: "blur" }],
         parentId: [
@@ -115,49 +114,20 @@ export default {
         ],
         pstat: [{ required: true, message: "请选择状态", trigger: "change" }],
       },
-      stateOPtions: [],
+      stateOptions: [],
       menuOptions: [
         { permissionId: 0, permissionName: "主类目", children: [] },
       ],
     };
   },
   created() {
-    console.log(this.checkId, "checkid");
-    this.menuOptions[0].children.push(...this.tableData);
-    if (this.row && 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.checkId;
-    } else {
-      this.menuForm.parentId = 0;
-    }
+    this.initializeForm();
   },
   watch: {
     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;
-          }
+          this.initializeForm();
         }
       },
       immediate: true,
@@ -165,55 +135,67 @@ export default {
     },
     checkId(newVal) {
       if (newVal !== null && newVal !== undefined) {
-        console.log(newVal, "checkId");
         this.menuForm.parentId = newVal;
-        if (
-          this.menuForm.pname === null &&
-          this.row &&
-          this.title === "编辑" &&
-          this.activeName === "2"
-        ) {
-          console.log(this.props, " this.row");
-          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,
-          };
-        }
+        this.initializeForm();
       }
     },
     tableData: {
       handler(newData) {
         this.$nextTick(() => {
-          console.log("gengxin", this.setExpandAll(newData));
-          this.setExpandAll(newData);
           this.menuOptions[0].children = [];
-          this.menuOptions[0].children.push(...this.tableData);
+          this.menuOptions[0].children.push(...newData);
         });
       },
       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);
-            });
-          }
-        });
-        console.log(this.tableData, "新值");
+    initializeForm() {
+      console.log(this.checkId, "checkid");
+      this.menuOptions[0].children.push(...this.tableData);
+      if (this.row && 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.checkId;
+      } else {
+        this.menuForm.parentId = 0;
+      }
+
+      if (this.row && this.title === "编辑") {
+        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,
+        };
+        if (this.activeName === "1") {
+          this.$nextTick(() => {
+            this.menuForm = {
+              pname: this.row.permissionName,
+              pstat: this.row.permissionState,
+              parentId: 0,
+              pcode: this.row.permissionCode,
+              permissionShow: this.row.permissionShow,
+            };
+          });
+        }
+      } else if (this.title === "新增" && this.activeName === "2") {
+        this.menuForm.parentId = this.checkId;
+      } else {
+        this.menuForm.parentId = 0;
       }
     },
+
     normalizer(node) {
       if (node.children && !node.children.length) {
         delete node.children;
@@ -225,7 +207,6 @@ export default {
       };
     },
     submit() {
-      const that = this;
       this.$refs["addUserForm"].validate((valid) => {
         if (valid) {
           if (this.title === "编辑" && this.row) {
@@ -239,7 +220,7 @@ export default {
                   message: "编辑成功",
                 });
                 this.cancel();
-                that.$emit("updateList");
+                this.$emit("updateList");
               })
               .catch((error) => {
                 this.$message({
@@ -248,7 +229,6 @@ export default {
                 });
               });
           } else if (this.title === "新增") {
-            console.log("新增", this.activeName);
             addMenuFn({
               ...this.menuForm,
               purl:
@@ -263,7 +243,7 @@ export default {
                   message: "新增成功",
                 });
                 this.cancel();
-                that.$emit("updateList");
+                this.$emit("updateList");
               })
               .catch((error) => {
                 this.$message({

+ 26 - 25
src/views/system/menuMag/index.vue

@@ -125,29 +125,25 @@
       :title="title"
       :visible.sync="unusualdialog"
       width="500px"
-      @close="
-        () => {
-          this.$refs.addMenu.cancel();
-          this.loadingView = false;
-          this.unusualdialog = false;
-          this.checkId = null;
-        }
-      "
+      @close="handleClose"
     >
       <div v-loading="loadingView" class="views">
         <el-tabs type="border-card" class="tabs" v-model="activeName">
           <el-tab-pane label="目录" name="1"
             ><EditMenu
+              v-if="activeName === '1'"
               ref="addList"
               :activeName="activeName"
               :tableData="tableData"
               :checkId="checkId"
               :title="title"
               @updateList="updateList"
+              :row="row"
             />
           </el-tab-pane>
           <el-tab-pane label="菜单" name="2"
             ><EditMenu
+              v-if="activeName === '2'"
               ref="addMenu"
               :activeName="activeName"
               :tableData="tableData"
@@ -158,18 +154,7 @@
           /></el-tab-pane>
         </el-tabs>
         <span slot="footer" class="dialog-footer">
-          <el-button
-            @click="
-              () => {
-                this.$refs.addMenu.cancel();
-                this.loadingView = false;
-                this.unusualdialog = false;
-                this.checkId = null;
-              }
-            "
-            size="small"
-            >取 消</el-button
-          >
+          <el-button @click="handleClose" size="small">取 消</el-button>
           <el-button type="primary" @click="editAuthMenu" size="small"
             >确 定</el-button
           >
@@ -227,6 +212,18 @@ export default {
     },
   },
   methods: {
+    handleClose() {
+      if (this.activeName === "1") {
+        this.$refs.addList.cancel();
+        console.log("取消1");
+      } else {
+        this.$refs.addMenu.cancel();
+      }
+
+      this.loadingView = false;
+      this.unusualdialog = false;
+      this.checkId = null;
+    },
     toggleExpandAll() {
       this.defaultExpandAll = !this.defaultExpandAll;
       this.$nextTick(() => {
@@ -272,7 +269,6 @@ export default {
       }
     },
     updateList() {
-      console.log("updateList");
       this.getTableList();
       this.unusualdialog = false;
     },
@@ -288,14 +284,19 @@ export default {
     // 编辑
     compile(row) {
       this.unusualdialog = true;
-      this.activeName = "2";
-      this.checkId = row.parentId;
-      this.row = row;
+
+      if (row.permissionType === 1) {
+        this.activeName = "1";
+        this.checkId = 0;
+      } else {
+        this.activeName = "2";
+        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";

+ 2 - 2
vue.config.js

@@ -56,8 +56,8 @@ module.exports = {
   devServer: {
     proxy: {
       "/api": {
-        target: "http://192.168.5.4:16200", // 石月
-        // target: "http://192.168.50.235:16200",
+        // target: "http://192.168.5.4:16200", // 石月
+        target: "http://192.168.50.235:16200",
         // target: "http://106.120.102.238:16600",//外网
         changeOrigin: true,
         pathRewrite: {