diff --git a/java/cloud/common/src/main/java/cn/toesbieya/jxc/common/enumeration/ResourceTypeEnum.java b/java/cloud/common/src/main/java/cn/toesbieya/jxc/common/enumeration/ResourceTypeEnum.java index 8e63c76..21152a8 100644 --- a/java/cloud/common/src/main/java/cn/toesbieya/jxc/common/enumeration/ResourceTypeEnum.java +++ b/java/cloud/common/src/main/java/cn/toesbieya/jxc/common/enumeration/ResourceTypeEnum.java @@ -1,7 +1,7 @@ package cn.toesbieya.jxc.common.enumeration; public enum ResourceTypeEnum { - FOLDER(1), LEAF(2), API(3); + ROOT(0), FOLDER(1), LEAF(2), API(3); private final int code; diff --git a/java/cloud/web/web-modules/system/src/main/java/cn/toesbieya/jxc/system/service/ResourceService.java b/java/cloud/web/web-modules/system/src/main/java/cn/toesbieya/jxc/system/service/ResourceService.java index 8e5e8f3..0cf4013 100644 --- a/java/cloud/web/web-modules/system/src/main/java/cn/toesbieya/jxc/system/service/ResourceService.java +++ b/java/cloud/web/web-modules/system/src/main/java/cn/toesbieya/jxc/system/service/ResourceService.java @@ -43,7 +43,11 @@ public class ResourceService implements ResourceApi { return Collections.emptyList(); } - return getEnableResourceTree(ids, i -> !i.getType().equals(ResourceTypeEnum.FOLDER.getCode())); + return getEnableResourceTree(ids, i -> { + Integer type = i.getType(); + return !type.equals(ResourceTypeEnum.ROOT.getCode()) + && !type.equals(ResourceTypeEnum.FOLDER.getCode()); + }); } public R add(SysResource entity) { @@ -100,7 +104,7 @@ public class ResourceService implements ResourceApi { } String path = r.getPath(); - int index = path.indexOf("//"); + int index = path.lastIndexOf("//"); if (index != -1 && !path.startsWith("http")) { //去掉'//'前拼接的父节点的path r.setPath(path.substring(index + 1)); @@ -116,11 +120,9 @@ public class ResourceService implements ResourceApi { Integer pid = entity.getPid(); Integer type = entity.getType(); - boolean isApi = type.equals(ResourceTypeEnum.API.getCode()); - - //根节点不能为数据接口 - if (pid.equals(0)) { - return isApi ? "数据接口不能作为根节点" : null; + //顶部菜单的pid必须为0 + if (type.equals(ResourceTypeEnum.ROOT.getCode())) { + return pid.equals(0) ? null : "顶部菜单不能有父节点"; } //校验父节点 @@ -130,6 +132,7 @@ public class ResourceService implements ResourceApi { } Integer parentType = parent.getType(); //1.待添加的节点为数据接口且父节点必须为叶子菜单 + boolean isApi = type.equals(ResourceTypeEnum.API.getCode()); if (isApi) { if (!parentType.equals(ResourceTypeEnum.LEAF.getCode())) { return "数据接口只能以页面菜单为父节点"; @@ -144,22 +147,23 @@ public class ResourceService implements ResourceApi { //数据转换 private void transform(SysResource entity) { - Integer pid = entity.getPid(); Integer type = entity.getType(); + boolean isRoot = type.equals(ResourceTypeEnum.ROOT.getCode()); boolean isFolder = type.equals(ResourceTypeEnum.FOLDER.getCode()); + boolean isLeaf = type.equals(ResourceTypeEnum.LEAF.getCode()); + boolean isApi = type.equals(ResourceTypeEnum.API.getCode()); //能自定义component的只有叶子菜单 - if (!type.equals(ResourceTypeEnum.LEAF.getCode())) { - //根节点的聚合菜单的组件只能为'Layout' - boolean isRootFolder = isFolder && pid.equals(0); - entity.setComponent(isRootFolder ? "Layout" : null); + if (!isLeaf) { + //顶部菜单的组件只能为'Layout' + entity.setComponent(isRoot ? "Layout" : null); } - //聚合菜单不能设置name - if (isFolder) { + //顶部或聚合菜单不能设置name(此处的name是路由名称) + if (isRoot || isFolder) { entity.setName(null); } //数据接口不能设置meta - if (type.equals(ResourceTypeEnum.API.getCode())) { + if (isApi) { entity.setMeta(null); } } diff --git a/java/db/my.rar b/java/db/my.rar index 7c458dd..62f75a0 100644 Binary files a/java/db/my.rar and b/java/db/my.rar differ diff --git a/java/local/src/main/java/cn/toesbieya/jxc/enumeration/ResourceTypeEnum.java b/java/local/src/main/java/cn/toesbieya/jxc/enumeration/ResourceTypeEnum.java index e0f1bc7..42d9f33 100644 --- a/java/local/src/main/java/cn/toesbieya/jxc/enumeration/ResourceTypeEnum.java +++ b/java/local/src/main/java/cn/toesbieya/jxc/enumeration/ResourceTypeEnum.java @@ -1,7 +1,7 @@ package cn.toesbieya.jxc.enumeration; public enum ResourceTypeEnum { - FOLDER(1), LEAF(2), API(3); + ROOT(0), FOLDER(1), LEAF(2), API(3); private final int code; diff --git a/java/local/src/main/java/cn/toesbieya/jxc/service/sys/SysResourceService.java b/java/local/src/main/java/cn/toesbieya/jxc/service/sys/SysResourceService.java index 714bda0..2ba7c95 100644 --- a/java/local/src/main/java/cn/toesbieya/jxc/service/sys/SysResourceService.java +++ b/java/local/src/main/java/cn/toesbieya/jxc/service/sys/SysResourceService.java @@ -41,7 +41,11 @@ public class SysResourceService { return Collections.emptyList(); } - return getEnableResourceTree(ids, i -> !i.getType().equals(ResourceTypeEnum.FOLDER.getCode())); + return getEnableResourceTree(ids, i -> { + Integer type = i.getType(); + return !type.equals(ResourceTypeEnum.ROOT.getCode()) + && !type.equals(ResourceTypeEnum.FOLDER.getCode()); + }); } public R add(SysResource entity) { @@ -99,7 +103,7 @@ public class SysResourceService { } String path = r.getPath(); - int index = path.indexOf("//"); + int index = path.lastIndexOf("//"); if (index != -1 && !path.startsWith("http")) { //去掉'//'前拼接的父节点的path r.setPath(path.substring(index + 1)); @@ -115,11 +119,9 @@ public class SysResourceService { Integer pid = entity.getPid(); Integer type = entity.getType(); - boolean isApi = type.equals(ResourceTypeEnum.API.getCode()); - - //根节点不能为数据接口 - if (pid.equals(0)) { - return isApi ? "数据接口不能作为根节点" : null; + //顶部菜单的pid必须为0 + if (type.equals(ResourceTypeEnum.ROOT.getCode())) { + return pid.equals(0) ? null : "顶部菜单不能有父节点"; } //校验父节点 @@ -129,6 +131,7 @@ public class SysResourceService { } Integer parentType = parent.getType(); //1.待添加的节点为数据接口且父节点必须为叶子菜单 + boolean isApi = type.equals(ResourceTypeEnum.API.getCode()); if (isApi) { if (!parentType.equals(ResourceTypeEnum.LEAF.getCode())) { return "数据接口只能以页面菜单为父节点"; @@ -143,22 +146,23 @@ public class SysResourceService { //数据转换 private void transform(SysResource entity) { - Integer pid = entity.getPid(); Integer type = entity.getType(); + boolean isRoot = type.equals(ResourceTypeEnum.ROOT.getCode()); boolean isFolder = type.equals(ResourceTypeEnum.FOLDER.getCode()); + boolean isLeaf = type.equals(ResourceTypeEnum.LEAF.getCode()); + boolean isApi = type.equals(ResourceTypeEnum.API.getCode()); //能自定义component的只有叶子菜单 - if (!type.equals(ResourceTypeEnum.LEAF.getCode())) { - //根节点的聚合菜单的组件只能为'Layout' - boolean isRootFolder = isFolder && pid.equals(0); - entity.setComponent(isRootFolder ? "Layout" : null); + if (!isLeaf) { + //顶部菜单的组件只能为'Layout' + entity.setComponent(isRoot ? "Layout" : null); } - //聚合菜单不能设置name - if (isFolder) { + //顶部或聚合菜单不能设置name(此处的name是路由名称) + if (isRoot || isFolder) { entity.setName(null); } //数据接口不能设置meta - if (type.equals(ResourceTypeEnum.API.getCode())) { + if (isApi) { entity.setMeta(null); } } diff --git a/vue/element-ui-personal/component/Menu/Submenu.vue b/vue/element-ui-personal/component/Menu/Submenu.vue index 1369cc4..fcef7d1 100644 --- a/vue/element-ui-personal/component/Menu/Submenu.vue +++ b/vue/element-ui-personal/component/Menu/Submenu.vue @@ -272,7 +272,3 @@ export default { } } - - diff --git a/vue/src/App.vue b/vue/src/App.vue index 69fb943..0ef3762 100644 --- a/vue/src/App.vue +++ b/vue/src/App.vue @@ -1,8 +1,6 @@ diff --git a/vue/src/asset/icon/index.js b/vue/src/asset/icon/index.js index e90beeb..b72ebbe 100644 --- a/vue/src/asset/icon/index.js +++ b/vue/src/asset/icon/index.js @@ -1,5 +1,5 @@ import Vue from 'vue' -import VIcon from '@/component/VIcon' +import VIcon from '@/component/Icon' Vue.component('v-icon', VIcon) diff --git a/vue/src/component/VIcon/index.vue b/vue/src/component/Icon/index.vue similarity index 89% rename from vue/src/component/VIcon/index.vue rename to vue/src/component/Icon/index.vue index 2a1c57c..158feb7 100644 --- a/vue/src/component/VIcon/index.vue +++ b/vue/src/component/Icon/index.vue @@ -19,7 +19,7 @@ export default { ) } - return + return } } @@ -29,6 +29,5 @@ export default { width: 1em; height: 1em; fill: currentColor; - overflow: hidden; } diff --git a/vue/src/layout/component/Main.vue b/vue/src/layout/component/Main.vue index 5e3f9ad..6086fca 100644 --- a/vue/src/layout/component/Main.vue +++ b/vue/src/layout/component/Main.vue @@ -70,7 +70,6 @@ export default { background-color: #f5f7f9; .scroll-container { - position: relative; height: 100%; display: flex; flex-direction: column; diff --git a/vue/src/layout/component/Navbar/component/RootMenu.vue b/vue/src/layout/component/Navbar/component/RootMenu.vue new file mode 100644 index 0000000..6c20d78 --- /dev/null +++ b/vue/src/layout/component/Navbar/component/RootMenu.vue @@ -0,0 +1,80 @@ + + + diff --git a/vue/src/layout/component/Navbar/index.vue b/vue/src/layout/component/Navbar/index.vue index bab43bf..d9b5d29 100644 --- a/vue/src/layout/component/Navbar/index.vue +++ b/vue/src/layout/component/Navbar/index.vue @@ -4,6 +4,8 @@ + +
@@ -51,8 +53,8 @@ import GuideMixin from '@/mixin/guide' import Bell from "./component/Bell" import Breadcrumb from './component/Breadcrumb' import Hamburger from './component/Hamburger' +import RootMenu from "./component/RootMenu" import SettingDrawer from './component/SettingDrawer' -import {auth} from "@/util/auth" import {elConfirm} from "@/util/message" export default { @@ -60,11 +62,13 @@ export default { mixins: [GuideMixin.navbar], - components: {Hamburger, Breadcrumb, Bell, SettingDrawer}, + components: {Hamburger, Breadcrumb, Bell, RootMenu, SettingDrawer}, data: () => ({settingDrawer: false}), computed: { + ...mapState('resource', ['activeRootMenu', 'menus']), + ...mapState('user', ['avatar', 'name', 'prepareLogout']), ...mapState('setting', ['sidebarCollapse', 'showBreadcrumb']) @@ -74,6 +78,7 @@ export default { sidebarCtrl() { this.$store.commit('setting/sidebarCollapse', !this.sidebarCollapse) }, + refresh() { this.$router.replace({path: `/redirect${this.$route.fullPath}`}) }, diff --git a/vue/src/layout/component/Sidebar/component/SidebarItem.vue b/vue/src/layout/component/Sidebar/component/SidebarItem.vue index 717ab70..ee61402 100644 --- a/vue/src/layout/component/Sidebar/component/SidebarItem.vue +++ b/vue/src/layout/component/Sidebar/component/SidebarItem.vue @@ -14,7 +14,7 @@ function getOnlyChild(menu) { function renderSingleMenu(h, {index, icon, title}) { return ( - + ) @@ -22,7 +22,7 @@ function renderSingleMenu(h, {index, icon, title}) { function renderSubMenu(h, {index, icon, title, children}) { return ( - + {children} diff --git a/vue/src/layout/component/Sidebar/component/SidebarItemContent.vue b/vue/src/layout/component/Sidebar/component/SidebarItemContent.vue index 53b9e53..c0c7e6b 100644 --- a/vue/src/layout/component/Sidebar/component/SidebarItemContent.vue +++ b/vue/src/layout/component/Sidebar/component/SidebarItemContent.vue @@ -4,10 +4,7 @@ export default { functional: true, - props: { - icon: String, - title: String - }, + props: {icon: String, title: String}, render(h, context) { const {icon, title} = context.props diff --git a/vue/src/layout/component/Sidebar/index.vue b/vue/src/layout/component/Sidebar/index.vue index 9d313f4..91c76a5 100644 --- a/vue/src/layout/component/Sidebar/index.vue +++ b/vue/src/layout/component/Sidebar/index.vue @@ -1,31 +1,42 @@