fix: normalize dashboard nav path matching

This commit is contained in:
liuwei
2026-04-07 12:56:48 +08:00
parent 684a22b3a6
commit 2938a6b056

View File

@@ -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));
},