refactor(frontend): 重构前端目录结构并优化认证流程
将前端文件从html目录迁移到views目录,按功能模块组织 重构认证中间件和路由处理,简化页面权限控制 更新静态资源引用路径,统一使用/public前缀 添加学生仪表板页面,优化移动端显示 移除旧版html和js文件,更新样式和脚本
This commit is contained in:
494
frontend/views/admin/user_management.html
Normal file
494
frontend/views/admin/user_management.html
Normal file
@@ -0,0 +1,494 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>用户管理 - XX学校成绩管理系统</title>
|
||||
<link rel="stylesheet" href="/public/css/style.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<!-- 导航<E5AFBC><E888AA>?-->
|
||||
<nav class="navbar">
|
||||
<div class="container">
|
||||
<div class="navbar-brand">
|
||||
<a href="/">
|
||||
<i class="fas fa-graduation-cap"></i>
|
||||
<span>XX学校成绩管理系统</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="navbar-menu">
|
||||
<div class="navbar-start">
|
||||
<a href="/admin/dashboard" class="navbar-item">
|
||||
<i class="fas fa-tachometer-alt"></i>
|
||||
<span>仪表<EFBFBD><EFBFBD>?/span>
|
||||
</a>
|
||||
<a href="/admin/user_management" class="navbar-item active">
|
||||
<i class="fas fa-users"></i>
|
||||
<span>用户管理</span>
|
||||
</a>
|
||||
<a href="/admin/student_management" class="navbar-item">
|
||||
<i class="fas fa-user-graduate"></i>
|
||||
<span>学生管理</span>
|
||||
</a>
|
||||
<a href="/teacher/grade_management" class="navbar-item">
|
||||
<i class="fas fa-chart-bar"></i>
|
||||
<span>成绩统计</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="navbar-end">
|
||||
<div class="navbar-item user-info">
|
||||
<i class="fas fa-user-circle"></i>
|
||||
<span>管理<EFBFBD><EFBFBD>?/span>
|
||||
<div class="dropdown">
|
||||
<a href="#" class="dropdown-toggle">
|
||||
<i class="fas fa-caret-down"></i>
|
||||
</a>
|
||||
<div class="dropdown-menu">
|
||||
<a href="/admin/dashboard" class="dropdown-item">
|
||||
<i class="fas fa-tachometer-alt"></i>
|
||||
仪表<E4BBAA><E8A1A8>? </a>
|
||||
<a href="#" class="dropdown-item">
|
||||
<i class="fas fa-cog"></i>
|
||||
系统设置
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a href="/" class="dropdown-item">
|
||||
<i class="fas fa-sign-out-alt"></i>
|
||||
退出登<E587BA><E799BB>? </a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<main class="main-content">
|
||||
<div class="container">
|
||||
<div class="user-management">
|
||||
<!-- 页面标题和面包屑导航 -->
|
||||
<div class="page-header">
|
||||
<h1>用户管理</h1>
|
||||
<div class="breadcrumb">
|
||||
<a href="/">主页</a> >
|
||||
<a href="/admin/dashboard">管理员仪表板</a> >
|
||||
<span>用户管理</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 筛选区<E98089><E58CBA>?-->
|
||||
<div class="filter-section">
|
||||
<form class="filter-form" id="filter-form">
|
||||
<div class="filter-group">
|
||||
<label for="user-id">用户ID</label>
|
||||
<input type="text" id="user-id" placeholder="请输入用户ID">
|
||||
</div>
|
||||
<div class="filter-group">
|
||||
<label for="user-name">姓名</label>
|
||||
<input type="text" id="user-name" placeholder="请输入姓<E585A5><E5A793>?>
|
||||
</div>
|
||||
<div class="filter-group">
|
||||
<label for="role-select">角色</label>
|
||||
<select id="role-select">
|
||||
<option value="">全部角色</option>
|
||||
<option value="admin">管理<EFBFBD><EFBFBD>?/option>
|
||||
<option value="teacher">教师</option>
|
||||
<option value="student">学生</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter-group">
|
||||
<label for="class-select">班级</label>
|
||||
<select id="class-select">
|
||||
<option value="">全部班级</option>
|
||||
<option value="计算机科学与技<E4B88E><E68A80>?<3F><>?>计算机科学与技<E4B88E><E68A80>?<3F><>?/option>
|
||||
<option value="计算机科学与技<EFBFBD><EFBFBD>?<EFBFBD><EFBFBD>?>计算机科学与技<EFBFBD><EFBFBD>?<3F><>?/option>
|
||||
<option value="软件工程1<E7A88B><31>?>软件工程1<E7A88B><31>?/option>
|
||||
<option value="软件工程2<EFBFBD><EFBFBD>?>软件工程2<EFBFBD><EFBFBD>?/option>
|
||||
<option value="网络工程1<E7A88B><31>?>网络工程1<E7A88B><31>?/option>
|
||||
<option value="网络工程2<EFBFBD><EFBFBD>?>网络工程2<EFBFBD><EFBFBD>?/option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter-actions">
|
||||
<button type="button" class="btn-add" id="add-btn">
|
||||
<i class="fas fa-plus"></i>
|
||||
添加用户
|
||||
</button>
|
||||
<button type="button" class="btn-search" id="search-btn">
|
||||
<i class="fas fa-search"></i>
|
||||
查询
|
||||
</button>
|
||||
<button type="button" class="btn-reset" id="reset-btn">
|
||||
<i class="fas fa-redo"></i>
|
||||
重置
|
||||
</button>
|
||||
<button type="button" class="btn-export" id="export-btn">
|
||||
<i class="fas fa-file-export"></i>
|
||||
导出
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- 结果区域 -->
|
||||
<div class="table-container">
|
||||
<table class="user-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>用户ID</th>
|
||||
<th>姓名</th>
|
||||
<th>角色</th>
|
||||
<th>班级</th>
|
||||
<th>联系电话</th>
|
||||
<th>邮箱</th>
|
||||
<th>注册时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="user-table-body">
|
||||
<!-- 数据将通过JavaScript动态加<E68081><E58AA0>?-->
|
||||
<tr>
|
||||
<td colspan="8" class="loading">
|
||||
<i class="fas fa-spinner fa-spin"></i>
|
||||
<p>正在加载用户数据...</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 分页控件 -->
|
||||
<div class="pagination" id="pagination">
|
||||
<button id="prev-btn" disabled>
|
||||
<i class="fas fa-chevron-left"></i>
|
||||
上一<E4B88A><E4B880>? </button>
|
||||
<div id="page-numbers">
|
||||
<button class="active">1</button>
|
||||
<button>2</button>
|
||||
<button>3</button>
|
||||
</div>
|
||||
<button id="next-btn">
|
||||
下一<E4B88B><E4B880>? <i class="fas fa-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- 页脚 -->
|
||||
<footer class="footer">
|
||||
<div class="container">
|
||||
<p>© 2023 XX学校成绩管理系统. 版权所<E69D83><E68980>?</p>
|
||||
<p>技术支<EFBFBD><EFBFBD>? 信息技术中<E69CAF><E4B8AD>?| 联系电话: 010-12345678</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- JavaScript -->
|
||||
<script>
|
||||
// 模拟用户数据
|
||||
const mockUsers = [
|
||||
{
|
||||
id: 'admin001',
|
||||
name: '张管理员',
|
||||
role: 'admin',
|
||||
className: '',
|
||||
phone: '13800138001',
|
||||
email: 'admin@xxschool.edu.cn',
|
||||
registerTime: '2023-01-15'
|
||||
},
|
||||
{
|
||||
id: 'teacher001',
|
||||
name: '李老师',
|
||||
role: 'teacher',
|
||||
className: '计算机科学与技<E4B88E><E68A80>?<3F><>?,
|
||||
phone: '13800138002',
|
||||
email: 'li.teacher@xxschool.edu.cn',
|
||||
registerTime: '2023-02-10'
|
||||
},
|
||||
{
|
||||
id: 'teacher002',
|
||||
name: '王老师',
|
||||
role: 'teacher',
|
||||
className: '软件工程1<EFBFBD><EFBFBD>?,
|
||||
phone: '13800138003',
|
||||
email: 'wang.teacher@xxschool.edu.cn',
|
||||
registerTime: '2023-02-12'
|
||||
},
|
||||
{
|
||||
id: 'student001',
|
||||
name: '张三',
|
||||
role: 'student',
|
||||
className: '计算机科学与技<E4B88E><E68A80>?<3F><>?,
|
||||
phone: '13800138004',
|
||||
email: 'zhangsan@xxschool.edu.cn',
|
||||
registerTime: '2023-03-01'
|
||||
},
|
||||
{
|
||||
id: 'student002',
|
||||
name: '李四',
|
||||
role: 'student',
|
||||
className: '计算机科学与技<EFBFBD><EFBFBD>?<EFBFBD><EFBFBD>?,
|
||||
phone: '13800138005',
|
||||
email: 'lisi@xxschool.edu.cn',
|
||||
registerTime: '2023-03-01'
|
||||
},
|
||||
{
|
||||
id: 'student003',
|
||||
name: '王五',
|
||||
role: 'student',
|
||||
className: '软件工程1<E7A88B><31>?,
|
||||
phone: '13800138006',
|
||||
email: 'wangwu@xxschool.edu.cn',
|
||||
registerTime: '2023-03-02'
|
||||
},
|
||||
{
|
||||
id: 'student004',
|
||||
name: '赵六',
|
||||
role: 'student',
|
||||
className: '软件工程1<EFBFBD><EFBFBD>?,
|
||||
phone: '13800138007',
|
||||
email: 'zhaoliu@xxschool.edu.cn',
|
||||
registerTime: '2023-03-02'
|
||||
},
|
||||
{
|
||||
id: 'student005',
|
||||
name: '钱七',
|
||||
role: 'student',
|
||||
className: '网络工程1<E7A88B><31>?,
|
||||
phone: '13800138008',
|
||||
email: 'qianqi@xxschool.edu.cn',
|
||||
registerTime: '2023-03-03'
|
||||
},
|
||||
{
|
||||
id: 'student006',
|
||||
name: '孙八',
|
||||
role: 'student',
|
||||
className: '网络工程2<EFBFBD><EFBFBD>?,
|
||||
phone: '13800138009',
|
||||
email: 'sunba@xxschool.edu.cn',
|
||||
registerTime: '2023-03-03'
|
||||
},
|
||||
{
|
||||
id: 'student007',
|
||||
name: '周九',
|
||||
role: 'student',
|
||||
className: '计算机科学与技<E4B88E><E68A80>?<3F><>?,
|
||||
phone: '13800138010',
|
||||
email: 'zhoujiu@xxschool.edu.cn',
|
||||
registerTime: '2023-03-04'
|
||||
}
|
||||
];
|
||||
|
||||
// 当前显示的用户数<E688B7><E695B0>? let currentUsers = [...mockUsers];
|
||||
let currentPage = 1;
|
||||
const usersPerPage = 5;
|
||||
|
||||
// DOM元素
|
||||
const userTableBody = document.getElementById('user-table-body');
|
||||
const pagination = document.getElementById('pagination');
|
||||
const prevBtn = document.getElementById('prev-btn');
|
||||
const nextBtn = document.getElementById('next-btn');
|
||||
const pageNumbers = document.getElementById('page-numbers');
|
||||
const searchBtn = document.getElementById('search-btn');
|
||||
const resetBtn = document.getElementById('reset-btn');
|
||||
const addBtn = document.getElementById('add-btn');
|
||||
const exportBtn = document.getElementById('export-btn');
|
||||
const userIdInput = document.getElementById('user-id');
|
||||
const userNameInput = document.getElementById('user-name');
|
||||
const roleSelect = document.getElementById('role-select');
|
||||
const classSelect = document.getElementById('class-select');
|
||||
|
||||
// 初始<E5889D><E5A78B>? document.addEventListener('DOMContentLoaded', function() {
|
||||
renderUserTable();
|
||||
setupEventListeners();
|
||||
updatePagination();
|
||||
});
|
||||
|
||||
// 设置事件监听<E79B91><E590AC>? function setupEventListeners() {
|
||||
searchBtn.addEventListener('click', handleSearch);
|
||||
resetBtn.addEventListener('click', handleReset);
|
||||
addBtn.addEventListener('click', handleAddUser);
|
||||
exportBtn.addEventListener('click', handleExport);
|
||||
prevBtn.addEventListener('click', goToPrevPage);
|
||||
nextBtn.addEventListener('click', goToNextPage);
|
||||
}
|
||||
|
||||
// 渲染用户表格
|
||||
function renderUserTable() {
|
||||
if (currentUsers.length === 0) {
|
||||
userTableBody.innerHTML = `
|
||||
<tr>
|
||||
<td colspan="8" class="no-results">
|
||||
<i class="fas fa-user-slash"></i>
|
||||
<h3>没有找到用户</h3>
|
||||
<p>请尝试其他筛选条件或添加新用<E696B0><E794A8>?/p>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算当前页的用户
|
||||
const startIndex = (currentPage - 1) * usersPerPage;
|
||||
const endIndex = startIndex + usersPerPage;
|
||||
const pageUsers = currentUsers.slice(startIndex, endIndex);
|
||||
|
||||
let tableHTML = '';
|
||||
pageUsers.forEach(user => {
|
||||
// 角色徽章
|
||||
let roleBadge = '';
|
||||
if (user.role === 'admin') {
|
||||
roleBadge = '<span class="role-badge role-admin">管理<EFBFBD><EFBFBD>?/span>';
|
||||
} else if (user.role === 'teacher') {
|
||||
roleBadge = '<span class="role-badge role-teacher">教师</span>';
|
||||
} else {
|
||||
roleBadge = '<span class="role-badge role-student">学生</span>';
|
||||
}
|
||||
|
||||
tableHTML += `
|
||||
<tr>
|
||||
<td>${user.id}</td>
|
||||
<td>${user.name}</td>
|
||||
<td>${roleBadge}</td>
|
||||
<td>${user.className || '<27><>?}</td>
|
||||
<td>${user.phone}</td>
|
||||
<td>${user.email}</td>
|
||||
<td>${user.registerTime}</td>
|
||||
<td>
|
||||
<div class="action-buttons-cell">
|
||||
<button class="btn-edit" onclick="editUser('${user.id}')">
|
||||
<i class="fas fa-edit"></i>
|
||||
编辑
|
||||
</button>
|
||||
<button class="btn-delete" onclick="deleteUser('${user.id}')">
|
||||
<i class="fas fa-trash"></i>
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
|
||||
userTableBody.innerHTML = tableHTML;
|
||||
}
|
||||
|
||||
// 更新分页
|
||||
function updatePagination() {
|
||||
const totalPages = Math.ceil(currentUsers.length / usersPerPage);
|
||||
|
||||
// 更新按钮状<E992AE><E78AB6>? prevBtn.disabled = currentPage === 1;
|
||||
nextBtn.disabled = currentPage === totalPages || totalPages === 0;
|
||||
|
||||
// 更新页码按钮
|
||||
let pageButtonsHTML = '';
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
if (i <= 5) { // 最多显<E5A49A><E698BE>?个页<E4B8AA><E9A1B5>? pageButtonsHTML += `<button class="${i === currentPage ? 'active' : ''}" onclick="goToPage(${i})">${i}</button>`;
|
||||
}
|
||||
}
|
||||
pageNumbers.innerHTML = pageButtonsHTML;
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
const userId = userIdInput.value.trim();
|
||||
const userName = userNameInput.value.trim();
|
||||
const role = roleSelect.value;
|
||||
const className = classSelect.value;
|
||||
|
||||
currentUsers = mockUsers.filter(user => {
|
||||
// 用户ID筛<44><E7AD9B>? if (userId && !user.id.toLowerCase().includes(userId.toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 姓名筛<E5908D><E7AD9B>? if (userName && !user.name.toLowerCase().includes(userName.toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 角色筛<E889B2><E7AD9B>? if (role && user.role !== role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 班级筛<E7BAA7><E7AD9B>? if (className && user.className !== className) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
currentPage = 1;
|
||||
renderUserTable();
|
||||
updatePagination();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
userIdInput.value = '';
|
||||
userNameInput.value = '';
|
||||
roleSelect.value = '';
|
||||
classSelect.value = '';
|
||||
|
||||
currentUsers = [...mockUsers];
|
||||
currentPage = 1;
|
||||
renderUserTable();
|
||||
updatePagination();
|
||||
}
|
||||
|
||||
// 处理添加用户
|
||||
function handleAddUser() {
|
||||
alert('添加用户功能将在后端API完成后实<E5908E><E5AE9E>?);
|
||||
// 这里可以打开一个模态框来添加新用户
|
||||
}
|
||||
|
||||
// 处理导出
|
||||
function handleExport() {
|
||||
alert('导出功能将在后端API完成后实<EFBFBD><EFBFBD>?);
|
||||
// 这里可以导出为Excel或CSV格式
|
||||
}
|
||||
|
||||
// 编辑用户
|
||||
function editUser(userId) {
|
||||
alert(`编辑用户 ${userId} - 功能将在后端API完成后实现`);
|
||||
// 这里可以打开一个模态框来编辑用户信<E688B7><E4BFA1>? }
|
||||
|
||||
// 删除用户
|
||||
function deleteUser(userId) {
|
||||
if (confirm(`确定要删除用<EFBFBD><EFBFBD>?${userId} 吗?此操作不可撤销。`)) {
|
||||
// 从模拟数据中删除
|
||||
const index = mockUsers.findIndex(user => user.id === userId);
|
||||
if (index !== -1) {
|
||||
mockUsers.splice(index, 1);
|
||||
// 更新当前显示的数<E79A84><E695B0>? handleSearch();
|
||||
alert('用户删除成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 分页函数
|
||||
function goToPage(page) {
|
||||
currentPage = page;
|
||||
renderUserTable();
|
||||
updatePagination();
|
||||
}
|
||||
|
||||
function goToPrevPage() {
|
||||
if (currentPage > 1) {
|
||||
currentPage--;
|
||||
renderUserTable();
|
||||
updatePagination();
|
||||
}
|
||||
}
|
||||
|
||||
function goToNextPage() {
|
||||
const totalPages = Math.ceil(currentUsers.length / usersPerPage);
|
||||
if (currentPage < totalPages) {
|
||||
currentPage++;
|
||||
renderUserTable();
|
||||
updatePagination();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user