refactor(frontend): 抽离公共导航组件,消除各页面重复代码

- 创建 navigation-component.js:统一的PC左边栏 + H5底部导航组件
- 重构 topics.html、logs.html、admin.html、users.html、index.html
- 删除各页面重复的 sidebar 和 mobile-nav HTML 结构
- 删除重复的导航样式定义,由组件统一提供
- 修复 component 插入重复的问题,确保每个页面只插入一次

现在修改导航只需更新组件文件,无需改动每个页面,提升维护性。
This commit is contained in:
lt
2026-05-08 10:36:51 +08:00
parent 284b18e5fc
commit b8d9e0c209
6 changed files with 296 additions and 163 deletions
+20 -84
View File
@@ -88,42 +88,10 @@
flex-direction: column;
gap: 4px;
}
.sidebar-btn {
width: 100%;
text-align: left;
padding: 12px 16px;
border: none;
background: transparent;
border-radius: 12px;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
color: #a0aec0;
font-size: 14px;
font-weight: 500;
position: relative;
overflow: hidden;
}
.sidebar-btn:hover {
background: rgba(102, 126, 234, 0.1);
color: #667eea;
transform: translateX(4px);
}
.sidebar-btn.active {
background: linear-gradient(90deg, rgba(102, 126, 234, 0.2), rgba(118, 75, 162, 0.2));
color: #667eea;
font-weight: 600;
box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}
.sidebar-btn.active::after {
content: '';
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 3px;
background: linear-gradient(180deg, #667eea, #764ba2);
border-radius: 0 4px 4px 0;
}
/* 内容区域 */
.content-area {
@@ -276,33 +244,9 @@
z-index: 1000;
box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
}
.mobile-nav-btn {
flex: 1;
border: none;
background: transparent;
padding: 12px 8px;
text-align: center;
font-size: 12px;
color: #a0aec0;
cursor: pointer;
transition: all 0.3s;
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
}
.mobile-nav-btn.active {
color: #667eea;
font-weight: 600;
}
.mobile-nav-btn.active::before {
content: '';
width: 4px;
height: 4px;
border-radius: 50%;
background: linear-gradient(135deg, #667eea, #764ba2);
margin-bottom: 2px;
}
/* 响应式 */
@media (max-width: 768px) {
@@ -328,15 +272,17 @@
.user-info { color: white !important; }
.avatar { background: rgba(255,255,255,0.2) !important; color: white !important; }
.sidebar { background: white !important; border-right: 1px solid #ebeef5 !important; backdrop-filter: none !important; }
.sidebar-btn { color: #606266 !important; }
.sidebar-btn:hover, .sidebar-btn.active { background: #ecf5ff !important; color: #409eff !important; }
.mobile-nav { background: white !important; border-top: 1px solid #ebeef5 !important; backdrop-filter: none !important; box-shadow: 0 -2px 8px rgba(0,0,0,0.1) !important; }
.mobile-nav-btn { color: #606266 !important; }
.mobile-nav-btn.active { color: #409eff !important; }
.mobile-nav-btn.active::before { content: none !important; display: none !important; }
#page-overview h2, #page-overview h3, #page-overview .module-title { color: #303133 !important; }
#page-overview .module-content { color: #303133 !important; }
</style>
<script src="navigation-component.js"></script>
</head>
<body>
<div id="app">
@@ -354,22 +300,12 @@
</div>
</nav>
<div class="main-content" v-if="isLoggedIn">
<aside class="sidebar">
<button class="sidebar-btn" :class="{ active: currentPage === 'overview' }" @click="redirectToPage('/')">
📊 系统概览
</button>
<button class="sidebar-btn" :class="{ active: currentPage === 'topics' }" @click="redirectToPage('topics.html')">
📋 选题管理
</button>
<button class="sidebar-btn" :class="{ active: currentPage === 'logs' }" @click="redirectToPage('logs.html')">
📄 系统日志
</button>
<button v-if="isAdmin" class="sidebar-btn" :class="{ active: currentPage === 'users' }" @click="redirectToPage('users.html')">
👥 用户管理
</button>
</aside>
<navigation-component
current-page="dashboard"
:is-admin="isAdmin"
@navigate="redirectToPage"
></navigation-component>
<div class="main-content" v-if="isLoggedIn">
<main class="content-area">
<!-- 系统概览页面 -->
<div id="page-overview" class="page" :class="{ active: currentPage === 'overview' }">