guanqb
2024-01-29 bf45ce8559383eb2c940affc6296c4c156ecf5e2
src/views/system/menu.vue
@@ -32,20 +32,20 @@
    update,
    add,
    getMenu
  } from "@/api/system/menu";
} from "@/api/system/menu"
  import {
    mapGetters
  } from "vuex";
  import iconList from "@/config/iconList";
  import func from "@/util/func";
} from "vuex"
import iconList from "@/config/iconList"
import func from "@/util/func"
  import {
    getMenuTree
  } from "@/api/system/menu";
} from "@/api/system/menu"
  import {
    getTreeList
  } from "@/api/label/label";
} from "@/api/label/label"
  export default {
    data() {
@@ -78,6 +78,7 @@
              label: "菜单名称",
              prop: "name",
              search: true,
                    searchLabelWidth: 76,
              rules: [{
                required: true,
                message: "请输入菜单名称",
@@ -252,19 +253,19 @@
        },
        data: [],
        labelList: [],
      };
        }
    },
    watch: {
      'form.category'() {
        const category = func.toInt(this.form.category);
            const category = func.toInt(this.form.category)
        this.$refs.crud.option.column.filter(item => {
          if (item.prop === "path") {
            item.rules[0].required = category === 1;
                    item.rules[0].required = category === 1
          }
          if (item.prop === 'isOpen') {
            item.disabled = category === 2;
                    item.disabled = category === 2
          }
        });
            })
      },
    },
    computed: {
@@ -275,64 +276,64 @@
          viewBtn: this.vaildData(this.permission.menu_view, false),
          delBtn: this.vaildData(this.permission.menu_delete, false),
          editBtn: this.vaildData(this.permission.menu_edit, false)
        };
            }
      },
      ids() {
        let ids = [];
            let ids = []
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
                ids.push(ele.id)
            })
            return ids.join(",")
      }
    },
    methods: {
      initData() {
        getMenuTree().then(res => {
          const column = this.findObject(this.option.column, "parentId");
          column.dicData = res.data.data;
        });
                const column = this.findObject(this.option.column, "parentId")
                column.dicData = res.data.data
            })
        // getTreeList().then(res => {
        // console.log(JSON.stringify(res.data.data))
        const column = this.findObject(this.option.column, "labelList");
        column.dicData = this.labelList;
            const column = this.findObject(this.option.column, "labelList")
            column.dicData = this.labelList
        // });
      },
      handleAdd(row) {
        this.parentId = row.id;
        const column = this.findObject(this.option.column, "parentId");
        column.value = row.id;
        column.addDisabled = true;
        this.$refs.crud.rowAdd();
            this.parentId = row.id
            const column = this.findObject(this.option.column, "parentId")
            column.value = row.id
            column.addDisabled = true
            this.$refs.crud.rowAdd()
      },
      rowSave(row, done, loading) {
        add(row).then((res) => {
          // 获取新增数据的相关字段
          const data = res.data.data;
          row.id = data.id;
                const data = res.data.data
                row.id = data.id
          this.$message({
            type: "success",
            message: "操作成功!"
          });
                })
          // 数据回调进行刷新
          done(row);
                done(row)
        }, error => {
          window.console.log(error);
          loading();
        });
                window.console.log(error)
                loading()
            })
      },
      rowUpdate(row, index, done, loading) {
        update(row).then(() => {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
                })
          // 数据回调进行刷新
          done(row);
                done(row)
        }, error => {
          window.console.log(error);
          loading();
        });
                window.console.log(error)
                loading()
            })
      },
      rowDel(row, index, done) {
        this.$confirm("确定将选择数据删除?", {
@@ -341,21 +342,21 @@
            type: "warning"
          })
          .then(() => {
            return remove(row.id);
                    return remove(row.id)
          })
          .then(() => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
                    })
            // 数据回调进行刷新
            done(row);
          });
                    done(row)
                })
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
                this.$message.warning("请选择至少一条数据")
                return
        }
        this.$confirm("确定将选择数据删除?", {
            confirmButtonText: "确定",
@@ -363,93 +364,92 @@
            type: "warning"
          })
          .then(() => {
            return remove(this.ids);
                    return remove(this.ids)
          })
          .then(() => {
            // 刷新表格数据并重载
            this.data = [];
            this.parentId = 0;
            this.$refs.crud.refreshTable();
            this.$refs.crud.toggleSelection();
                    this.data = []
                    this.parentId = 0
                    this.$refs.crud.refreshTable()
                    this.$refs.crud.toggleSelection()
            // 表格数据重载
            this.onLoad(this.page);
                    this.onLoad(this.page)
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
                    })
                })
      },
      searchReset() {
        this.query = {};
        this.parentId = 0;
        this.onLoad(this.page);
            this.query = {}
            this.parentId = 0
            this.onLoad(this.page)
      },
      searchChange(params, done) {
        this.query = params;
        this.parentId = '';
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
            this.query = params
            this.parentId = ''
            this.page.currentPage = 1
            this.onLoad(this.page, params)
            done()
      },
      selectionChange(list) {
        this.selectionList = list;
            this.selectionList = list
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
            this.selectionList = []
            this.$refs.crud.toggleSelection()
      },
      beforeOpen(done, type) {
        if (["add", "edit"].includes(type)) {
          this.initData();
                this.initData()
        }
        if (["edit", "view"].includes(type)) {
          getMenu(this.form.id).then(res => {
            this.form = res.data.data;
          });
                    this.form = res.data.data
                })
        }
        done();
            done()
      },
      beforeClose(done) {
        this.parentId = "";
        const column = this.findObject(this.option.column, "parentId");
        column.value = "";
        column.addDisabled = false;
        done();
            this.parentId = ""
            const column = this.findObject(this.option.column, "parentId")
            column.value = ""
            column.addDisabled = false
            done()
      },
      currentChange(currentPage) {
        this.page.currentPage = currentPage;
            this.page.currentPage = currentPage
      },
      sizeChange(pageSize) {
        this.page.pageSize = pageSize;
            this.page.pageSize = pageSize
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
            this.onLoad(this.page, this.query)
      },
      onLoad(page, params = {}) {
        this.loading = true;
            this.loading = true
        getLazyList(this.parentId, Object.assign(params, this.query)).then(res => {
          this.data = res.data.data;
          this.loading = false;
          this.selectionClear();
        });
                this.data = res.data.data
                this.loading = false
                this.selectionClear()
            })
        getTreeList().then(res => {
          this.labelList = res.data.data;
        });
                this.labelList = res.data.data
            })
      },
      treeLoad(tree, treeNode, resolve) {
        const parentId = tree.id;
            const parentId = tree.id
        getLazyList(parentId).then(res => {
          resolve(res.data.data);
        });
                resolve(res.data.data)
            })
        // getTreeList().then(res => {
        // console.log(JSON.stringify(res.data.data))
        const column = this.findObject(this.option.column, "labelList");
        column.dicData = this.labelList;
            const column = this.findObject(this.option.column, "labelList")
            column.dicData = this.labelList
        // });
      }
    }
  };
}
</script>
<style>
</style>
<style></style>