From 89a5a346d3469a554ad2dc47244967d378da30be Mon Sep 17 00:00:00 2001 From: chenxing Date: Thu, 17 Sep 2026 01:10:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(portal):=20=E6=9C=8D=E5=8A=A1=E4=B8=AD?= =?UTF-8?q?=E5=BF=83/=E6=8C=87=E5=8D=97=E9=A1=B5=E9=A1=B6=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E9=AB=98=E4=BA=AE=E2=80=94=E2=80=94=E5=A4=96=E9=93=BE?= =?UTF-8?q?=E6=A0=8F=E7=9B=AE=E5=8C=B9=E9=85=8D=E4=B8=BA=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E6=A0=8F=E7=9B=AE=EF=BC=8C=E9=A6=96=E9=A1=B5=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E8=AF=AF=E9=AB=98=E4=BA=AE=EF=BC=888=20=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E5=85=9C=E5=BA=95=20navServiceActive=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/portal/PortalController.java | 67 +++++++++++++++++++ .../themes/blue-white/fragments/header.html | 2 +- .../themes/campus-glow/fragments/header.html | 2 +- .../themes/classic-red/fragments/header.html | 2 +- .../themes/default/fragments/header.html | 2 +- .../themes/fresh-mint/fragments/header.html | 2 +- .../themes/mint-breeze/fragments/header.html | 2 +- .../themes/scholar-blue/fragments/header.html | 2 +- .../themes/warm-kinder/fragments/header.html | 2 +- 9 files changed, 75 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/yunhai/cms/controller/portal/PortalController.java b/src/main/java/com/yunhai/cms/controller/portal/PortalController.java index eda9eb7..a6adc50 100644 --- a/src/main/java/com/yunhai/cms/controller/portal/PortalController.java +++ b/src/main/java/com/yunhai/cms/controller/portal/PortalController.java @@ -343,6 +343,7 @@ public class PortalController { } String effectiveTheme = pageRenderer.resolveEffectiveTheme(site, "service.html"); PortalUrlHelper url = buildUrl(site, request, effectiveTheme); + applyServiceNavHighlight(site, url, model); SvcItemPortalQuery query = new SvcItemPortalQuery(); query.setSiteId(site.getId()); @@ -442,6 +443,7 @@ public class PortalController { } String effectiveTheme = pageRenderer.resolveEffectiveTheme(site, "guide.html"); PortalUrlHelper url = buildUrl(site, request, effectiveTheme); + applyServiceNavHighlight(site, url, model); model.addAttribute("svcUnavailable", svcUnavailable); if (svcUnavailable) { addChromeAttributes(model, site, request, effectiveTheme, url, "服务中心 - " + site.getName()); @@ -515,6 +517,71 @@ public class PortalController { return "themes/" + effectiveTheme + "/guide"; } + /** + * 服务中心/指南页的顶导航高亮:服务中心页不是栏目页,currentCategoryId 为空会让 + * 皮肤 header 的"首页"误高亮。若站点导航里存在指向本站服务中心列表页的外链栏目 + * (type=3,如"服务中心"),则把它视为当前栏目——既有高亮逻辑即同时达成 + * "首页不高亮 + 服务中心高亮";找不到匹配栏目时置 navServiceActive, + * 皮肤以该标记单独关闭"首页"高亮(无服务中心入口的站点保持原状)。 + */ + private void applyServiceNavHighlight(PortalSiteSnapshot site, PortalUrlHelper url, Model model) { + String servicePath = pathOf(url.serviceList()); + Integer matched = null; + if (servicePath != null) { + for (PortalCategory cat : site.getCategories()) { + if (isServiceNavLink(cat, servicePath)) { + matched = cat.getId(); + break; + } + for (PortalCategory sub : cat.getChildren()) { + if (isServiceNavLink(sub, servicePath)) { + matched = sub.getId(); + break; + } + } + if (matched != null) { + break; + } + } + } + if (matched != null) { + model.addAttribute("currentCategoryId", matched); + } else { + model.addAttribute("navServiceActive", true); + } + } + + private boolean isServiceNavLink(PortalCategory cat, String servicePath) { + Integer type = cat.getType(); + return type != null && type == CategoryTypeEnum.LINK.getCode() + && servicePath.equals(pathOf(cat.getLinkUrl())); + } + + /** 取 URL 的归一化路径:剥 scheme://host / query / fragment / 尾斜杠(相对链接原样返回路径) */ + private static String pathOf(String url) { + if (url == null) { + return null; + } + String u = url.trim(); + int hash = u.indexOf('#'); + if (hash >= 0) { + u = u.substring(0, hash); + } + int query = u.indexOf('?'); + if (query >= 0) { + u = u.substring(0, query); + } + while (u.endsWith("/")) { + u = u.substring(0, u.length() - 1); + } + int scheme = u.indexOf("://"); + if (scheme >= 0) { + int slash = u.indexOf('/', scheme + 3); + u = slash >= 0 ? u.substring(slash) : ""; + } + return u.isEmpty() ? null : u; + } + /** 门户页面公共骨架属性(P1-4 降级路径与正常路径共用;q/seoDescription 等页面特有属性由调用方补) */ private void addChromeAttributes(Model model, PortalSiteSnapshot site, HttpServletRequest request, String effectiveTheme, PortalUrlHelper url, String pageTitle) { diff --git a/src/main/resources/templates/themes/blue-white/fragments/header.html b/src/main/resources/templates/themes/blue-white/fragments/header.html index 5395271..195a80d 100644 --- a/src/main/resources/templates/themes/blue-white/fragments/header.html +++ b/src/main/resources/templates/themes/blue-white/fragments/header.html @@ -29,7 +29,7 @@