refactor: 简化各页面模板,移除重复代码;添加plan_common.js

This commit is contained in:
hmo
2026-04-23 06:40:23 +08:00
parent baaa6ca2f8
commit 285979ff70
6 changed files with 163 additions and 259 deletions
+7 -56
View File
@@ -2,34 +2,6 @@
{% block title %}API设置 - 钢琴练习方案系统{% endblock %}
{% block sidebar_nav %}
<a class="nav-link" href="/">
<i class="bi bi-people"></i> 学员管理
</a>
<a class="nav-link" href="/settings">
<i class="bi bi-gear"></i> 问题配置
</a>
<a class="nav-link active" href="/api-settings">
<i class="bi bi-key"></i> API设置
</a>
<a class="nav-link" href="/templates" id="templatesNav" style="display:none;">
<i class="bi bi-file-earmark-text"></i> 模板管理
</a>
<a class="nav-link" href="/classes">
<i class="bi bi-collection"></i> 班级管理
</a>
<a class="nav-link" href="/users" id="usersNav" style="display:none;">
<i class="bi bi-person-badge"></i> 用户管理
</a>
<hr>
<a class="nav-link" href="#" onclick="showChangePasswordModal()">
<i class="bi bi-key"></i> 修改密码
</a>
<a class="nav-link" href="#" onclick="logout()">
<i class="bi bi-box-arrow-right"></i> 退出登录
</a>
{% endblock %}
{% block content %}
<div class="card">
<div class="card-header">
@@ -141,34 +113,13 @@
{% block extra_js %}
<script>
const ROLE_LABELS = { 'admin': '管理员', 'user': '普通用户' };
document.addEventListener('DOMContentLoaded', function() {
fetch('/api/check-login').then(r => r.json()).then(data => {
if (!data.logged_in) {
window.location.href = '/login';
return;
}
if (data.role !== 'admin') {
window.location.href = '/';
return;
}
const userDisplay = data.username + ' (' + ROLE_LABELS[data.role] + ')';
document.getElementById('currentUserDisplay').textContent = userDisplay;
const mobileDisplay = document.getElementById('mobileUserDisplay');
if (mobileDisplay) mobileDisplay.textContent = userDisplay;
if (data.role === 'admin') {
document.getElementById('usersNav').style.display = '';
document.getElementById('templatesNav').style.display = '';
}
loadApiConfig();
}).catch(() => {
window.location.href = '/login';
});
});
window.pageInit = function(data) {
if (data.role !== 'admin') {
window.location.href = '/';
return;
}
loadApiConfig();
};
const providerDefaults = {
'minimax': {