refactor(frontend): 重构前端目录结构并优化认证流程
将前端文件从html目录迁移到views目录,按功能模块组织 重构认证中间件和路由处理,简化页面权限控制 更新静态资源引用路径,统一使用/public前缀 添加学生仪表板页面,优化移动端显示 移除旧版html和js文件,更新样式和脚本
This commit is contained in:
@@ -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>
|
||||
<!-- 撖潸⏛�?-->
|
||||
<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>隞芾”�?/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>蝞∠��?/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>
|
||||
隞芾”�? </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>
|
||||
���箇蒈敶? </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>
|
||||
|
||||
<!-- 蝑偦�匧躹�?-->
|
||||
<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="霂瑁��亦鍂�弒D">
|
||||
</div>
|
||||
<div class="filter-group">
|
||||
<label for="user-name">憪枏�</label>
|
||||
<input type="text" id="user-name" placeholder="霂瑁��亙��?>
|
||||
</div>
|
||||
<div class="filter-group">
|
||||
<label for="role-select">閫坿𠧧</label>
|
||||
<select id="role-select">
|
||||
<option value="">�券�閫坿𠧧</option>
|
||||
<option value="admin">蝞∠��?/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="霈∠��箇�摮虫����?�?>霈∠��箇�摮虫����?�?/option>
|
||||
<option value="霈∠��箇�摮虫����?�?>霈∠��箇�摮虫����?�?/option>
|
||||
<option value="頧臭辣撌亦�1�?>頧臭辣撌亦�1�?/option>
|
||||
<option value="頧臭辣撌亦�2�?>頧臭辣撌亦�2�?/option>
|
||||
<option value="蝵𤑳�撌亦�1�?>蝵𤑳�撌亦�1�?/option>
|
||||
<option value="蝵𤑳�撌亦�2�?>蝵𤑳�撌亦�2�?/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�冽���頧?-->
|
||||
<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>
|
||||
銝𠹺�憿? </button>
|
||||
<div id="page-numbers">
|
||||
<button class="active">1</button>
|
||||
<button>2</button>
|
||||
<button>3</button>
|
||||
</div>
|
||||
<button id="next-btn">
|
||||
銝衤�憿? <i class="fas fa-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- 憿菔� -->
|
||||
<footer class="footer">
|
||||
<div class="container">
|
||||
<p>© 2023 XX摮行嵗�鞟貍蝞∠�蝟餌�. ������?</p>
|
||||
<p>���舀𣈲�? 靽⊥����臭葉敹?| �𠉛頂�菔�: 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: '霈∠��箇�摮虫����?�?,
|
||||
phone: '13800138002',
|
||||
email: 'li.teacher@xxschool.edu.cn',
|
||||
registerTime: '2023-02-10'
|
||||
},
|
||||
{
|
||||
id: 'teacher002',
|
||||
name: '�贝���',
|
||||
role: 'teacher',
|
||||
className: '頧臭辣撌亦�1�?,
|
||||
phone: '13800138003',
|
||||
email: 'wang.teacher@xxschool.edu.cn',
|
||||
registerTime: '2023-02-12'
|
||||
},
|
||||
{
|
||||
id: 'student001',
|
||||
name: '撘牐�',
|
||||
role: 'student',
|
||||
className: '霈∠��箇�摮虫����?�?,
|
||||
phone: '13800138004',
|
||||
email: 'zhangsan@xxschool.edu.cn',
|
||||
registerTime: '2023-03-01'
|
||||
},
|
||||
{
|
||||
id: 'student002',
|
||||
name: '�𤾸�',
|
||||
role: 'student',
|
||||
className: '霈∠��箇�摮虫����?�?,
|
||||
phone: '13800138005',
|
||||
email: 'lisi@xxschool.edu.cn',
|
||||
registerTime: '2023-03-01'
|
||||
},
|
||||
{
|
||||
id: 'student003',
|
||||
name: '�衤�',
|
||||
role: 'student',
|
||||
className: '頧臭辣撌亦�1�?,
|
||||
phone: '13800138006',
|
||||
email: 'wangwu@xxschool.edu.cn',
|
||||
registerTime: '2023-03-02'
|
||||
},
|
||||
{
|
||||
id: 'student004',
|
||||
name: '韏萄�',
|
||||
role: 'student',
|
||||
className: '頧臭辣撌亦�1�?,
|
||||
phone: '13800138007',
|
||||
email: 'zhaoliu@xxschool.edu.cn',
|
||||
registerTime: '2023-03-02'
|
||||
},
|
||||
{
|
||||
id: 'student005',
|
||||
name: '�曹�',
|
||||
role: 'student',
|
||||
className: '蝵𤑳�撌亦�1�?,
|
||||
phone: '13800138008',
|
||||
email: 'qianqi@xxschool.edu.cn',
|
||||
registerTime: '2023-03-03'
|
||||
},
|
||||
{
|
||||
id: 'student006',
|
||||
name: '摮坔�',
|
||||
role: 'student',
|
||||
className: '蝵𤑳�撌亦�2�?,
|
||||
phone: '13800138009',
|
||||
email: 'sunba@xxschool.edu.cn',
|
||||
registerTime: '2023-03-03'
|
||||
},
|
||||
{
|
||||
id: 'student007',
|
||||
name: '�其�',
|
||||
role: 'student',
|
||||
className: '霈∠��箇�摮虫����?�?,
|
||||
phone: '13800138010',
|
||||
email: 'zhoujiu@xxschool.edu.cn',
|
||||
registerTime: '2023-03-04'
|
||||
}
|
||||
];
|
||||
|
||||
// 敶枏��曄內��鍂�瑟㺭�? 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');
|
||||
|
||||
// �嘥��? document.addEventListener('DOMContentLoaded', function() {
|
||||
renderUserTable();
|
||||
setupEventListeners();
|
||||
updatePagination();
|
||||
});
|
||||
|
||||
// 霈曄蔭鈭衤辣�穃𨯬�? 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>霂瑕�霂訫�隞𣇉��㗇辺隞嗆�瘛餃��啁鍂�?/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">蝞∠��?/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 || '�?}</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);
|
||||
|
||||
// �湔鰵�厰僼�嗆�? prevBtn.disabled = currentPage === 1;
|
||||
nextBtn.disabled = currentPage === totalPages || totalPages === 0;
|
||||
|
||||
// �湔鰵憿萇��厰僼
|
||||
let pageButtonsHTML = '';
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
if (i <= 5) { // ��憭𡁏遬蝷?銝芷△�? 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蝑偦�? if (userId && !user.id.toLowerCase().includes(userId.toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 憪枏�蝑偦�? if (userName && !user.name.toLowerCase().includes(userName.toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 閫坿𠧧蝑偦�? if (role && user.role !== role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// �剔漣蝑偦�? 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摰峕��𤾸��?);
|
||||
// 餈䠷��臭誑�枏�銝�銝芣芋����交溶�䭾鰵�冽�
|
||||
}
|
||||
|
||||
// 憭��撖澆枂
|
||||
function handleExport() {
|
||||
alert('撖澆枂�蠘�撠�銁�𡒊垢API摰峕��𤾸��?);
|
||||
// 餈䠷��臭誑撖澆枂銝慟xcel�𥟟SV�澆�
|
||||
}
|
||||
|
||||
// 蝻𤥁��冽�
|
||||
function editUser(userId) {
|
||||
alert(`蝻𤥁��冽� ${userId} - �蠘�撠�銁�𡒊垢API摰峕��𤾸��躬);
|
||||
// 餈䠷��臭誑�枏�銝�銝芣芋����亦�颲𤑳鍂�瑚縑�? }
|
||||
|
||||
// �𣳇膄�冽�
|
||||
function deleteUser(userId) {
|
||||
if (confirm(`蝖桀�閬���斤鍂�?${userId} �梹�甇斗�雿靝��舀伃����)) {
|
||||
// 隞擧芋��㺭�桐葉�𣳇膄
|
||||
const index = mockUsers.findIndex(user => user.id === userId);
|
||||
if (index !== -1) {
|
||||
mockUsers.splice(index, 1);
|
||||
// �湔鰵敶枏��曄內��㺭�? 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