From 2938a6b056058e0e2e97d8f0d0d3a911989efe27 Mon Sep 17 00:00:00 2001 From: liuwei Date: Tue, 7 Apr 2026 12:56:48 +0800 Subject: [PATCH] fix: normalize dashboard nav path matching --- admin/dashboard/templates/base.html | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/admin/dashboard/templates/base.html b/admin/dashboard/templates/base.html index fb1444a..160c1f8 100644 --- a/admin/dashboard/templates/base.html +++ b/admin/dashboard/templates/base.html @@ -661,9 +661,7 @@ defaultPath: '/messages', items: [ { label: '消息列表', path: '/messages' }, - { label: '定时推送', path: '/message_push' }, - { label: '运行日志', path: '/wx_logs' }, - { label: '错误日志', path: '/errors' } + { label: '定时推送', path: '/message_push' } ] }, { @@ -710,7 +708,9 @@ items: [ { label: '用户统计', path: '/users' }, { label: '资源监控', path: '/system_status' }, - { label: '文件浏览', path: '/file_browser' } + { label: '文件浏览', path: '/file_browser' }, + { label: '运行日志', path: '/wx_logs' }, + { label: '错误日志', path: '/errors' } ] } ]; @@ -726,9 +726,9 @@ }, computed: { activeGroup() { - const path = window.location.pathname; + const path = this.normalizePath(window.location.pathname); const matched = this.navGroups.find(group => - group.items.some(item => item.path === path) + group.items.some(item => this.normalizePath(item.path) === path) ); return matched ? matched.key : 'overview'; }, @@ -747,18 +747,25 @@ document.querySelector('.app-container').classList.add('loaded'); }, methods: { + normalizePath(path) { + if (!path) return '/'; + if (path.length > 1 && path.endsWith('/')) { + return path.slice(0, -1); + } + return path; + }, isPathActive(path) { - return window.location.pathname === path; + return this.normalizePath(window.location.pathname) === this.normalizePath(path); }, go(path) { - if (path && window.location.pathname !== path) { + if (path && this.normalizePath(window.location.pathname) !== this.normalizePath(path)) { window.location.href = path; } }, goToPrimary(group) { if (!group) return; - const current = window.location.pathname; - const ownPaths = (group.items || []).map(item => item.path); + const current = this.normalizePath(window.location.pathname); + const ownPaths = (group.items || []).map(item => this.normalizePath(item.path)); if (ownPaths.includes(current)) return; this.go(group.defaultPath || (group.items && group.items[0] && group.items[0].path)); },