|
@@ -86,9 +86,10 @@
|
|
|
</el-form-item>
|
|
|
<el-form-item label="图标"
|
|
|
prop="icon">
|
|
|
- <el-input v-model="form.icon"
|
|
|
- :disabled="formEdit"
|
|
|
- placeholder="请输入图标"></el-input>
|
|
|
+ <avue-crud-icon-select v-model="form.icon"
|
|
|
+ :iconList="iconList"
|
|
|
+ :disabled="formEdit"
|
|
|
+ placeholder="请输入图标"></avue-crud-icon-select>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="类型"
|
|
|
prop="type">
|
|
@@ -152,202 +153,207 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- import {addObj, delObj, fetchMenuTree, getObj, putObj} from '@/api/admin/menu'
|
|
|
- import {mapGetters} from 'vuex'
|
|
|
+import {
|
|
|
+ addObj,
|
|
|
+ delObj,
|
|
|
+ fetchMenuTree,
|
|
|
+ getObj,
|
|
|
+ putObj
|
|
|
+} from "@/api/admin/menu";
|
|
|
+import { mapGetters } from "vuex";
|
|
|
+import iconList from "@/const/iconList";
|
|
|
|
|
|
- export default {
|
|
|
- name: 'menu',
|
|
|
- data() {
|
|
|
- return {
|
|
|
- list: null,
|
|
|
- total: null,
|
|
|
- formEdit: true,
|
|
|
- formAdd: true,
|
|
|
- formStatus: '',
|
|
|
- showElement: false,
|
|
|
- typeOptions: ['0', '1'],
|
|
|
- methodOptions: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
|
- listQuery: {
|
|
|
- name: undefined
|
|
|
- },
|
|
|
- treeData: [],
|
|
|
- oExpandedKey: {
|
|
|
- // key (from tree id) : expandedOrNot boolean
|
|
|
- },
|
|
|
- oTreeNodeChildren: {
|
|
|
- // id1 : [children] (from tree node id1)
|
|
|
- // id2 : [children] (from tree node id2)
|
|
|
- },
|
|
|
- aExpandedKeys: [],
|
|
|
- defaultProps: {
|
|
|
- children: 'children',
|
|
|
- label: 'name'
|
|
|
- },
|
|
|
- labelPosition: 'right',
|
|
|
- form: {
|
|
|
- permission: undefined,
|
|
|
- name: undefined,
|
|
|
- menuId: undefined,
|
|
|
- parentId: undefined,
|
|
|
- icon: undefined,
|
|
|
- sort: undefined,
|
|
|
- component: undefined,
|
|
|
- type: undefined,
|
|
|
- path: undefined
|
|
|
- },
|
|
|
- currentId: -1,
|
|
|
- menuManager_btn_add: false,
|
|
|
- menuManager_btn_edit: false,
|
|
|
- menuManager_btn_del: false
|
|
|
- }
|
|
|
- },
|
|
|
- filters: {
|
|
|
- typeFilter(type) {
|
|
|
- const typeMap = {
|
|
|
- 0: '菜单',
|
|
|
- 1: '按钮'
|
|
|
- }
|
|
|
- return typeMap[type]
|
|
|
- }
|
|
|
- },
|
|
|
- created() {
|
|
|
- this.getList()
|
|
|
- this.menuManager_btn_add = this.permissions['sys_menu_add']
|
|
|
- this.menuManager_btn_edit = this.permissions['sys_menu_edit']
|
|
|
- this.menuManager_btn_del = this.permissions['sys_menu_del']
|
|
|
- },
|
|
|
- computed: {
|
|
|
- ...mapGetters([
|
|
|
- 'elements',
|
|
|
- 'permissions'
|
|
|
- ])
|
|
|
- },
|
|
|
- methods: {
|
|
|
- getList() {
|
|
|
- fetchMenuTree(this.listQuery).then(response => {
|
|
|
- this.treeData = response.data.data
|
|
|
- })
|
|
|
- },
|
|
|
- filterNode(value, data) {
|
|
|
- if (!value) return true
|
|
|
- return data.label.indexOf(value) !== -1
|
|
|
+export default {
|
|
|
+ name: "menu",
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ iconList: iconList,
|
|
|
+ list: null,
|
|
|
+ total: null,
|
|
|
+ formEdit: true,
|
|
|
+ formAdd: true,
|
|
|
+ formStatus: "",
|
|
|
+ showElement: false,
|
|
|
+ typeOptions: ["0", "1"],
|
|
|
+ methodOptions: ["GET", "POST", "PUT", "DELETE"],
|
|
|
+ listQuery: {
|
|
|
+ name: undefined
|
|
|
},
|
|
|
-
|
|
|
- nodeExpand(data) {
|
|
|
- let aChildren = data.children
|
|
|
- if (aChildren.length > 0) {
|
|
|
- this.oExpandedKey[data.id] = true
|
|
|
- this.oTreeNodeChildren[data.id] = aChildren
|
|
|
- }
|
|
|
- this.setExpandedKeys()
|
|
|
+ treeData: [],
|
|
|
+ oExpandedKey: {
|
|
|
+ // key (from tree id) : expandedOrNot boolean
|
|
|
},
|
|
|
- nodeCollapse(data) {
|
|
|
- this.oExpandedKey[data.id] = false
|
|
|
- // 如果有子节点
|
|
|
- this.treeRecursion(this.oTreeNodeChildren[data.id], (oNode) => {
|
|
|
- this.oExpandedKey[oNode.id] = false
|
|
|
- });
|
|
|
- this.setExpandedKeys()
|
|
|
+ oTreeNodeChildren: {
|
|
|
+ // id1 : [children] (from tree node id1)
|
|
|
+ // id2 : [children] (from tree node id2)
|
|
|
},
|
|
|
- setExpandedKeys() {
|
|
|
- let oTemp = this.oExpandedKey
|
|
|
- this.aExpandedKeys = []
|
|
|
- for (let sKey in oTemp) {
|
|
|
- if (oTemp[sKey]) {
|
|
|
- this.aExpandedKeys.push(parseInt(sKey));
|
|
|
- }
|
|
|
- }
|
|
|
+ aExpandedKeys: [],
|
|
|
+ defaultProps: {
|
|
|
+ children: "children",
|
|
|
+ label: "name"
|
|
|
},
|
|
|
- treeRecursion(aChildren, fnCallback) {
|
|
|
- if (aChildren) {
|
|
|
- for (let i = 0; i < aChildren.length; ++i) {
|
|
|
- let oNode = aChildren[i]
|
|
|
- fnCallback && fnCallback(oNode)
|
|
|
- this.treeRecursion(oNode.children, fnCallback)
|
|
|
- }
|
|
|
- }
|
|
|
+ labelPosition: "right",
|
|
|
+ form: {
|
|
|
+ permission: undefined,
|
|
|
+ name: undefined,
|
|
|
+ menuId: undefined,
|
|
|
+ parentId: undefined,
|
|
|
+ icon: undefined,
|
|
|
+ sort: undefined,
|
|
|
+ component: undefined,
|
|
|
+ type: undefined,
|
|
|
+ path: undefined
|
|
|
},
|
|
|
+ currentId: -1,
|
|
|
+ menuManager_btn_add: false,
|
|
|
+ menuManager_btn_edit: false,
|
|
|
+ menuManager_btn_del: false
|
|
|
+ };
|
|
|
+ },
|
|
|
+ filters: {
|
|
|
+ typeFilter(type) {
|
|
|
+ const typeMap = {
|
|
|
+ 0: "菜单",
|
|
|
+ 1: "按钮"
|
|
|
+ };
|
|
|
+ return typeMap[type];
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.getList();
|
|
|
+ this.menuManager_btn_add = this.permissions["sys_menu_add"];
|
|
|
+ this.menuManager_btn_edit = this.permissions["sys_menu_edit"];
|
|
|
+ this.menuManager_btn_del = this.permissions["sys_menu_del"];
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapGetters(["elements", "permissions"])
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getList() {
|
|
|
+ fetchMenuTree(this.listQuery).then(response => {
|
|
|
+ this.treeData = response.data.data;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ filterNode(value, data) {
|
|
|
+ if (!value) return true;
|
|
|
+ return data.label.indexOf(value) !== -1;
|
|
|
+ },
|
|
|
|
|
|
- getNodeData(data) {
|
|
|
- if (!this.formEdit) {
|
|
|
- this.formStatus = 'update'
|
|
|
+ nodeExpand(data) {
|
|
|
+ let aChildren = data.children;
|
|
|
+ if (aChildren.length > 0) {
|
|
|
+ this.oExpandedKey[data.id] = true;
|
|
|
+ this.oTreeNodeChildren[data.id] = aChildren;
|
|
|
+ }
|
|
|
+ this.setExpandedKeys();
|
|
|
+ },
|
|
|
+ nodeCollapse(data) {
|
|
|
+ this.oExpandedKey[data.id] = false;
|
|
|
+ // 如果有子节点
|
|
|
+ this.treeRecursion(this.oTreeNodeChildren[data.id], oNode => {
|
|
|
+ this.oExpandedKey[oNode.id] = false;
|
|
|
+ });
|
|
|
+ this.setExpandedKeys();
|
|
|
+ },
|
|
|
+ setExpandedKeys() {
|
|
|
+ let oTemp = this.oExpandedKey;
|
|
|
+ this.aExpandedKeys = [];
|
|
|
+ for (let sKey in oTemp) {
|
|
|
+ if (oTemp[sKey]) {
|
|
|
+ this.aExpandedKeys.push(parseInt(sKey));
|
|
|
}
|
|
|
- getObj(data.id).then(response => {
|
|
|
- this.form = response.data.data
|
|
|
- })
|
|
|
- this.currentId = data.id
|
|
|
- this.showElement = true
|
|
|
- },
|
|
|
- handlerEdit() {
|
|
|
- if (this.form.menuId) {
|
|
|
- this.formEdit = false
|
|
|
- this.formStatus = 'update'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ treeRecursion(aChildren, fnCallback) {
|
|
|
+ if (aChildren) {
|
|
|
+ for (let i = 0; i < aChildren.length; ++i) {
|
|
|
+ let oNode = aChildren[i];
|
|
|
+ fnCallback && fnCallback(oNode);
|
|
|
+ this.treeRecursion(oNode.children, fnCallback);
|
|
|
}
|
|
|
- },
|
|
|
- handlerAdd() {
|
|
|
- this.resetForm()
|
|
|
- this.formEdit = false
|
|
|
- this.formStatus = 'create'
|
|
|
- },
|
|
|
- handleDelete() {
|
|
|
- this.$confirm('此操作将永久删除, 是否继续?', '提示', {
|
|
|
- confirmButtonText: '确定',
|
|
|
- cancelButtonText: '取消',
|
|
|
- type: 'warning'
|
|
|
- }).then(() => {
|
|
|
- delObj(this.currentId).then(() => {
|
|
|
- this.getList()
|
|
|
- this.resetForm()
|
|
|
- this.onCancel()
|
|
|
- this.$notify({
|
|
|
- title: '成功',
|
|
|
- message: '删除成功',
|
|
|
- type: 'success',
|
|
|
- duration: 2000
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- update() {
|
|
|
- putObj(this.form).then(() => {
|
|
|
- this.getList()
|
|
|
- this.$notify({
|
|
|
- title: '成功',
|
|
|
- message: '更新成功',
|
|
|
- type: 'success',
|
|
|
- duration: 2000
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- create() {
|
|
|
- addObj(this.form).then(() => {
|
|
|
- this.getList()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ getNodeData(data) {
|
|
|
+ if (!this.formEdit) {
|
|
|
+ this.formStatus = "update";
|
|
|
+ }
|
|
|
+ getObj(data.id).then(response => {
|
|
|
+ this.form = response.data.data;
|
|
|
+ });
|
|
|
+ this.currentId = data.id;
|
|
|
+ this.showElement = true;
|
|
|
+ },
|
|
|
+ handlerEdit() {
|
|
|
+ if (this.form.menuId) {
|
|
|
+ this.formEdit = false;
|
|
|
+ this.formStatus = "update";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handlerAdd() {
|
|
|
+ this.resetForm();
|
|
|
+ this.formEdit = false;
|
|
|
+ this.formStatus = "create";
|
|
|
+ },
|
|
|
+ handleDelete() {
|
|
|
+ this.$confirm("此操作将永久删除, 是否继续?", "提示", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ cancelButtonText: "取消",
|
|
|
+ type: "warning"
|
|
|
+ }).then(() => {
|
|
|
+ delObj(this.currentId).then(() => {
|
|
|
+ this.getList();
|
|
|
+ this.resetForm();
|
|
|
+ this.onCancel();
|
|
|
this.$notify({
|
|
|
- title: '成功',
|
|
|
- message: '创建成功',
|
|
|
- type: 'success',
|
|
|
+ title: "成功",
|
|
|
+ message: "删除成功",
|
|
|
+ type: "success",
|
|
|
duration: 2000
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- onCancel() {
|
|
|
- this.formEdit = true
|
|
|
- this.formStatus = ''
|
|
|
- },
|
|
|
- resetForm() {
|
|
|
- this.form = {
|
|
|
- permission: undefined,
|
|
|
- name: undefined,
|
|
|
- menuId: undefined,
|
|
|
- parentId: this.currentId,
|
|
|
- icon: undefined,
|
|
|
- sort: undefined,
|
|
|
- component: undefined,
|
|
|
- type: undefined,
|
|
|
- path: undefined
|
|
|
- }
|
|
|
- }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ update() {
|
|
|
+ putObj(this.form).then(() => {
|
|
|
+ this.getList();
|
|
|
+ this.$notify({
|
|
|
+ title: "成功",
|
|
|
+ message: "更新成功",
|
|
|
+ type: "success",
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ create() {
|
|
|
+ addObj(this.form).then(() => {
|
|
|
+ this.getList();
|
|
|
+ this.$notify({
|
|
|
+ title: "成功",
|
|
|
+ message: "创建成功",
|
|
|
+ type: "success",
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onCancel() {
|
|
|
+ this.formEdit = true;
|
|
|
+ this.formStatus = "";
|
|
|
+ },
|
|
|
+ resetForm() {
|
|
|
+ this.form = {
|
|
|
+ permission: undefined,
|
|
|
+ name: undefined,
|
|
|
+ menuId: undefined,
|
|
|
+ parentId: this.currentId,
|
|
|
+ icon: undefined,
|
|
|
+ sort: undefined,
|
|
|
+ component: undefined,
|
|
|
+ type: undefined,
|
|
|
+ path: undefined
|
|
|
+ };
|
|
|
}
|
|
|
}
|
|
|
+};
|
|
|
</script>
|
|
|
|