Update admin.js

This commit is contained in:
Furrium Network authored and GitHub committed 2026-08-10 12:44:56 +08:00
1 parent d87f1b2ab9
commit 0953234bc9
1 file changed
+16 -7
+16 -7
View File
@@ -597,13 +597,23 @@ function loadCustomCSS() {
} }
// ============================================================ // ============================================================
// 管理后台Tab切换 // 管理后台Tab切换(侧边栏适配)
// ============================================================ // ============================================================
document.querySelectorAll('.admin-tab').forEach(tab => { // 使用事件委托监听 .admin-nav 下的点击
tab.addEventListener('click', function() { document.querySelector('.admin-nav')?.addEventListener('click', function(e) {
document.querySelectorAll('.admin-tab').forEach(t => t.classList.remove('active')); const tabLink = e.target.closest('.admin-nav-item');
this.classList.add('active'); if (!tabLink) return;
e.preventDefault();
const tab = tabLink.dataset.tab;
if (!tab) return;
// 切换高亮
document.querySelectorAll('.admin-nav-item').forEach(el => el.classList.remove('active'));
tabLink.classList.add('active');
// 渲染对应内容
const tabMap = { const tabMap = {
reports: renderAdminReports, reports: renderAdminReports,
users: renderAdminUsers, users: renderAdminUsers,
@@ -612,8 +622,7 @@ document.querySelectorAll('.admin-tab').forEach(tab => {
settings: renderAdminSettings, settings: renderAdminSettings,
custom: renderAdminCustomPages custom: renderAdminCustomPages
}; };
if (tabMap[this.dataset.tab]) tabMap[this.dataset.tab](); if (tabMap[tab]) tabMap[tab]();
});
}); });
// 页面加载时尝试加载自定义 CSS // 页面加载时尝试加载自定义 CSS