From f2c83958b4b7bfb5f68cdbc1019ae4c60f0b770c 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: Tue, 21 Dec 2021 17:56:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Common/Tools.cs | 19 +++++++++++++ ZR.Model/System/UserConstants.cs | 10 +++++++ ZR.Service/System/SysMenuService.cs | 41 ++++++++++++++++++++++++----- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/ZR.Common/Tools.cs b/ZR.Common/Tools.cs index 1215a39..eee60ab 100644 --- a/ZR.Common/Tools.cs +++ b/ZR.Common/Tools.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Text.RegularExpressions; namespace ZR.Common { @@ -60,5 +61,23 @@ namespace ZR.Common : (diffday / 7)) + 1 + (dayInMonth > firstWeekEndDay ? 1 : 0); return weekNumInMonth; } + /// + /// 判断一个字符串是否为url + /// + /// + /// + public static bool IsUrl(string str) + { + try + { + string Url = @"^http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?$"; + return Regex.IsMatch(str, Url); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return false; + } + } } } diff --git a/ZR.Model/System/UserConstants.cs b/ZR.Model/System/UserConstants.cs index bc68af6..e0906f7 100644 --- a/ZR.Model/System/UserConstants.cs +++ b/ZR.Model/System/UserConstants.cs @@ -60,5 +60,15 @@ namespace ZR.Model.System /** 校验返回结果码 */ public static string UNIQUE = "0"; public static string NOT_UNIQUE = "1"; + + /// + /// http请求 + /// + public static string HTTP = "http://"; + + /// + /// https请求 + /// + public static string HTTPS = "https://"; } } diff --git a/ZR.Service/System/SysMenuService.cs b/ZR.Service/System/SysMenuService.cs index 1afff0b..c1eedda 100644 --- a/ZR.Service/System/SysMenuService.cs +++ b/ZR.Service/System/SysMenuService.cs @@ -8,6 +8,7 @@ using ZR.Model.Vo; using ZR.Model.Vo.System; using ZR.Repository.System; using ZR.Service.System.IService; +using ZR.Common; namespace ZR.Service { @@ -359,17 +360,23 @@ namespace ZR.Service /// 路由地址 public string GetRoutePath(SysMenu menu) { - string routePath = menu.path; + string routerPath = menu.path; + // 内链打开外网方式 + //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)) + if (0 == menu.parentId && UserConstants.TYPE_DIR.Equals(menu.menuType) + && UserConstants.NO_FRAME.Equals(menu.isFrame)) { - routePath = "/" + menu.path; + routerPath = "/" + menu.path; } else if (IsMeunFrame(menu))// 非外链并且是一级目录(类型为菜单) { - routePath = "/"; + routerPath = "/"; } - return routePath; + return routerPath; } /// @@ -398,7 +405,18 @@ namespace ZR.Service /// public bool IsMeunFrame(SysMenu menu) { - return menu.parentId == 0 && UserConstants.TYPE_MENU.Equals(menu.menuType) && menu.isFrame.Equals(UserConstants.NO_FRAME); + return menu.parentId == 0 && UserConstants.TYPE_MENU.Equals(menu.menuType) + && menu.isFrame.Equals(UserConstants.NO_FRAME); + } + + /// + /// 是否为内链组件 + /// + /// 菜单信息 + /// 结果 + public bool IsInnerLink(SysMenu menu) + { + return menu.isFrame.Equals(UserConstants.NO_FRAME) && Tools.IsUrl(menu.path); } /// @@ -411,7 +429,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[] { "", "" }); + //} #endregion }