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 @@