From d37a1ffbd58617602f729b0a0e738808f25de918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 16 Jun 2022 20:51:18 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=8F=9C=E5=8D=95=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=86=85=E9=93=BE=E6=89=93=E5=BC=80=E5=A4=96=E7=BD=91?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Model/System/UserConstants.cs | 3 +- ZR.Model/System/Vo/RouterVo.cs | 15 ++++++++- ZR.Service/System/SysMenuService.cs | 48 ++++++++++++++++++++--------- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/ZR.Model/System/UserConstants.cs b/ZR.Model/System/UserConstants.cs index e0906f7..8751269 100644 --- a/ZR.Model/System/UserConstants.cs +++ b/ZR.Model/System/UserConstants.cs @@ -56,7 +56,8 @@ namespace ZR.Model.System public static string LAYOUT = "Layout"; /** ParentView组件标识 */ public static string PARENT_VIEW = "ParentView"; - + /** InnerLink组件标识 */ + public static string INNER_LINK = "InnerLink"; /** 校验返回结果码 */ public static string UNIQUE = "0"; public static string NOT_UNIQUE = "1"; diff --git a/ZR.Model/System/Vo/RouterVo.cs b/ZR.Model/System/Vo/RouterVo.cs index 9c0140d..b48fa2f 100644 --- a/ZR.Model/System/Vo/RouterVo.cs +++ b/ZR.Model/System/Vo/RouterVo.cs @@ -39,19 +39,32 @@ namespace ZR.Model.System.Vo /// public bool NoCache { get; set; } public string TitleKey { get; set; } = string.Empty; + public string Link { get; set; } = string.Empty; + public Meta(string title, string icon) + { + Title = title; + Icon = icon; + } + public Meta(string title, string icon, string path) + { + Title = title; + Icon = icon; + Link = path; + } public Meta(string title, string icon, bool noCache) { Title = title; Icon = icon; NoCache = noCache; } - public Meta(string title, string icon, bool noCache, string titleKey) + public Meta(string title, string icon, bool noCache, string titleKey, string path) { Title = title; Icon = icon; NoCache = noCache; TitleKey = titleKey; + Link = path; } } } diff --git a/ZR.Service/System/SysMenuService.cs b/ZR.Service/System/SysMenuService.cs index 9154000..e0d4631 100644 --- a/ZR.Service/System/SysMenuService.cs +++ b/ZR.Service/System/SysMenuService.cs @@ -8,6 +8,7 @@ using ZR.Model.Vo.System; using ZR.Repository.System; using ZR.Service.System.IService; using ZR.Common; +using Infrastructure.Extensions; namespace ZR.Service { @@ -281,13 +282,13 @@ namespace ZR.Service foreach (var menu in menus) { - RouterVo router = new RouterVo + RouterVo router = new() { Hidden = "1".Equals(menu.visible), Name = GetRouteName(menu), Path = GetRoutePath(menu), Component = GetComponent(menu), - Meta = new Meta(menu.MenuName, menu.icon, "1".Equals(menu.isCache), menu.MenuNameKey) + Meta = new Meta(menu.MenuName, menu.icon, "1".Equals(menu.isCache), menu.MenuNameKey, menu.path) }; List cMenus = menu.children; @@ -300,17 +301,32 @@ namespace ZR.Service } else if (IsMeunFrame(menu)) { - List childrenList = new List(); - RouterVo children = new RouterVo + router.Meta = null; + List childrenList = new(); + RouterVo children = new() { Path = menu.path, Component = menu.component, Name = string.IsNullOrEmpty(menu.path) ? "" : menu.path.ToLower(), - Meta = new Meta(menu.MenuName, menu.icon, "1".Equals(menu.isCache), menu.MenuNameKey) + Meta = new Meta(menu.MenuName, menu.icon, "1".Equals(menu.isCache), menu.MenuNameKey, menu.path) }; childrenList.Add(children); router.Children = childrenList; } + else if (menu.parentId == 0 && IsInnerLink(menu)) + { + router.Meta = new Meta(menu.MenuName, menu.icon); + router.Path = "/"; + List childrenList = new(); + RouterVo children = new(); + string routerPath = InnerLinkReplaceEach(menu.path); + children.Path = routerPath; + children.Component = UserConstants.INNER_LINK; + children.Name = routerPath.ToLower(); + children.Meta = new Meta(menu.MenuName, menu.icon, menu.path); + childrenList.Add(children); + router.Children = childrenList; + } routers.Add(router); } @@ -384,10 +400,10 @@ namespace ZR.Service { string routerPath = menu.path; // 内链打开外网方式 - //if (menu.parentId != 0 && IsInnerLink(menu)) - //{ - // routerPath = innerLinkReplaceEach(routerPath); - //} + if (menu.parentId != 0 && IsInnerLink(menu)) + { + routerPath = InnerLinkReplaceEach(routerPath); + } // 非外链并且是一级目录(类型为目录) if (0 == menu.parentId && UserConstants.TYPE_DIR.Equals(menu.menuType) && UserConstants.NO_FRAME.Equals(menu.isFrame)) @@ -413,6 +429,10 @@ namespace ZR.Service { component = menu.component; } + else if (menu.component.IsEmpty() && menu.parentId != 0 && IsInnerLink(menu)) + { + component = UserConstants.INNER_LINK; + } else if (string.IsNullOrEmpty(menu.component) && IsParentView(menu)) { component = UserConstants.PARENT_VIEW; @@ -451,16 +471,16 @@ namespace ZR.Service { return menu.parentId != 0 && UserConstants.TYPE_DIR.Equals(menu.menuType); } + /// /// 内链域名特殊字符替换 /// /// /// < returns > - //public string innerLinkReplaceEach(string path) - //{ - // return stringUtils.replaceEach(path, new String[] { Constants.HTTP, Constants.HTTPS }, - // new String[] { "", "" }); - //} + public string InnerLinkReplaceEach(string path) + { + return path.IsNotEmpty() ? path.Replace(UserConstants.HTTP, "").Replace(UserConstants.HTTPS, "") : path; + } #endregion }