v2.1更新
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -51,3 +51,6 @@ docs/guide/parent.pdf
|
||||
docs/guide/student.pdf
|
||||
docs/guide/teacher.pdf
|
||||
qrcode.png
|
||||
|
||||
# 展示内容
|
||||
example
|
||||
@@ -272,6 +272,7 @@ classmanager/
|
||||
| v1.7 | 2026.5.21 | 全量一致性审计:前后端配置统一(.env.example/config.py/config.php)、清理废弃全局变量、角色权限表精确化 |
|
||||
| v1.8 | 2026.5.22 | 科目管理融入作业管理页、科目删除数据依赖检查、加减分记录类型区分(manual/homework/attendance)、学生端作业详情优化 |
|
||||
| v2.0.1 | 2026.5.23 | 操作列折叠优化、扣分类型大类区分、科目选择修复、改名作业扣分、记录人优化、家长端优化、学期管理优化 |
|
||||
| v2.1 | 2025.7.14 | CSS变量化统一配色方案、简化按钮系统、操作列按钮风格统一、清理内联颜色、修复科目管理面板无法展开、数据库索引优化、清理init.sql冗余迁移代码、安全审计通过 |
|
||||
|
||||
## 许可证
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ include __DIR__ . '/../includes/header.php';
|
||||
<span style="font-size: 14px; color: #666;">显示前</span>
|
||||
<input type="number" id="percentileFilter" style="width: 70px; padding: 4px 8px; border: 1px solid #ddd; border-radius: 4px;" min="1" max="100" value="100" placeholder="1-100">
|
||||
<span style="font-size: 14px; color: #666;">% 的学生</span>
|
||||
<button class="btn btn-sm" style="background: #667eea; color: white;" onclick="applyPercentileFilter()">筛选</button>
|
||||
<button class="btn btn-sm" style="border: 1px solid #ccc; color: #666;" onclick="resetPercentileFilter()">显示全部</button>
|
||||
<button class="btn btn-sm btn-primary" onclick="applyPercentileFilter()">筛选</button>
|
||||
<button class="btn btn-sm btn-ghost" onclick="resetPercentileFilter()">显示全部</button>
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
@@ -52,7 +52,154 @@ include __DIR__ . '/../includes/header.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($role === '班主任'): ?>
|
||||
<!-- 升级提示模态框 -->
|
||||
<div id="upgradeModal" class="modal" style="display:none;">
|
||||
<div class="modal-content" style="max-width:520px;">
|
||||
<div class="modal-header">
|
||||
<h3>🔄 系统升级</h3>
|
||||
<button class="modal-close" onclick="closeModal('upgradeModal')" id="upgradeCloseBtn">×</button>
|
||||
</div>
|
||||
<div style="padding: 16px 0;">
|
||||
<div style="text-align: center; margin-bottom: 12px;">
|
||||
<p style="font-size: 15px; color: var(--color-text);">检测到数据库有新版本可用</p>
|
||||
<p style="font-size: 13px; color: var(--color-text-muted); margin-top: 8px;">
|
||||
当前版本: <span id="currentDbVersion">--</span> → 目标版本: <span id="targetDbVersion">--</span>
|
||||
</p>
|
||||
</div>
|
||||
<div id="upgradeStepsList" style="margin: 12px 0;"></div>
|
||||
<div id="upgradeResult" style="display:none; margin-top: 12px;"></div>
|
||||
<p id="upgradeWarning" class="text-danger" style="font-size: 12px; text-align: center; margin-top: 8px;">⚠️ 升级前请确保已备份数据库</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn" onclick="closeModal('upgradeModal')" id="upgradeLaterBtn">稍后再说</button>
|
||||
<button class="btn btn-primary" onclick="startUpgrade()" id="startUpgradeBtn">开始升级</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<script>window.PAGE_CONFIG = { role: '<?php echo $role; ?>' };</script>
|
||||
<script src="/assets/js/dashboard.js"></script>
|
||||
|
||||
<?php if ($role === '班主任'): ?>
|
||||
<script>
|
||||
(function() {
|
||||
var upgradeSteps = [];
|
||||
var currentStepIndex = 0;
|
||||
|
||||
fetch('/api/check_upgrade.php')
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(data) {
|
||||
if (data.needs_upgrade) {
|
||||
document.getElementById('currentDbVersion').textContent = data.current;
|
||||
document.getElementById('targetDbVersion').textContent = data.target;
|
||||
upgradeSteps = data.steps || [];
|
||||
|
||||
// 渲染步骤列表
|
||||
var listHtml = '';
|
||||
for (var i = 0; i < upgradeSteps.length; i++) {
|
||||
listHtml += '<div style="display:flex;align-items:center;padding:8px 12px;margin:4px 0;border-radius:6px;font-size:13px;background:var(--color-hover);border-left:3px solid var(--color-border);" id="ustep-' + i + '">' +
|
||||
'<span style="margin-right:8px;" id="ustep-icon-' + i + '">○</span>' +
|
||||
'<span>升级至 v' + upgradeSteps[i].version + '</span>' +
|
||||
'</div>';
|
||||
}
|
||||
document.getElementById('upgradeStepsList').innerHTML = listHtml;
|
||||
document.getElementById('upgradeModal').style.display = 'flex';
|
||||
}
|
||||
})
|
||||
.catch(function() {});
|
||||
|
||||
window.startUpgrade = function() {
|
||||
var btn = document.getElementById('startUpgradeBtn');
|
||||
var closeBtn = document.getElementById('upgradeCloseBtn');
|
||||
var laterBtn = document.getElementById('upgradeLaterBtn');
|
||||
|
||||
btn.disabled = true;
|
||||
btn.textContent = '升级中...';
|
||||
btn.style.opacity = '0.7';
|
||||
closeBtn.style.display = 'none';
|
||||
laterBtn.style.display = 'none';
|
||||
document.getElementById('upgradeWarning').style.display = 'none';
|
||||
|
||||
currentStepIndex = 0;
|
||||
executeNextUpgradeStep();
|
||||
};
|
||||
|
||||
function executeNextUpgradeStep() {
|
||||
if (currentStepIndex >= upgradeSteps.length) {
|
||||
// 所有步骤完成
|
||||
var btn = document.getElementById('startUpgradeBtn');
|
||||
btn.textContent = '升级完成 ✓';
|
||||
btn.style.background = '#52c41a';
|
||||
|
||||
var laterBtn = document.getElementById('upgradeLaterBtn');
|
||||
laterBtn.style.display = '';
|
||||
laterBtn.textContent = '关闭';
|
||||
laterBtn.onclick = function() { location.reload(); };
|
||||
|
||||
document.getElementById('upgradeResult').style.display = 'block';
|
||||
document.getElementById('upgradeResult').innerHTML = '<div style="background:#f6ffed;border:1px solid #b7eb8f;border-radius:6px;padding:12px;text-align:center;color:var(--color-success);font-size:14px;">✓ 数据库升级成功!</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
var step = upgradeSteps[currentStepIndex];
|
||||
var stepEl = document.getElementById('ustep-' + currentStepIndex);
|
||||
var iconEl = document.getElementById('ustep-icon-' + currentStepIndex);
|
||||
|
||||
// 标记为执行中
|
||||
if (stepEl) {
|
||||
stepEl.style.borderLeftColor = 'var(--color-primary)';
|
||||
stepEl.style.background = 'var(--color-primary-light)';
|
||||
}
|
||||
if (iconEl) iconEl.textContent = '⟳';
|
||||
|
||||
fetch('/upgrade.php?action=step&version=' + encodeURIComponent(step.version), { method: 'POST' })
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(data) {
|
||||
if (data.success) {
|
||||
if (stepEl) {
|
||||
stepEl.style.borderLeftColor = 'var(--color-success)';
|
||||
stepEl.style.background = '#f6ffed';
|
||||
}
|
||||
if (iconEl) iconEl.textContent = '✓';
|
||||
currentStepIndex++;
|
||||
executeNextUpgradeStep();
|
||||
} else {
|
||||
if (stepEl) {
|
||||
stepEl.style.borderLeftColor = 'var(--color-danger)';
|
||||
stepEl.style.background = 'var(--color-danger-light)';
|
||||
}
|
||||
if (iconEl) iconEl.textContent = '✗';
|
||||
showUpgradeError(data.error || '未知错误');
|
||||
}
|
||||
})
|
||||
.catch(function(err) {
|
||||
if (stepEl) {
|
||||
stepEl.style.borderLeftColor = 'var(--color-danger)';
|
||||
stepEl.style.background = 'var(--color-danger-light)';
|
||||
}
|
||||
if (iconEl) iconEl.textContent = '✗';
|
||||
showUpgradeError(err.message);
|
||||
});
|
||||
}
|
||||
|
||||
function showUpgradeError(msg) {
|
||||
var btn = document.getElementById('startUpgradeBtn');
|
||||
btn.textContent = '升级失败';
|
||||
btn.style.background = 'var(--color-danger)';
|
||||
btn.disabled = false;
|
||||
btn.style.opacity = '';
|
||||
|
||||
var laterBtn = document.getElementById('upgradeLaterBtn');
|
||||
laterBtn.style.display = '';
|
||||
laterBtn.textContent = '关闭';
|
||||
|
||||
document.getElementById('upgradeResult').style.display = 'block';
|
||||
document.getElementById('upgradeResult').innerHTML = '<div style="background:var(--color-danger-light);border:1px solid #ffccc7;border-radius:6px;padding:12px;color:var(--color-danger-dark);font-size:13px;"><strong>升级失败:</strong>' + msg + '</div>';
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include __DIR__ . '/../includes/footer.php'; ?>
|
||||
@@ -83,7 +83,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>window.PAGE_CONFIG = { role: '<?php echo $role; ?>', userId: <?php echo intval($_SESSION['user_id']); ?> };</script>
|
||||
<script>window.PAGE_CONFIG = { role: '<?php echo htmlspecialchars($role, ENT_QUOTES, 'UTF-8'); ?>', userId: <?php echo intval($_SESSION['user_id']); ?> };</script>
|
||||
<script src="/assets/js/modules/modal-utils.js"></script>
|
||||
<script src="/assets/js/modules/utils.js"></script>
|
||||
<script src="/assets/js/modules/points-mgmt.js"></script>
|
||||
|
||||
@@ -32,12 +32,12 @@ include __DIR__ . '/../includes/header.php';
|
||||
|
||||
<div class="container">
|
||||
<!-- 科目管理折叠面板 -->
|
||||
<div class="card" style="margin-bottom: 20px;">
|
||||
<div class="collapsible-header" onclick="toggleSubjectPanel()" style="cursor: pointer; display: flex; justify-content: space-between; align-items: center; padding: 15px 20px;">
|
||||
<div class="card collapsible-card" style="margin-bottom: 20px;">
|
||||
<div class="collapsible-header" id="subjectPanelHeader">
|
||||
<h3 style="margin: 0; font-size: 16px;">📚 科目管理</h3>
|
||||
<span id="subjectPanelToggle" class="toggle-icon">▶ 展开</span>
|
||||
</div>
|
||||
<div id="subjectPanelContent" style="display: none; padding: 0 20px 20px;">
|
||||
<div id="subjectPanelContent" class="collapsible-content">
|
||||
<div class="action-bar">
|
||||
<button class="btn btn-primary" onclick="showAddSubjectModal()">添加科目</button>
|
||||
</div>
|
||||
@@ -92,9 +92,6 @@ include __DIR__ . '/../includes/header.php';
|
||||
<div class="deduction-types">
|
||||
<button type="button" class="btn btn-sm" onclick="selectDeductionType(-window.DEDUCTION_HOMEWORK_NOT_SUBMIT, '未交作业')">未交作业(-<span class="hw-not-submit"></span>分)</button>
|
||||
<button type="button" class="btn btn-sm" onclick="selectDeductionType(-window.DEDUCTION_HOMEWORK_LATE, '迟交作业')">迟交作业(-<span class="hw-late"></span>分)</button>
|
||||
<button type="button" class="btn btn-sm" onclick="selectDeductionType(null, '卫生')">卫生</button>
|
||||
<button type="button" class="btn btn-sm" onclick="selectDeductionType(null, '课堂')">课堂</button>
|
||||
<button type="button" class="btn btn-sm" onclick="selectDeductionType(null, '纪律')">纪律</button>
|
||||
<button type="button" class="btn btn-sm" onclick="selectDeductionType(0, '')">自定义</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -189,7 +186,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
gap: 12px;
|
||||
}
|
||||
.subject-item {
|
||||
background: #f8f9fa;
|
||||
background: var(--color-hover);
|
||||
padding: 12px 20px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
@@ -201,7 +198,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
font-size: 16px;
|
||||
}
|
||||
.subject-code {
|
||||
color: #999;
|
||||
color: var(--color-text-muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
.subject-status {
|
||||
@@ -217,22 +214,36 @@ include __DIR__ . '/../includes/header.php';
|
||||
background: #fed7d7;
|
||||
color: #742a2a;
|
||||
}
|
||||
.collapsible-header {
|
||||
.collapsible-card .collapsible-header {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 15px 20px;
|
||||
user-select: none;
|
||||
transition: background 0.2s;
|
||||
border-radius: 12px;
|
||||
}
|
||||
.collapsible-header:hover {
|
||||
background: #f8f9fa;
|
||||
.collapsible-card .collapsible-header:hover {
|
||||
background: var(--color-hover, #f7fafc);
|
||||
}
|
||||
.collapsible-card .collapsible-content {
|
||||
max-height: 0;
|
||||
overflow: hidden;
|
||||
transition: max-height 0.3s ease-out, padding 0.3s ease-out;
|
||||
padding: 0 20px;
|
||||
}
|
||||
.collapsible-card .collapsible-content.expanded {
|
||||
max-height: 1000px;
|
||||
padding: 0 20px 20px;
|
||||
}
|
||||
.toggle-icon {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
color: var(--color-text-secondary, #666);
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
.btn-danger {
|
||||
background: #e53e3e;
|
||||
color: white;
|
||||
}
|
||||
.btn-danger:hover {
|
||||
background: #c53030;
|
||||
.toggle-icon.expanded {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -66,8 +66,8 @@ include __DIR__ . '/../includes/header.php';
|
||||
<input type="text" id="semesterName" required placeholder="如:2025春季学期" maxlength="100">
|
||||
</div>
|
||||
<div style="margin-bottom: 8px;">
|
||||
<button type="button" class="btn btn-sm" style="border: 1px solid #667eea; color: #667eea; margin-right: 6px;" onclick="fillSemesterDates('upper')">上学期(9月-次年2月)</button>
|
||||
<button type="button" class="btn btn-sm" style="border: 1px solid #667eea; color: #667eea;" onclick="fillSemesterDates('lower')">下学期(3月-7月)</button>
|
||||
<button type="button" class="btn btn-sm btn-outline" style="margin-right: 6px;" onclick="fillSemesterDates('upper')">上学期(9月-次年2月)</button>
|
||||
<button type="button" class="btn btn-sm btn-outline" onclick="fillSemesterDates('lower')">下学期(3月-7月)</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>开始日期</label>
|
||||
|
||||
@@ -30,7 +30,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
<div class="action-buttons">
|
||||
<?php if ($role === '班主任'): ?>
|
||||
<button class="btn btn-primary" onclick="showImportModal()">导入学生</button>
|
||||
<button class="btn btn-success" onclick="showAddStudentModal()">新增学生</button>
|
||||
<button class="btn btn-primary" onclick="showAddStudentModal()">新增学生</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="search-bar">
|
||||
|
||||
103
frontend/api/check_upgrade.php
Normal file
103
frontend/api/check_upgrade.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* 检查数据库版本是否需要升级
|
||||
* 返回 JSON: {needs_upgrade: bool, current: string, target: string}
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../config.php';
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
// 只有班主任才能检查升级
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
||||
echo json_encode(['error' => '未授权']);
|
||||
exit();
|
||||
}
|
||||
|
||||
$role = $_SESSION['role'] ?? '';
|
||||
if ($role !== '班主任') {
|
||||
echo json_encode(['needs_upgrade' => false]);
|
||||
exit();
|
||||
}
|
||||
|
||||
// 读取后端 .env 获取数据库配置
|
||||
$envPath = __DIR__ . '/../../backend/.env';
|
||||
if (!file_exists($envPath)) {
|
||||
echo json_encode(['error' => '数据库配置文件不存在']);
|
||||
exit();
|
||||
}
|
||||
|
||||
$lines = file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
$dbConfig = [];
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '' || strpos($line, '#') === 0) {
|
||||
continue;
|
||||
}
|
||||
if (strpos($line, '=') !== false) {
|
||||
list($key, $value) = explode('=', $line, 2);
|
||||
$dbConfig[trim($key)] = trim($value);
|
||||
}
|
||||
}
|
||||
|
||||
$required = ['DB_HOST', 'DB_PORT', 'DB_USER', 'DB_PASSWORD', 'DB_NAME'];
|
||||
foreach ($required as $key) {
|
||||
if (!isset($dbConfig[$key]) || $dbConfig[$key] === '') {
|
||||
echo json_encode(['error' => "缺少数据库配置: {$key}"]);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$dsn = "mysql:host={$dbConfig['DB_HOST']};port={$dbConfig['DB_PORT']};dbname={$dbConfig['DB_NAME']};charset=utf8mb4";
|
||||
$pdo = new PDO($dsn, $dbConfig['DB_USER'], $dbConfig['DB_PASSWORD'], [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
]);
|
||||
|
||||
// 检测当前版本
|
||||
$currentVersion = '0.0.0';
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT setting_value FROM system_settings WHERE setting_key = 'db_version'");
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row) {
|
||||
$currentVersion = $row['setting_value'];
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
// 表不存在,使用默认值
|
||||
}
|
||||
|
||||
// 读取目标版本
|
||||
$versionFile = __DIR__ . '/../../VERSION';
|
||||
if (!file_exists($versionFile)) {
|
||||
echo json_encode(['error' => 'VERSION 文件不存在']);
|
||||
exit();
|
||||
}
|
||||
$targetVersion = trim(file_get_contents($versionFile));
|
||||
|
||||
$needsUpgrade = version_compare($targetVersion, $currentVersion, '>');
|
||||
|
||||
$allVersions = [
|
||||
'1.7' => 'v1.7.sql',
|
||||
'1.8' => 'v1.8.sql',
|
||||
'2.0' => 'v2.0.sql',
|
||||
'2.0.1' => 'v2.0.1.sql',
|
||||
'2.1' => 'v2.1.sql',
|
||||
];
|
||||
$steps = [];
|
||||
foreach ($allVersions as $version => $file) {
|
||||
if (version_compare($version, $currentVersion, '>') &&
|
||||
version_compare($version, $targetVersion, '<=')) {
|
||||
$steps[] = ['version' => $version, 'file' => $file];
|
||||
}
|
||||
}
|
||||
usort($steps, function($a, $b) { return version_compare($a['version'], $b['version']); });
|
||||
|
||||
echo json_encode([
|
||||
'needs_upgrade' => $needsUpgrade,
|
||||
'current' => $currentVersion,
|
||||
'target' => $targetVersion,
|
||||
'steps' => $steps
|
||||
]);
|
||||
} catch (PDOException $e) {
|
||||
echo json_encode(['error' => '数据库连接失败: ' . $e->getMessage()]);
|
||||
}
|
||||
@@ -21,13 +21,13 @@
|
||||
}
|
||||
|
||||
.batch-info {
|
||||
color: #667eea;
|
||||
color: var(--color-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 导入区域 */
|
||||
.import-area {
|
||||
border: 2px dashed #ddd;
|
||||
border: 2px dashed var(--color-border);
|
||||
border-radius: 12px;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
@@ -37,7 +37,7 @@
|
||||
}
|
||||
|
||||
.import-area:hover {
|
||||
border-color: #667eea;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.import-area input {
|
||||
@@ -45,7 +45,7 @@
|
||||
}
|
||||
|
||||
.import-label {
|
||||
color: #667eea;
|
||||
color: var(--color-primary);
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -59,7 +59,7 @@
|
||||
|
||||
/* 筛选栏 */
|
||||
.filter-bar {
|
||||
background: #f8f9fa;
|
||||
background: var(--color-hover);
|
||||
padding: 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
@@ -78,14 +78,14 @@
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.filter-group input,
|
||||
.filter-group select {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 1px solid #ddd;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
@@ -106,18 +106,18 @@
|
||||
.assignment-title {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.assignment-meta {
|
||||
color: #999;
|
||||
color: var(--color-text-muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* 状态选择器 */
|
||||
.status-select {
|
||||
padding: 4px 8px;
|
||||
border: 1px solid #ddd;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
@@ -201,8 +201,8 @@
|
||||
}
|
||||
|
||||
.attendance-toolbar .status-btn.active {
|
||||
border-color: #667eea;
|
||||
background: #eef2ff;
|
||||
border-color: var(--color-primary);
|
||||
background: var(--color-primary-light);
|
||||
color: #4338ca;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,43 @@
|
||||
* 版权所有 © Sea Network Technology Studio
|
||||
*/
|
||||
|
||||
:root {
|
||||
/* 主色调 */
|
||||
--color-primary: #4361ee;
|
||||
--color-primary-light: #eef0ff;
|
||||
--color-primary-dark: #3651d4;
|
||||
--color-primary-hover: #3a56d4;
|
||||
|
||||
/* 语义色 */
|
||||
--color-danger: #e53e3e;
|
||||
--color-danger-light: #fff5f5;
|
||||
--color-danger-dark: #c53030;
|
||||
--color-success: #38a169;
|
||||
--color-success-light: #f0fff4;
|
||||
--color-warning: #d69e2e;
|
||||
--color-warning-light: #fffff0;
|
||||
|
||||
/* 灰度 */
|
||||
--color-text: #1a202c;
|
||||
--color-text-secondary: #4a5568;
|
||||
--color-text-muted: #a0aec0;
|
||||
--color-bg: #f5f7fb;
|
||||
--color-card: #ffffff;
|
||||
--color-border: #e2e8f0;
|
||||
--color-border-light: #edf2f7;
|
||||
--color-hover: #f7fafc;
|
||||
|
||||
/* 按钮 */
|
||||
--btn-primary-bg: var(--color-primary);
|
||||
--btn-primary-text: #ffffff;
|
||||
--btn-outline-bg: transparent;
|
||||
--btn-outline-border: var(--color-primary);
|
||||
--btn-outline-text: var(--color-primary);
|
||||
--btn-danger-bg: var(--color-danger);
|
||||
--btn-danger-text: #ffffff;
|
||||
--btn-ghost-text: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
@@ -17,10 +54,10 @@
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
background: #f5f7fb;
|
||||
background: var(--color-bg);
|
||||
min-height: 100vh;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
/* ========== 登录页面 ========== */
|
||||
@@ -41,12 +78,12 @@ body {
|
||||
|
||||
.login-header h1 {
|
||||
font-size: 24px;
|
||||
color: #333;
|
||||
color: var(--color-text);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.login-header p {
|
||||
color: #666;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@@ -57,14 +94,14 @@ body {
|
||||
.login-form label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
color: #555;
|
||||
color: var(--color-text-secondary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.login-form input {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 1px solid #ddd;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.3s;
|
||||
@@ -72,13 +109,13 @@ body {
|
||||
|
||||
.login-form input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.btn-login {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
background: linear-gradient(135deg, var(--color-primary) 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
@@ -93,8 +130,8 @@ body {
|
||||
}
|
||||
|
||||
.error-msg {
|
||||
background: #fee;
|
||||
color: #c33;
|
||||
background: var(--color-danger-light);
|
||||
color: var(--color-danger);
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin-top: 15px;
|
||||
@@ -106,8 +143,8 @@ body {
|
||||
text-align: center;
|
||||
margin-top: 30px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #eee;
|
||||
color: #999;
|
||||
border-top: 1px solid var(--color-border-light);
|
||||
color: var(--color-text-muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@@ -126,7 +163,7 @@ body {
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
color: #333;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.header-info {
|
||||
@@ -136,12 +173,12 @@ body {
|
||||
}
|
||||
|
||||
.user-name {
|
||||
color: #666;
|
||||
color: var(--color-text-secondary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.user-role {
|
||||
background: #667eea;
|
||||
background: var(--color-primary);
|
||||
color: white;
|
||||
padding: 2px 8px;
|
||||
border-radius: 20px;
|
||||
@@ -149,7 +186,7 @@ body {
|
||||
}
|
||||
|
||||
.btn-logout {
|
||||
background: #e53e3e;
|
||||
background: var(--color-danger);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 6px 16px;
|
||||
@@ -160,14 +197,14 @@ body {
|
||||
}
|
||||
|
||||
.btn-logout:hover {
|
||||
background: #c53030;
|
||||
background: var(--color-danger-dark);
|
||||
}
|
||||
|
||||
/* ========== 导航菜单 ========== */
|
||||
.nav {
|
||||
background: white;
|
||||
padding: 0 24px;
|
||||
border-bottom: 1px solid #eee;
|
||||
border-bottom: 1px solid var(--color-border-light);
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
overflow-x: auto;
|
||||
@@ -177,7 +214,7 @@ body {
|
||||
padding: 12px 20px;
|
||||
background: none;
|
||||
border: none;
|
||||
color: #666;
|
||||
color: var(--color-text-secondary);
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s;
|
||||
@@ -187,12 +224,12 @@ body {
|
||||
}
|
||||
|
||||
.nav-item:hover {
|
||||
color: #667eea;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.nav-item.active {
|
||||
color: #667eea;
|
||||
border-bottom-color: #667eea;
|
||||
color: var(--color-primary);
|
||||
border-bottom-color: var(--color-primary);
|
||||
}
|
||||
|
||||
/* ========== 容器 ========== */
|
||||
@@ -216,8 +253,8 @@ body {
|
||||
font-weight: bold;
|
||||
margin-bottom: 16px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 2px solid #667eea;
|
||||
color: #333;
|
||||
border-bottom: 2px solid var(--color-primary);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
/* ========== 统计卡片网格 ========== */
|
||||
@@ -239,12 +276,12 @@ body {
|
||||
.stat-value {
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
color: var(--color-primary);
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: #666;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
@@ -261,17 +298,17 @@ table {
|
||||
th, td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #eee;
|
||||
border-bottom: 1px solid var(--color-border-light);
|
||||
}
|
||||
|
||||
th {
|
||||
background: #f8f9fa;
|
||||
background: var(--color-hover);
|
||||
font-weight: 600;
|
||||
color: #555;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
tr:hover {
|
||||
background: #f8f9fa;
|
||||
background: var(--color-hover);
|
||||
}
|
||||
|
||||
/* ========== 状态标签 ========== */
|
||||
@@ -324,57 +361,94 @@ tr:hover {
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
background: var(--btn-primary-bg);
|
||||
color: var(--btn-primary-text);
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #5a67d8;
|
||||
background: var(--color-primary-hover);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #e53e3e;
|
||||
color: white;
|
||||
background: var(--btn-danger-bg);
|
||||
color: var(--btn-danger-text);
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: #c53030;
|
||||
background: var(--color-danger-dark);
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: #38a169;
|
||||
color: white;
|
||||
background: var(--color-success-light);
|
||||
color: var(--color-success);
|
||||
border: 1px solid #c6f6d5;
|
||||
}
|
||||
|
||||
.btn-success:hover {
|
||||
background: #2f855a;
|
||||
background: #c6f6d5;
|
||||
}
|
||||
|
||||
.btn-warning {
|
||||
background: #d69e2e;
|
||||
color: white;
|
||||
background: var(--color-warning-light);
|
||||
color: var(--color-warning);
|
||||
border: 1px solid #fefcbf;
|
||||
}
|
||||
|
||||
.btn-warning:hover {
|
||||
background: #b7791f;
|
||||
background: #fefcbf;
|
||||
}
|
||||
|
||||
.btn-info {
|
||||
background: #3182ce;
|
||||
color: white;
|
||||
background: #e3f2fd;
|
||||
color: #1565c0;
|
||||
border: 1px solid #bbdefb;
|
||||
}
|
||||
|
||||
.btn-info:hover {
|
||||
background: #2b6cb0;
|
||||
background: #bbdefb;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #718096;
|
||||
color: white;
|
||||
background: var(--color-hover);
|
||||
color: var(--color-text-secondary);
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: #4a5568;
|
||||
background: var(--color-border-light);
|
||||
}
|
||||
|
||||
.btn-outline {
|
||||
background: transparent;
|
||||
color: var(--color-primary);
|
||||
border: 1px solid var(--color-primary);
|
||||
}
|
||||
|
||||
.btn-outline:hover {
|
||||
background: var(--color-primary-light);
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
background: transparent;
|
||||
color: var(--color-text-secondary);
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.btn-ghost:hover {
|
||||
background: var(--color-hover);
|
||||
border-color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.btn-outline-danger {
|
||||
background: transparent;
|
||||
color: var(--color-danger);
|
||||
border: 1px solid var(--color-danger);
|
||||
}
|
||||
|
||||
.btn-outline-danger:hover {
|
||||
background: var(--color-danger-light);
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
@@ -412,12 +486,12 @@ tr:hover {
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 1px solid #eee;
|
||||
border-bottom: 1px solid var(--color-border-light);
|
||||
}
|
||||
|
||||
.modal-header h3 {
|
||||
font-size: 18px;
|
||||
color: #333;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
@@ -425,13 +499,13 @@ tr:hover {
|
||||
border: none;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
color: #999;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
margin-top: 20px;
|
||||
padding-top: 16px;
|
||||
border-top: 1px solid #eee;
|
||||
border-top: 1px solid var(--color-border-light);
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
@@ -446,7 +520,7 @@ tr:hover {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-weight: 500;
|
||||
color: #555;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
@@ -454,7 +528,7 @@ tr:hover {
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
}
|
||||
@@ -463,12 +537,12 @@ tr:hover {
|
||||
.form-group select:focus,
|
||||
.form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.form-group small {
|
||||
display: block;
|
||||
color: #999;
|
||||
color: var(--color-text-muted);
|
||||
font-size: 12px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
@@ -513,7 +587,7 @@ tr:hover {
|
||||
|
||||
.search-bar input {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
width: 200px;
|
||||
}
|
||||
@@ -530,10 +604,10 @@ tr:hover {
|
||||
|
||||
.pagination a, .pagination span {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
text-decoration: none;
|
||||
color: #666;
|
||||
color: var(--color-text-secondary);
|
||||
cursor: pointer;
|
||||
min-width: 36px;
|
||||
text-align: center;
|
||||
@@ -542,22 +616,22 @@ tr:hover {
|
||||
}
|
||||
|
||||
.pagination a:hover {
|
||||
background: #f0f0ff;
|
||||
border-color: #667eea;
|
||||
color: #667eea;
|
||||
background: var(--color-primary-light);
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.pagination .active {
|
||||
background: #667eea;
|
||||
background: var(--color-primary);
|
||||
color: white;
|
||||
border-color: #667eea;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.pagination .ellipsis {
|
||||
border: none;
|
||||
cursor: default;
|
||||
padding: 6px 4px;
|
||||
color: #999;
|
||||
color: var(--color-text-muted);
|
||||
min-width: auto;
|
||||
}
|
||||
|
||||
@@ -567,13 +641,13 @@ tr:hover {
|
||||
gap: 4px;
|
||||
margin-left: 8px;
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.pagination .page-jump input {
|
||||
width: 50px;
|
||||
padding: 5px 8px;
|
||||
border: 1px solid #ddd;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
@@ -581,8 +655,8 @@ tr:hover {
|
||||
}
|
||||
|
||||
.pagination .page-jump input:focus {
|
||||
border-color: #667eea;
|
||||
box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.15);
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.15);
|
||||
}
|
||||
|
||||
.pagination .page-nav {
|
||||
@@ -605,11 +679,11 @@ tr:hover {
|
||||
}
|
||||
|
||||
.toast-success {
|
||||
background: #38a169;
|
||||
background: var(--color-success);
|
||||
}
|
||||
|
||||
.toast-error {
|
||||
background: #e53e3e;
|
||||
background: var(--color-danger);
|
||||
}
|
||||
|
||||
.toast-warning {
|
||||
@@ -632,8 +706,8 @@ tr:hover {
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid #ddd;
|
||||
border-top-color: #667eea;
|
||||
border: 2px solid var(--color-border);
|
||||
border-top-color: var(--color-primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
@@ -646,14 +720,14 @@ tr:hover {
|
||||
.footer {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: #999;
|
||||
color: var(--color-text-muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* ========== 记录项 ========== */
|
||||
.record-item {
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid #eee;
|
||||
border-bottom: 1px solid var(--color-border-light);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
@@ -664,22 +738,22 @@ tr:hover {
|
||||
}
|
||||
|
||||
.record-points.plus {
|
||||
color: #38a169;
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
.record-points.minus {
|
||||
color: #e53e3e;
|
||||
color: var(--color-danger);
|
||||
}
|
||||
|
||||
.record-reason {
|
||||
flex: 1;
|
||||
margin: 0 15px;
|
||||
color: #555;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.record-time {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.view-more {
|
||||
@@ -688,7 +762,7 @@ tr:hover {
|
||||
}
|
||||
|
||||
.view-more a {
|
||||
color: #667eea;
|
||||
color: var(--color-primary);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
@@ -700,7 +774,7 @@ tr:hover {
|
||||
.score-number {
|
||||
font-size: 64px;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
/* ========== 响应式 ========== */
|
||||
@@ -755,9 +829,9 @@ tr:hover {
|
||||
}
|
||||
|
||||
.action-dropdown-toggle {
|
||||
background: #f7fafc;
|
||||
color: #4a5568;
|
||||
border: 1px solid #e2e8f0;
|
||||
background: var(--color-hover);
|
||||
color: var(--color-text-secondary);
|
||||
border: 1px solid var(--color-border);
|
||||
padding: 4px 10px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
@@ -767,13 +841,13 @@ tr:hover {
|
||||
}
|
||||
|
||||
.action-dropdown-toggle:hover {
|
||||
background: #edf2f7;
|
||||
background: var(--color-border-light);
|
||||
border-color: #cbd5e0;
|
||||
}
|
||||
|
||||
.action-dropdown-toggle.open {
|
||||
background: #edf2f7;
|
||||
border-color: #a0aec0;
|
||||
background: var(--color-border-light);
|
||||
border-color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.action-dropdown-menu {
|
||||
@@ -785,7 +859,7 @@ tr:hover {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
|
||||
border: 1px solid #e2e8f0;
|
||||
border: 1px solid var(--color-border);
|
||||
min-width: 120px;
|
||||
z-index: 200;
|
||||
overflow: hidden;
|
||||
@@ -799,7 +873,7 @@ tr:hover {
|
||||
.action-dropdown-menu a {
|
||||
display: block;
|
||||
padding: 8px 14px;
|
||||
color: #4a5568;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
@@ -808,20 +882,20 @@ tr:hover {
|
||||
}
|
||||
|
||||
.action-dropdown-menu a:hover {
|
||||
background: #f7fafc;
|
||||
background: var(--color-hover);
|
||||
color: #2d3748;
|
||||
}
|
||||
|
||||
.action-dropdown-menu a.danger {
|
||||
color: #e53e3e;
|
||||
border-top: 1px solid #edf2f7;
|
||||
color: var(--color-danger);
|
||||
border-top: 1px solid var(--color-border-light);
|
||||
margin-top: 4px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
.action-dropdown-menu a.danger:hover {
|
||||
background: #fff5f5;
|
||||
color: #c53030;
|
||||
background: var(--color-danger-light);
|
||||
color: var(--color-danger-dark);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
@@ -830,3 +904,25 @@ tr:hover {
|
||||
left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ========== 链接 ========== */
|
||||
.link {
|
||||
color: var(--color-primary);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* ========== 文本工具类 ========== */
|
||||
.text-danger { color: var(--color-danger); }
|
||||
.text-success { color: var(--color-success); }
|
||||
.text-muted { color: var(--color-text-muted); }
|
||||
|
||||
/* ========== 标签 ========== */
|
||||
.tag { padding: 2px 8px; border-radius: 10px; font-size: 12px; }
|
||||
.tag-success { background: #e8f5e9; color: #2e7d32; }
|
||||
.tag-danger { background: #ffebee; color: #c62828; }
|
||||
.tag-warning { background: #fff3e0; color: #e65100; }
|
||||
.tag-info { background: #e3f2fd; color: #1565c0; }
|
||||
|
||||
@@ -18,9 +18,9 @@ async function loadStudents() {
|
||||
html += `<tr>
|
||||
<td><input type="checkbox" class="student-checkbox" data-id="${student.student_id}"></td>
|
||||
<td>${escapeHtml(student.student_no)}</td>
|
||||
<td><a href="/admin/history.php?student_id=${student.student_id}" style="color: #3498db; text-decoration: none;">${escapeHtml(student.name)}</a></td>
|
||||
<td><a href="/admin/history.php?student_id=${student.student_id}" class="link">${escapeHtml(student.name)}</a></td>
|
||||
<td>${student.total_points}</td>
|
||||
<td><button class="btn btn-sm btn-primary" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button></td>
|
||||
<td><button class="btn btn-sm btn-outline" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button></td>
|
||||
</tr>`;
|
||||
});
|
||||
if (res.data.students.length === 0) {
|
||||
|
||||
@@ -29,7 +29,7 @@ async function loadDashboard() {
|
||||
quickActions += '<button class="btn btn-primary" onclick="location.href=\'/admin/conduct.php\'">操行分管理</button>';
|
||||
}
|
||||
if (role === '班主任') {
|
||||
quickActions += '<button class="btn btn-success" onclick="location.href=\'/admin/students.php\'">导入学生</button>';
|
||||
quickActions += '<button class="btn btn-outline" onclick="location.href=\'/admin/students.php\'">导入学生</button>';
|
||||
quickActions += '<button class="btn btn-secondary" onclick="location.href=\'/admin/conduct.php\'">导出德育分记录</button>';
|
||||
}
|
||||
document.getElementById('quickActions').innerHTML = quickActions || '<p>暂无快捷操作</p>';
|
||||
|
||||
@@ -50,7 +50,7 @@ async function loadStudents() {
|
||||
<td>${escapeHtml(student.student_no)}</td>
|
||||
<td>${escapeHtml(student.name)}</td>
|
||||
<td>${student.total_points}</td>
|
||||
<td><button class="btn btn-sm btn-primary" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button></td>
|
||||
<td><button class="btn btn-sm btn-outline" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button></td>
|
||||
</tr>`;
|
||||
});
|
||||
if (res.data.students.length === 0) {
|
||||
@@ -110,13 +110,18 @@ function handleSubmitPoints() {
|
||||
function toggleSubjectPanel() {
|
||||
const content = document.getElementById('subjectPanelContent');
|
||||
const toggle = document.getElementById('subjectPanelToggle');
|
||||
if (content.style.display === 'none') {
|
||||
content.style.display = 'block';
|
||||
if (!content || !toggle) return;
|
||||
|
||||
const isExpanded = content.classList.contains('expanded');
|
||||
if (isExpanded) {
|
||||
content.classList.remove('expanded');
|
||||
toggle.classList.remove('expanded');
|
||||
toggle.textContent = '▶ 展开';
|
||||
} else {
|
||||
content.classList.add('expanded');
|
||||
toggle.classList.add('expanded');
|
||||
toggle.textContent = '▼ 收起';
|
||||
loadSubjectList();
|
||||
} else {
|
||||
content.style.display = 'none';
|
||||
toggle.textContent = '▶ 展开';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,11 +137,11 @@ async function loadSubjectList() {
|
||||
<span class="subject-status ${sub.is_active ? 'subject-status-active' : 'subject-status-inactive'}">
|
||||
${sub.is_active ? '启用' : '禁用'}
|
||||
</span>
|
||||
<button class="btn btn-sm btn-primary" onclick="showEditSubjectModal(${sub.subject_id}, '${escapeHtml(sub.subject_name)}', '${escapeHtml(sub.subject_code || '')}', ${sub.sort_order || 0})">编辑</button>
|
||||
<button class="btn btn-sm" onclick="toggleSubjectStatus(${sub.subject_id}, ${!sub.is_active})">
|
||||
<button class="btn btn-sm btn-outline" onclick="showEditSubjectModal(${sub.subject_id}, '${escapeHtml(sub.subject_name)}', '${escapeHtml(sub.subject_code || '')}', ${sub.sort_order || 0})">编辑</button>
|
||||
<button class="btn btn-sm btn-ghost" onclick="toggleSubjectStatus(${sub.subject_id}, ${!sub.is_active})">
|
||||
${sub.is_active ? '禁用' : '启用'}
|
||||
</button>
|
||||
<button class="btn btn-sm btn-danger" onclick="deleteSubject(${sub.subject_id})">删除</button>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deleteSubject(${sub.subject_id})">删除</button>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
@@ -234,6 +239,12 @@ async function submitEditSubject() {
|
||||
}
|
||||
}
|
||||
|
||||
// 绑定科目管理折叠面板
|
||||
var subjectHeader = document.getElementById('subjectPanelHeader');
|
||||
if (subjectHeader) {
|
||||
subjectHeader.addEventListener('click', toggleSubjectPanel);
|
||||
}
|
||||
|
||||
loadStudents();
|
||||
loadSubjectsForHomework();
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ async function loadHomework() {
|
||||
statusDisplay = getStatusBadge(hw.status, 'homework');
|
||||
}
|
||||
// 扣分显示
|
||||
const pointsDisplay = hw.points ? `<span style="color: #e53e3e;">${hw.points}分</span>` : '-';
|
||||
const pointsDisplay = hw.points ? `<span class="text-danger">${hw.points}分</span>` : '-';
|
||||
|
||||
html += `<tr>
|
||||
<td>${escapeHtml(hw.title)}</td>
|
||||
|
||||
@@ -25,13 +25,13 @@ async function loadStudents(page = 1) {
|
||||
html += `<tr>
|
||||
<td><input type="checkbox" class="student-checkbox" data-id="${student.student_id}"></td>
|
||||
<td>${escapeHtml(student.student_no)}</td>
|
||||
<td><a href="/admin/history.php?student_id=${student.student_id}" style="color: #3498db; text-decoration: none;">${escapeHtml(student.name)}</a></td>
|
||||
<td><a href="/admin/history.php?student_id=${student.student_id}" class="link">${escapeHtml(student.name)}</a></td>
|
||||
<td>${escapeHtml(student.dormitory_number || '-')}</td>
|
||||
<td>${student.total_points}</td>
|
||||
${userRole === '班主任' ? `<td>${student.parent_phone ? student.parent_phone.slice(0,3) + '******' + student.parent_phone.slice(-2) : '-'}</td>` : ''}
|
||||
<td>
|
||||
<div class="action-dropdown">
|
||||
<button class="btn btn-sm btn-primary" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button>
|
||||
<button class="btn btn-sm btn-outline" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button>
|
||||
${userRole === '班主任' ? `<button class="btn btn-sm action-dropdown-toggle" onclick="toggleActionDropdown(this)">更多 ▼</button>
|
||||
<div class="action-dropdown-menu">
|
||||
<a onclick="showEditStudentModal(${student.student_id}, '${escapeHtml(student.student_no)}', '${escapeHtml(student.name)}', '${escapeHtml(student.parent_phone || '')}', '${escapeHtml(student.dormitory_number || '')}')">编辑</a>
|
||||
|
||||
@@ -22,11 +22,11 @@ async function loadSubjects() {
|
||||
<span class="subject-status ${sub.is_active ? 'subject-status-active' : 'subject-status-inactive'}">
|
||||
${sub.is_active ? '启用' : '禁用'}
|
||||
</span>
|
||||
<button class="btn btn-sm btn-primary" onclick="showEditSubjectModal(${sub.subject_id}, '${escapeHtml(sub.subject_name)}', '${escapeHtml(sub.subject_code || '')}', ${sub.sort_order || 0})">编辑</button>
|
||||
<button class="btn btn-sm" onclick="toggleSubject(${sub.subject_id}, ${!sub.is_active})">
|
||||
<button class="btn btn-sm btn-outline" onclick="showEditSubjectModal(${sub.subject_id}, '${escapeHtml(sub.subject_name)}', '${escapeHtml(sub.subject_code || '')}', ${sub.sort_order || 0})">编辑</button>
|
||||
<button class="btn btn-sm btn-ghost" onclick="toggleSubject(${sub.subject_id}, ${!sub.is_active})">
|
||||
${sub.is_active ? '禁用' : '启用'}
|
||||
</button>
|
||||
<button class="btn btn-sm btn-danger" onclick="deleteSubject(${sub.subject_id})">删除</button>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deleteSubject(${sub.subject_id})">删除</button>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
@@ -37,8 +37,8 @@ include __DIR__ . '/../includes/header.php';
|
||||
border-bottom: 2px solid transparent;
|
||||
}
|
||||
.nav .nav-item.active {
|
||||
color: #667eea;
|
||||
border-bottom-color: #667eea;
|
||||
color: var(--color-primary);
|
||||
border-bottom-color: var(--color-primary);
|
||||
font-weight: bold;
|
||||
}
|
||||
.semester-card {
|
||||
@@ -54,7 +54,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 1px solid #eee;
|
||||
border-bottom: 1px solid var(--color-border-light);
|
||||
}
|
||||
.semester-name {
|
||||
font-size: 18px;
|
||||
@@ -77,7 +77,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
.semester-stat-value {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
.semester-stat-label {
|
||||
font-size: 12px;
|
||||
@@ -169,18 +169,18 @@ async function loadSemesterRecords() {
|
||||
<div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid #eee;">
|
||||
<div style="font-size: 12px; color: #999; margin-bottom: 8px;">考勤统计</div>
|
||||
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
||||
<span style="background: #e8f5e9; color: #388e3c; padding: 2px 8px; border-radius: 10px; font-size: 12px;">出勤 ${record.attendance_present || 0}</span>
|
||||
<span style="background: #ffebee; color: #c62828; padding: 2px 8px; border-radius: 10px; font-size: 12px;">缺勤 ${record.attendance_absent || 0}</span>
|
||||
<span style="background: #fff3e0; color: #e65100; padding: 2px 8px; border-radius: 10px; font-size: 12px;">迟到 ${record.attendance_late || 0}</span>
|
||||
<span style="background: #e3f2fd; color: #1565c0; padding: 2px 8px; border-radius: 10px; font-size: 12px;">请假 ${record.attendance_leave || 0}</span>
|
||||
<span class="tag tag-success">出勤 ${record.attendance_present || 0}</span>
|
||||
<span class="tag tag-danger">缺勤 ${record.attendance_absent || 0}</span>
|
||||
<span class="tag tag-warning">迟到 ${record.attendance_late || 0}</span>
|
||||
<span class="tag tag-info">请假 ${record.attendance_leave || 0}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div style="margin-top: 8px;">
|
||||
<div style="font-size: 12px; color: #999; margin-bottom: 8px;">作业统计</div>
|
||||
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
||||
<span style="background: #e8f5e9; color: #388e3c; padding: 2px 8px; border-radius: 10px; font-size: 12px;">已交 ${record.homework_submitted || 0}</span>
|
||||
<span style="background: #ffebee; color: #c62828; padding: 2px 8px; border-radius: 10px; font-size: 12px;">未交 ${record.homework_not_submitted || 0}</span>
|
||||
<span style="background: #fff3e0; color: #e65100; padding: 2px 8px; border-radius: 10px; font-size: 12px;">迟交 ${record.homework_late || 0}</span>
|
||||
<span class="tag tag-success">已交 ${record.homework_submitted || 0}</span>
|
||||
<span class="tag tag-danger">未交 ${record.homework_not_submitted || 0}</span>
|
||||
<span class="tag tag-warning">迟交 ${record.homework_late || 0}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
264
sql/init.sql
264
sql/init.sql
@@ -204,272 +204,10 @@ CREATE TABLE IF NOT EXISTS `semester_archives` (
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
-- ===========================================
|
||||
-- 迁移语句:为现有表新增字段(仅在字段不存在时添加)
|
||||
-- ===========================================
|
||||
|
||||
-- conduct_records 表:添加 semester_id 字段(如不存在)
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'conduct_records'
|
||||
AND COLUMN_NAME = 'semester_id'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `conduct_records` ADD COLUMN `semester_id` INT DEFAULT NULL COMMENT ''所属学期ID'' AFTER `revoked_at`',
|
||||
'SELECT ''conduct_records.semester_id already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 为新增的 semester_id 添加外键(如不存在)
|
||||
SET @fk_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'conduct_records'
|
||||
AND COLUMN_NAME = 'semester_id'
|
||||
AND REFERENCED_TABLE_NAME IS NOT NULL
|
||||
);
|
||||
SET @sql = IF(@fk_exists = 0,
|
||||
'ALTER TABLE `conduct_records` ADD FOREIGN KEY (`semester_id`) REFERENCES `semesters`(`semester_id`) ON DELETE SET NULL',
|
||||
'SELECT ''conduct_records semester_id FK already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- attendance_records 表:添加 semester_id 字段(如不存在)
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'attendance_records'
|
||||
AND COLUMN_NAME = 'semester_id'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `attendance_records` ADD COLUMN `semester_id` INT DEFAULT NULL COMMENT ''所属学期ID'' AFTER `deduction_record_id`',
|
||||
'SELECT ''attendance_records.semester_id already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 为新增的 semester_id 添加外键(如不存在)
|
||||
SET @fk_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'attendance_records'
|
||||
AND COLUMN_NAME = 'semester_id'
|
||||
AND REFERENCED_TABLE_NAME IS NOT NULL
|
||||
);
|
||||
SET @sql = IF(@fk_exists = 0,
|
||||
'ALTER TABLE `attendance_records` ADD FOREIGN KEY (`semester_id`) REFERENCES `semesters`(`semester_id`) ON DELETE SET NULL',
|
||||
'SELECT ''attendance_records semester_id FK already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- attendance_records 表:添加 slot 字段(如不存在)
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'attendance_records'
|
||||
AND COLUMN_NAME = 'slot'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `attendance_records` ADD COLUMN `slot` VARCHAR(20) DEFAULT ''morning'' COMMENT ''时段: morning/afternoon/evening'' AFTER `date`',
|
||||
'SELECT ''attendance_records.slot already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 删除旧唯一键并添加新唯一键(含slot)
|
||||
SET @uk_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'attendance_records'
|
||||
AND CONSTRAINT_NAME = 'uk_student_date'
|
||||
);
|
||||
SET @sql = IF(@uk_exists > 0,
|
||||
'ALTER TABLE `attendance_records` DROP INDEX `uk_student_date`, ADD UNIQUE KEY `uk_student_date_slot` (`student_id`, `date`, `slot`)',
|
||||
'SELECT ''uk_student_date does not exist, skipping'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 attendance_present 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'attendance_present'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `attendance_present` INT DEFAULT 0 COMMENT ''出勤次数'' AFTER `total_students`',
|
||||
'SELECT ''semester_archives.attendance_present already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 attendance_absent 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'attendance_absent'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `attendance_absent` INT DEFAULT 0 COMMENT ''缺勤次数'' AFTER `attendance_present`',
|
||||
'SELECT ''semester_archives.attendance_absent already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 attendance_late 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'attendance_late'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `attendance_late` INT DEFAULT 0 COMMENT ''迟到次数'' AFTER `attendance_absent`',
|
||||
'SELECT ''semester_archives.attendance_late already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 attendance_leave 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'attendance_leave'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `attendance_leave` INT DEFAULT 0 COMMENT ''请假次数'' AFTER `attendance_late`',
|
||||
'SELECT ''semester_archives.attendance_leave already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 homework_submitted 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'homework_submitted'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `homework_submitted` INT DEFAULT 0 COMMENT ''已交作业数'' AFTER `attendance_leave`',
|
||||
'SELECT ''semester_archives.homework_submitted already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 homework_not_submitted 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'homework_not_submitted'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `homework_not_submitted` INT DEFAULT 0 COMMENT ''未交作业数'' AFTER `homework_submitted`',
|
||||
'SELECT ''semester_archives.homework_not_submitted already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 homework_late 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'homework_late'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `homework_late` INT DEFAULT 0 COMMENT ''迟交作业数'' AFTER `homework_not_submitted`',
|
||||
'SELECT ''semester_archives.homework_late already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:attendance_records 表新增 slot 字段(考勤时段系统 v1.3)
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'attendance_records'
|
||||
AND COLUMN_NAME = 'slot'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `attendance_records` ADD COLUMN `slot` ENUM(''morning'', ''afternoon'', ''evening'') DEFAULT ''morning'' COMMENT ''考勤时段:早上/中午/晚修'' AFTER `date`',
|
||||
'SELECT ''attendance_records.slot already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:attendance_records 唯一索引从 (student_id, date) 改为 (student_id, date, slot)
|
||||
SET @index_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'attendance_records'
|
||||
AND INDEX_NAME = 'uk_student_date_slot'
|
||||
);
|
||||
SET @sql = IF(@index_exists = 0,
|
||||
'ALTER TABLE `attendance_records` DROP INDEX `uk_student_date`, ADD UNIQUE KEY `uk_student_date_slot` (`student_id`, `date`, `slot`)',
|
||||
'SELECT ''attendance_records.uk_student_date_slot already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 插入初始科目(仅语数英,如不存在)
|
||||
INSERT IGNORE INTO `subjects` (`subject_name`, `subject_code`, `sort_order`) VALUES
|
||||
('语文', 'CHI', 1),
|
||||
('数学', 'MATH', 2),
|
||||
('英语', 'ENG', 3);
|
||||
|
||||
SELECT '数据库初始化/迁移完成!' AS message;
|
||||
|
||||
-- ===========================================
|
||||
-- v2.0 迁移脚本
|
||||
-- ===========================================
|
||||
|
||||
-- 扩展密码哈希字段长度以支持bcrypt
|
||||
ALTER TABLE users MODIFY COLUMN password_hash VARCHAR(255) NOT NULL;
|
||||
|
||||
-- 添加宿舍号字段
|
||||
SET @dbname = DATABASE();
|
||||
SET @tablename = 'students';
|
||||
SET @columnname = 'dormitory_number';
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND COLUMN_NAME = @columnname) > 0,
|
||||
'SELECT 1',
|
||||
'ALTER TABLE students ADD COLUMN dormitory_number VARCHAR(20) DEFAULT NULL COMMENT ''宿舍号'' AFTER parent_phone'
|
||||
));
|
||||
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||
EXECUTE alterIfNotExists;
|
||||
DEALLOCATE PREPARE alterIfNotExists;
|
||||
|
||||
-- 添加分数最后更新时间字段
|
||||
SET @columnname = 'points_updated_at';
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND COLUMN_NAME = @columnname) > 0,
|
||||
'SELECT 1',
|
||||
'ALTER TABLE students ADD COLUMN points_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ''分数最后更新时间'''
|
||||
));
|
||||
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||
EXECUTE alterIfNotExists;
|
||||
DEALLOCATE PREPARE alterIfNotExists;
|
||||
SELECT '数据库初始化完成!' AS message;
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
-- ===========================================
|
||||
-- 班级操行分管理系统 - v2.0 数据库迁移脚本
|
||||
-- 适用版本: v1.8 → v2.0
|
||||
-- 字符集: utf8mb4
|
||||
--
|
||||
-- 说明:
|
||||
-- v2.0 主要为应用层代码变更(UI折叠菜单、扣分类型扩展、
|
||||
-- 科目选择修复、页面改名、记录人优化、学期管理优化等),
|
||||
-- 数据库 schema 变更较少。本脚本主要处理历史数据迁移
|
||||
-- 和索引优化。
|
||||
--
|
||||
-- 迁移内容:
|
||||
-- 1. 将 conduct_records.recorder_name 从用户名更新为真实姓名
|
||||
-- 2. 将 attendance_records 相关记录中的 recorder_name 同步更新
|
||||
-- 3. 确保 semester_id 索引存在(学期记录数统计优化)
|
||||
-- 4. 数据验证
|
||||
--
|
||||
-- 重要: 执行前请备份数据库!
|
||||
-- ===========================================
|
||||
|
||||
USE `classmanagerdb`;
|
||||
|
||||
-- ===========================================
|
||||
-- 1. 更新 conduct_records 中的 recorder_name
|
||||
-- v2.0 将 recorder_name 从用户名(username)改为真实姓名(real_name)
|
||||
-- 需要将历史记录中的用户名更新为对应的真实姓名
|
||||
-- ===========================================
|
||||
|
||||
-- 通过 JOIN users 表将 recorder_name 从 username 更新为 real_name
|
||||
UPDATE conduct_records cr
|
||||
INNER JOIN users u ON cr.recorder_id = u.user_id
|
||||
SET cr.recorder_name = u.real_name
|
||||
WHERE cr.recorder_name != u.real_name
|
||||
OR cr.recorder_name IS NULL;
|
||||
|
||||
-- ===========================================
|
||||
-- 2. 确保学期相关索引存在
|
||||
-- v2.0 新增学期记录数统计功能,需要 semester_id 索引优化查询
|
||||
-- ===========================================
|
||||
|
||||
SET @dbname = DATABASE();
|
||||
|
||||
-- conduct_records 表 semester_id 索引
|
||||
SET @indexname = 'idx_conduct_semester_id';
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = 'conduct_records' AND INDEX_NAME = @indexname) > 0,
|
||||
'SELECT 1',
|
||||
'ALTER TABLE conduct_records ADD INDEX idx_conduct_semester_id (semester_id)'
|
||||
));
|
||||
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||
EXECUTE alterIfNotExists;
|
||||
DEALLOCATE PREPARE alterIfNotExists;
|
||||
|
||||
-- attendance_records 表 semester_id 索引
|
||||
SET @indexname = 'idx_attendance_semester_id';
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = 'attendance_records' AND INDEX_NAME = @indexname) > 0,
|
||||
'SELECT 1',
|
||||
'ALTER TABLE attendance_records ADD INDEX idx_attendance_semester_id (semester_id)'
|
||||
));
|
||||
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||
EXECUTE alterIfNotExists;
|
||||
DEALLOCATE PREPARE alterIfNotExists;
|
||||
|
||||
-- ===========================================
|
||||
-- 3. 确保之前版本的索引也存在(幂等兼容)
|
||||
-- ===========================================
|
||||
|
||||
-- assignments 表 subject_id 索引(v1.8 科目删除数据检查)
|
||||
SET @indexname = 'idx_assignments_subject_id';
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = 'assignments' AND INDEX_NAME = @indexname) > 0,
|
||||
'SELECT 1',
|
||||
'ALTER TABLE assignments ADD INDEX idx_assignments_subject_id (subject_id)'
|
||||
));
|
||||
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||
EXECUTE alterIfNotExists;
|
||||
DEALLOCATE PREPARE alterIfNotExists;
|
||||
|
||||
-- conduct_records 表 student_id 索引
|
||||
SET @indexname = 'idx_conduct_student_id';
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = 'conduct_records' AND INDEX_NAME = @indexname) > 0,
|
||||
'SELECT 1',
|
||||
'ALTER TABLE conduct_records ADD INDEX idx_conduct_student_id (student_id)'
|
||||
));
|
||||
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||
EXECUTE alterIfNotExists;
|
||||
DEALLOCATE PREPARE alterIfNotExists;
|
||||
|
||||
-- conduct_records 表 created_at 索引
|
||||
SET @indexname = 'idx_conduct_created_at';
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = 'conduct_records' AND INDEX_NAME = @indexname) > 0,
|
||||
'SELECT 1',
|
||||
'ALTER TABLE conduct_records ADD INDEX idx_conduct_created_at (created_at)'
|
||||
));
|
||||
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||
EXECUTE alterIfNotExists;
|
||||
DEALLOCATE PREPARE alterIfNotExists;
|
||||
|
||||
-- ===========================================
|
||||
-- 4. 验证迁移结果
|
||||
-- ===========================================
|
||||
|
||||
SELECT '===== v2.0 数据库迁移验证 =====' AS '';
|
||||
|
||||
-- 检查 recorder_name 是否已更新为真实姓名
|
||||
SELECT
|
||||
'recorder_name 迁移验证' AS `检查项`,
|
||||
COUNT(*) AS `总记录数`,
|
||||
SUM(CASE WHEN cr.recorder_name = u.real_name THEN 1 ELSE 0 END) AS `已匹配真实姓名`,
|
||||
SUM(CASE WHEN cr.recorder_name != u.real_name AND u.real_name IS NOT NULL THEN 1 ELSE 0 END) AS `仍为用户名`
|
||||
FROM conduct_records cr
|
||||
INNER JOIN users u ON cr.recorder_id = u.user_id;
|
||||
|
||||
-- 检查学期相关索引
|
||||
SELECT
|
||||
'学期索引验证' AS `检查项`,
|
||||
TABLE_NAME AS `表名`,
|
||||
INDEX_NAME AS `索引名`
|
||||
FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = @dbname
|
||||
AND INDEX_NAME IN ('idx_conduct_semester_id', 'idx_attendance_semester_id')
|
||||
GROUP BY TABLE_NAME, INDEX_NAME;
|
||||
|
||||
-- 检查学期记录数统计示例
|
||||
SELECT
|
||||
'学期记录统计示例' AS `检查项`,
|
||||
s.semester_name,
|
||||
s.is_active,
|
||||
(SELECT COUNT(*) FROM conduct_records WHERE semester_id = s.semester_id) AS `操行分记录数`,
|
||||
(SELECT COUNT(*) FROM attendance_records WHERE semester_id = s.semester_id) AS `考勤记录数`
|
||||
FROM semesters s
|
||||
ORDER BY s.is_active DESC, s.created_at DESC
|
||||
LIMIT 5;
|
||||
|
||||
SELECT 'v2.0 数据库迁移完成!' AS message;
|
||||
31
sql/upgrades/v1.7.sql
Normal file
31
sql/upgrades/v1.7.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
-- ===========================================
|
||||
-- 班级操行分管理系统 - 升级至 v1.7
|
||||
-- 字符集: utf8mb4
|
||||
--
|
||||
-- 说明: 此脚本用于在已有数据库中创建版本管理系统。
|
||||
-- 适用于从 v1.7 之前的版本升级。
|
||||
--
|
||||
-- 变更内容:
|
||||
-- 1. 创建 system_settings 表(用于存储版本号等系统配置)
|
||||
-- 2. 插入初始版本号 1.7
|
||||
--
|
||||
-- 兼容性: 使用 IF NOT EXISTS 实现幂等,phpMyAdmin 可直接执行
|
||||
-- ===========================================
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 1: 创建 system_settings 表
|
||||
-- ===========================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `system_settings` (
|
||||
`setting_key` VARCHAR(50) PRIMARY KEY,
|
||||
`setting_value` VARCHAR(255) NOT NULL,
|
||||
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 2: 插入初始版本号
|
||||
-- ===========================================
|
||||
|
||||
INSERT INTO `system_settings` (`setting_key`, `setting_value`)
|
||||
VALUES ('db_version', '1.7')
|
||||
ON DUPLICATE KEY UPDATE `setting_value` = '1.7';
|
||||
131
sql/upgrades/v1.8.sql
Normal file
131
sql/upgrades/v1.8.sql
Normal file
@@ -0,0 +1,131 @@
|
||||
-- ===========================================
|
||||
-- 班级操行分管理系统 - v1.7 → v1.8 升级脚本
|
||||
-- 字符集: utf8mb4
|
||||
--
|
||||
-- 变更内容:
|
||||
-- 1. conduct_records 表添加 related_type 列
|
||||
-- 2. conduct_records 表添加 semester_id 列 + 外键
|
||||
-- 3. attendance_records 表添加 semester_id 列 + 外键
|
||||
--
|
||||
-- 兼容性: 使用存储过程实现幂等,phpMyAdmin 可直接执行
|
||||
-- ===========================================
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 1: conduct_records 添加 related_type 列
|
||||
-- ===========================================
|
||||
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `upgrade_step`()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'conduct_records'
|
||||
AND COLUMN_NAME = 'related_type'
|
||||
) THEN
|
||||
ALTER TABLE `conduct_records`
|
||||
ADD COLUMN `related_type` ENUM('manual', 'homework', 'attendance') DEFAULT 'manual'
|
||||
AFTER `recorder_name`;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `upgrade_step`();
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 2: conduct_records 添加 semester_id 列
|
||||
-- ===========================================
|
||||
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `upgrade_step`()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'conduct_records'
|
||||
AND COLUMN_NAME = 'semester_id'
|
||||
) THEN
|
||||
ALTER TABLE `conduct_records`
|
||||
ADD COLUMN `semester_id` INT DEFAULT NULL COMMENT '所属学期ID'
|
||||
AFTER `revoked_at`;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `upgrade_step`();
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 3: conduct_records 添加 semester_id 外键
|
||||
-- ===========================================
|
||||
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `upgrade_step`()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'conduct_records'
|
||||
AND COLUMN_NAME = 'semester_id'
|
||||
AND REFERENCED_TABLE_NAME IS NOT NULL
|
||||
) THEN
|
||||
ALTER TABLE `conduct_records`
|
||||
ADD FOREIGN KEY (`semester_id`) REFERENCES `semesters`(`semester_id`) ON DELETE SET NULL;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `upgrade_step`();
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 4: attendance_records 添加 semester_id 列
|
||||
-- ===========================================
|
||||
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `upgrade_step`()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'attendance_records'
|
||||
AND COLUMN_NAME = 'semester_id'
|
||||
) THEN
|
||||
ALTER TABLE `attendance_records`
|
||||
ADD COLUMN `semester_id` INT DEFAULT NULL COMMENT '所属学期ID'
|
||||
AFTER `deduction_record_id`;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `upgrade_step`();
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 5: attendance_records 添加 semester_id 外键
|
||||
-- ===========================================
|
||||
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `upgrade_step`()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'attendance_records'
|
||||
AND COLUMN_NAME = 'semester_id'
|
||||
AND REFERENCED_TABLE_NAME IS NOT NULL
|
||||
) THEN
|
||||
ALTER TABLE `attendance_records`
|
||||
ADD FOREIGN KEY (`semester_id`) REFERENCES `semesters`(`semester_id`) ON DELETE SET NULL;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `upgrade_step`();
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
6
sql/upgrades/v2.0.1.sql
Normal file
6
sql/upgrades/v2.0.1.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
-- ===========================================
|
||||
-- 班级操行分管理系统 - v2.0 → v2.0.1 升级脚本
|
||||
-- 字符集: utf8mb4
|
||||
--
|
||||
-- 说明: v2.0.1 为纯前端修改版本,无数据库 schema 变更。
|
||||
-- ===========================================
|
||||
145
sql/upgrades/v2.0.sql
Normal file
145
sql/upgrades/v2.0.sql
Normal file
@@ -0,0 +1,145 @@
|
||||
-- ===========================================
|
||||
-- 班级操行分管理系统 - v1.8 → v2.0 升级脚本
|
||||
-- 字符集: utf8mb4
|
||||
--
|
||||
-- 变更内容:
|
||||
-- 1. 添加性能索引: conduct_records.semester_id
|
||||
-- 2. 添加性能索引: attendance_records.semester_id
|
||||
-- 3. 添加性能索引: conduct_records.student_id
|
||||
-- 4. 数据迁移: recorder_name 从 username 更新为 real_name
|
||||
-- 5. students 表添加 dormitory_number 列
|
||||
-- 6. students 表添加 points_updated_at 列
|
||||
--
|
||||
-- 兼容性: 使用存储过程实现幂等,phpMyAdmin 可直接执行
|
||||
-- ===========================================
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 1: 添加 conduct_records.semester_id 索引
|
||||
-- ===========================================
|
||||
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `upgrade_step`()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'conduct_records'
|
||||
AND INDEX_NAME = 'idx_conduct_semester'
|
||||
) THEN
|
||||
CREATE INDEX `idx_conduct_semester` ON `conduct_records`(`semester_id`);
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `upgrade_step`();
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 2: 添加 attendance_records.semester_id 索引
|
||||
-- ===========================================
|
||||
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `upgrade_step`()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'attendance_records'
|
||||
AND INDEX_NAME = 'idx_attendance_semester'
|
||||
) THEN
|
||||
CREATE INDEX `idx_attendance_semester` ON `attendance_records`(`semester_id`);
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `upgrade_step`();
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 3: 添加 conduct_records.student_id 索引
|
||||
-- ===========================================
|
||||
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `upgrade_step`()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'conduct_records'
|
||||
AND INDEX_NAME = 'idx_conduct_student'
|
||||
) THEN
|
||||
CREATE INDEX `idx_conduct_student` ON `conduct_records`(`student_id`);
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `upgrade_step`();
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 4: 数据迁移 - recorder_name 从 username 更新为 real_name
|
||||
-- ===========================================
|
||||
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `upgrade_step`()
|
||||
BEGIN
|
||||
UPDATE `conduct_records` cr
|
||||
INNER JOIN `users` u ON cr.recorder_id = u.user_id
|
||||
SET cr.recorder_name = u.real_name
|
||||
WHERE cr.recorder_name = u.username;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `upgrade_step`();
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 5: students 表添加 dormitory_number 列
|
||||
-- ===========================================
|
||||
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `upgrade_step`()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'students'
|
||||
AND COLUMN_NAME = 'dormitory_number'
|
||||
) THEN
|
||||
ALTER TABLE `students`
|
||||
ADD COLUMN `dormitory_number` VARCHAR(20) DEFAULT NULL COMMENT '宿舍号'
|
||||
AFTER `parent_phone`;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `upgrade_step`();
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
|
||||
-- ===========================================
|
||||
-- 升级步骤 6: students 表添加 points_updated_at 列
|
||||
-- ===========================================
|
||||
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `upgrade_step`()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'students'
|
||||
AND COLUMN_NAME = 'points_updated_at'
|
||||
) THEN
|
||||
ALTER TABLE `students`
|
||||
ADD COLUMN `points_updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '分数最后更新时间';
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `upgrade_step`();
|
||||
DROP PROCEDURE IF EXISTS `upgrade_step`;
|
||||
102
sql/upgrades/v2.1.sql
Normal file
102
sql/upgrades/v2.1.sql
Normal file
@@ -0,0 +1,102 @@
|
||||
-- ===========================================
|
||||
-- 班级操行分管理系统 - v2.0.1 → v2.1 升级脚本
|
||||
-- 主要内容:添加缺失的数据库索引,优化查询性能
|
||||
-- ===========================================
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
-- conduct_records 表:添加 student_id + created_at 联合索引(学生端查询历史记录)
|
||||
CREATE PROCEDURE upgrade_add_conduct_student_created_idx()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'conduct_records'
|
||||
AND INDEX_NAME = 'idx_student_created'
|
||||
) THEN
|
||||
ALTER TABLE `conduct_records` ADD INDEX `idx_student_created` (`student_id`, `created_at`);
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
-- conduct_records 表:添加 recorder_id 索引(班干查询自己记录的)
|
||||
CREATE PROCEDURE upgrade_add_conduct_recorder_idx()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'conduct_records'
|
||||
AND INDEX_NAME = 'idx_recorder_id'
|
||||
) THEN
|
||||
ALTER TABLE `conduct_records` ADD INDEX `idx_recorder_id` (`recorder_id`);
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
-- attendance_records 表:添加 date 索引(按日期查询考勤记录)
|
||||
CREATE PROCEDURE upgrade_add_attendance_date_idx()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'attendance_records'
|
||||
AND INDEX_NAME = 'idx_date'
|
||||
) THEN
|
||||
ALTER TABLE `attendance_records` ADD INDEX `idx_date` (`date`);
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
-- login_logs 表:添加 username + created_at 联合索引(查询登录历史)
|
||||
CREATE PROCEDURE upgrade_add_login_username_created_idx()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'login_logs'
|
||||
AND INDEX_NAME = 'idx_username_created'
|
||||
) THEN
|
||||
ALTER TABLE `login_logs` ADD INDEX `idx_username_created` (`username`, `created_at`);
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
-- operation_logs 表:添加 operator_id + created_at 联合索引(查询操作历史)
|
||||
CREATE PROCEDURE upgrade_add_operation_operator_created_idx()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'operation_logs'
|
||||
AND INDEX_NAME = 'idx_operator_created'
|
||||
) THEN
|
||||
ALTER TABLE `operation_logs` ADD INDEX `idx_operator_created` (`operator_id`, `created_at`);
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
-- semester_archives 表:添加 semester_id 索引(查询学期归档数据)
|
||||
CREATE PROCEDURE upgrade_add_archive_semester_idx()
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND INDEX_NAME = 'idx_semester_id'
|
||||
) THEN
|
||||
ALTER TABLE `semester_archives` ADD INDEX `idx_semester_id` (`semester_id`);
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
||||
-- 执行所有升级存储过程
|
||||
CALL upgrade_add_conduct_student_created_idx();
|
||||
CALL upgrade_add_conduct_recorder_idx();
|
||||
CALL upgrade_add_attendance_date_idx();
|
||||
CALL upgrade_add_login_username_created_idx();
|
||||
CALL upgrade_add_operation_operator_created_idx();
|
||||
CALL upgrade_add_archive_semester_idx();
|
||||
|
||||
-- 清理存储过程
|
||||
DROP PROCEDURE IF EXISTS upgrade_add_conduct_student_created_idx;
|
||||
DROP PROCEDURE IF EXISTS upgrade_add_conduct_recorder_idx;
|
||||
DROP PROCEDURE IF EXISTS upgrade_add_attendance_date_idx;
|
||||
DROP PROCEDURE IF EXISTS upgrade_add_login_username_created_idx;
|
||||
DROP PROCEDURE IF EXISTS upgrade_add_operation_operator_created_idx;
|
||||
DROP PROCEDURE IF EXISTS upgrade_add_archive_semester_idx;
|
||||
532
upgrade.php
Normal file
532
upgrade.php
Normal file
@@ -0,0 +1,532 @@
|
||||
<?php
|
||||
/**
|
||||
* 班级操行分管理系统 - 自动升级脚本
|
||||
*
|
||||
* 读取 VERSION 文件确定目标版本,自动检测数据库当前版本,
|
||||
* 依次执行增量 SQL 升级脚本。
|
||||
*/
|
||||
|
||||
// ===========================================
|
||||
// 辅助函数
|
||||
// ===========================================
|
||||
|
||||
/**
|
||||
* 读取 backend/.env 文件并解析数据库配置
|
||||
*/
|
||||
function readEnvConfig($envPath) {
|
||||
if (!file_exists($envPath)) {
|
||||
throw new RuntimeException('配置文件不存在: ' . $envPath);
|
||||
}
|
||||
|
||||
$lines = file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
$config = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '' || strpos($line, '#') === 0) {
|
||||
continue;
|
||||
}
|
||||
if (strpos($line, '=') !== false) {
|
||||
list($key, $value) = explode('=', $line, 2);
|
||||
$config[trim($key)] = trim($value);
|
||||
}
|
||||
}
|
||||
|
||||
$required = ['DB_HOST', 'DB_PORT', 'DB_USER', 'DB_PASSWORD', 'DB_NAME'];
|
||||
foreach ($required as $key) {
|
||||
if (!isset($config[$key]) || $config[$key] === '') {
|
||||
throw new RuntimeException("缺少必要的数据库配置: {$key}");
|
||||
}
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测数据库当前版本
|
||||
*/
|
||||
function detectCurrentVersion($pdo) {
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT setting_value FROM system_settings WHERE setting_key = 'db_version'");
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
return $row ? $row['setting_value'] : '0.0.0';
|
||||
} catch (PDOException $e) {
|
||||
return '0.0.0';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需要执行的升级步骤
|
||||
*/
|
||||
function getUpgradeSteps($currentVersion, $targetVersion) {
|
||||
$allVersions = [
|
||||
'1.7' => __DIR__ . '/sql/upgrades/v1.7.sql',
|
||||
'1.8' => __DIR__ . '/sql/upgrades/v1.8.sql',
|
||||
'2.0' => __DIR__ . '/sql/upgrades/v2.0.sql',
|
||||
'2.0.1' => __DIR__ . '/sql/upgrades/v2.0.1.sql',
|
||||
'2.1' => __DIR__ . '/sql/upgrades/v2.1.sql',
|
||||
];
|
||||
|
||||
$steps = [];
|
||||
foreach ($allVersions as $version => $sqlFile) {
|
||||
if (version_compare($version, $currentVersion, '>') &&
|
||||
version_compare($version, $targetVersion, '<=')) {
|
||||
$steps[$version] = $sqlFile;
|
||||
}
|
||||
}
|
||||
|
||||
uksort($steps, 'version_compare');
|
||||
return $steps;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行单个版本的升级 SQL
|
||||
*/
|
||||
function executeUpgrade($pdo, $version, $sqlFile) {
|
||||
if (!file_exists($sqlFile)) {
|
||||
throw new RuntimeException("SQL 文件不存在: {$sqlFile}");
|
||||
}
|
||||
|
||||
$sql = file_get_contents($sqlFile);
|
||||
|
||||
if (trim($sql) === '' || trim($sql) === '--') {
|
||||
// 空文件或纯注释,无需执行 SQL,仅更新版本号
|
||||
} else {
|
||||
$pdo->exec($sql);
|
||||
}
|
||||
|
||||
// 更新版本号(使用预处理语句防止 SQL 注入)
|
||||
$stmt = $pdo->prepare(
|
||||
"INSERT INTO system_settings (setting_key, setting_value) VALUES ('db_version', :version)
|
||||
ON DUPLICATE KEY UPDATE setting_value = :version"
|
||||
);
|
||||
$stmt->execute([':version' => $version]);
|
||||
}
|
||||
|
||||
// ===========================================
|
||||
// 主逻辑
|
||||
// ===========================================
|
||||
|
||||
// POST 模式:执行单个升级步骤(依次执行)
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_GET['action'] ?? '') === 'step') {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$stepVersion = $_GET['version'] ?? '';
|
||||
if (empty($stepVersion)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => '缺少版本号参数']);
|
||||
exit();
|
||||
}
|
||||
|
||||
try {
|
||||
$envPath = __DIR__ . '/backend/.env';
|
||||
$config = readEnvConfig($envPath);
|
||||
|
||||
$dsn = "mysql:host={$config['DB_HOST']};port={$config['DB_PORT']};dbname={$config['DB_NAME']};charset=utf8mb4";
|
||||
$pdo = new PDO($dsn, $config['DB_USER'], $config['DB_PASSWORD'], [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
]);
|
||||
|
||||
// 获取该版本对应的 SQL 文件
|
||||
$allVersions = [
|
||||
'1.7' => __DIR__ . '/sql/upgrades/v1.7.sql',
|
||||
'1.8' => __DIR__ . '/sql/upgrades/v1.8.sql',
|
||||
'2.0' => __DIR__ . '/sql/upgrades/v2.0.sql',
|
||||
'2.0.1' => __DIR__ . '/sql/upgrades/v2.0.1.sql',
|
||||
'2.1' => __DIR__ . '/sql/upgrades/v2.1.sql',
|
||||
];
|
||||
|
||||
if (!isset($allVersions[$stepVersion])) {
|
||||
throw new RuntimeException("未知版本: {$stepVersion}");
|
||||
}
|
||||
|
||||
$sqlFile = $allVersions[$stepVersion];
|
||||
$shortFile = basename($sqlFile);
|
||||
|
||||
executeUpgrade($pdo, $stepVersion, $sqlFile);
|
||||
|
||||
// 重新检测当前版本
|
||||
$newVersion = detectCurrentVersion($pdo);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'version' => $stepVersion,
|
||||
'message' => "升级至 v{$stepVersion} 成功 ({$shortFile})",
|
||||
'current' => $newVersion
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'version' => $stepVersion,
|
||||
'error' => "升级至 v{$stepVersion} 失败: " . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
|
||||
// POST 模式:执行升级(AJAX 请求)
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_GET['action'] ?? '') === 'execute') {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$upgradeLog = [];
|
||||
$currentVersion = '未知';
|
||||
$targetVersion = '未知';
|
||||
|
||||
try {
|
||||
$envPath = __DIR__ . '/backend/.env';
|
||||
$config = readEnvConfig($envPath);
|
||||
|
||||
$dsn = "mysql:host={$config['DB_HOST']};port={$config['DB_PORT']};dbname={$config['DB_NAME']};charset=utf8mb4";
|
||||
$pdo = new PDO($dsn, $config['DB_USER'], $config['DB_PASSWORD'], [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
]);
|
||||
|
||||
$currentVersion = detectCurrentVersion($pdo);
|
||||
|
||||
$versionFile = __DIR__ . '/VERSION';
|
||||
if (!file_exists($versionFile)) {
|
||||
throw new RuntimeException('VERSION 文件不存在');
|
||||
}
|
||||
$targetVersion = trim(file_get_contents($versionFile));
|
||||
|
||||
$upgradeSteps = getUpgradeSteps($currentVersion, $targetVersion);
|
||||
|
||||
if (empty($upgradeSteps)) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'current' => $currentVersion,
|
||||
'target' => $targetVersion,
|
||||
'steps' => [['version' => '', 'status' => 'uptodate', 'message' => '数据库已是最新版本,无需升级。']]
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
foreach ($upgradeSteps as $version => $sqlFile) {
|
||||
$shortFile = basename($sqlFile);
|
||||
try {
|
||||
executeUpgrade($pdo, $version, $sqlFile);
|
||||
$upgradeLog[] = [
|
||||
'version' => $version,
|
||||
'status' => 'success',
|
||||
'message' => "升级至 v{$version} 成功 ({$shortFile})"
|
||||
];
|
||||
} catch (Exception $e) {
|
||||
$upgradeLog[] = [
|
||||
'version' => $version,
|
||||
'status' => 'error',
|
||||
'message' => "升级至 v{$version} 失败 ({$shortFile}): " . $e->getMessage()
|
||||
];
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
$pdo->commit();
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'current' => $currentVersion,
|
||||
'target' => $targetVersion,
|
||||
'steps' => $upgradeLog
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'current' => $currentVersion,
|
||||
'target' => $targetVersion,
|
||||
'steps' => $upgradeLog,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
|
||||
// GET 模式:显示升级信息页面
|
||||
$currentVersion = '未知';
|
||||
$targetVersion = '未知';
|
||||
$upgradeSteps = [];
|
||||
$hasError = false;
|
||||
$errorMessage = '';
|
||||
$isUpToDate = false;
|
||||
|
||||
try {
|
||||
$envPath = __DIR__ . '/backend/.env';
|
||||
$config = readEnvConfig($envPath);
|
||||
|
||||
$dsn = "mysql:host={$config['DB_HOST']};port={$config['DB_PORT']};dbname={$config['DB_NAME']};charset=utf8mb4";
|
||||
$pdo = new PDO($dsn, $config['DB_USER'], $config['DB_PASSWORD'], [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
]);
|
||||
|
||||
$currentVersion = detectCurrentVersion($pdo);
|
||||
|
||||
$versionFile = __DIR__ . '/VERSION';
|
||||
if (!file_exists($versionFile)) {
|
||||
throw new RuntimeException('VERSION 文件不存在: ' . $versionFile);
|
||||
}
|
||||
$targetVersion = trim(file_get_contents($versionFile));
|
||||
|
||||
$upgradeSteps = getUpgradeSteps($currentVersion, $targetVersion);
|
||||
$isUpToDate = empty($upgradeSteps);
|
||||
} catch (Exception $e) {
|
||||
$hasError = true;
|
||||
$errorMessage = $e->getMessage();
|
||||
}
|
||||
|
||||
?>
|
||||
<!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; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
background: #f5f7fa;
|
||||
color: #333;
|
||||
line-height: 1.6;
|
||||
padding: 20px;
|
||||
}
|
||||
.container {
|
||||
max-width: 720px;
|
||||
margin: 40px auto;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px rgba(0,0,0,0.08);
|
||||
overflow: hidden;
|
||||
}
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
padding: 24px 32px;
|
||||
}
|
||||
.header h1 { font-size: 20px; font-weight: 600; }
|
||||
.header p { font-size: 13px; opacity: 0.85; margin-top: 4px; }
|
||||
.content { padding: 24px 32px; }
|
||||
.info-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 10px 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
font-size: 14px;
|
||||
}
|
||||
.info-row:last-child { border-bottom: none; }
|
||||
.info-label { color: #888; }
|
||||
.info-value { font-weight: 600; }
|
||||
.section-title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
margin: 20px 0 12px;
|
||||
color: #444;
|
||||
}
|
||||
.step {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
padding: 10px 12px;
|
||||
margin-bottom: 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
background: #fafafa;
|
||||
border-left: 3px solid #ddd;
|
||||
}
|
||||
.step.success { border-left-color: #52c41a; background: #f6ffed; }
|
||||
.step.error { border-left-color: #ff4d4f; background: #fff2f0; }
|
||||
.step.pending { border-left-color: #faad14; background: #fffbe6; }
|
||||
.step-icon { margin-right: 10px; font-size: 16px; flex-shrink: 0; }
|
||||
.step.success .step-icon { color: #52c41a; }
|
||||
.step.error .step-icon { color: #ff4d4f; }
|
||||
.step.pending .step-icon { color: #faad14; }
|
||||
.step-message { word-break: break-all; }
|
||||
.error-box {
|
||||
background: #fff2f0;
|
||||
border: 1px solid #ffccc7;
|
||||
border-radius: 6px;
|
||||
padding: 12px 16px;
|
||||
margin-top: 16px;
|
||||
color: #cf1322;
|
||||
font-size: 13px;
|
||||
word-break: break-all;
|
||||
}
|
||||
.warning-box {
|
||||
background: #fffbe6;
|
||||
border: 1px solid #ffe58f;
|
||||
border-radius: 6px;
|
||||
padding: 12px 16px;
|
||||
margin-top: 16px;
|
||||
color: #ad6800;
|
||||
font-size: 13px;
|
||||
}
|
||||
.btn-upgrade {
|
||||
display: inline-block;
|
||||
padding: 10px 32px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
margin-top: 20px;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
.btn-upgrade:hover { opacity: 0.9; }
|
||||
.btn-upgrade:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.btn-upgrade.loading {
|
||||
opacity: 0.7;
|
||||
cursor: wait;
|
||||
}
|
||||
.action-area {
|
||||
text-align: center;
|
||||
margin-top: 16px;
|
||||
}
|
||||
.result-area {
|
||||
margin-top: 16px;
|
||||
}
|
||||
.footer {
|
||||
text-align: center;
|
||||
padding: 16px 32px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
color: #aaa;
|
||||
font-size: 12px;
|
||||
}
|
||||
.success-box {
|
||||
background: #f6ffed;
|
||||
border: 1px solid #b7eb8f;
|
||||
border-radius: 6px;
|
||||
padding: 16px;
|
||||
margin-top: 16px;
|
||||
text-align: center;
|
||||
color: #389e0d;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>班级操行分管理系统 - 数据库升级</h1>
|
||||
<p>自动检测版本并执行增量升级</p>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="info-row">
|
||||
<span class="info-label">当前数据库版本</span>
|
||||
<span class="info-value" id="currentVersion"><?php echo htmlspecialchars($currentVersion); ?></span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="info-label">目标版本</span>
|
||||
<span class="info-value" id="targetVersion"><?php echo htmlspecialchars($targetVersion); ?></span>
|
||||
</div>
|
||||
|
||||
<?php if ($hasError): ?>
|
||||
<div class="error-box">
|
||||
<strong>错误:</strong><?php echo htmlspecialchars($errorMessage); ?>
|
||||
</div>
|
||||
<?php elseif ($isUpToDate): ?>
|
||||
<div class="success-box">
|
||||
✓ 数据库已是最新版本,无需升级。
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="section-title">待执行升级步骤</div>
|
||||
<?php foreach ($upgradeSteps as $version => $sqlFile): ?>
|
||||
<div class="step pending" id="step-<?php echo htmlspecialchars($version); ?>">
|
||||
<span class="step-icon">○</span>
|
||||
<span class="step-message">升级至 v<?php echo htmlspecialchars($version); ?> (<?php echo htmlspecialchars(basename($sqlFile)); ?>)</span>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<div class="warning-box">
|
||||
⚠️ 升级前请确保已备份数据库,升级过程中请勿关闭页面。
|
||||
</div>
|
||||
|
||||
<div class="action-area">
|
||||
<button class="btn-upgrade" id="btnUpgrade" onclick="executeUpgrade()">立即升级</button>
|
||||
</div>
|
||||
|
||||
<div class="result-area" id="resultArea" style="display:none;"></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="footer">
|
||||
班级操行分管理系统 v<?php echo htmlspecialchars($targetVersion); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!$hasError && !$isUpToDate): ?>
|
||||
<script>
|
||||
function executeUpgrade() {
|
||||
var btn = document.getElementById('btnUpgrade');
|
||||
var resultArea = document.getElementById('resultArea');
|
||||
|
||||
btn.disabled = true;
|
||||
btn.classList.add('loading');
|
||||
btn.textContent = '升级中...';
|
||||
resultArea.style.display = 'none';
|
||||
|
||||
// 收集所有待执行步骤
|
||||
var steps = [];
|
||||
<?php foreach ($upgradeSteps as $version => $sqlFile): ?>
|
||||
steps.push('<?php echo htmlspecialchars($version); ?>');
|
||||
<?php endforeach; ?>
|
||||
|
||||
var currentIndex = 0;
|
||||
|
||||
function executeNextStep() {
|
||||
if (currentIndex >= steps.length) {
|
||||
btn.classList.remove('loading');
|
||||
btn.textContent = '升级完成';
|
||||
resultArea.style.display = 'block';
|
||||
resultArea.innerHTML = '<div class="success-box">✓ 升级成功!数据库已更新至最新版本<br><br><small style="color:#888">建议升级完成后删除 upgrade.php 文件</small></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
var version = steps[currentIndex];
|
||||
fetch('?action=step&version=' + encodeURIComponent(version), { method: 'POST' })
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(data) {
|
||||
var el = document.getElementById('step-' + version);
|
||||
if (el) {
|
||||
el.className = 'step ' + (data.success ? 'success' : 'error');
|
||||
el.querySelector('.step-icon').textContent = data.success ? '✓' : '✗';
|
||||
}
|
||||
|
||||
if (data.success) {
|
||||
currentIndex++;
|
||||
executeNextStep();
|
||||
} else {
|
||||
btn.classList.remove('loading');
|
||||
btn.textContent = '升级失败';
|
||||
btn.disabled = false;
|
||||
resultArea.style.display = 'block';
|
||||
resultArea.innerHTML = '<div class="error-box"><strong>升级失败:</strong>' + (data.error || '未知错误') + '</div>';
|
||||
}
|
||||
})
|
||||
.catch(function(err) {
|
||||
var el = document.getElementById('step-' + version);
|
||||
if (el) {
|
||||
el.className = 'step error';
|
||||
el.querySelector('.step-icon').textContent = '✗';
|
||||
}
|
||||
btn.classList.remove('loading');
|
||||
btn.disabled = false;
|
||||
btn.textContent = '立即升级';
|
||||
resultArea.style.display = 'block';
|
||||
resultArea.innerHTML = '<div class="error-box"><strong>请求失败:</strong>' + err.message + '</div>';
|
||||
});
|
||||
}
|
||||
|
||||
executeNextStep();
|
||||
}
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user