From ceede3118d44793798a7851b3963e3d8c32fd054 Mon Sep 17 00:00:00 2001 From: yaojn Date: Wed, 6 Mar 2024 11:29:49 +0800 Subject: [PATCH] =?UTF-8?q?-=20[=E5=8A=9F=E8=83=BD]=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E4=BC=98=E5=8C=96=20=20=20-=20[=E5=85=B3?= =?UTF-8?q?=E8=81=94]#[1083997143138304]=E8=8F=9C=E5=8D=95=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E4=BC=98=E5=8C=96=20http://192.168.0.96:8090/demo/rdm?= =?UTF-8?q?.html#/story-detail/939050947543040/939050947543042/10839971431?= =?UTF-8?q?38304?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/resources/assets/languages/term/en.json | 5 +- src/resources/assets/languages/term/zh.json | 5 +- .../framework/extramenu/extramenu-manage.vue | 231 +++++++++++++++--- 3 files changed, 208 insertions(+), 33 deletions(-) diff --git a/src/resources/assets/languages/term/en.json b/src/resources/assets/languages/term/en.json index 8587c2cb..75d3075e 100644 --- a/src/resources/assets/languages/term/en.json +++ b/src/resources/assets/languages/term/en.json @@ -1224,7 +1224,10 @@ "globalreadonly": "Global read-only", "globalreadonlytip": "The global read-only priority is higher than the internal read and write settings of the component. After turning on the global read-only switch, all components in the scene are in a read-only state", "iscannotdeletenode": "There are child nodes that cannot be deleted", - "requiredselectedtips": "If the current component is set as mandatory and only one option remains after filtering, the system will automatically select that option" + "requiredselectedtips": "If the current component is set as mandatory and only one option remains after filtering, the system will automatically select that option", + "internalmenu": "Internal menu", + "custommenu": "Custom menu", + "internalmenuoperationtips": "The internal menu can only be viewed with permission, and cannot add an editing menu" }, "knowledge": { "document": "Document", diff --git a/src/resources/assets/languages/term/zh.json b/src/resources/assets/languages/term/zh.json index 887c9893..d1523774 100644 --- a/src/resources/assets/languages/term/zh.json +++ b/src/resources/assets/languages/term/zh.json @@ -1223,7 +1223,10 @@ "globalreadonly": "全局只读", "globalreadonlytip": "全局只读优先级高于组件内部的读写设置,打开全局只读开关后,场景内所有组件均为只读状态", "iscannotdeletenode": "存在子节点不可删除", - "requiredselectedtips": "若当前组件设置为必填,且过滤后仅剩余一个选项,系统会自动选中该选项" + "requiredselectedtips": "若当前组件设置为必填,且过滤后仅剩余一个选项,系统会自动选中该选项", + "internalmenu": "内部菜单", + "custommenu": "自定义菜单", + "internalmenuoperationtips": "内部菜单只能查看权限,不能新增编辑菜单" }, "knowledge": { "document": "文档", diff --git a/src/views/pages/framework/extramenu/extramenu-manage.vue b/src/views/pages/framework/extramenu/extramenu-manage.vue index ffd9c3df..fbcb7f3e 100644 --- a/src/views/pages/framework/extramenu/extramenu-manage.vue +++ b/src/views/pages/framework/extramenu/extramenu-manage.vue @@ -7,18 +7,27 @@ @@ -55,6 +73,7 @@ export default { name: '', components: { TsZtree: resolve => require(['@/resources/plugins/TsZtree/TsZtree.vue'], resolve), + TsTable: resolve => require(['@/resources/components/TsTable/TsTable.vue'], resolve), MenuEdit: resolve => require(['./menu-edit'], resolve), AuthorityViewDialog: resolve => require(['./authority-view-dialog'], resolve) }, @@ -66,12 +85,34 @@ export default { saving: false, selectedTreeId: null, nodeList: [], + menuType: '', + routerAuth: {}, + tableConfig: { + tbodyList: [], + currentPage: 1, + pageSize: 100, + fixedHeader: false + }, + theadList: [ + { + title: this.$t('page.menuname'), + key: 'menuName' + }, + { + title: this.$t('term.framework.belongmodule'), + key: 'moduleName' + }, + { + title: this.$t('page.authority'), + key: 'authority' + } + ], hoverDomList: [ { icon: 'tsfont-plus', desc: this.$t('page.subdirectory'), isAddFn: (treeNode) => { - if (treeNode.type == 1) { + if (treeNode.type == 1 || treeNode.menuType == 'innerMenu') { return false; //菜单不能添加目录 } else { return true; @@ -85,7 +126,7 @@ export default { icon: 'tsfont-putongjigui', desc: this.$t('dialog.title.addtarget', { target: this.$t('page.menu') }), isAddFn: (treeNode) => { - if (treeNode.type == 1) { + if (treeNode.type == 1 || treeNode.menuType == 'innerMenu') { return false; //菜单不能添加菜单 } else { return true; @@ -99,14 +140,14 @@ export default { icon: 'tsfont-trash-o', desc: this.$t('page.delete'), isAddFn: treeNode => { - if (this.$utils.isEmpty(treeNode.parentId) || treeNode.parentId == 0) { + if (this.$utils.isEmpty(treeNode.parentId) || treeNode.parentId == 0 || treeNode.menuType == 'innerMenu') { return false; // 总的根节点不能删除 } else { return true; } }, initFn: (treeNode, $span) => { - if (treeNode.childCount > 0) { + if (treeNode.childCount > 0 || treeNode.menuType == 'innerMenu') { $span[0].classList.add('text-disabled'); $span[0].title = this.$t('term.framework.iscannotdeletenode'); } @@ -126,6 +167,8 @@ export default { beforeCreate() {}, created() { this.init(true); + this.updateMenu(); + this.routerAuth = this.handleRouterAuth(); }, beforeMount() {}, mounted() {}, @@ -183,19 +226,52 @@ export default { return false; } }, + flattenArrayWithChildren(array) { + let result = []; + let _this = this; + function flatten(items) { + items && items.forEach(item => { + result.push(item); + if (!_this.$utils.isEmpty(item) && Array.isArray(item.children)) { + flatten(item.children); // 递归调用 flatten 函数 + } + }); + } + flatten(array); // 开始扁平化过程 + return result; + }, clickNode(tree, node) { - this.isMenu = node.type; - this.selectedTreeId = node.id; - this.selectSaveId = node.id; - this.parentId = node.parentId; - if (node.type == 0) { + this.menuType = node.isMenu ? 'innerMenu' : ''; + this.tableConfig.tbodyList = []; + if (node.isMenu || node.menuType == 'innerMenu') { + this.menuType = 'innerMenu'; + this.catalogName = this.$t('page.viewauthority'); + let childrenList = this.flattenArrayWithChildren(this.$utils.deepClone(Array.isArray(node.children) && !this.$utils.isEmpty(node.children) ? node.children : [node])); + let moduleAuthList = this.routerAuth[node.moduleId] && this.routerAuth[node.moduleId] || []; // 获取点击的模块菜单权限 + childrenList.forEach((item) => { + let findItem = moduleAuthList.find((v) => item.id.indexOf(v.name) > 0); + if (findItem) { + this.tableConfig.tbodyList.push({ + menuName: item.name, + moduleName: node.moduleName, + authority: findItem.authority + }); + } + }); + } else { + this.isMenu = node.type; + this.selectedTreeId = node.id; + this.selectSaveId = node.id; + this.parentId = node.parentId; + if (node.type == 0) { // 编辑目录 - this.catalogName = this.$t('dialog.title.edittarget', { target: this.$t('page.catalogue') }); - } else if (node.type == 1) { + this.catalogName = this.$t('dialog.title.edittarget', { target: this.$t('page.catalogue') }); + } else if (node.type == 1) { // 编辑菜单 - this.catalogName = this.$t('dialog.title.edittarget', { target: this.$t('page.menu')}); + this.catalogName = this.$t('dialog.title.edittarget', { target: this.$t('page.menu')}); + } + this.getMenuTreeNode(); } - this.getMenuTreeNode(); }, addTreeChildren(node) { this.loadingShow = true; @@ -265,6 +341,9 @@ export default { beforeDrop(treeId, treeNodes, targetNode, moveType) { if (targetNode === null) { return; + } else if ((treeNodes && treeNodes[0] && treeNodes[0].menuType == 'innerMenu') || targetNode.menuType == 'innerMenu') { + // 内部菜单不可拖拽 + return false; } else if (moveType === 'inner' && targetNode.type === 1) { return false; } else if ((moveType === 'prev' || moveType === 'next') && !targetNode.parentId) { @@ -289,10 +368,100 @@ export default { }, openAuthorityViewDialog() { this.isShowAuthorityViewDialog = true; + }, + updateMenu() { + this.$store.dispatch('updateMenu'); + }, + handleChildren(moduleId, moduleName, menuGroupList) { + let list = []; + if (this.$utils.isEmpty(menuGroupList)) { + return list; + } + menuGroupList.forEach((item) => { + if (item.menuTypeName) { + list.push({ + id: item.menuType || this.$utils.setUuid(), + name: item.menuTypeName, + menuType: 'innerMenu', + moduleId: moduleId, + moduleName: moduleName, + children: item.menuList.map((v) => ({ + id: v.path, + name: v.name, + menuType: 'innerMenu', + isMenu: true, + moduleId: moduleId, + moduleName: moduleName + }) + ) + }); + } + }); + return list; + }, + handleRouterAuth() { + const pageConfig = require.context('@/views/pages', true, /router.js$/); + const commercialConfig = require.context('@/commercial-module', true, /router.js$/); + const routerConfig = {}; + const routerConfigKeys = pageConfig.keys(); + const commercialConfigKeys = commercialConfig.keys() || []; + routerConfigKeys.forEach(routerPath => { + const moduleId = routerPath.split('/')[1]; + const routeList = (!this.$utils.isEmpty(commercialConfigKeys) && commercialConfigKeys.indexOf(routerPath) != -1) ? [...pageConfig(routerPath).default, ...(commercialConfig[routerPath] && commercialConfig[routerPath].default || [])] : (pageConfig(routerPath).default || []); + const menuList = routeList + .filter(item => item.meta && item.meta.authority) + .map(item => ({ + title: item.meta.title, + name: item.name, + path: item.path, + authority: item.meta.authority ? (typeof item.meta.authority == 'string' ? item.meta.authority : (typeof item.meta.authority == 'object' ? item.meta.authority.join(',') : '')) : '' + })); + if (menuList.length) { + routerConfig[moduleId] = menuList; + } + }); + return routerConfig; } }, filter: {}, - computed: {}, + computed: { + moduleList() { + const moduleList = []; + this.$store.state.topMenu.moduleList.forEach((item, index) => { + if (item.moduleId && item.moduleName) { + moduleList.push({ + id: item.moduleId, + name: item.moduleName, + children: this.handleChildren(item.moduleId, item.moduleName, item.menuGroupList), + menuType: 'innerMenu', + moduleId: item.moduleId, + moduleName: item.moduleName + }); + } + }); + return [ + { + id: 0, + name: this.$t('page.allofthem'), + menuType: 'innerMenu', // 用于判断不能新增和编辑菜单 + children: [ + { + id: this.$utils.setUuid(), + name: this.$t('term.framework.internalmenu'), + children: moduleList, + menuType: 'innerMenu' + }, + { + id: 0, + name: this.$t('term.framework.custommenu'), + children: this.nodeList, + menuType: !this.$utils.isEmpty(this.nodeList) ? 'innerMenu' : '' //自定义菜单没有子菜单,可以新增一个目录,存在不能新增 + } + ] + } + ]; + } + }, watch: {} }; -- Gitee