初版:教务抢课系统 jwxt(从线上实例导出)
This commit is contained in:
@@ -0,0 +1,446 @@
|
||||
{% extends "base_tailwind.html" %}
|
||||
|
||||
{% block title %}仪表盘 - {{ brand_name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="space-y-6">
|
||||
<!-- 欢迎区域 -->
|
||||
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 0ms;">
|
||||
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
||||
<div>
|
||||
<h1 class="text-2xl md:text-3xl font-bold text-neutral-900 dark:text-white">欢迎回来,{{ current_user.username }}</h1>
|
||||
<p class="text-neutral-500 dark:text-neutral-400 mt-1">这里是您的抢课任务概览</p>
|
||||
</div>
|
||||
<div class="flex gap-3 flex-wrap">
|
||||
<a href="{{ url_for('main.courses') }}" class="btn-primary px-5 py-2.5 rounded-full text-sm font-bold inline-flex items-center">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
|
||||
</svg>
|
||||
查询课程
|
||||
</a>
|
||||
<a href="{{ url_for('main.timetable') }}" class="px-5 py-2.5 rounded-full text-sm font-bold bg-blue-600 text-white hover:bg-blue-700 transition inline-flex items-center">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
|
||||
</svg>
|
||||
课表查询
|
||||
</a>
|
||||
<a href="{{ url_for('main.tasks') }}" class="px-5 py-2.5 rounded-full text-sm font-bold bg-green-600 text-white hover:bg-green-700 transition inline-flex items-center">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
|
||||
</svg>
|
||||
创建任务
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 统计卡片 -->
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 50ms;">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-neutral-500 dark:text-neutral-400">总任务数</p>
|
||||
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1">{{ task_count }}</p>
|
||||
</div>
|
||||
<div class="w-10 h-10 rounded-xl bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center">
|
||||
<svg class="w-5 h-5 text-blue-600 dark:text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"></path>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 100ms;">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-neutral-500 dark:text-neutral-400">待执行</p>
|
||||
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1">{{ pending_count }}</p>
|
||||
</div>
|
||||
<div class="w-10 h-10 rounded-xl bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center">
|
||||
<svg class="w-5 h-5 text-amber-600 dark:text-amber-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 150ms;">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-neutral-500 dark:text-neutral-400">抢课成功</p>
|
||||
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1">{{ success_count }}</p>
|
||||
</div>
|
||||
<div class="w-10 h-10 rounded-xl bg-green-100 dark:bg-green-900/30 flex items-center justify-center">
|
||||
<svg class="w-5 h-5 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 200ms;">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-neutral-500 dark:text-neutral-400">选课系统</p>
|
||||
<p class="text-lg font-bold mt-1" id="systemStatus">
|
||||
<span class="inline-block w-4 h-4 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="w-10 h-10 rounded-xl bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center">
|
||||
<svg class="w-5 h-5 text-purple-600 dark:text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Session 状态 -->
|
||||
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 250ms;">
|
||||
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white flex items-center gap-2">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path>
|
||||
</svg>
|
||||
登录状态
|
||||
</h3>
|
||||
<p class="text-sm text-neutral-500 mt-1" id="sessionStatusInfo">
|
||||
<span class="inline-block w-3 h-3 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin mr-1"></span>
|
||||
检查中...
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex gap-3">
|
||||
<button onclick="refreshSession()" class="px-4 py-2 bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 rounded-full text-sm font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||||
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
|
||||
</svg>
|
||||
刷新登录
|
||||
</button>
|
||||
<button onclick="showJwxtConfigModal()" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-full text-sm font-medium hover:shadow-lg transition">
|
||||
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
|
||||
</svg>
|
||||
配置账号
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 最近任务 -->
|
||||
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 300ms;">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">最近任务</h3>
|
||||
<a href="{{ url_for('main.tasks') }}" class="text-sm text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 transition flex items-center gap-1">
|
||||
查看全部
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if recent_tasks %}
|
||||
<div class="overflow-x-auto max-w-5xl mx-auto">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>课程名称</th>
|
||||
<th>类型</th>
|
||||
<th>状态</th>
|
||||
<th>创建时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for task in recent_tasks %}
|
||||
<tr class="list-item-enter" style="animation-delay: {{ (loop.index0 * 30) }}ms;">
|
||||
<td class="font-medium">{{ task.course_name }}</td>
|
||||
<td>
|
||||
{% if task.task_type == 'immediate' %}
|
||||
<span class="status-badge status-info">立即</span>
|
||||
{% else %}
|
||||
<span class="status-badge status-warning">定时</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if task.status == 'success' %}
|
||||
<span class="status-badge status-success">成功</span>
|
||||
{% elif task.status == 'pending' %}
|
||||
<span class="status-badge status-warning">待执行</span>
|
||||
{% elif task.status == 'running' %}
|
||||
<span class="status-badge status-info">运行中</span>
|
||||
{% else %}
|
||||
<span class="status-badge status-danger">失败</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="text-sm text-neutral-500">{{ task.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="text-center py-8">
|
||||
<svg class="w-12 h-12 text-neutral-300 dark:text-neutral-700 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"></path>
|
||||
</svg>
|
||||
<p class="text-neutral-500">暂无任务,快去创建抢课任务吧!</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 刷新 Session 模态框 -->
|
||||
<div id="refreshSessionModal" class="fixed inset-0 z-50 flex items-center justify-center p-4 opacity-0 pointer-events-none transition-opacity duration-240">
|
||||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeRefreshSessionModal()"></div>
|
||||
<div class="relative w-full max-w-md p-4">
|
||||
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">刷新登录状态</h3>
|
||||
<button onclick="closeRefreshSessionModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="bg-blue-50 dark:bg-blue-900/20 border border-blue-100 dark:border-blue-800 rounded-xl p-4 mb-4">
|
||||
<p class="text-sm text-blue-800 dark:text-blue-200">系统将自动使用已保存的教务系统密码刷新登录状态</p>
|
||||
</div>
|
||||
<div id="refreshResult"></div>
|
||||
<div class="flex gap-3 mt-6">
|
||||
<button type="button" onclick="closeRefreshSessionModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||||
取消
|
||||
</button>
|
||||
<button type="button" onclick="doRefreshSession()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
|
||||
刷新
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 配置教务系统账号模态框 -->
|
||||
<div id="jwxtConfigModal" class="fixed inset-0 z-50 flex items-center justify-center p-4 opacity-0 pointer-events-none transition-opacity duration-240">
|
||||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeJwxtConfigModal()"></div>
|
||||
<div class="relative w-full max-w-md p-4">
|
||||
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">配置教务系统账号</h3>
|
||||
<button onclick="closeJwxtConfigModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="bg-amber-50 dark:bg-amber-900/20 border border-amber-100 dark:border-amber-800 rounded-xl p-4 mb-4">
|
||||
<p class="text-sm text-amber-800 dark:text-amber-200">修改账号信息需要重新验证</p>
|
||||
</div>
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="input-label">学号</label>
|
||||
<input type="text" id="configJwxtUsername" class="input-field" placeholder="请输入学号">
|
||||
</div>
|
||||
<div>
|
||||
<label class="input-label">密码</label>
|
||||
<input type="password" id="configJwxtPassword" class="input-field" placeholder="请输入密码">
|
||||
</div>
|
||||
<div>
|
||||
<label class="input-label">姓名(选填)</label>
|
||||
<input type="text" id="configJwxtName" class="input-field" placeholder="请输入姓名">
|
||||
</div>
|
||||
<div id="configResult"></div>
|
||||
</div>
|
||||
<div class="flex gap-3 mt-6">
|
||||
<button type="button" onclick="closeJwxtConfigModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
|
||||
取消
|
||||
</button>
|
||||
<button type="button" onclick="saveJwxtConfig()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
|
||||
保存并验证
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
// 页面加载完成后执行
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// 将弹窗移到 body 直接子级,确保 fixed 定位基于视口
|
||||
['refreshSessionModal', 'jwxtConfigModal'].forEach(id => {
|
||||
const el = document.getElementById(id);
|
||||
if (el) document.body.appendChild(el);
|
||||
});
|
||||
|
||||
checkSystemStatus();
|
||||
checkSessionStatus();
|
||||
|
||||
// 每30秒刷新一次状态
|
||||
setInterval(checkSystemStatus, 30000);
|
||||
setInterval(checkSessionStatus, 60000);
|
||||
});
|
||||
|
||||
// 检查选课系统状态
|
||||
async function checkSystemStatus() {
|
||||
try {
|
||||
const data = await apiRequest('/api/courses/status');
|
||||
const statusEl = document.getElementById('systemStatus');
|
||||
|
||||
if (data.success && data.is_open) {
|
||||
statusEl.innerHTML = '<span class="text-green-600 dark:text-green-400 flex items-center gap-1"><span class="w-2 h-2 bg-green-500 rounded-full"></span>开放中</span>';
|
||||
} else {
|
||||
statusEl.innerHTML = '<span class="text-amber-600 dark:text-amber-400 flex items-center gap-1"><span class="w-2 h-2 bg-amber-500 rounded-full"></span>未开放</span>';
|
||||
}
|
||||
} catch (error) {
|
||||
document.getElementById('systemStatus').innerHTML = '<span class="text-red-600">获取失败</span>';
|
||||
}
|
||||
}
|
||||
|
||||
// 检查 Session 状态
|
||||
async function checkSessionStatus() {
|
||||
try {
|
||||
const data = await apiRequest('/api/user/session/status');
|
||||
const infoEl = document.getElementById('sessionStatusInfo');
|
||||
|
||||
if (data.is_valid) {
|
||||
infoEl.innerHTML = `
|
||||
<span class="text-green-600 dark:text-green-400 flex items-center gap-2">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
登录有效
|
||||
<span class="text-neutral-400 text-xs">更新时间: ${data.updated_at ? formatTime(data.updated_at) : '未知'}</span>
|
||||
</span>
|
||||
`;
|
||||
} else {
|
||||
infoEl.innerHTML = `
|
||||
<span class="text-red-600 dark:text-red-400 flex items-center gap-2">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
登录已过期
|
||||
${data.error_msg ? `<span class="text-neutral-400 text-xs">${data.error_msg}</span>` : ''}
|
||||
</span>
|
||||
`;
|
||||
}
|
||||
} catch (error) {
|
||||
document.getElementById('sessionStatusInfo').innerHTML = '<span class="text-red-600">检查失败</span>';
|
||||
}
|
||||
}
|
||||
|
||||
// 显示刷新 Session 模态框
|
||||
function refreshSession() {
|
||||
document.getElementById('refreshResult').innerHTML = '';
|
||||
const modal = document.getElementById('refreshSessionModal');
|
||||
modal.classList.remove('opacity-0', 'pointer-events-none');
|
||||
modal.classList.add('opacity-100', 'pointer-events-auto');
|
||||
document.documentElement.style.overflow = 'hidden';
|
||||
document.body.style.overflow = 'hidden';
|
||||
}
|
||||
|
||||
function closeRefreshSessionModal() {
|
||||
const modal = document.getElementById('refreshSessionModal');
|
||||
modal.classList.add('opacity-0', 'pointer-events-none');
|
||||
modal.classList.remove('opacity-100', 'pointer-events-auto');
|
||||
document.documentElement.style.overflow = '';
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
|
||||
// 执行刷新 Session
|
||||
async function doRefreshSession() {
|
||||
const btn = document.querySelector('#refreshSessionModal button[onclick="doRefreshSession()"]');
|
||||
if (btn) { btn.disabled = true; btn.textContent = '刷新中…'; }
|
||||
const loadingToast = showToast('正在刷新登录状态…', 'info', 30000);
|
||||
try {
|
||||
const data = await apiRequest('/api/user/session/refresh', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({})
|
||||
});
|
||||
loadingToast.remove();
|
||||
|
||||
if (data.success) {
|
||||
showToast(data.message || '刷新成功', 'success');
|
||||
document.getElementById('refreshResult').innerHTML = `<div class="p-3 bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 rounded-lg text-sm">${data.message}</div>`;
|
||||
setTimeout(() => {
|
||||
closeRefreshSessionModal();
|
||||
checkSessionStatus();
|
||||
}, 1500);
|
||||
} else {
|
||||
showToast(data.message || '刷新失败', 'error');
|
||||
document.getElementById('refreshResult').innerHTML = `<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">${data.message}</div>`;
|
||||
}
|
||||
} catch (error) {
|
||||
loadingToast.remove();
|
||||
showToast('刷新失败,请稍后重试', 'error');
|
||||
document.getElementById('refreshResult').innerHTML = '<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">刷新失败</div>';
|
||||
} finally {
|
||||
if (btn) { btn.disabled = false; btn.textContent = '刷新'; }
|
||||
}
|
||||
}
|
||||
|
||||
// 显示配置模态框
|
||||
function showJwxtConfigModal() {
|
||||
document.getElementById('configJwxtUsername').value = '';
|
||||
document.getElementById('configJwxtPassword').value = '';
|
||||
document.getElementById('configJwxtName').value = '';
|
||||
document.getElementById('configResult').innerHTML = '';
|
||||
const modal = document.getElementById('jwxtConfigModal');
|
||||
modal.classList.remove('opacity-0', 'pointer-events-none');
|
||||
modal.classList.add('opacity-100', 'pointer-events-auto');
|
||||
document.documentElement.style.overflow = 'hidden';
|
||||
document.body.style.overflow = 'hidden';
|
||||
}
|
||||
|
||||
function closeJwxtConfigModal() {
|
||||
const modal = document.getElementById('jwxtConfigModal');
|
||||
modal.classList.add('opacity-0', 'pointer-events-none');
|
||||
modal.classList.remove('opacity-100', 'pointer-events-auto');
|
||||
document.documentElement.style.overflow = '';
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
|
||||
// 保存教务系统配置
|
||||
async function saveJwxtConfig() {
|
||||
const username = document.getElementById('configJwxtUsername').value.trim();
|
||||
const password = document.getElementById('configJwxtPassword').value.trim();
|
||||
const name = document.getElementById('configJwxtName').value.trim();
|
||||
|
||||
if (!username || !password) {
|
||||
document.getElementById('configResult').innerHTML = '<div class="p-3 bg-amber-50 dark:bg-amber-900/20 text-amber-800 dark:text-amber-200 rounded-lg text-sm">请填写学号和密码</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
const btn = document.querySelector('#jwxtConfigModal button[onclick="saveJwxtConfig()"]');
|
||||
if (btn) { btn.disabled = true; btn.textContent = '登录中…'; }
|
||||
const loadingToast = showToast('正在登录教务系统…', 'info', 30000);
|
||||
|
||||
try {
|
||||
const data = await apiRequest('/api/user/jwxt/config', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
jwxt_username: username,
|
||||
jwxt_password: password,
|
||||
jwxt_name: name
|
||||
})
|
||||
});
|
||||
loadingToast.remove();
|
||||
|
||||
if (data.success) {
|
||||
showToast(data.message || '登录成功', 'success');
|
||||
document.getElementById('configResult').innerHTML = `<div class="p-3 bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 rounded-lg text-sm">${data.message}</div>`;
|
||||
setTimeout(() => {
|
||||
closeJwxtConfigModal();
|
||||
checkSessionStatus();
|
||||
}, 1500);
|
||||
} else {
|
||||
showToast(data.message || '登录失败', 'error');
|
||||
document.getElementById('configResult').innerHTML = `<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">${data.message}</div>`;
|
||||
}
|
||||
} catch (error) {
|
||||
loadingToast.remove();
|
||||
showToast('配置失败,请稍后重试', 'error');
|
||||
document.getElementById('configResult').innerHTML = '<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">配置失败</div>';
|
||||
} finally {
|
||||
if (btn) { btn.disabled = false; btn.textContent = '保存并验证'; }
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user