1052 lines
33 KiB
HTML
1052 lines
33 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>测评报告列表</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
font-family: 'Microsoft YaHei', sans-serif;
|
|
}
|
|
|
|
body {
|
|
background-color: #f5f7fa;
|
|
color: #333;
|
|
padding: 20px;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
.container {
|
|
width: 100%;
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
border-radius: 12px;
|
|
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.header {
|
|
background: linear-gradient(135deg, #ff7e5f 0%, #feb47b 50%, #ff7e5f 100%);
|
|
color: white;
|
|
padding: 30px;
|
|
position: relative;
|
|
overflow: hidden;
|
|
box-shadow: 0 4px 20px rgba(255, 126, 95, 0.3);
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 32px;
|
|
margin-bottom: 10px;
|
|
position: relative;
|
|
z-index: 2;
|
|
text-align: center;
|
|
}
|
|
|
|
.header p {
|
|
text-align: center;
|
|
position: relative;
|
|
z-index: 2;
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.content {
|
|
padding: 30px;
|
|
}
|
|
|
|
.table-container {
|
|
background: white;
|
|
border-radius: 10px;
|
|
overflow-x: auto;
|
|
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
|
|
}
|
|
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
background: white;
|
|
table-layout: fixed;
|
|
}
|
|
|
|
thead {
|
|
background: linear-gradient(135deg, #fef6f0, #ffffff);
|
|
border-bottom: 2px solid #ffe4d6;
|
|
}
|
|
|
|
th {
|
|
padding: 18px 15px;
|
|
text-align: left;
|
|
font-weight: 600;
|
|
color: #2d5a3d;
|
|
font-size: 16px;
|
|
border-bottom: 1px solid #ffe4d6;
|
|
}
|
|
|
|
th:nth-child(1) { width: 12%; } /* 姓名 */
|
|
th:nth-child(2) { width: 18%; } /* 测评时间 */
|
|
th:nth-child(3) { width: 8%; } /* 分数 */
|
|
th:nth-child(4) { width: 12%; } /* 年级 */
|
|
th:nth-child(5) { width: 20%; } /* 学校 */
|
|
th:nth-child(6) { width: 30%; } /* 操作 */
|
|
|
|
td {
|
|
padding: 16px 15px;
|
|
border-bottom: 1px solid #f0f0f0;
|
|
font-size: 15px;
|
|
color: #333;
|
|
word-wrap: break-word;
|
|
overflow-wrap: break-word;
|
|
}
|
|
|
|
tbody tr {
|
|
transition: all 0.3s ease;
|
|
border-bottom: 1px solid #f0f0f0;
|
|
}
|
|
|
|
tbody tr:hover {
|
|
background: linear-gradient(135deg, #fff8f3, #ffffff);
|
|
transform: translateY(-1px);
|
|
box-shadow: 0 2px 8px rgba(255, 126, 95, 0.1);
|
|
}
|
|
|
|
tbody tr:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.name-cell {
|
|
font-weight: 500;
|
|
color: #2d5a3d;
|
|
}
|
|
|
|
.time-cell {
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.subject-cell {
|
|
display: inline-block;
|
|
padding: 6px 12px;
|
|
background: linear-gradient(135deg, #ffe4d6, #fff);
|
|
border: 1px solid #ff7e5f;
|
|
border-radius: 20px;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
color: #ff7e5f;
|
|
}
|
|
|
|
.action-cell {
|
|
text-align: center;
|
|
}
|
|
|
|
.view-btn {
|
|
display: inline-block;
|
|
padding: 8px 16px;
|
|
background: linear-gradient(135deg, #ff7e5f, #feb47b);
|
|
color: white;
|
|
text-decoration: none;
|
|
border-radius: 6px;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
transition: all 0.3s ease;
|
|
border: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.view-btn:hover {
|
|
background: linear-gradient(135deg, #ff6b52, #fe9b5b);
|
|
transform: translateY(-1px);
|
|
box-shadow: 0 3px 10px rgba(255, 126, 95, 0.3);
|
|
}
|
|
|
|
.submit-btn {
|
|
display: inline-block;
|
|
padding: 12px 24px;
|
|
background: linear-gradient(135deg, #4CAF50, #66BB6A);
|
|
color: white;
|
|
text-decoration: none;
|
|
border-radius: 8px;
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
transition: all 0.3s ease;
|
|
border: none;
|
|
cursor: pointer;
|
|
box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
|
|
}
|
|
|
|
.submit-btn:hover {
|
|
background: linear-gradient(135deg, #45a049, #5cb85c);
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
|
|
}
|
|
|
|
.pagination-container {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 20px;
|
|
background: #f9f9f9;
|
|
border-top: 1px solid #e0e0e0;
|
|
flex-wrap: wrap;
|
|
gap: 15px;
|
|
}
|
|
|
|
.pagination-left {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 20px;
|
|
}
|
|
|
|
.pagination-info {
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.page-size-selector {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.page-size-selector label {
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.page-size-select {
|
|
padding: 6px 8px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
background: white;
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.pagination-controls {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 5px;
|
|
}
|
|
|
|
.page-info {
|
|
color: #666;
|
|
font-size: 14px;
|
|
margin-left: 10px;
|
|
}
|
|
|
|
.pagination-btn {
|
|
padding: 8px 12px;
|
|
background: white;
|
|
border: 1px solid #ddd;
|
|
color: #666;
|
|
text-decoration: none;
|
|
border-radius: 4px;
|
|
font-size: 14px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
min-width: 36px;
|
|
}
|
|
|
|
.pagination-btn:hover:not(.disabled) {
|
|
background: linear-gradient(135deg, #ff7e5f, #feb47b);
|
|
color: white;
|
|
border-color: #ff7e5f;
|
|
}
|
|
|
|
.pagination-btn.active {
|
|
background: linear-gradient(135deg, #ff7e5f, #feb47b);
|
|
color: white;
|
|
border-color: #ff7e5f;
|
|
}
|
|
|
|
.pagination-btn.disabled {
|
|
background: #f5f5f5;
|
|
color: #ccc;
|
|
cursor: not-allowed;
|
|
border-color: #e0e0e0;
|
|
}
|
|
|
|
.pagination-ellipsis {
|
|
padding: 8px 4px;
|
|
color: #999;
|
|
}
|
|
|
|
.loading {
|
|
text-align: center;
|
|
padding: 40px;
|
|
color: #666;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.error {
|
|
text-align: center;
|
|
padding: 40px;
|
|
color: #e74c3c;
|
|
font-size: 16px;
|
|
background: #fff9f7;
|
|
border-radius: 8px;
|
|
border-left: 4px solid #ff7e5f;
|
|
margin: 20px 0;
|
|
}
|
|
|
|
.empty {
|
|
text-align: center;
|
|
padding: 60px 20px;
|
|
color: #999;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.empty-icon {
|
|
font-size: 48px;
|
|
margin-bottom: 15px;
|
|
opacity: 0.5;
|
|
}
|
|
|
|
.footer {
|
|
padding: 20px;
|
|
text-align: center;
|
|
color: #8b5a2b;
|
|
font-size: 14px;
|
|
background: #fef6f0;
|
|
border-top: 1px solid #ffe4d6;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
body {
|
|
padding: 0;
|
|
}
|
|
|
|
.header {
|
|
padding: 20px;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 24px;
|
|
}
|
|
|
|
.content {
|
|
padding: 15px;
|
|
}
|
|
|
|
.table-container {
|
|
overflow-x: auto;
|
|
}
|
|
|
|
table {
|
|
min-width: 500px;
|
|
}
|
|
|
|
th, td {
|
|
padding: 12px 10px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.subject-cell {
|
|
font-size: 12px;
|
|
padding: 4px 8px;
|
|
}
|
|
|
|
.view-btn {
|
|
padding: 6px 12px;
|
|
font-size: 13px;
|
|
}
|
|
|
|
.submit-btn {
|
|
padding: 10px 20px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.pagination-container {
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
padding: 15px;
|
|
}
|
|
|
|
.pagination-left {
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
align-items: flex-start;
|
|
}
|
|
|
|
.pagination-controls {
|
|
flex-wrap: wrap;
|
|
gap: 3px;
|
|
}
|
|
|
|
.pagination-btn {
|
|
padding: 6px 10px;
|
|
font-size: 12px;
|
|
min-width: 32px;
|
|
}
|
|
|
|
.pagination-info, .page-info {
|
|
font-size: 12px;
|
|
}
|
|
|
|
.page-size-selector {
|
|
font-size: 12px;
|
|
}
|
|
|
|
.page-size-select {
|
|
padding: 4px 6px;
|
|
font-size: 12px;
|
|
}
|
|
|
|
.delete-btn {
|
|
padding: 6px 12px;
|
|
background: linear-gradient(135deg, #e74c3c, #c0392b);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
font-size: 12px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
margin-left: 5px;
|
|
}
|
|
|
|
.delete-btn:hover {
|
|
background: linear-gradient(135deg, #c0392b, #a93226);
|
|
transform: translateY(-1px);
|
|
box-shadow: 0 2px 8px rgba(231, 76, 60, 0.3);
|
|
}
|
|
}
|
|
|
|
/* 登录相关样式 */
|
|
.auth-status {
|
|
position: absolute;
|
|
top: 20px;
|
|
right: 20px;
|
|
z-index: 10;
|
|
}
|
|
|
|
.user-info {
|
|
background: rgba(255, 255, 255, 0.2);
|
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
border-radius: 20px;
|
|
padding: 8px 16px;
|
|
color: white;
|
|
font-size: 14px;
|
|
backdrop-filter: blur(10px);
|
|
}
|
|
|
|
|
|
.logout-btn {
|
|
background: rgba(231, 76, 60, 0.8);
|
|
border: 1px solid rgba(231, 76, 60, 0.9);
|
|
color: white;
|
|
padding: 4px 12px;
|
|
border-radius: 15px;
|
|
cursor: pointer;
|
|
font-size: 12px;
|
|
margin-left: 10px;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.logout-btn:hover {
|
|
background: rgba(192, 57, 43, 0.9);
|
|
}
|
|
|
|
/* 模态框样式 */
|
|
.modal {
|
|
display: none;
|
|
position: fixed;
|
|
z-index: 1000;
|
|
left: 0;
|
|
top: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
backdrop-filter: blur(5px);
|
|
}
|
|
|
|
.modal-content {
|
|
background: white;
|
|
margin: 10% auto;
|
|
padding: 30px;
|
|
border-radius: 12px;
|
|
width: 90%;
|
|
max-width: 400px;
|
|
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
|
|
animation: modalSlideIn 0.3s ease-out;
|
|
}
|
|
|
|
@keyframes modalSlideIn {
|
|
from {
|
|
opacity: 0;
|
|
transform: translateY(-50px);
|
|
}
|
|
to {
|
|
opacity: 1;
|
|
transform: translateY(0);
|
|
}
|
|
}
|
|
|
|
@keyframes slideInRight {
|
|
from {
|
|
opacity: 0;
|
|
transform: translateX(100px);
|
|
}
|
|
to {
|
|
opacity: 1;
|
|
transform: translateX(0);
|
|
}
|
|
}
|
|
|
|
.modal-header {
|
|
text-align: center;
|
|
margin-bottom: 25px;
|
|
}
|
|
|
|
.modal-header h2 {
|
|
color: #2d5a3d;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
color: #333;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 2px solid #e0e0e0;
|
|
border-radius: 6px;
|
|
font-size: 14px;
|
|
transition: border-color 0.3s ease;
|
|
}
|
|
|
|
.form-group input:focus {
|
|
outline: none;
|
|
border-color: #ff7e5f;
|
|
}
|
|
|
|
.modal-buttons {
|
|
display: flex;
|
|
gap: 10px;
|
|
margin-top: 25px;
|
|
}
|
|
|
|
.modal-btn {
|
|
flex: 1;
|
|
padding: 12px;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.modal-btn-primary {
|
|
background: linear-gradient(135deg, #ff7e5f, #feb47b);
|
|
color: white;
|
|
}
|
|
|
|
.modal-btn-primary:hover {
|
|
background: linear-gradient(135deg, #ff6b52, #fe9b5b);
|
|
}
|
|
|
|
.modal-btn-secondary {
|
|
background: #f5f5f5;
|
|
color: #666;
|
|
}
|
|
|
|
.modal-btn-secondary:hover {
|
|
background: #e0e0e0;
|
|
}
|
|
|
|
.delete-btn {
|
|
padding: 6px 12px;
|
|
background: linear-gradient(135deg, #e74c3c, #c0392b);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
font-size: 13px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.delete-btn:hover {
|
|
background: linear-gradient(135deg, #c0392b, #a93226);
|
|
transform: translateY(-1px);
|
|
box-shadow: 0 2px 8px rgba(231, 76, 60, 0.3);
|
|
}
|
|
|
|
.action-cell {
|
|
display: flex;
|
|
gap: 5px;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<div class="auth-status" id="auth-status">
|
|
<!-- 登录状态将由JavaScript动态生成 -->
|
|
</div>
|
|
<h1>📊 测评报告列表</h1>
|
|
<p>查看所有学员的学科能力测评报告</p>
|
|
<div style="text-align: center; margin-top: 20px;">
|
|
<button id="create-report-btn" class="submit-btn">✏️ 开始测评</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<div class="table-container">
|
|
<div id="loading" class="loading">正在加载数据...</div>
|
|
<div id="error" class="error" style="display: none;"></div>
|
|
<div id="table-content" style="display: none;">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>姓名</th>
|
|
<th>测评时间</th>
|
|
<th>分数</th>
|
|
<th>年级</th>
|
|
<th>学校</th>
|
|
<th>操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="report-list">
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div id="empty" class="empty" style="display: none;">
|
|
<div class="empty-icon">📋</div>
|
|
<p>暂无测评报告数据</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="pagination-container">
|
|
<div class="pagination-left" id="pagination-left">
|
|
<div class="pagination-info">
|
|
<span>显示</span>
|
|
<select class="page-size-select">
|
|
<option value="5">5</option>
|
|
<option value="10" selected>10</option>
|
|
<option value="20">20</option>
|
|
<option value="50">50</option>
|
|
</select>
|
|
<span>条记录</span>
|
|
</div>
|
|
<div class="pagination-controls">
|
|
<!-- 分页按钮将由JavaScript动态生成 -->
|
|
</div>
|
|
</div>
|
|
<div class="page-info">
|
|
<!-- 页面信息将由JavaScript动态生成 -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<p>© 2024 尚逸基石学科能力测评系统</p>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<!-- 删除确认模态框 -->
|
|
<div id="delete-modal" class="modal">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h2>⚠️ 确认删除</h2>
|
|
<p style="color: #666; font-size: 14px;">此操作不可撤销</p>
|
|
</div>
|
|
<div style="text-align: center; margin: 20px 0;">
|
|
<p id="delete-message" style="color: #e74c3c; font-weight: 500;"></p>
|
|
</div>
|
|
<div class="modal-buttons">
|
|
<button type="button" class="modal-btn modal-btn-primary" onclick="confirmDelete()" style="background: linear-gradient(135deg, #e74c3c, #c0392b);">确认删除</button>
|
|
<button type="button" class="modal-btn modal-btn-secondary" onclick="closeDeleteModal()">取消</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// 全局变量
|
|
let currentDeleteId = null;
|
|
let currentDeleteName = null;
|
|
let isAuthenticated = false;
|
|
|
|
// 更新认证状态显示
|
|
function updateAuthStatus() {
|
|
const authStatus = document.getElementById('auth-status');
|
|
if (isAuthenticated) {
|
|
authStatus.innerHTML = `
|
|
<div class="user-info">
|
|
👤 管理员
|
|
<button class="logout-btn" onclick="logout()">退出</button>
|
|
</div>
|
|
`;
|
|
} else {
|
|
authStatus.innerHTML = '';
|
|
}
|
|
}
|
|
|
|
// 退出登录
|
|
function logout() {
|
|
isAuthenticated = false;
|
|
localStorage.removeItem('isAuthenticated');
|
|
// 跳转到登录页面
|
|
window.location.href = '/login.html';
|
|
}
|
|
|
|
// 删除相关函数
|
|
function showDeleteModal(reportId, reportName) {
|
|
currentDeleteId = reportId;
|
|
currentDeleteName = reportName;
|
|
document.getElementById('delete-message').textContent =
|
|
`确定要删除「${reportName}」的报告吗?此操作无法撤销!`;
|
|
document.getElementById('delete-modal').style.display = 'block';
|
|
}
|
|
|
|
function closeDeleteModal() {
|
|
document.getElementById('delete-modal').style.display = 'none';
|
|
currentDeleteId = null;
|
|
currentDeleteName = null;
|
|
}
|
|
|
|
function confirmDelete() {
|
|
if (currentDeleteId && window.reportManager) {
|
|
window.reportManager.executeDelete(currentDeleteId);
|
|
closeDeleteModal();
|
|
}
|
|
}
|
|
|
|
// 点击删除模态框外部关闭
|
|
window.onclick = function(event) {
|
|
const deleteModal = document.getElementById('delete-modal');
|
|
|
|
if (event.target === deleteModal) {
|
|
closeDeleteModal();
|
|
}
|
|
}
|
|
|
|
// 页面加载完成
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// 检查登录状态
|
|
const savedAuth = localStorage.getItem('isAuthenticated');
|
|
if (savedAuth === 'true') {
|
|
isAuthenticated = true;
|
|
}
|
|
updateAuthStatus();
|
|
|
|
// 初始化报告列表管理器
|
|
new ReportListManager();
|
|
|
|
// 添加页面大小选择事件
|
|
const pageSizeSelect = document.querySelector('.page-size-select');
|
|
if (pageSizeSelect) {
|
|
pageSizeSelect.addEventListener('change', function() {
|
|
const pageSize = parseInt(this.value);
|
|
if (window.reportManager) {
|
|
window.reportManager.changePageSize(pageSize);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 创建新测评按钮事件
|
|
const createBtn = document.getElementById('create-report-btn');
|
|
if (createBtn) {
|
|
createBtn.addEventListener('click', function() {
|
|
window.location.href = '/survey.html?admin=true';
|
|
});
|
|
}
|
|
});
|
|
|
|
// 全局变量,用于报告管理器实例
|
|
window.ReportListManager = class ReportListManager {
|
|
constructor() {
|
|
this.reports = [];
|
|
this.allReports = [];
|
|
this.currentPage = 1;
|
|
this.pageSize = 10;
|
|
this.totalPages = 1;
|
|
this.totalRecords = 0;
|
|
window.reportManager = this;
|
|
this.init();
|
|
}
|
|
|
|
async init() {
|
|
try {
|
|
// 检查是否已登录,如果未登录则跳转到登录页面
|
|
if (!isAuthenticated) {
|
|
window.location.href = '/login.html';
|
|
return;
|
|
}
|
|
await this.fetchReports();
|
|
this.render();
|
|
} catch (error) {
|
|
console.error('初始化失败:', error);
|
|
this.showError(`数据加载失败: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
|
|
async fetchReports() {
|
|
try {
|
|
document.getElementById('loading').style.display = 'block';
|
|
|
|
const response = await fetch(`/api/reports?page=${this.currentPage}&pageSize=${this.pageSize}`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'content-type': 'application/json'
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`API请求失败: ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
this.reports = data.reports || [];
|
|
this.totalRecords = data.total || 0;
|
|
this.totalPages = data.total_pages || 1;
|
|
this.currentPage = data.page || 1;
|
|
|
|
document.getElementById('loading').style.display = 'none';
|
|
|
|
if (this.reports.length === 0) {
|
|
document.getElementById('empty').style.display = 'block';
|
|
document.getElementById('table-content').style.display = 'none';
|
|
} else {
|
|
document.getElementById('empty').style.display = 'none';
|
|
document.getElementById('table-content').style.display = 'block';
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('获取报告失败:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
render() {
|
|
this.renderTable();
|
|
this.renderPagination();
|
|
}
|
|
|
|
renderTable() {
|
|
const tbody = document.getElementById('report-list');
|
|
tbody.innerHTML = '';
|
|
|
|
this.reports.forEach((report, index) => {
|
|
const row = document.createElement('tr');
|
|
|
|
// 解析时间戳并转换为东八区时间
|
|
const dateObj = new Date(report.generated_at);
|
|
// 加8小时转换为东八区时间
|
|
const east8Time = new Date(dateObj.getTime() + 8 * 60 * 60 * 1000);
|
|
|
|
// 格式化为 YYYY-MM-DD HH:MM
|
|
const year = east8Time.getFullYear();
|
|
const month = String(east8Time.getMonth() + 1).padStart(2, '0');
|
|
const day = String(east8Time.getDate()).padStart(2, '0');
|
|
const hours = String(east8Time.getHours()).padStart(2, '0');
|
|
const minutes = String(east8Time.getMinutes()).padStart(2, '0');
|
|
|
|
const date = `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
|
|
// 根据登录状态决定是否显示删除按钮
|
|
const deleteButtonStyle = isAuthenticated ? 'display: inline-block;' : 'display: none;';
|
|
|
|
row.innerHTML = `
|
|
<td class="name-cell">${report.name}</td>
|
|
<td class="time-cell">${date}</td>
|
|
<td class="score-cell">${report.total_score}分</td>
|
|
<td class="grade-cell">${report.grade}</td>
|
|
<td class="school-cell">${report.school}</td>
|
|
<td class="action-cell">
|
|
<a href="/report.html?id=${report.id}" class="view-btn">查看报告</a>
|
|
<button class="delete-btn" onclick="reportManager.deleteReport('${report.id}', '${report.name}')"
|
|
style="${deleteButtonStyle}" id="delete-${report.id}">删除</button>
|
|
</td>
|
|
`;
|
|
|
|
tbody.appendChild(row);
|
|
});
|
|
}
|
|
|
|
renderPagination() {
|
|
const pagination = document.getElementById('pagination-left');
|
|
const pageInfo = document.querySelector('.page-info');
|
|
const controls = document.querySelector('.pagination-controls');
|
|
|
|
if (!pageInfo || !controls) return;
|
|
|
|
pageInfo.textContent = `第 ${this.currentPage} 页,共 ${this.totalPages} 页`;
|
|
|
|
const pageSizeSelect = document.querySelector('.page-size-select');
|
|
if (pageSizeSelect) {
|
|
pageSizeSelect.value = this.pageSize;
|
|
}
|
|
|
|
controls.innerHTML = '';
|
|
|
|
const prevBtn = document.createElement('button');
|
|
prevBtn.className = 'pagination-btn';
|
|
prevBtn.textContent = '上一页';
|
|
prevBtn.disabled = this.currentPage === 1;
|
|
prevBtn.onclick = () => this.goToPage(this.currentPage - 1);
|
|
controls.appendChild(prevBtn);
|
|
|
|
const startPage = Math.max(1, this.currentPage - 2);
|
|
const endPage = Math.min(this.totalPages, this.currentPage + 2);
|
|
|
|
if (startPage > 1) {
|
|
this.addPageButton(controls, 1);
|
|
if (startPage > 2) {
|
|
const ellipsis = document.createElement('span');
|
|
ellipsis.className = 'pagination-ellipsis';
|
|
ellipsis.textContent = '...';
|
|
controls.appendChild(ellipsis);
|
|
}
|
|
}
|
|
|
|
for (let i = startPage; i <= endPage; i++) {
|
|
this.addPageButton(controls, i);
|
|
}
|
|
|
|
if (endPage < this.totalPages) {
|
|
if (endPage < this.totalPages - 1) {
|
|
const ellipsis = document.createElement('span');
|
|
ellipsis.className = 'pagination-ellipsis';
|
|
ellipsis.textContent = '...';
|
|
controls.appendChild(ellipsis);
|
|
}
|
|
this.addPageButton(controls, this.totalPages);
|
|
}
|
|
|
|
const nextBtn = document.createElement('button');
|
|
nextBtn.className = 'pagination-btn';
|
|
nextBtn.textContent = '下一页';
|
|
nextBtn.disabled = this.currentPage === this.totalPages;
|
|
nextBtn.onclick = () => this.goToPage(this.currentPage + 1);
|
|
controls.appendChild(nextBtn);
|
|
}
|
|
|
|
addPageButton(container, pageNum) {
|
|
const btn = document.createElement('button');
|
|
btn.className = `pagination-btn ${pageNum === this.currentPage ? 'active' : ''}`;
|
|
btn.textContent = pageNum;
|
|
btn.onclick = () => this.goToPage(pageNum);
|
|
container.appendChild(btn);
|
|
}
|
|
|
|
async goToPage(page) {
|
|
if (page < 1 || page > this.totalPages || page === this.currentPage) {
|
|
return;
|
|
}
|
|
|
|
this.currentPage = page;
|
|
await this.fetchReports();
|
|
this.render();
|
|
}
|
|
|
|
async changePageSize(pageSize) {
|
|
if (pageSize === this.pageSize) {
|
|
return;
|
|
}
|
|
|
|
this.pageSize = pageSize;
|
|
this.currentPage = 1;
|
|
await this.fetchReports();
|
|
this.render();
|
|
}
|
|
|
|
deleteReport(reportId, reportName) {
|
|
if (!isAuthenticated) {
|
|
alert('请先登录后再进行删除操作!');
|
|
showLoginModal();
|
|
return;
|
|
}
|
|
showDeleteModal(reportId, reportName);
|
|
}
|
|
|
|
async executeDelete(reportId) {
|
|
try {
|
|
const response = await fetch(`/api/reports/${reportId}`, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`删除失败: ${response.status}`);
|
|
}
|
|
|
|
// 删除成功,刷新列表
|
|
await this.fetchReports();
|
|
this.render();
|
|
|
|
// 显示成功消息
|
|
this.showMessage('报告删除成功!', 'success');
|
|
|
|
} catch (error) {
|
|
console.error('删除报告失败:', error);
|
|
this.showMessage(`删除失败: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
showMessage(message, type = 'info') {
|
|
// 创建消息元素
|
|
const messageDiv = document.createElement('div');
|
|
messageDiv.style.cssText = `
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
padding: 15px 20px;
|
|
border-radius: 6px;
|
|
color: white;
|
|
font-weight: 500;
|
|
z-index: 2000;
|
|
max-width: 300px;
|
|
animation: slideInRight 0.3s ease-out;
|
|
`;
|
|
|
|
if (type === 'success') {
|
|
messageDiv.style.background = 'linear-gradient(135deg, #27ae60, #2ecc71)';
|
|
} else if (type === 'error') {
|
|
messageDiv.style.background = 'linear-gradient(135deg, #e74c3c, #c0392b)';
|
|
} else {
|
|
messageDiv.style.background = 'linear-gradient(135deg, #3498db, #2980b9)';
|
|
}
|
|
|
|
messageDiv.textContent = message;
|
|
document.body.appendChild(messageDiv);
|
|
|
|
// 3秒后自动移除
|
|
setTimeout(() => {
|
|
if (messageDiv.parentNode) {
|
|
messageDiv.parentNode.removeChild(messageDiv);
|
|
}
|
|
}, 3000);
|
|
}
|
|
|
|
showError(message) {
|
|
const errorDiv = document.getElementById('error');
|
|
errorDiv.textContent = message;
|
|
errorDiv.style.display = 'block';
|
|
|
|
setTimeout(() => {
|
|
errorDiv.style.display = 'none';
|
|
}, 5000);
|
|
}
|
|
};
|
|
</script>
|
|
<script src="report-list.js"></script>
|
|
</body>
|
|
</html>
|