From 5e2aafeede13d337380f736567caf74f49713be7 Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Fri, 09 Aug 2024 14:38:32 +0800
Subject: [PATCH] 代码优化
---
src/views/system/menu.vue | 223 ++++++++++++++++++++++++++++++-------------------------
1 files changed, 121 insertions(+), 102 deletions(-)
diff --git a/src/views/system/menu.vue b/src/views/system/menu.vue
index a931424..590c750 100644
--- a/src/views/system/menu.vue
+++ b/src/views/system/menu.vue
@@ -12,7 +12,7 @@
</template>
<template slot-scope="scope" slot="menu">
<el-button type="text" icon="el-icon-circle-plus-outline" size="small"
- @click.stop="handleAdd(scope.row,scope.index)"
+ @click.stop="handleAdd(scope.row, scope.index)"
v-if="userInfo.role_name.includes('admin') && scope.row.category === 1">新增子项
</el-button>
</template>
@@ -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() {
@@ -75,9 +75,11 @@
menuWidth: 300,
dialogClickModal: false,
column: [{
+ width: 276,
label: "菜单名称",
prop: "name",
search: true,
+ searchLabelWidth: 76,
rules: [{
required: true,
message: "请输入菜单名称",
@@ -161,6 +163,24 @@
message: "请输入菜单别名",
trigger: "blur"
}]
+ }, {
+ label: "菜单",
+ prop: "menuType",
+ type: "radio",
+ rules: [{
+ required: true,
+ message: "请选择菜单",
+ trigger: "blur"
+ }],
+ dicData: [{
+ label: "PC端",
+ value: 0
+ },
+ {
+ label: "移动端",
+ value: 1
+ }
+ ],
},
{
label: "新窗口",
@@ -195,14 +215,6 @@
}]
},
{
- label: "菜单备注",
- prop: "remark",
- type: "textarea",
- span: 24,
- minRows: 2,
- hide: true
- },
- {
label: "背景色",
prop: "background",
span: 12,
@@ -229,24 +241,32 @@
},
multiple: true,
// hide: true
- }
+ },
+ {
+ label: "菜单备注",
+ prop: "remark",
+ type: "textarea",
+ span: 24,
+ minRows: 2,
+ hide: true
+ },
]
},
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: {
@@ -257,64 +277,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;
+ // console.log(JSON.stringify(res.data.data))
+ 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("确定将选择数据删除?", {
@@ -323,21 +343,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: "确定",
@@ -345,93 +365,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;
+ // console.log(JSON.stringify(res.data.data))
+ const column = this.findObject(this.option.column, "labelList")
+ column.dicData = this.labelList
// });
}
}
- };
+ }
</script>
-<style>
-</style>
+<style></style>
\ No newline at end of file
--
Gitblit v1.9.3