add login
This commit is contained in:
parent
ddd7792644
commit
23ee1b4780
16
README.md
16
README.md
@ -2,13 +2,19 @@
|
|||||||
|
|
||||||
## 🌐 系统启动
|
## 🌐 系统启动
|
||||||
|
|
||||||
确保系统运行在您的服务器域名
|
### 方式一:使用 Docker(推荐)
|
||||||
|
|
||||||
启动命令:
|
|
||||||
```bash
|
```bash
|
||||||
poetry run python enhanced_server.py
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 方式二:本地开发
|
||||||
|
```bash
|
||||||
|
poetry install
|
||||||
|
poetry run uvicorn main:app --host 0.0.0.0 --port 8000 --reload
|
||||||
|
```
|
||||||
|
|
||||||
|
确保系统运行在您的服务器域名或本地环境
|
||||||
|
|
||||||
## 📋 完整使用流程
|
## 📋 完整使用流程
|
||||||
|
|
||||||
### 1️⃣ 访问测评列表页
|
### 1️⃣ 访问测评列表页
|
||||||
@ -120,7 +126,7 @@ JSON格式示例:
|
|||||||
### 常见问题
|
### 常见问题
|
||||||
|
|
||||||
**Q: 点击"开始新的测评"显示404**
|
**Q: 点击"开始新的测评"显示404**
|
||||||
A: 确保服务器正在运行:`poetry run python enhanced_server.py`
|
A: 确保服务器正在运行,检查Docker容器状态或使用本地开发命令启动
|
||||||
|
|
||||||
**Q: 报告生成失败**
|
**Q: 报告生成失败**
|
||||||
A: 检查网络连接和外部API是否可访问
|
A: 检查网络连接和外部API是否可访问
|
||||||
|
|||||||
1205
enhanced_server.py
1205
enhanced_server.py
File diff suppressed because it is too large
Load Diff
@ -496,5 +496,37 @@ class EnhancedSurveySystem:
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
def delete_report(self, report_id):
|
||||||
|
"""删除报告"""
|
||||||
|
try:
|
||||||
|
conn = sqlite3.connect('data/survey.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# 检查报告是否存在
|
||||||
|
cursor.execute('SELECT id FROM reports WHERE id = ?', (report_id,))
|
||||||
|
if not cursor.fetchone():
|
||||||
|
conn.close()
|
||||||
|
return {
|
||||||
|
'success': False,
|
||||||
|
'message': '报告不存在'
|
||||||
|
}
|
||||||
|
|
||||||
|
# 删除报告
|
||||||
|
cursor.execute('DELETE FROM reports WHERE id = ?', (report_id,))
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return {
|
||||||
|
'success': True,
|
||||||
|
'message': '报告删除成功'
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"删除报告失败: {e}")
|
||||||
|
return {
|
||||||
|
'success': False,
|
||||||
|
'message': f'删除失败: {str(e)}'
|
||||||
|
}
|
||||||
|
|
||||||
# 全局系统实例
|
# 全局系统实例
|
||||||
enhanced_system = EnhancedSurveySystem()
|
enhanced_system = EnhancedSurveySystem()
|
||||||
|
|||||||
23
main.py
23
main.py
@ -297,6 +297,19 @@ async def get_report(report_id: str):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=f"解析报告数据失败: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"解析报告数据失败: {str(e)}")
|
||||||
|
|
||||||
|
@app.delete("/api/reports/{report_id}", response_model=ApiResponse)
|
||||||
|
async def delete_report(report_id: str):
|
||||||
|
"""删除报告"""
|
||||||
|
result = enhanced_system.delete_report(report_id)
|
||||||
|
|
||||||
|
if result['success']:
|
||||||
|
return ApiResponse(
|
||||||
|
success=True,
|
||||||
|
message=result['message']
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=400, detail=result['message'])
|
||||||
|
|
||||||
@app.get("/api/questions")
|
@app.get("/api/questions")
|
||||||
async def get_questions():
|
async def get_questions():
|
||||||
"""获取题库数据"""
|
"""获取题库数据"""
|
||||||
@ -456,6 +469,16 @@ async def index_page(request: Request):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise HTTPException(status_code=404, detail="主页文件不存在")
|
raise HTTPException(status_code=404, detail="主页文件不存在")
|
||||||
|
|
||||||
|
@app.get("/login.html")
|
||||||
|
async def login_page(request: Request):
|
||||||
|
"""提供登录页面"""
|
||||||
|
try:
|
||||||
|
with open('public/login.html', 'r', encoding='utf-8') as f:
|
||||||
|
content = f.read()
|
||||||
|
return Response(content=content, media_type="text/html; charset=utf-8")
|
||||||
|
except FileNotFoundError:
|
||||||
|
raise HTTPException(status_code=404, detail="登录页面文件不存在")
|
||||||
|
|
||||||
@app.get("/survey.html")
|
@app.get("/survey.html")
|
||||||
async def survey_page(request: Request):
|
async def survey_page(request: Request):
|
||||||
"""提供测评配置页面"""
|
"""提供测评配置页面"""
|
||||||
|
|||||||
@ -85,12 +85,12 @@
|
|||||||
border-bottom: 1px solid #ffe4d6;
|
border-bottom: 1px solid #ffe4d6;
|
||||||
}
|
}
|
||||||
|
|
||||||
th:nth-child(1) { width: 15%; } /* 姓名 */
|
th:nth-child(1) { width: 12%; } /* 姓名 */
|
||||||
th:nth-child(2) { width: 20%; } /* 测评时间 */
|
th:nth-child(2) { width: 18%; } /* 测评时间 */
|
||||||
th:nth-child(3) { width: 10%; } /* 分数 */
|
th:nth-child(3) { width: 8%; } /* 分数 */
|
||||||
th:nth-child(4) { width: 15%; } /* 年级 */
|
th:nth-child(4) { width: 12%; } /* 年级 */
|
||||||
th:nth-child(5) { width: 25%; } /* 学校 */
|
th:nth-child(5) { width: 20%; } /* 学校 */
|
||||||
th:nth-child(6) { width: 15%; } /* 操作 */
|
th:nth-child(6) { width: 30%; } /* 操作 */
|
||||||
|
|
||||||
td {
|
td {
|
||||||
padding: 16px 15px;
|
padding: 16px 15px;
|
||||||
@ -393,12 +393,208 @@
|
|||||||
padding: 4px 6px;
|
padding: 4px 6px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.delete-btn {
|
||||||
|
padding: 6px 12px;
|
||||||
|
background: linear-gradient(135deg, #e74c3c, #c0392b);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-btn:hover {
|
||||||
|
background: linear-gradient(135deg, #c0392b, #a93226);
|
||||||
|
transform: translateY(-1px);
|
||||||
|
box-shadow: 0 2px 8px rgba(231, 76, 60, 0.3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 登录相关样式 */
|
||||||
|
.auth-status {
|
||||||
|
position: absolute;
|
||||||
|
top: 20px;
|
||||||
|
right: 20px;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-info {
|
||||||
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 8px 16px;
|
||||||
|
color: white;
|
||||||
|
font-size: 14px;
|
||||||
|
backdrop-filter: blur(10px);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.logout-btn {
|
||||||
|
background: rgba(231, 76, 60, 0.8);
|
||||||
|
border: 1px solid rgba(231, 76, 60, 0.9);
|
||||||
|
color: white;
|
||||||
|
padding: 4px 12px;
|
||||||
|
border-radius: 15px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 12px;
|
||||||
|
margin-left: 10px;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logout-btn:hover {
|
||||||
|
background: rgba(192, 57, 43, 0.9);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 模态框样式 */
|
||||||
|
.modal {
|
||||||
|
display: none;
|
||||||
|
position: fixed;
|
||||||
|
z-index: 1000;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
backdrop-filter: blur(5px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-content {
|
||||||
|
background: white;
|
||||||
|
margin: 10% auto;
|
||||||
|
padding: 30px;
|
||||||
|
border-radius: 12px;
|
||||||
|
width: 90%;
|
||||||
|
max-width: 400px;
|
||||||
|
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
|
||||||
|
animation: modalSlideIn 0.3s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes modalSlideIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(-50px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes slideInRight {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(100px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header h2 {
|
||||||
|
color: #2d5a3d;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
color: #333;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 12px;
|
||||||
|
border: 2px solid #e0e0e0;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
transition: border-color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #ff7e5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
margin-top: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-btn {
|
||||||
|
flex: 1;
|
||||||
|
padding: 12px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-btn-primary {
|
||||||
|
background: linear-gradient(135deg, #ff7e5f, #feb47b);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-btn-primary:hover {
|
||||||
|
background: linear-gradient(135deg, #ff6b52, #fe9b5b);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-btn-secondary {
|
||||||
|
background: #f5f5f5;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-btn-secondary:hover {
|
||||||
|
background: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-btn {
|
||||||
|
padding: 6px 12px;
|
||||||
|
background: linear-gradient(135deg, #e74c3c, #c0392b);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-btn:hover {
|
||||||
|
background: linear-gradient(135deg, #c0392b, #a93226);
|
||||||
|
transform: translateY(-1px);
|
||||||
|
box-shadow: 0 2px 8px rgba(231, 76, 60, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-cell {
|
||||||
|
display: flex;
|
||||||
|
gap: 5px;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
|
<div class="auth-status" id="auth-status">
|
||||||
|
<!-- 登录状态将由JavaScript动态生成 -->
|
||||||
|
</div>
|
||||||
<h1>📊 测评报告列表</h1>
|
<h1>📊 测评报告列表</h1>
|
||||||
<p>查看所有学员的学科能力测评报告</p>
|
<p>查看所有学员的学科能力测评报告</p>
|
||||||
<div style="text-align: center; margin-top: 20px;">
|
<div style="text-align: center; margin-top: 20px;">
|
||||||
@ -459,8 +655,93 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 删除确认模态框 -->
|
||||||
|
<div id="delete-modal" class="modal">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h2>⚠️ 确认删除</h2>
|
||||||
|
<p style="color: #666; font-size: 14px;">此操作不可撤销</p>
|
||||||
|
</div>
|
||||||
|
<div style="text-align: center; margin: 20px 0;">
|
||||||
|
<p id="delete-message" style="color: #e74c3c; font-weight: 500;"></p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-buttons">
|
||||||
|
<button type="button" class="modal-btn modal-btn-primary" onclick="confirmDelete()" style="background: linear-gradient(135deg, #e74c3c, #c0392b);">确认删除</button>
|
||||||
|
<button type="button" class="modal-btn modal-btn-secondary" onclick="closeDeleteModal()">取消</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// 全局变量
|
||||||
|
let currentDeleteId = null;
|
||||||
|
let currentDeleteName = null;
|
||||||
|
let isAuthenticated = false;
|
||||||
|
|
||||||
|
// 更新认证状态显示
|
||||||
|
function updateAuthStatus() {
|
||||||
|
const authStatus = document.getElementById('auth-status');
|
||||||
|
if (isAuthenticated) {
|
||||||
|
authStatus.innerHTML = `
|
||||||
|
<div class="user-info">
|
||||||
|
👤 管理员
|
||||||
|
<button class="logout-btn" onclick="logout()">退出</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
authStatus.innerHTML = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 退出登录
|
||||||
|
function logout() {
|
||||||
|
isAuthenticated = false;
|
||||||
|
localStorage.removeItem('isAuthenticated');
|
||||||
|
// 跳转到登录页面
|
||||||
|
window.location.href = '/login.html';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除相关函数
|
||||||
|
function showDeleteModal(reportId, reportName) {
|
||||||
|
currentDeleteId = reportId;
|
||||||
|
currentDeleteName = reportName;
|
||||||
|
document.getElementById('delete-message').textContent =
|
||||||
|
`确定要删除「${reportName}」的报告吗?此操作无法撤销!`;
|
||||||
|
document.getElementById('delete-modal').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeDeleteModal() {
|
||||||
|
document.getElementById('delete-modal').style.display = 'none';
|
||||||
|
currentDeleteId = null;
|
||||||
|
currentDeleteName = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmDelete() {
|
||||||
|
if (currentDeleteId && window.reportManager) {
|
||||||
|
window.reportManager.executeDelete(currentDeleteId);
|
||||||
|
closeDeleteModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 点击删除模态框外部关闭
|
||||||
|
window.onclick = function(event) {
|
||||||
|
const deleteModal = document.getElementById('delete-modal');
|
||||||
|
|
||||||
|
if (event.target === deleteModal) {
|
||||||
|
closeDeleteModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 页面加载完成
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
// 检查登录状态
|
||||||
|
const savedAuth = localStorage.getItem('isAuthenticated');
|
||||||
|
if (savedAuth === 'true') {
|
||||||
|
isAuthenticated = true;
|
||||||
|
}
|
||||||
|
updateAuthStatus();
|
||||||
|
|
||||||
// 初始化报告列表管理器
|
// 初始化报告列表管理器
|
||||||
new ReportListManager();
|
new ReportListManager();
|
||||||
|
|
||||||
@ -499,6 +780,11 @@
|
|||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
try {
|
try {
|
||||||
|
// 检查是否已登录,如果未登录则跳转到登录页面
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
window.location.href = '/login.html';
|
||||||
|
return;
|
||||||
|
}
|
||||||
await this.fetchReports();
|
await this.fetchReports();
|
||||||
this.render();
|
this.render();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -507,6 +793,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fetchReports() {
|
async fetchReports() {
|
||||||
try {
|
try {
|
||||||
document.getElementById('loading').style.display = 'block';
|
document.getElementById('loading').style.display = 'block';
|
||||||
@ -571,6 +858,9 @@
|
|||||||
|
|
||||||
const date = `${year}-${month}-${day} ${hours}:${minutes}`;
|
const date = `${year}-${month}-${day} ${hours}:${minutes}`;
|
||||||
|
|
||||||
|
// 根据登录状态决定是否显示删除按钮
|
||||||
|
const deleteButtonStyle = isAuthenticated ? 'display: inline-block;' : 'display: none;';
|
||||||
|
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
<td class="name-cell">${report.name}</td>
|
<td class="name-cell">${report.name}</td>
|
||||||
<td class="time-cell">${date}</td>
|
<td class="time-cell">${date}</td>
|
||||||
@ -579,6 +869,8 @@
|
|||||||
<td class="school-cell">${report.school}</td>
|
<td class="school-cell">${report.school}</td>
|
||||||
<td class="action-cell">
|
<td class="action-cell">
|
||||||
<a href="/report.html?id=${report.id}" class="view-btn">查看报告</a>
|
<a href="/report.html?id=${report.id}" class="view-btn">查看报告</a>
|
||||||
|
<button class="delete-btn" onclick="reportManager.deleteReport('${report.id}', '${report.name}')"
|
||||||
|
style="${deleteButtonStyle}" id="delete-${report.id}">删除</button>
|
||||||
</td>
|
</td>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -673,6 +965,76 @@
|
|||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteReport(reportId, reportName) {
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
alert('请先登录后再进行删除操作!');
|
||||||
|
showLoginModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
showDeleteModal(reportId, reportName);
|
||||||
|
}
|
||||||
|
|
||||||
|
async executeDelete(reportId) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/reports/${reportId}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`删除失败: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除成功,刷新列表
|
||||||
|
await this.fetchReports();
|
||||||
|
this.render();
|
||||||
|
|
||||||
|
// 显示成功消息
|
||||||
|
this.showMessage('报告删除成功!', 'success');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('删除报告失败:', error);
|
||||||
|
this.showMessage(`删除失败: ${error.message}`, 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
showMessage(message, type = 'info') {
|
||||||
|
// 创建消息元素
|
||||||
|
const messageDiv = document.createElement('div');
|
||||||
|
messageDiv.style.cssText = `
|
||||||
|
position: fixed;
|
||||||
|
top: 20px;
|
||||||
|
right: 20px;
|
||||||
|
padding: 15px 20px;
|
||||||
|
border-radius: 6px;
|
||||||
|
color: white;
|
||||||
|
font-weight: 500;
|
||||||
|
z-index: 2000;
|
||||||
|
max-width: 300px;
|
||||||
|
animation: slideInRight 0.3s ease-out;
|
||||||
|
`;
|
||||||
|
|
||||||
|
if (type === 'success') {
|
||||||
|
messageDiv.style.background = 'linear-gradient(135deg, #27ae60, #2ecc71)';
|
||||||
|
} else if (type === 'error') {
|
||||||
|
messageDiv.style.background = 'linear-gradient(135deg, #e74c3c, #c0392b)';
|
||||||
|
} else {
|
||||||
|
messageDiv.style.background = 'linear-gradient(135deg, #3498db, #2980b9)';
|
||||||
|
}
|
||||||
|
|
||||||
|
messageDiv.textContent = message;
|
||||||
|
document.body.appendChild(messageDiv);
|
||||||
|
|
||||||
|
// 3秒后自动移除
|
||||||
|
setTimeout(() => {
|
||||||
|
if (messageDiv.parentNode) {
|
||||||
|
messageDiv.parentNode.removeChild(messageDiv);
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
showError(message) {
|
showError(message) {
|
||||||
const errorDiv = document.getElementById('error');
|
const errorDiv = document.getElementById('error');
|
||||||
errorDiv.textContent = message;
|
errorDiv.textContent = message;
|
||||||
|
|||||||
335
public/login.html
Normal file
335
public/login.html
Normal file
@ -0,0 +1,335 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>管理员登录 - 测评报告系统</title>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-family: 'Microsoft YaHei', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: linear-gradient(135deg, #ff7e5f 0%, #feb47b 50%, #ff7e5f 100%);
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-container {
|
||||||
|
background: white;
|
||||||
|
border-radius: 20px;
|
||||||
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||||
|
overflow: hidden;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 400px;
|
||||||
|
animation: slideUp 0.5s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes slideUp {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(50px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-header {
|
||||||
|
background: linear-gradient(135deg, #ff7e5f, #feb47b);
|
||||||
|
color: white;
|
||||||
|
padding: 40px 30px;
|
||||||
|
text-align: center;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-header::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: -50%;
|
||||||
|
left: -50%;
|
||||||
|
width: 200%;
|
||||||
|
height: 200%;
|
||||||
|
background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 1px, transparent 1px);
|
||||||
|
background-size: 20px 20px;
|
||||||
|
animation: float 20s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes float {
|
||||||
|
0% { transform: translate(0, 0); }
|
||||||
|
100% { transform: translate(20px, 20px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-header h1 {
|
||||||
|
font-size: 28px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-header p {
|
||||||
|
opacity: 0.9;
|
||||||
|
font-size: 14px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-body {
|
||||||
|
padding: 40px 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
color: #333;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 15px;
|
||||||
|
border: 2px solid #e0e0e0;
|
||||||
|
border-radius: 10px;
|
||||||
|
font-size: 16px;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
background: #f9f9f9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #ff7e5f;
|
||||||
|
background: white;
|
||||||
|
box-shadow: 0 0 0 3px rgba(255, 126, 95, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-btn {
|
||||||
|
width: 100%;
|
||||||
|
padding: 15px;
|
||||||
|
background: linear-gradient(135deg, #ff7e5f, #feb47b);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 10px;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
box-shadow: 0 5px 20px rgba(255, 126, 95, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-btn:hover {
|
||||||
|
background: linear-gradient(135deg, #ff6b52, #fe9b5b);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 8px 25px rgba(255, 126, 95, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-btn:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.credentials-info {
|
||||||
|
background: #f8f9fa;
|
||||||
|
border-left: 4px solid #ff7e5f;
|
||||||
|
padding: 15px;
|
||||||
|
margin: 25px 0;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.credentials-info h4 {
|
||||||
|
color: #2d5a3d;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.credentials-info p {
|
||||||
|
color: #666;
|
||||||
|
font-size: 13px;
|
||||||
|
margin: 5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.credentials-info strong {
|
||||||
|
color: #ff7e5f;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message {
|
||||||
|
background: #fff5f5;
|
||||||
|
border: 1px solid #fed7d7;
|
||||||
|
color: #e53e3e;
|
||||||
|
padding: 12px;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
font-size: 14px;
|
||||||
|
display: none;
|
||||||
|
animation: shake 0.5s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes shake {
|
||||||
|
0%, 100% { transform: translateX(0); }
|
||||||
|
25% { transform: translateX(-5px); }
|
||||||
|
75% { transform: translateX(5px); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.success-message {
|
||||||
|
background: #f0fff4;
|
||||||
|
border: 1px solid #c6f6d5;
|
||||||
|
color: #38a169;
|
||||||
|
padding: 12px;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
font-size: 14px;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
text-align: center;
|
||||||
|
padding: 20px;
|
||||||
|
color: #8b5a2b;
|
||||||
|
font-size: 12px;
|
||||||
|
background: #fef6f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.login-container {
|
||||||
|
margin: 10px;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-header {
|
||||||
|
padding: 30px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-header h1 {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-body {
|
||||||
|
padding: 30px 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="login-container">
|
||||||
|
<div class="login-header">
|
||||||
|
<h1>🔐 管理员登录</h1>
|
||||||
|
<p>测评报告管理系统</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="login-body">
|
||||||
|
<div class="error-message" id="error-message">
|
||||||
|
用户名或密码错误,请重试!
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="success-message" id="success-message">
|
||||||
|
登录成功,正在跳转...
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form id="login-form">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="username">用户名</label>
|
||||||
|
<input type="text" id="username" name="username" required
|
||||||
|
placeholder="请输入用户名" autocomplete="username">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">密码</label>
|
||||||
|
<input type="password" id="password" name="password" required
|
||||||
|
placeholder="请输入密码" autocomplete="current-password">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="login-btn">
|
||||||
|
🚀 登录系统
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="credentials-info">
|
||||||
|
<h4>📋 登录信息</h4>
|
||||||
|
<p>用户名:<strong>admin</strong></p>
|
||||||
|
<p>密码:<strong>admin123</strong></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
<p>© 2024 尚逸基石学科能力测评系统</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
// 检查是否已经登录
|
||||||
|
const isAuthenticated = localStorage.getItem('isAuthenticated') === 'true';
|
||||||
|
if (isAuthenticated) {
|
||||||
|
window.location.href = '/';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loginForm = document.getElementById('login-form');
|
||||||
|
const errorMessage = document.getElementById('error-message');
|
||||||
|
const successMessage = document.getElementById('success-message');
|
||||||
|
|
||||||
|
loginForm.addEventListener('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const username = document.getElementById('username').value;
|
||||||
|
const password = document.getElementById('password').value;
|
||||||
|
|
||||||
|
// 隐藏之前的消息
|
||||||
|
errorMessage.style.display = 'none';
|
||||||
|
successMessage.style.display = 'none';
|
||||||
|
|
||||||
|
// 简单的硬编码验证(实际项目中应该使用后端API)
|
||||||
|
if (username === 'admin' && password === 'admin123') {
|
||||||
|
// 登录成功
|
||||||
|
localStorage.setItem('isAuthenticated', 'true');
|
||||||
|
successMessage.style.display = 'block';
|
||||||
|
|
||||||
|
// 禁用登录按钮
|
||||||
|
const loginBtn = document.querySelector('.login-btn');
|
||||||
|
loginBtn.disabled = true;
|
||||||
|
loginBtn.textContent = '⏳ 正在跳转...';
|
||||||
|
|
||||||
|
// 延迟跳转以显示成功消息
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.href = '/';
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// 登录失败
|
||||||
|
errorMessage.style.display = 'block';
|
||||||
|
|
||||||
|
// 清空密码字段
|
||||||
|
document.getElementById('password').value = '';
|
||||||
|
document.getElementById('password').focus();
|
||||||
|
|
||||||
|
// 3秒后自动隐藏错误消息
|
||||||
|
setTimeout(() => {
|
||||||
|
errorMessage.style.display = 'none';
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 自动聚焦到用户名输入框
|
||||||
|
document.getElementById('username').focus();
|
||||||
|
|
||||||
|
// 回车键快速提交
|
||||||
|
document.getElementById('password').addEventListener('keypress', function(e) {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
loginForm.dispatchEvent(new Event('submit'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -8,6 +8,7 @@ et_xmlfile==2.0.0
|
|||||||
fastapi==0.120.1
|
fastapi==0.120.1
|
||||||
h11==0.16.0
|
h11==0.16.0
|
||||||
idna==3.11
|
idna==3.11
|
||||||
|
Jinja2==3.1.6
|
||||||
MarkupSafe==3.0.3
|
MarkupSafe==3.0.3
|
||||||
openpyxl==3.1.5
|
openpyxl==3.1.5
|
||||||
pydantic==2.12.3
|
pydantic==2.12.3
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user