2026 lines
109 KiB
HTML
2026 lines
109 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN" class="scroll-smooth">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
||
<title>{% block title %}{{ brand_name }}{% endblock %}</title>
|
||
<link rel="icon" href="{{ brand_favicon }}">
|
||
<link rel="apple-touch-icon" href="{{ brand_favicon }}">
|
||
<script>
|
||
(function() {
|
||
var theme = localStorage.getItem('theme');
|
||
var isDark = theme === 'dark' || (!theme && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||
if (isDark) {
|
||
document.documentElement.classList.add('dark');
|
||
}
|
||
// 立即用内联样式设置背景色,防止深色模式下刷新白屏(FOUC)
|
||
document.documentElement.style.backgroundColor = isDark ? '#0a0a0a' : '#fafafa';
|
||
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light';
|
||
})();
|
||
</script>
|
||
<script src="https://cdn.tailwindcss.com"></script>
|
||
<script>
|
||
tailwind.config = {
|
||
darkMode: 'class',
|
||
theme: {
|
||
extend: {
|
||
colors: {
|
||
dark: {
|
||
bg: '#0a0a0a',
|
||
card: '#171717',
|
||
border: '#262626'
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;800;900&family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap" rel="stylesheet">
|
||
<style>
|
||
* {
|
||
-webkit-tap-highlight-color: transparent;
|
||
}
|
||
body {
|
||
font-family: 'Inter', 'Noto Sans SC', sans-serif;
|
||
transition: background-color 0.3s ease, color 0.3s ease;
|
||
width: 100%;
|
||
overflow-x: hidden;
|
||
}
|
||
html {
|
||
width: 100%;
|
||
overflow-x: hidden;
|
||
}
|
||
.layer-1 { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); }
|
||
.layer-2 { box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.08); }
|
||
.layer-3 { box-shadow: 0 12px 40px -5px rgba(0, 0, 0, 0.12); }
|
||
.layer-4 { box-shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.15); }
|
||
.dark .layer-1 { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
|
||
.dark .layer-2 { box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.5); }
|
||
.dark .layer-3 { box-shadow: 0 12px 40px -5px rgba(0, 0, 0, 0.6); }
|
||
.dark .layer-4 { box-shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.7); }
|
||
.glass {
|
||
background: rgba(255, 255, 255, 0.85);
|
||
backdrop-filter: blur(20px);
|
||
-webkit-backdrop-filter: blur(20px);
|
||
border: 1px solid rgba(255, 255, 255, 0.9);
|
||
position: relative;
|
||
}
|
||
.glass::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: 0;
|
||
left: 20px;
|
||
right: 20px;
|
||
height: 1px;
|
||
background: linear-gradient(90deg, transparent, rgba(0,0,0,0.08), transparent);
|
||
opacity: 0;
|
||
transition: opacity 0.3s;
|
||
}
|
||
.glass:hover::before {
|
||
opacity: 1;
|
||
}
|
||
@media (max-width: 640px) {
|
||
.glass { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
|
||
}
|
||
.dark .glass {
|
||
background: rgba(23, 23, 23, 0.85);
|
||
border: 1px solid rgba(38, 38, 38, 0.9);
|
||
}
|
||
.dark .glass::before {
|
||
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
|
||
}
|
||
.glass-dark {
|
||
background: rgba(17, 17, 17, 0.85);
|
||
backdrop-filter: blur(20px);
|
||
-webkit-backdrop-filter: blur(20px);
|
||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||
transition: all 0.3s ease;
|
||
}
|
||
.dark .glass-dark {
|
||
background: rgba(10, 10, 10, 0.9);
|
||
border: 1px solid rgba(38, 38, 38, 0.5);
|
||
}
|
||
.btn-primary {
|
||
background: #111;
|
||
color: #fff;
|
||
position: relative;
|
||
overflow: hidden;
|
||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||
}
|
||
.dark .btn-primary {
|
||
background: #fff;
|
||
color: #000;
|
||
}
|
||
.btn-primary:hover:not(:disabled) {
|
||
transform: translateY(-2px);
|
||
box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.3);
|
||
}
|
||
.btn-primary:active:not(:disabled) {
|
||
transform: translateY(0);
|
||
}
|
||
.btn-outline {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
padding: 8px 20px;
|
||
border: 1.5px solid #e5e5e5;
|
||
border-radius: 9999px;
|
||
font-size: 14px;
|
||
font-weight: 500;
|
||
transition: all 0.2s;
|
||
background: transparent;
|
||
color: inherit;
|
||
}
|
||
.btn-outline:hover {
|
||
border-color: #111;
|
||
background: rgba(0,0,0,0.03);
|
||
}
|
||
.dark .btn-outline {
|
||
border-color: #404040;
|
||
}
|
||
.dark .btn-outline:hover {
|
||
border-color: #fff;
|
||
background: rgba(255,255,255,0.05);
|
||
}
|
||
.btn-primary:disabled {
|
||
opacity: 0.5;
|
||
cursor: not-allowed;
|
||
}
|
||
.bg-grid {
|
||
background-size: 40px 40px;
|
||
background-image: linear-gradient(to right, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
|
||
linear-gradient(to bottom, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
|
||
}
|
||
.dark .bg-grid {
|
||
background-image: linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
|
||
linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
|
||
}
|
||
.tag {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
padding: 0.25rem 0.75rem;
|
||
background: rgba(0, 0, 0, 0.05);
|
||
border: 1px solid rgba(0, 0, 0, 0.08);
|
||
border-radius: 9999px;
|
||
font-size: 0.75rem;
|
||
font-weight: 500;
|
||
transition: all 0.2s;
|
||
}
|
||
.dark .tag {
|
||
background: rgba(255, 255, 255, 0.1);
|
||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||
color: #e5e5e5;
|
||
}
|
||
.dark .tag:hover {
|
||
background: #fff;
|
||
color: #000;
|
||
border-color: #fff;
|
||
}
|
||
.tag:hover {
|
||
background: #111;
|
||
color: #fff;
|
||
border-color: #111;
|
||
}
|
||
.input-field {
|
||
width: 100%;
|
||
padding: 12px 16px;
|
||
border: 2px solid #e5e5e5;
|
||
border-radius: 12px;
|
||
font-size: 16px;
|
||
transition: all 0.3s ease;
|
||
background: white;
|
||
color: #111;
|
||
}
|
||
.dark .input-field {
|
||
background: #262626;
|
||
border-color: #404040;
|
||
color: #fff;
|
||
}
|
||
.input-field:focus {
|
||
outline: none;
|
||
border-color: #111;
|
||
}
|
||
.dark .input-field:focus {
|
||
border-color: #fff;
|
||
}
|
||
.input-field::placeholder {
|
||
color: #999;
|
||
}
|
||
.input-label {
|
||
display: block;
|
||
margin-bottom: 8px;
|
||
font-weight: 600;
|
||
color: #333;
|
||
font-size: 14px;
|
||
}
|
||
.dark .input-label {
|
||
color: #ccc;
|
||
}
|
||
/* Toast 通知系统 */
|
||
@media (min-width: 769px) {
|
||
.toast-container {
|
||
position: fixed;
|
||
top: 20px;
|
||
right: 20px;
|
||
z-index: 9999;
|
||
pointer-events: none;
|
||
}
|
||
.toast {
|
||
background: #2c3e50;
|
||
color: white;
|
||
padding: 14px 22px;
|
||
border-radius: 8px;
|
||
margin-bottom: 10px;
|
||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||
transform: translateX(100%);
|
||
opacity: 0;
|
||
transition: all 0.3s ease;
|
||
pointer-events: all;
|
||
min-width: 250px;
|
||
max-width: 350px;
|
||
font-size: 14px;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
}
|
||
.toast.show {
|
||
transform: translateX(0);
|
||
opacity: 1;
|
||
}
|
||
}
|
||
@media (max-width: 768px) {
|
||
.toast-container {
|
||
position: fixed;
|
||
bottom: max(20px, env(safe-area-inset-bottom));
|
||
left: 50%;
|
||
transform: translateX(-50%);
|
||
z-index: 9999;
|
||
pointer-events: none;
|
||
width: 90%;
|
||
max-width: 400px;
|
||
}
|
||
.toast {
|
||
background: #2c3e50;
|
||
color: white;
|
||
padding: 12px 20px;
|
||
border-radius: 24px;
|
||
margin-bottom: 8px;
|
||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
|
||
transform: translateY(100px);
|
||
opacity: 0;
|
||
transition: all 0.3s ease;
|
||
pointer-events: all;
|
||
width: 100%;
|
||
font-size: 14px;
|
||
display: flex;
|
||
justify-content: center;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
.toast.show {
|
||
transform: translateY(0);
|
||
opacity: 1;
|
||
}
|
||
}
|
||
.toast.success { background: #27ae60; }
|
||
.toast.error { background: #e74c3c; }
|
||
.toast.info { background: #3498db; }
|
||
.toast.warning { background: #f39c12; }
|
||
.dark .toast.warning { background: #fbbf24; color: #1f2937; }
|
||
.dark .toast.success { background: #4caf50; }
|
||
.dark .toast.error { background: #ff6b6b; }
|
||
.dark .toast.info { background: #4a9eff; }
|
||
/* 移动端导航菜单 */
|
||
.mobile-menu {
|
||
position: fixed;
|
||
top: 0;
|
||
left: 0;
|
||
right: 0;
|
||
bottom: 0;
|
||
background: rgba(0, 0, 0, 0.5);
|
||
backdrop-filter: blur(4px);
|
||
z-index: 100;
|
||
opacity: 0;
|
||
visibility: hidden;
|
||
transition: all 0.3s ease;
|
||
}
|
||
.mobile-menu.active {
|
||
opacity: 1;
|
||
visibility: visible;
|
||
}
|
||
.mobile-menu-panel {
|
||
position: fixed;
|
||
top: 0;
|
||
right: -100%;
|
||
width: 80%;
|
||
max-width: 320px;
|
||
height: 100vh;
|
||
background: white;
|
||
transition: right 0.3s ease;
|
||
box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
|
||
overflow-y: auto;
|
||
overscroll-behavior: contain;
|
||
}
|
||
.dark .mobile-menu-panel {
|
||
background: #171717;
|
||
box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
|
||
}
|
||
.mobile-menu.active .mobile-menu-panel {
|
||
right: 0;
|
||
}
|
||
.hamburger-btn {
|
||
display: none;
|
||
flex-direction: column;
|
||
justify-content: center;
|
||
width: 32px;
|
||
height: 32px;
|
||
gap: 5px;
|
||
cursor: pointer;
|
||
padding: 4px;
|
||
}
|
||
.hamburger-btn span {
|
||
display: block;
|
||
height: 2px;
|
||
background: currentColor;
|
||
border-radius: 2px;
|
||
transition: all 0.3s ease;
|
||
}
|
||
.hamburger-btn.active span:nth-child(1) {
|
||
transform: rotate(45deg) translate(5px, 5px);
|
||
}
|
||
.hamburger-btn.active span:nth-child(2) {
|
||
opacity: 0;
|
||
}
|
||
.hamburger-btn.active span:nth-child(3) {
|
||
transform: rotate(-45deg) translate(5px, -5px);
|
||
}
|
||
@media (max-width: 768px) {
|
||
.hamburger-btn {
|
||
display: flex;
|
||
}
|
||
.desktop-nav-links {
|
||
display: none;
|
||
}
|
||
}
|
||
.theme-toggle {
|
||
transition: transform 0.3s ease;
|
||
}
|
||
.theme-toggle:hover {
|
||
transform: rotate(15deg);
|
||
}
|
||
/* 表格样式 */
|
||
.data-table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
}
|
||
.data-table th,
|
||
.data-table td {
|
||
padding: 12px 16px;
|
||
text-align: left;
|
||
border-bottom: 1px solid #e5e5e5;
|
||
}
|
||
.dark .data-table th,
|
||
.dark .data-table td {
|
||
border-bottom: 1px solid #262626;
|
||
}
|
||
.data-table th {
|
||
font-weight: 600;
|
||
color: #666;
|
||
font-size: 12px;
|
||
text-transform: uppercase;
|
||
letter-spacing: 0.5px;
|
||
}
|
||
.dark .data-table th {
|
||
color: #999;
|
||
}
|
||
.data-table tbody tr:hover {
|
||
background: rgba(0, 0, 0, 0.02);
|
||
}
|
||
.dark .data-table tbody tr:hover {
|
||
background: rgba(255, 255, 255, 0.02);
|
||
}
|
||
/* 状态标签 */
|
||
.status-badge {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
padding: 4px 12px;
|
||
border-radius: 9999px;
|
||
font-size: 12px;
|
||
font-weight: 500;
|
||
}
|
||
.status-success {
|
||
background: #dcfce7;
|
||
color: #166534;
|
||
}
|
||
.dark .status-success {
|
||
background: #166534;
|
||
color: #86efac;
|
||
}
|
||
.status-warning {
|
||
background: #fef3c7;
|
||
color: #92400e;
|
||
}
|
||
.dark .status-warning {
|
||
background: #92400e;
|
||
color: #fcd34d;
|
||
}
|
||
.status-danger {
|
||
background: #fee2e2;
|
||
color: #991b1b;
|
||
}
|
||
.dark .status-danger {
|
||
background: #991b1b;
|
||
color: #fca5a5;
|
||
}
|
||
.status-info {
|
||
background: #dbeafe;
|
||
color: #1e40af;
|
||
}
|
||
.dark .status-info {
|
||
background: #1e40af;
|
||
color: #93c5fd;
|
||
}
|
||
.status-pending {
|
||
background: #f1f5f9;
|
||
color: #475569;
|
||
}
|
||
.dark .status-pending {
|
||
background: #334155;
|
||
color: #cbd5e1;
|
||
}
|
||
.status-running {
|
||
background: #dbeafe;
|
||
color: #1d4ed8;
|
||
position: relative;
|
||
}
|
||
.status-running::after {
|
||
content: '';
|
||
display: inline-block;
|
||
width: 6px;
|
||
height: 6px;
|
||
border-radius: 50%;
|
||
background: #3b82f6;
|
||
margin-left: 6px;
|
||
animation: pulse-dot 1.4s ease-in-out infinite;
|
||
}
|
||
@keyframes pulse-dot {
|
||
0%, 100% { opacity: 1; transform: scale(1); }
|
||
50% { opacity: 0.4; transform: scale(0.7); }
|
||
}
|
||
.dark .status-running {
|
||
background: #1e3a5f;
|
||
color: #93c5fd;
|
||
}
|
||
.status-failed {
|
||
background: #fee2e2;
|
||
color: #991b1b;
|
||
}
|
||
.dark .status-failed {
|
||
background: #7f1d1d;
|
||
color: #fca5a5;
|
||
}
|
||
.status-cancelled {
|
||
background: #f1f5f9;
|
||
color: #64748b;
|
||
}
|
||
.dark .status-cancelled {
|
||
background: #334155;
|
||
color: #94a3b8;
|
||
}
|
||
/* 模态框动画 */
|
||
@keyframes modal-enter {
|
||
from {
|
||
opacity: 0;
|
||
transform: scale(0.95);
|
||
}
|
||
to {
|
||
opacity: 1;
|
||
transform: scale(1);
|
||
}
|
||
}
|
||
.modal-animate {
|
||
animation: modal-enter 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
||
}
|
||
|
||
/* ========== 自定义滚动条 ========== */
|
||
.scrollbar-thin::-webkit-scrollbar {
|
||
width: 4px;
|
||
height: 4px;
|
||
}
|
||
.scrollbar-thin::-webkit-scrollbar-track {
|
||
background: transparent;
|
||
}
|
||
.scrollbar-thin::-webkit-scrollbar-thumb {
|
||
background: rgba(0,0,0,0.15);
|
||
border-radius: 4px;
|
||
}
|
||
.dark .scrollbar-thin::-webkit-scrollbar-thumb {
|
||
background: rgba(255,255,255,0.15);
|
||
}
|
||
.scrollbar-thin {
|
||
scrollbar-width: thin;
|
||
scrollbar-color: rgba(0,0,0,0.15) transparent;
|
||
}
|
||
.dark .scrollbar-thin {
|
||
scrollbar-color: rgba(255,255,255,0.15) transparent;
|
||
}
|
||
|
||
/* ========== 移动端表格→卡片转换 ========== */
|
||
@media (max-width: 768px) {
|
||
.card-on-mobile,
|
||
.card-on-mobile thead,
|
||
.card-on-mobile tbody,
|
||
.card-on-mobile th,
|
||
.card-on-mobile td,
|
||
.card-on-mobile tr {
|
||
display: block;
|
||
}
|
||
.card-on-mobile thead {
|
||
display: none;
|
||
}
|
||
.card-on-mobile tbody tr {
|
||
padding: 12px;
|
||
margin-bottom: 12px;
|
||
border-radius: 16px;
|
||
background: rgba(255,255,255,0.6);
|
||
border: 1px solid #e5e5e5;
|
||
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
|
||
}
|
||
.dark .card-on-mobile tbody tr {
|
||
background: rgba(23,23,23,0.8);
|
||
border-color: #262626;
|
||
}
|
||
.card-on-mobile tbody td {
|
||
padding: 6px 0;
|
||
border: none;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
gap: 8px;
|
||
text-align: right;
|
||
font-size: 13px;
|
||
}
|
||
.card-on-mobile tbody td::before {
|
||
content: attr(data-label);
|
||
font-weight: 600;
|
||
font-size: 12px;
|
||
color: #999;
|
||
text-align: left;
|
||
flex-shrink: 0;
|
||
}
|
||
.card-on-mobile tbody td:last-child {
|
||
padding-top: 10px;
|
||
margin-top: 6px;
|
||
border-top: 1px solid #eee;
|
||
justify-content: flex-end;
|
||
flex-wrap: wrap;
|
||
gap: 6px;
|
||
}
|
||
.dark .card-on-mobile tbody td:last-child {
|
||
border-top-color: #262626;
|
||
}
|
||
.dark .card-on-mobile tbody td::before {
|
||
color: #777;
|
||
}
|
||
}
|
||
|
||
/* ========== 卡片 / 列表项淡入动画 ========== */
|
||
@keyframes listItemEnter {
|
||
from {
|
||
opacity: 0;
|
||
transform: translateY(20px) scale(0.96);
|
||
}
|
||
to {
|
||
opacity: 1;
|
||
transform: translateY(0) scale(1);
|
||
}
|
||
}
|
||
.list-item-enter {
|
||
opacity: 0;
|
||
animation: listItemEnter 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
|
||
}
|
||
/* 减少动画偏好时禁用 */
|
||
@media (prefers-reduced-motion: reduce) {
|
||
.list-item-enter {
|
||
animation: none !important;
|
||
opacity: 1 !important;
|
||
}
|
||
}
|
||
/* Timing Bar */
|
||
#timingStrip { min-height: 3px; }
|
||
#timingStrip.timing-fast { background: #22c55e; }
|
||
#timingStrip.timing-medium { background: #eab308; }
|
||
#timingStrip.timing-slow { background: #ef4444; }
|
||
#timingStrip.timing-error { background: #ef4444; animation: timingPulse 0.8s ease-in-out infinite; }
|
||
@keyframes timingPulse {
|
||
0%, 100% { opacity: 1; }
|
||
50% { opacity: 0.4; }
|
||
}
|
||
#timingTooltip .timing-stage { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
|
||
#timingTooltip .timing-stage-ok { color: #22c55e; }
|
||
#timingTooltip .timing-stage-err { color: #ef4444; }
|
||
.dark #timingTooltip .timing-stage-ok { color: #4ade80; }
|
||
.dark #timingTooltip .timing-stage-err { color: #f87171; }
|
||
|
||
/* ========== Grain layer ========== */
|
||
.grain { mix-blend-mode: overlay; }
|
||
@media (prefers-color-scheme: dark) { .grain { mix-blend-mode: soft-light; } }
|
||
|
||
/* ========== Global reduced-motion fallback ========== */
|
||
@media (prefers-reduced-motion: reduce) {
|
||
*, *::before, *::after {
|
||
animation-duration: 0.01ms !important;
|
||
animation-iteration-count: 1 !important;
|
||
transition-duration: 0.01ms !important;
|
||
scroll-behavior: auto !important;
|
||
}
|
||
.list-item-enter { animation: none !important; opacity: 1 !important; }
|
||
.modal-animate { animation: none !important; opacity: 1 !important; transform: none !important; }
|
||
.mobile-menu-panel { transition: none !important; }
|
||
.mobile-menu { transition: none !important; }
|
||
.theme-toggle { transition: none !important; }
|
||
.hamburger-btn span { transition: none !important; }
|
||
}
|
||
/* ── AI 选课助手:固定工具窗口,不遮挡主选课流 ── */
|
||
#courseAiLauncher { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 55; }
|
||
#courseAiLauncher button { min-height: 48px; box-shadow: 0 18px 40px -18px rgba(15, 23, 42, .55); }
|
||
#courseAiPanel {
|
||
position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 60;
|
||
width: min(25.5rem, calc(100vw - 1.5rem)); height: min(39rem, calc(100dvh - 1.5rem));
|
||
opacity: 0; pointer-events: none; transform: translateY(12px) scale(.98);
|
||
transition: opacity .18s ease, transform .2s cubic-bezier(.22, 1, .36, 1);
|
||
}
|
||
#courseAiPanel.is-open { opacity: 1; pointer-events: auto; transform: translateY(0) scale(1); }
|
||
#courseAiMessages { scrollbar-width: thin; }
|
||
.course-ai-tool { border: 1px solid rgb(226 232 240); background: rgb(255 255 255 / .78); }
|
||
.dark .course-ai-tool { border-color: rgb(64 64 64); background: rgb(38 38 38 / .72); }
|
||
.course-ai-tool summary { list-style: none; }
|
||
.course-ai-tool summary::-webkit-details-marker { display: none; }
|
||
.course-ai-tool[data-state="running"] .course-ai-tool-icon { animation: courseAiPulse 1.1s ease-in-out infinite; }
|
||
.course-ai-tool[data-state="success"] .course-ai-tool-icon { color: rgb(22 101 52); background: rgb(220 252 231); }
|
||
.course-ai-tool[data-state="error"] .course-ai-tool-icon { color: rgb(185 28 28); background: rgb(254 226 226); }
|
||
.course-ai-tool[data-state="confirm"] { border-color: rgb(217 119 6 / .55); background: rgb(254 249 239 / .92); }
|
||
.dark .course-ai-tool[data-state="confirm"] { border-color: rgb(180 83 9 / .6); background: rgb(69 26 3 / .45); }
|
||
.course-ai-tool[data-state="ask"] { border-color: rgb(2 132 199 / .55); background: rgb(240 249 255 / .92); }
|
||
.dark .course-ai-tool[data-state="ask"] { border-color: rgb(3 105 161 / .6); background: rgb(8 47 73 / .45); }
|
||
.course-ai-tool [data-ask-option][aria-pressed="true"] { background: rgb(15 23 42); border-color: rgb(15 23 42); color: #fff; }
|
||
.dark .course-ai-tool [data-ask-option][aria-pressed="true"] { background: rgb(241 245 249); border-color: rgb(241 245 249); color: rgb(15 23 42); }
|
||
/* 回合气泡:文字分段与工具卡片按发生顺序内嵌排列 */
|
||
.course-ai-composite { display: flex; flex-direction: column; gap: .5rem; }
|
||
.course-ai-composite .course-ai-tool { max-width: 100%; }
|
||
.course-ai-thinking { color: rgb(100 116 139); animation: courseAiPulse 1.6s ease-in-out infinite; }
|
||
.dark .course-ai-thinking { color: rgb(148 163 184); }
|
||
.course-ai-io { display: flex; flex-direction: column; gap: .45rem; }
|
||
.course-ai-io-label { font-size: .68rem; font-weight: 600; letter-spacing: .02em; color: rgb(100 116 139); }
|
||
.dark .course-ai-io-label { color: rgb(148 163 184); }
|
||
.course-ai-io-pre { margin: .2rem 0 0; max-height: 13rem; overflow: auto; border: 1px solid rgb(203 213 225 / .6); border-radius: .5rem; background: rgb(15 23 42 / .96); padding: .45rem .55rem; font-size: .7rem; line-height: 1.5; color: rgb(226 232 240); white-space: pre-wrap; word-break: break-word; }
|
||
.dark .course-ai-io-pre { border-color: rgb(82 82 82); }
|
||
@keyframes courseAiPulse { 50% { opacity: .42; transform: scale(.88); } }
|
||
.course-ai-message { overflow-wrap: anywhere; }
|
||
.course-ai-markdown { min-width: 0; }
|
||
.course-ai-markdown > :first-child { margin-top: 0; }
|
||
.course-ai-markdown > :last-child { margin-bottom: 0; }
|
||
.course-ai-markdown p { margin: .35rem 0; }
|
||
.course-ai-markdown h1, .course-ai-markdown h2, .course-ai-markdown h3,
|
||
.course-ai-markdown h4, .course-ai-markdown h5, .course-ai-markdown h6 { margin: .7rem 0 .35rem; font-weight: 700; line-height: 1.35; }
|
||
.course-ai-markdown h1 { font-size: 1.15rem; }
|
||
.course-ai-markdown h2 { font-size: 1.05rem; }
|
||
.course-ai-markdown h3, .course-ai-markdown h4, .course-ai-markdown h5, .course-ai-markdown h6 { font-size: .95rem; }
|
||
.course-ai-markdown ul, .course-ai-markdown ol { margin: .35rem 0; padding-left: 1.25rem; }
|
||
.course-ai-markdown ul { list-style: disc; }
|
||
.course-ai-markdown ol { list-style: decimal; }
|
||
.course-ai-markdown li { margin: .16rem 0; }
|
||
.course-ai-markdown blockquote { margin: .5rem 0; border-left: 2px solid rgb(148 163 184 / .7); padding-left: .75rem; color: rgb(71 85 105); }
|
||
.dark .course-ai-markdown blockquote { color: rgb(203 213 225); }
|
||
.course-ai-markdown code:not(pre code) { border-radius: .35rem; background: rgb(226 232 240 / .75); padding: .1rem .3rem; font-size: .86em; }
|
||
.dark .course-ai-markdown code:not(pre code) { background: rgb(64 64 64 / .9); }
|
||
.course-ai-markdown pre { margin: .55rem 0; max-width: 100%; overflow-x: auto; border: 1px solid rgb(203 213 225 / .75); border-radius: .65rem; background: rgb(15 23 42 / .96); padding: .7rem .8rem; color: rgb(226 232 240); }
|
||
.dark .course-ai-markdown pre { border-color: rgb(82 82 82); }
|
||
.course-ai-markdown pre code { font-size: .8rem; line-height: 1.55; }
|
||
.course-ai-markdown a { color: rgb(29 78 216); text-decoration: underline; text-underline-offset: 2px; }
|
||
.dark .course-ai-markdown a { color: rgb(147 197 253); }
|
||
.course-ai-markdown hr { margin: .7rem 0; border: 0; border-top: 1px solid rgb(203 213 225 / .8); }
|
||
.dark .course-ai-markdown hr { border-color: rgb(82 82 82); }
|
||
.course-ai-markdown table { width: 100%; margin: .55rem 0; border-collapse: collapse; font-size: .86em; }
|
||
.course-ai-markdown th, .course-ai-markdown td { border-bottom: 1px solid rgb(203 213 225 / .8); padding: .35rem .45rem; text-align: left; vertical-align: top; }
|
||
.course-ai-markdown th { font-weight: 700; }
|
||
.dark .course-ai-markdown th, .dark .course-ai-markdown td { border-color: rgb(82 82 82); }
|
||
.course-ai-copy { margin-top: .5rem; border-top: 1px solid rgb(203 213 225 / .65); padding-top: .35rem; color: rgb(100 116 139); font-size: .72rem; }
|
||
.dark .course-ai-copy { border-color: rgb(82 82 82); color: rgb(148 163 184); }
|
||
.course-ai-copy button { cursor: pointer; }
|
||
.course-ai-user { background: #111827; color: #f8fafc; }
|
||
.dark .course-ai-user { background: #e5e7eb; color: #111827; }
|
||
.course-ai-assistant { background: rgba(241, 245, 249, .9); color: #1f2937; border: 1px solid rgba(148, 163, 184, .25); }
|
||
.dark .course-ai-assistant { background: rgba(38, 38, 38, .9); color: #f3f4f6; border-color: rgba(115, 115, 115, .36); }
|
||
@media (max-width: 640px) {
|
||
#courseAiLauncher { right: .75rem; bottom: .75rem; }
|
||
#courseAiPanel { right: .75rem; bottom: .75rem; width: calc(100vw - 1.5rem); height: min(42rem, calc(100dvh - 1.5rem)); }
|
||
}
|
||
@media (prefers-reduced-motion: reduce) {
|
||
#courseAiPanel { transition: none; }
|
||
.course-ai-tool[data-state="running"] .course-ai-tool-icon { animation: none; }
|
||
}
|
||
</style>
|
||
|
||
{% block extra_css %}{% endblock %}
|
||
</head>
|
||
<body class="bg-neutral-50 text-neutral-900 dark:bg-dark-bg dark:text-neutral-100 min-h-dvh flex flex-col" id="pageBody">
|
||
<!-- Skip to content -->
|
||
<a href="#mainContent" class="sr-only focus:not-sr-only focus:absolute focus:top-4 focus:left-4 focus:z-[9999] focus:px-4 focus:py-2 focus:bg-black focus:text-white dark:focus:bg-white dark:focus:text-black focus:rounded-lg focus:text-sm focus:font-medium">
|
||
跳转到主内容
|
||
</a>
|
||
|
||
<!-- Grain overlay -->
|
||
<svg class="grain" aria-hidden="true" style="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9998;opacity:0.035;">
|
||
<filter id="grainFilter">
|
||
<feTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="4" stitchTiles="stitch"/>
|
||
</filter>
|
||
<rect width="100%" height="100%" filter="url(#grainFilter)"/>
|
||
</svg>
|
||
|
||
<!-- Toast 通知容器 -->
|
||
<div class="toast-container" id="toastContainer"></div>
|
||
|
||
<!-- 导航 -->
|
||
<nav class="fixed w-full z-50 glass border-b border-black/5 dark:border-white/10 layer-1 transition-colors duration-300" id="navbar">
|
||
<div class="max-w-7xl mx-auto px-4 md:px-6 h-16 flex justify-between items-center">
|
||
<div class="flex items-center gap-2 md:gap-3 group cursor-pointer" onclick="window.location.href='{{ url_for('main.dashboard') }}'">
|
||
<div class="w-8 h-8 bg-black dark:bg-white rounded-lg flex items-center justify-center text-white dark:text-black font-bold text-sm group-hover:rotate-12 transition-transform shrink-0">
|
||
{{ brand_name[0] }}
|
||
</div>
|
||
<span class="font-bold tracking-tight text-sm md:text-base truncate">{{ brand_name }}</span>
|
||
</div>
|
||
|
||
<div class="flex items-center gap-2 md:gap-6">
|
||
<div class="desktop-nav-links hidden md:flex items-center gap-6 text-sm font-medium text-neutral-600 dark:text-neutral-400">
|
||
{% if current_user.is_authenticated %}
|
||
<a href="{{ url_for('main.dashboard') }}" class="hover:text-black dark:hover:text-white transition-colors">仪表盘</a>
|
||
<a href="{{ url_for('main.courses') }}" class="hover:text-black dark:hover:text-white transition-colors">课程</a>
|
||
<a href="{{ url_for('main.timetable') }}" class="hover:text-black dark:hover:text-white transition-colors">课表</a>
|
||
<a href="{{ url_for('main.page_grades') }}" class="hover:text-black dark:hover:text-white transition-colors">成绩</a>
|
||
<a href="{{ url_for('main.page_exams') }}" class="hover:text-black dark:hover:text-white transition-colors">考试</a>
|
||
<div class="relative group">
|
||
<button class="hover:text-black dark:hover:text-white transition-colors flex items-center gap-1">
|
||
教务
|
||
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/></svg>
|
||
</button>
|
||
<div class="absolute top-full left-0 mt-2 py-2 w-44 bg-white dark:bg-neutral-800 rounded-xl shadow-xl border border-neutral-200 dark:border-neutral-700 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all z-50">
|
||
<a href="{{ url_for('main.page_personal_info') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">个人信息</a>
|
||
<a href="{{ url_for('main.page_personal_info_edit') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">个人信息编辑</a>
|
||
<a href="{{ url_for('main.page_academic_warning') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">学业预警</a>
|
||
<a href="{{ url_for('main.page_classrooms') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">空闲教室</a>
|
||
<a href="{{ url_for('main.page_retake_courses') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">重修课程</a>
|
||
<a href="{{ url_for('main.page_textbook_details') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">教材明细</a>
|
||
<a href="{{ url_for('main.page_textbook_order') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">教材预订</a>
|
||
<a href="{{ url_for('main.page_teacher_schedule') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">教师课表</a>
|
||
<a href="{{ url_for('main.course_search') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">课程搜索</a>
|
||
<a href="{{ url_for('main.page_classroom_schedule') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">场地课表</a>
|
||
<a href="{{ url_for('main.page_academic_status') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">学业情况</a>
|
||
<a href="{{ url_for('main.page_teaching_plan') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">教学计划</a>
|
||
<a href="{{ url_for('main.page_api_playground') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">API 测试</a>
|
||
</div>
|
||
</div>
|
||
<div class="relative group">
|
||
<button class="hover:text-black dark:hover:text-white transition-colors flex items-center gap-1">
|
||
报名申请
|
||
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/></svg>
|
||
</button>
|
||
<div class="absolute top-full left-0 mt-2 py-2 w-48 bg-white dark:bg-neutral-800 rounded-xl shadow-xl border border-neutral-200 dark:border-neutral-700 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all z-50">
|
||
<a href="{{ url_for('main.page_enrollment_change') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">学籍异动申请</a>
|
||
<a href="{{ url_for('main.page_retake_registration') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">重修报名</a>
|
||
<a href="{{ url_for('main.page_exam_registration') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">考级项目报名</a>
|
||
<a href="{{ url_for('main.page_teaching_project') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">教学项目报名</a>
|
||
<a href="{{ url_for('main.page_credit_recognition') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">成绩学分认定</a>
|
||
<a href="{{ url_for('main.page_course_substitution') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">校内课程替代</a>
|
||
<a href="{{ url_for('main.page_grade_review') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">成绩复查申请</a>
|
||
</div>
|
||
</div>
|
||
<div class="relative group">
|
||
<button class="hover:text-black dark:hover:text-white transition-colors flex items-center gap-1">
|
||
毕业论文
|
||
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/></svg>
|
||
</button>
|
||
<div class="absolute top-full left-0 mt-2 py-2 w-48 bg-white dark:bg-neutral-800 rounded-xl shadow-xl border border-neutral-200 dark:border-neutral-700 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all z-50">
|
||
<a href="{{ url_for('main.page_thesis_topic') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">学生选题</a>
|
||
<a href="{{ url_for('main.page_supervisor_change') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">更换指导教师</a>
|
||
<a href="{{ url_for('main.page_thesis_process_docs') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">过程资料</a>
|
||
<a href="{{ url_for('main.page_thesis_plagiarism_check') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">论文查重</a>
|
||
<a href="{{ url_for('main.page_thesis_grades') }}" class="block px-4 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-700 transition">成绩查看</a>
|
||
</div>
|
||
</div>
|
||
<a href="{{ url_for('main.tasks') }}" class="hover:text-black dark:hover:text-white transition-colors">任务</a>
|
||
{% if current_user.is_admin %}
|
||
<a href="{{ url_for('main.admin_users') }}" class="hover:text-black dark:hover:text-white transition-colors">管理</a>
|
||
{% endif %}
|
||
{% endif %}
|
||
</div>
|
||
|
||
<button onclick="toggleTheme()" class="theme-toggle p-2 rounded-full hover:bg-neutral-200 dark:hover:bg-neutral-800 transition-colors shrink-0" aria-label="切换主题">
|
||
<svg id="sun-icon" class="w-5 h-5 hidden dark:block text-neutral-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"></path>
|
||
</svg>
|
||
<svg id="moon-icon" class="w-5 h-5 block dark:hidden text-neutral-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"></path>
|
||
</svg>
|
||
</button>
|
||
|
||
{% if current_user.is_authenticated %}
|
||
<div class="flex items-center gap-3">
|
||
<span class="hidden md:block text-sm text-neutral-600 dark:text-neutral-400">{{ current_user.username }}</span>
|
||
<a href="{{ url_for('main.logout') }}" class="px-4 py-2 bg-black text-white dark:bg-white dark:text-black text-sm font-medium rounded-full hover:shadow-lg transition-all shrink-0">
|
||
退出
|
||
</a>
|
||
</div>
|
||
{% else %}
|
||
<a href="{{ url_for('main.login') }}" class="px-4 py-2 bg-black text-white dark:bg-white dark:text-black text-sm font-medium rounded-full hover:shadow-lg transition-all shrink-0">
|
||
登录
|
||
</a>
|
||
{% endif %}
|
||
|
||
<!-- 移动端汉堡菜单按钮 -->
|
||
<button onclick="toggleMobileMenu()" class="hamburger-btn md:hidden shrink-0" aria-label="打开菜单">
|
||
<span></span>
|
||
<span></span>
|
||
<span></span>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</nav>
|
||
|
||
<!-- 移动端菜单 -->
|
||
<div class="mobile-menu" id="mobileMenu" onclick="closeMobileMenu(event)">
|
||
<div class="mobile-menu-panel" onclick="event.stopPropagation()">
|
||
<div class="p-6 min-h-screen flex flex-col">
|
||
<div class="flex justify-between items-center mb-8">
|
||
<div class="flex items-center gap-3">
|
||
<div class="w-8 h-8 bg-black dark:bg-white rounded-lg flex items-center justify-center text-white dark:text-black font-bold text-sm">
|
||
S
|
||
</div>
|
||
<span class="font-bold">菜单</span>
|
||
</div>
|
||
<button onclick="closeMobileMenu()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
|
||
<svg class="w-6 h-6" 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>
|
||
|
||
<nav class="flex flex-col gap-4">
|
||
{% if current_user.is_authenticated %}
|
||
<a href="{{ url_for('main.dashboard') }}" onclick="closeMobileMenu()" class="text-lg font-medium py-3 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition">仪表盘</a>
|
||
<a href="{{ url_for('main.courses') }}" onclick="closeMobileMenu()" class="text-lg font-medium py-3 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition">课程查询</a>
|
||
<a href="{{ url_for('main.timetable') }}" onclick="closeMobileMenu()" class="text-lg font-medium py-3 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition">课表查询</a>
|
||
<a href="{{ url_for('main.page_grades') }}" onclick="closeMobileMenu()" class="text-lg font-medium py-3 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition">成绩查询</a>
|
||
<a href="{{ url_for('main.page_exams') }}" onclick="closeMobileMenu()" class="text-lg font-medium py-3 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition">考试安排</a>
|
||
<div class="px-4 pt-4 pb-2 text-xs font-semibold text-neutral-500 dark:text-neutral-500 uppercase tracking-wide">教务功能</div>
|
||
<a href="{{ url_for('main.page_personal_info') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">个人信息</a>
|
||
<a href="{{ url_for('main.page_personal_info_edit') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">· 编辑个人信息</a>
|
||
<a href="{{ url_for('main.page_academic_warning') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">学业预警</a>
|
||
<a href="{{ url_for('main.page_classrooms') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">空闲教室</a>
|
||
<a href="{{ url_for('main.page_retake_courses') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">重修课程</a>
|
||
<a href="{{ url_for('main.page_textbook_details') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">教材明细</a>
|
||
<a href="{{ url_for('main.page_textbook_order') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">教材预订</a>
|
||
<a href="{{ url_for('main.page_teacher_schedule') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">教师课表</a>
|
||
<a href="{{ url_for('main.course_search') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">课程搜索</a>
|
||
<a href="{{ url_for('main.page_classroom_schedule') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">场地课表</a>
|
||
<a href="{{ url_for('main.page_academic_status') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">学业情况</a>
|
||
<a href="{{ url_for('main.page_teaching_plan') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">教学计划</a>
|
||
<a href="{{ url_for('main.page_api_playground') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">API 测试</a>
|
||
<div class="px-4 pt-4 pb-2 text-xs font-semibold text-neutral-500 dark:text-neutral-500 uppercase tracking-wide">报名申请</div>
|
||
<a href="{{ url_for('main.page_enrollment_change') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">学籍异动申请</a>
|
||
<a href="{{ url_for('main.page_retake_registration') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">重修报名</a>
|
||
<a href="{{ url_for('main.page_exam_registration') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">考级项目报名</a>
|
||
<a href="{{ url_for('main.page_teaching_project') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">教学项目报名</a>
|
||
<a href="{{ url_for('main.page_credit_recognition') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">成绩学分认定</a>
|
||
<a href="{{ url_for('main.page_course_substitution') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">校内课程替代</a>
|
||
<a href="{{ url_for('main.page_grade_review') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">成绩复查申请</a>
|
||
<div class="px-4 pt-4 pb-2 text-xs font-semibold text-neutral-500 dark:text-neutral-500 uppercase tracking-wide">毕业论文(设计)</div>
|
||
<a href="{{ url_for('main.page_thesis_topic') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">学生选题</a>
|
||
<a href="{{ url_for('main.page_supervisor_change') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">更换指导教师</a>
|
||
<a href="{{ url_for('main.page_thesis_process_docs') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">过程资料</a>
|
||
<a href="{{ url_for('main.page_thesis_plagiarism_check') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">论文查重</a>
|
||
<a href="{{ url_for('main.page_thesis_grades') }}" onclick="closeMobileMenu()" class="text-base py-2 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition ml-2">成绩查看</a>
|
||
<a href="{{ url_for('main.tasks') }}" onclick="closeMobileMenu()" class="text-lg font-medium py-3 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition">抢课任务</a>
|
||
<a href="{{ url_for('main.logs') }}" onclick="closeMobileMenu()" class="text-lg font-medium py-3 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition">查看日志</a>
|
||
{% if current_user.is_admin %}
|
||
<a href="{{ url_for('main.admin_users') }}" onclick="closeMobileMenu()" class="text-lg font-medium py-3 px-4 rounded-xl hover:bg-neutral-100 dark:hover:bg-neutral-800 transition">用户管理</a>
|
||
{% endif %}
|
||
{% endif %}
|
||
</nav>
|
||
|
||
<div class="mt-auto pt-6 border-t border-neutral-200 dark:border-neutral-800">
|
||
{% if current_user.is_authenticated %}
|
||
<a href="{{ url_for('main.logout') }}" onclick="closeMobileMenu()" class="block w-full py-4 bg-black text-white dark:bg-white dark:text-black text-base font-bold rounded-full text-center">
|
||
退出登录
|
||
</a>
|
||
{% else %}
|
||
<a href="{{ url_for('main.login') }}" onclick="closeMobileMenu()" class="block w-full py-4 bg-black text-white dark:bg-white dark:text-black text-base font-bold rounded-full text-center">
|
||
登录
|
||
</a>
|
||
{% endif %}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 主内容区域 -->
|
||
<main class="pt-20 pb-8 px-4 md:px-6 flex-1" id="mainContent">
|
||
<div class="max-w-6xl mx-auto">
|
||
{% block content %}{% endblock %}
|
||
</div>
|
||
</main>
|
||
|
||
<!-- Timing Bar: 底部 28px 彩色信息条,显示文字 -->
|
||
{% if current_user.is_authenticated %}
|
||
<!-- 全局教务系统 AI 助手 -->
|
||
<div id="courseAiLauncher">
|
||
<button type="button" onclick="toggleCourseAi(true)" class="flex items-center gap-2 rounded-full bg-slate-900 dark:bg-slate-100 px-4 py-3 text-sm font-semibold text-white dark:text-slate-900 transition hover:-translate-y-0.5 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 dark:focus:ring-offset-neutral-950" aria-label="打开教务系统 AI 助手">
|
||
<svg class="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="m12 3-1.5 5.5L5 10l5.5 1.5L12 17l1.5-5.5L19 10l-5.5-1.5L12 3Z"/><path d="m19 16-.7 2.3L16 19l2.3.7L19 22l.7-2.3L19 16Z"/></svg>
|
||
<span>AI 助手</span>
|
||
</button>
|
||
</div>
|
||
|
||
<section id="courseAiPanel" class="flex flex-col overflow-hidden rounded-3xl border border-slate-200 bg-slate-50 shadow-2xl dark:border-neutral-700 dark:bg-neutral-900" aria-label="教务系统 AI 助手" aria-hidden="true">
|
||
<header class="flex items-center gap-3 border-b border-slate-100 px-4 py-3.5 dark:border-neutral-800">
|
||
<div class="flex h-10 w-10 items-center justify-center rounded-2xl bg-slate-900 text-white dark:bg-slate-100 dark:text-slate-900">
|
||
<svg class="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m12 3-1.5 5.5L5 10l5.5 1.5L12 17l-5.5-1.5L12 3Z"/></svg>
|
||
</div>
|
||
<div class="min-w-0 flex-1">
|
||
<h3 class="text-sm font-bold text-slate-900 dark:text-white">教务系统 AI 助手</h3>
|
||
<p id="courseAiAvailability" class="mt-0.5 text-xs text-slate-500 dark:text-slate-400">检查服务状态中…</p>
|
||
</div>
|
||
<button type="button" onclick="resetCourseAi()" class="flex h-11 w-11 items-center justify-center rounded-xl text-slate-400 transition hover:bg-slate-100 hover:text-slate-700 focus:outline-none focus:ring-2 focus:ring-slate-400 dark:hover:bg-neutral-800 dark:hover:text-neutral-200" title="新对话" aria-label="新对话">
|
||
<svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 12a9 9 0 0 1 15.5-6.2L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-15.5 6.2L3 16"/><path d="M3 21v-5h5"/></svg>
|
||
</button>
|
||
<button type="button" onclick="toggleCourseAi(false)" class="flex h-11 w-11 items-center justify-center rounded-xl text-slate-400 transition hover:bg-slate-100 hover:text-slate-700 focus:outline-none focus:ring-2 focus:ring-slate-400 dark:hover:bg-neutral-800 dark:hover:text-slate-200" aria-label="关闭教务系统 AI 助手">
|
||
<svg class="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m6 6 12 12M18 6 6 18"/></svg>
|
||
</button>
|
||
</header>
|
||
<div id="courseAiMessages" class="flex-1 space-y-3 overflow-y-auto bg-slate-50/70 p-4 dark:bg-neutral-950/40" aria-live="polite"></div>
|
||
<div class="border-t border-slate-100 bg-slate-50 p-3 dark:border-neutral-800 dark:bg-neutral-900">
|
||
<div id="courseAiSuggestions" class="mb-2 flex gap-2 overflow-x-auto pb-1">
|
||
<button type="button" data-prompt="帮我查看当前抢课任务" class="shrink-0 rounded-full border border-slate-200 px-3 py-1.5 text-xs text-slate-600 transition hover:bg-slate-100 dark:border-neutral-700 dark:text-slate-300 dark:hover:bg-neutral-800">查看我的任务</button>
|
||
<button type="button" data-prompt="查看最近的抢课日志" class="shrink-0 rounded-full border border-slate-200 px-3 py-1.5 text-xs text-slate-600 transition hover:bg-slate-100 dark:border-neutral-700 dark:text-slate-300 dark:hover:bg-neutral-800">查看日志</button>
|
||
<button type="button" data-prompt="查一下当前可选的英语课程" class="shrink-0 rounded-full border border-slate-200 px-3 py-1.5 text-xs text-slate-600 transition hover:bg-slate-100 dark:border-neutral-700 dark:text-slate-300 dark:hover:bg-neutral-800">查英语课</button>
|
||
</div>
|
||
<form id="courseAiForm" class="flex items-end gap-2">
|
||
<label class="sr-only" for="courseAiInput">向教务系统 AI 助手提问</label>
|
||
<textarea id="courseAiInput" rows="1" maxlength="2000" placeholder="例如:查课、看课表或管理抢课任务" class="max-h-28 min-h-[44px] flex-1 resize-none rounded-2xl border border-slate-200 bg-slate-50 px-3 py-2.5 text-sm text-slate-900 outline-none transition placeholder:text-slate-400 focus:border-slate-400 focus:ring-2 focus:ring-slate-200 dark:border-neutral-700 dark:bg-neutral-800 dark:text-white dark:focus:border-neutral-500 dark:focus:ring-neutral-700"></textarea>
|
||
<button id="courseAiSend" type="submit" class="flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl bg-slate-900 text-white transition hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-45 dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-white dark:focus:ring-offset-neutral-900" aria-label="发送消息">
|
||
<svg class="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m22 2-7 20-4-9-9-4Z"/><path d="m22 2-11 11"/></svg>
|
||
</button>
|
||
<button id="courseAiStop" type="button" onclick="stopCourseAi()" class="hidden h-11 shrink-0 items-center justify-center rounded-2xl border border-red-200 px-3 text-xs font-semibold text-red-600 transition hover:bg-red-50 focus:outline-none focus:ring-2 focus:ring-red-300 dark:border-red-900 dark:text-red-300 dark:hover:bg-red-950/40" aria-label="停止生成">停止</button>
|
||
</form>
|
||
</div>
|
||
</section>
|
||
{% endif %}
|
||
<div id="timingStrip" class="fixed bottom-0 left-0 right-0 z-50 h-7 flex items-center justify-between px-3
|
||
opacity-0 transition-opacity duration-300 pointer-events-auto cursor-pointer
|
||
text-[11px] font-mono font-medium select-none text-white">
|
||
<span id="timingLabel" class="truncate mr-2 opacity-90"></span>
|
||
<span id="timingMs" class="flex-shrink-0 opacity-90"></span>
|
||
</div>
|
||
<!-- Timing Tooltip: hover 弹出详细面板 -->
|
||
<div id="timingTooltip" class="fixed z-50 hidden bg-white dark:bg-gray-800 rounded-xl shadow-2xl border
|
||
border-gray-200 dark:border-gray-700 p-4 min-w-[300px] max-w-[400px]
|
||
text-xs leading-relaxed pointer-events-auto"
|
||
style="bottom: 34px; right: 8px;">
|
||
<div class="flex items-center justify-between mb-3 pb-2 border-b border-gray-100 dark:border-gray-700">
|
||
<span class="font-semibold text-gray-700 dark:text-gray-200 text-sm">⏱ 耗时分析</span>
|
||
<button onclick="closeTimingTooltip()" class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors text-base leading-none">×</button>
|
||
</div>
|
||
<div id="timingTooltipBody" class="space-y-2 text-gray-600 dark:text-gray-300"></div>
|
||
</div>
|
||
|
||
<!-- ⚠️ 所有 timing 逻辑放最前面,确保页面脚本 fetch 时 showTimingBar 已可用 -->
|
||
<script>
|
||
let _timingTimer = null;
|
||
let _timingPinned = false;
|
||
|
||
// ── 全局 fetch 拦截 ──
|
||
const _originalFetch = window.fetch;
|
||
window.fetch = async function(url, options) {
|
||
const resp = await _originalFetch.call(window, url, options);
|
||
const urlStr = typeof url === 'string' ? url : (url.url || '');
|
||
if (urlStr.includes('/api/') && resp.ok) {
|
||
try {
|
||
const cloned = resp.clone();
|
||
const data = await cloned.json();
|
||
if (data && data._timing) showTimingBar(data._timing);
|
||
} catch (_) {}
|
||
}
|
||
return resp;
|
||
};
|
||
|
||
function showTimingBar(timing) {
|
||
var strip = document.getElementById('timingStrip');
|
||
var label = document.getElementById('timingLabel');
|
||
var msEl = document.getElementById('timingMs');
|
||
if (!strip || !label || !msEl) return;
|
||
|
||
if (_timingTimer) clearTimeout(_timingTimer);
|
||
_timingPinned = false;
|
||
strip.className = strip.className.replace(/\s*timing-\w+/g, '').trim();
|
||
|
||
var total = timing.request_total_ms || timing.backend_total_ms || 0;
|
||
var jwxt = timing.jwxt_api_ms || 0;
|
||
var att = timing.attempts || 1;
|
||
var refr = timing.refreshed || false;
|
||
|
||
var cls = 'timing-fast';
|
||
if (!jwxt && refr) cls = 'timing-error';
|
||
else if (total >= 2000) cls = 'timing-slow';
|
||
else if (total >= 500) cls = 'timing-medium';
|
||
|
||
strip.className += ' ' + cls;
|
||
strip.classList.remove('opacity-0');
|
||
|
||
// 条上文字
|
||
label.innerHTML = jwxt ? '教务系统 ' + jwxt + 'ms' : (refr ? 'Session 刷新失败' : 'API 响应');
|
||
msEl.innerHTML = total + 'ms';
|
||
if (att > 1) msEl.innerHTML += ' <span class="opacity-60">(×' + att + ')</span>';
|
||
if (refr) msEl.innerHTML += ' <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="inline-block align-middle ml-0.5"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 21h5v-5"/></svg>';
|
||
|
||
buildTooltip(timing, cls);
|
||
|
||
// 4s 后自动隐藏
|
||
_timingTimer = setTimeout(function() {
|
||
if (!_timingPinned) {
|
||
strip.classList.add('opacity-0');
|
||
setTimeout(function() {
|
||
if (!_timingPinned) strip.className = strip.className.replace(/\s*timing-\w+/g, '').trim();
|
||
}, 300);
|
||
}
|
||
}, 4000);
|
||
|
||
strip.onclick = function(e) {
|
||
e.stopPropagation();
|
||
_timingPinned = !_timingPinned;
|
||
var tip = document.getElementById('timingTooltip');
|
||
if (_timingPinned) {
|
||
tip.classList.remove('hidden');
|
||
if (_timingTimer) clearTimeout(_timingTimer);
|
||
} else {
|
||
tip.classList.add('hidden');
|
||
_timingTimer = setTimeout(function() {
|
||
strip.classList.add('opacity-0');
|
||
setTimeout(function() {
|
||
strip.className = strip.className.replace(/\s*timing-\w+/g, '').trim();
|
||
}, 300);
|
||
}, 2000);
|
||
}
|
||
};
|
||
strip.onmouseenter = function() { document.getElementById('timingTooltip').classList.remove('hidden'); };
|
||
strip.onmouseleave = function() { if (!_timingPinned) document.getElementById('timingTooltip').classList.add('hidden'); };
|
||
}
|
||
|
||
function closeTimingTooltip() {
|
||
_timingPinned = false;
|
||
var tip = document.getElementById('timingTooltip');
|
||
var strip = document.getElementById('timingStrip');
|
||
if (tip) tip.classList.add('hidden');
|
||
if (strip) {
|
||
strip.classList.add('opacity-0');
|
||
setTimeout(function() { strip.className = strip.className.replace(/\s*timing-\w+/g, '').trim(); }, 300);
|
||
}
|
||
}
|
||
|
||
function buildTooltip(t, cls) {
|
||
var body = document.getElementById('timingTooltipBody');
|
||
if (!body) return;
|
||
|
||
var total = t.request_total_ms || t.backend_total_ms || 0;
|
||
var jwxt = t.jwxt_api_ms || 0;
|
||
var att = t.attempts || 1;
|
||
var refr = t.refreshed || false;
|
||
var ss = t.session || null;
|
||
|
||
var map = { 'timing-fast': '\u{1F7E2}', 'timing-medium': '\u{1F7E1}', 'timing-slow': '\u{1F534}', 'timing-error': '\u{1F480}' };
|
||
var emoji = map[cls] || '\u26AA';
|
||
|
||
var h = '<div class="space-y-1.5">';
|
||
|
||
h += '<div class="flex items-center gap-2 font-medium text-gray-800 dark:text-gray-100">';
|
||
h += '<span>' + emoji + '</span><span class="font-mono">总耗时 ' + total + 'ms</span></div>';
|
||
|
||
h += '<div class="ml-5 space-y-1">';
|
||
h += '<div class="flex justify-between"><span class="text-gray-400">教务系统 API</span><span class="font-mono">' + (jwxt ? jwxt + 'ms' : '\u2014') + '</span></div>';
|
||
if (t.request_total_ms && t.backend_total_ms) {
|
||
var ov = total - (t.backend_total_ms || 0);
|
||
if (ov > 0) h += '<div class="flex justify-between"><span class="text-gray-400">Flask 开销</span><span class="font-mono">' + ov + 'ms</span></div>';
|
||
}
|
||
h += '<div class="flex justify-between"><span class="text-gray-400">尝试次数</span><span class="font-mono">' + att + ' 次</span></div>';
|
||
if (refr) h += '<div class="flex justify-between"><span class="text-blue-500">Session 刷新</span><span class="font-mono text-blue-500">\u662F</span></div>';
|
||
h += '</div>';
|
||
|
||
var stages = t.stages || [];
|
||
if (stages.length > 0) {
|
||
h += '<div class="mt-2 pt-2 border-t border-gray-100 dark:border-gray-700"><div class="text-gray-400 mb-1">\u{1F4CA} 调用阶段</div>';
|
||
stages.forEach(function(s) {
|
||
var icon = s.ok ? '\u2705' : (s.session_error ? '\u26A0\uFE0F' : '\u274C');
|
||
var sc = s.ok ? 'text-green-600 dark:text-green-400' : 'text-red-500 dark:text-red-400';
|
||
var lbl = s.ok ? '' : (s.session_error ? '\uFF08\u4F1A\u8BDD\u8FC7\u671F\uFF09' : '\uFF08\u5931\u8D25\uFF09');
|
||
h += '<div class="flex items-center gap-2 ml-1"><span>' + icon + '</span><span class="text-gray-400">\u7B2C ' + s.attempt + ' \u6B21</span><span class="font-mono ' + sc + '">' + s.ms + 'ms</span>';
|
||
if (lbl) h += '<span class="' + sc + ' text-[10px]">' + lbl + '</span>';
|
||
h += '</div>';
|
||
});
|
||
h += '</div>';
|
||
}
|
||
|
||
if (ss && refr) {
|
||
h += '<div class="mt-2 pt-2 border-t border-gray-100 dark:border-gray-700"><div class="text-gray-400 mb-1">\u{1F510} Session 刷新</div>';
|
||
h += '<div class="flex justify-between ml-2"><span class="text-gray-400">耗时</span><span class="font-mono text-blue-500">' + (ss.refresh_ms || '?') + 'ms</span></div>';
|
||
if (ss.login) {
|
||
var lg = ss.login;
|
||
h += '<div class="flex justify-between ml-2"><span class="text-gray-400">登录尝试</span><span class="font-mono">' + (lg.attempts || '?') + ' 次</span></div>';
|
||
if (lg.ocr_ms > 0) h += '<div class="flex justify-between ml-2"><span class="text-gray-400">OCR 耗时</span><span class="font-mono">' + lg.ocr_ms + 'ms</span></div>';
|
||
if (lg.ocr_avg_ms > 0) h += '<div class="flex justify-between ml-2"><span class="text-gray-400">OCR 平均</span><span class="font-mono">' + lg.ocr_avg_ms + 'ms</span></div>';
|
||
}
|
||
h += '</div>';
|
||
}
|
||
|
||
h += '</div>';
|
||
body.innerHTML = h;
|
||
}
|
||
</script>
|
||
|
||
{% block body_children %}{% endblock %}
|
||
|
||
<script>
|
||
// 主题切换
|
||
function initTheme() {
|
||
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
||
document.documentElement.classList.add('dark');
|
||
} else {
|
||
document.documentElement.classList.remove('dark');
|
||
}
|
||
}
|
||
function toggleTheme() {
|
||
if (document.documentElement.classList.contains('dark')) {
|
||
document.documentElement.classList.remove('dark');
|
||
document.documentElement.style.backgroundColor = '#fafafa';
|
||
document.documentElement.style.colorScheme = 'light';
|
||
localStorage.theme = 'light';
|
||
} else {
|
||
document.documentElement.classList.add('dark');
|
||
document.documentElement.style.backgroundColor = '#0a0a0a';
|
||
document.documentElement.style.colorScheme = 'dark';
|
||
localStorage.theme = 'dark';
|
||
}
|
||
}
|
||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
|
||
if (!localStorage.theme) {
|
||
if (e.matches) document.documentElement.classList.add('dark');
|
||
else document.documentElement.classList.remove('dark');
|
||
}
|
||
});
|
||
initTheme();
|
||
|
||
// 移动端菜单控制
|
||
function toggleMobileMenu() {
|
||
const menu = document.getElementById('mobileMenu');
|
||
const btn = document.querySelector('.hamburger-btn');
|
||
menu.classList.toggle('active');
|
||
btn.classList.toggle('active');
|
||
document.body.style.overflow = menu.classList.contains('active') ? 'hidden' : '';
|
||
}
|
||
function closeMobileMenu(event) {
|
||
if (event && event.target !== document.getElementById('mobileMenu')) return;
|
||
const menu = document.getElementById('mobileMenu');
|
||
const btn = document.querySelector('.hamburger-btn');
|
||
menu.classList.remove('active');
|
||
btn.classList.remove('active');
|
||
document.body.style.overflow = '';
|
||
}
|
||
|
||
// Toast 通知系统
|
||
function showToast(message, type = 'info', duration = 3000) {
|
||
const container = document.getElementById('toastContainer');
|
||
const toast = document.createElement('div');
|
||
toast.className = `toast ${type}`;
|
||
const isMobile = window.innerWidth <= 768;
|
||
if (isMobile) {
|
||
toast.innerHTML = `<span>${message}</span>`;
|
||
} else {
|
||
toast.innerHTML = `
|
||
<span>${message}</span>
|
||
<span class="toast-close" onclick="this.parentElement.remove()">×</span>
|
||
`;
|
||
}
|
||
container.appendChild(toast);
|
||
setTimeout(() => toast.classList.add('show'), 10);
|
||
setTimeout(() => {
|
||
toast.classList.remove('show');
|
||
setTimeout(() => toast.remove(), 400);
|
||
}, duration);
|
||
return toast;
|
||
}
|
||
|
||
// API 请求封装(_timing 由全局 fetch wrapper 提取,此函数仅清理 _timing 字段)
|
||
|
||
async function apiRequest(url, options = {}) {
|
||
const defaultOptions = {
|
||
headers: {
|
||
'Content-Type': 'application/json',
|
||
},
|
||
};
|
||
const response = await fetch(url, { ...defaultOptions, ...options });
|
||
if (!response.ok) {
|
||
// 选课模式 503:把后端的友好提示带给页面,而不是干巴巴的 HTTP 状态码
|
||
let xkMsg = null;
|
||
try {
|
||
const errData = await response.clone().json();
|
||
if (errData && errData.xk_mode) {
|
||
xkMsg = errData.message || '选课模式进行中,该功能暂时关闭';
|
||
}
|
||
} catch (e) { /* 非 JSON 错误体,忽略 */ }
|
||
if (xkMsg) throw new Error(xkMsg);
|
||
throw new Error(`HTTP error! status: ${response.status}`);
|
||
}
|
||
const data = await response.json();
|
||
// 清理 _timing(全局 fetch 拦截已提取并显示)
|
||
if (data && data._timing) delete data._timing;
|
||
return data;
|
||
}
|
||
|
||
// HTML 转义
|
||
function escapeHtml(text) {
|
||
if (!text) return '';
|
||
const div = document.createElement('div');
|
||
div.textContent = text;
|
||
return div.innerHTML;
|
||
}
|
||
|
||
// 格式化时间(强制北京时间)
|
||
function formatTime(timeStr) {
|
||
if (!timeStr) return '-';
|
||
const date = new Date(timeStr);
|
||
return date.toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false }).replace(/\//g, '-');
|
||
}
|
||
|
||
// ESC 键关闭菜单 / 计时面板
|
||
document.addEventListener('keydown', (e) => {
|
||
if (e.key === 'Escape') {
|
||
closeMobileMenu();
|
||
if (_timingPinned) closeTimingTooltip();
|
||
}
|
||
});
|
||
|
||
// 点击页面其他地方关闭固定的计时面板
|
||
document.addEventListener('click', function(e) {
|
||
if (!_timingPinned) return;
|
||
const tooltip = document.getElementById('timingTooltip');
|
||
const strip = document.getElementById('timingStrip');
|
||
if (tooltip && !tooltip.contains(e.target) && strip && !strip.contains(e.target)) {
|
||
closeTimingTooltip();
|
||
}
|
||
});
|
||
</script>
|
||
{% if current_user.is_authenticated %}
|
||
<script>
|
||
// ==================== AI 选课助手 ====================
|
||
let courseAiMessages = [];
|
||
let courseAiReady = false;
|
||
let courseAiSending = false;
|
||
let courseAiSocket = null;
|
||
let courseAiStopRequested = false;
|
||
let courseAiActiveReply = null;
|
||
|
||
function courseAiEscapeHtml(value) {
|
||
return String(value ?? '').replace(/[&<>"']/g, char => ({
|
||
'&': '&', '<': '<', '>': '>', '"': '"', "'": ''',
|
||
}[char]));
|
||
}
|
||
|
||
function courseAiSafeUrl(value) {
|
||
const url = String(value || '').trim();
|
||
return /^(https?:\/\/|\/|#)/i.test(url) && !/^(javascript|data|vbscript):/i.test(url) ? url : null;
|
||
}
|
||
|
||
function courseAiInlineMarkdown(value) {
|
||
let text = courseAiEscapeHtml(value);
|
||
const tokens = [];
|
||
const token = html => {
|
||
const marker = `\u0000${tokens.length}\u0000`;
|
||
tokens.push(html);
|
||
return marker;
|
||
};
|
||
text = text.replace(/`([^`\n]+)`/g, (_, code) => token(`<code>${code}</code>`));
|
||
text = text.replace(/\[([^\]\n]+)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g, (_, label, rawUrl, title) => {
|
||
const url = courseAiSafeUrl(rawUrl);
|
||
if (!url) return label;
|
||
const titleAttr = title ? ` title="${courseAiEscapeHtml(title)}"` : '';
|
||
return token(`<a href="${courseAiEscapeHtml(url)}" target="_blank" rel="noopener noreferrer"${titleAttr}>${label}</a>`);
|
||
});
|
||
text = text.replace(/\*\*(.+?)\*\*|__(.+?)__/g, (_, strongA, strongB) => `<strong>${strongA || strongB}</strong>`);
|
||
text = text.replace(/~~(.+?)~~/g, '<del>$1</del>');
|
||
text = text.replace(/(^|[^*])\*([^*\n]+)\*(?!\*)/g, '$1<em>$2</em>');
|
||
text = text.replace(/(^|[^_])_([^_\n]+)_(?!_)/g, '$1<em>$2</em>');
|
||
return text.replace(/\u0000(\d+)\u0000/g, (_, index) => tokens[Number(index)] || '');
|
||
}
|
||
|
||
function courseAiSplitTableRow(line) {
|
||
return line.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map(cell => cell.trim());
|
||
}
|
||
|
||
function courseAiIsTableSeparator(line) {
|
||
return /^\s*\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(line);
|
||
}
|
||
|
||
function courseAiRenderMarkdown(source) {
|
||
const lines = String(source ?? '').replace(/\r\n?/g, '\n').split('\n');
|
||
const output = [];
|
||
let paragraph = [];
|
||
let list = null;
|
||
let code = null;
|
||
|
||
const flushParagraph = () => {
|
||
if (!paragraph.length) return;
|
||
output.push(`<p>${courseAiInlineMarkdown(paragraph.join('\n')).replace(/\n/g, '<br>')}</p>`);
|
||
paragraph = [];
|
||
};
|
||
const flushList = () => {
|
||
if (!list) return;
|
||
output.push(`<${list.type}>${list.items.map(item => `<li>${courseAiInlineMarkdown(item)}</li>`).join('')}</${list.type}>`);
|
||
list = null;
|
||
};
|
||
const isBlockStart = line => /^(#{1,6})\s+/.test(line) || /^\s*(?:[-*+]\s+|\d+\.\s+)/.test(line) || /^\s*>/.test(line) || /^\s*```/.test(line) || /^\s{0,3}(?:---+|\*\s*\*\s*\*|___+)\s*$/.test(line);
|
||
|
||
for (let index = 0; index < lines.length; index += 1) {
|
||
const line = lines[index];
|
||
if (code) {
|
||
if (/^\s*```/.test(line)) {
|
||
const language = code.language ? ` class="language-${courseAiEscapeHtml(code.language)}"` : '';
|
||
output.push(`<pre><code${language}>${courseAiEscapeHtml(code.lines.join('\n'))}</code></pre>`);
|
||
code = null;
|
||
} else {
|
||
code.lines.push(line);
|
||
}
|
||
continue;
|
||
}
|
||
const fence = line.match(/^\s*```\s*([\w+-]*)\s*$/);
|
||
if (fence) {
|
||
flushParagraph();
|
||
flushList();
|
||
code = { language: fence[1], lines: [] };
|
||
continue;
|
||
}
|
||
if (!line.trim()) {
|
||
flushParagraph();
|
||
flushList();
|
||
continue;
|
||
}
|
||
if (index + 1 < lines.length && courseAiIsTableSeparator(lines[index + 1]) && line.includes('|')) {
|
||
flushParagraph();
|
||
flushList();
|
||
const headers = courseAiSplitTableRow(line);
|
||
index += 1;
|
||
const rows = [];
|
||
while (index + 1 < lines.length && lines[index + 1].trim() && lines[index + 1].includes('|')) {
|
||
index += 1;
|
||
rows.push(courseAiSplitTableRow(lines[index]));
|
||
}
|
||
output.push(`<table><thead><tr>${headers.map(cell => `<th>${courseAiInlineMarkdown(cell)}</th>`).join('')}</tr></thead><tbody>${rows.map(row => `<tr>${headers.map((_, cellIndex) => `<td>${courseAiInlineMarkdown(row[cellIndex] || '')}</td>`).join('')}</tr>`).join('')}</tbody></table>`);
|
||
continue;
|
||
}
|
||
const heading = line.match(/^\s*(#{1,6})\s+(.+?)\s*#*\s*$/);
|
||
if (heading) {
|
||
flushParagraph();
|
||
flushList();
|
||
const level = heading[1].length;
|
||
output.push(`<h${level}>${courseAiInlineMarkdown(heading[2])}</h${level}>`);
|
||
continue;
|
||
}
|
||
if (/^\s{0,3}(?:---+|\*\s*\*\s*\*|___+)\s*$/.test(line)) {
|
||
flushParagraph();
|
||
flushList();
|
||
output.push('<hr>');
|
||
continue;
|
||
}
|
||
const quote = line.match(/^\s*>\s?(.*)$/);
|
||
if (quote) {
|
||
flushParagraph();
|
||
flushList();
|
||
const quoteLines = [quote[1]];
|
||
while (index + 1 < lines.length) {
|
||
const nextQuote = lines[index + 1].match(/^\s*>\s?(.*)$/);
|
||
if (!nextQuote) break;
|
||
index += 1;
|
||
quoteLines.push(nextQuote[1]);
|
||
}
|
||
output.push(`<blockquote>${courseAiInlineMarkdown(quoteLines.join('\n')).replace(/\n/g, '<br>')}</blockquote>`);
|
||
continue;
|
||
}
|
||
const unordered = line.match(/^\s*[-*+]\s+(.+)$/);
|
||
const ordered = line.match(/^\s*\d+\.\s+(.+)$/);
|
||
if (unordered || ordered) {
|
||
flushParagraph();
|
||
const type = unordered ? 'ul' : 'ol';
|
||
if (list && list.type !== type) flushList();
|
||
if (!list) list = { type, items: [] };
|
||
list.items.push((unordered || ordered)[1]);
|
||
continue;
|
||
}
|
||
if (list && !isBlockStart(line)) {
|
||
list.items[list.items.length - 1] += `\n${line.trim()}`;
|
||
continue;
|
||
}
|
||
flushList();
|
||
paragraph.push(line);
|
||
}
|
||
if (code) {
|
||
const language = code.language ? ` class="language-${courseAiEscapeHtml(code.language)}"` : '';
|
||
output.push(`<pre><code${language}>${courseAiEscapeHtml(code.lines.join('\n'))}</code></pre>`);
|
||
}
|
||
flushParagraph();
|
||
flushList();
|
||
return output.join('');
|
||
}
|
||
|
||
function courseAiAddCopyButton(item) {
|
||
if (item.querySelector('[data-copy-markdown]')) return;
|
||
const actions = document.createElement('div');
|
||
actions.className = 'course-ai-copy';
|
||
const button = document.createElement('button');
|
||
button.type = 'button';
|
||
button.dataset.copyMarkdown = 'true';
|
||
button.textContent = '复制 Markdown';
|
||
button.addEventListener('click', async () => {
|
||
try {
|
||
await navigator.clipboard.writeText(item._courseAiRawContent || '');
|
||
button.textContent = '已复制';
|
||
setTimeout(() => { button.textContent = '复制 Markdown'; }, 1200);
|
||
} catch (error) {
|
||
button.textContent = '复制失败';
|
||
setTimeout(() => { button.textContent = '复制 Markdown'; }, 1200);
|
||
}
|
||
});
|
||
actions.appendChild(button);
|
||
item.appendChild(actions);
|
||
}
|
||
|
||
function courseAiSetMessageContent(item, content, allowCopy) {
|
||
const rawContent = String(content ?? '');
|
||
item._courseAiRawContent = rawContent;
|
||
let body = item.querySelector('[data-markdown-body]');
|
||
if (!body) {
|
||
item.replaceChildren();
|
||
body = document.createElement('div');
|
||
body.dataset.markdownBody = 'true';
|
||
body.className = 'course-ai-markdown';
|
||
item.appendChild(body);
|
||
}
|
||
body.innerHTML = courseAiRenderMarkdown(rawContent);
|
||
if (allowCopy) courseAiAddCopyButton(item);
|
||
}
|
||
|
||
function courseAiAddMessage(role, content) {
|
||
const rawContent = String(content ?? '');
|
||
courseAiMessages.push({ role, content: rawContent });
|
||
const box = document.getElementById('courseAiMessages');
|
||
const item = document.createElement('div');
|
||
item.className = `course-ai-message max-w-[88%] rounded-2xl px-3.5 py-2.5 text-sm leading-6 ${role === 'user' ? 'course-ai-user ml-auto rounded-br-md' : 'course-ai-assistant mr-auto rounded-bl-md'}`;
|
||
courseAiSetMessageContent(item, rawContent, role === 'assistant');
|
||
box.appendChild(item);
|
||
box.scrollTop = box.scrollHeight;
|
||
}
|
||
|
||
function courseAiCreateStreamingMessage() {
|
||
const box = document.getElementById('courseAiMessages');
|
||
const item = document.createElement('div');
|
||
// 复合气泡:文字分段与工具卡片按发生顺序内嵌排列。
|
||
item.className = 'course-ai-message course-ai-composite max-w-[88%] rounded-2xl rounded-bl-md px-3.5 py-2.5 text-sm leading-6 course-ai-assistant mr-auto';
|
||
box.appendChild(item);
|
||
box.scrollTop = box.scrollHeight;
|
||
return item;
|
||
}
|
||
|
||
function courseAiShowThinking(bubble, text) {
|
||
if (!bubble._courseAiThinkingEl) {
|
||
const placeholder = document.createElement('div');
|
||
placeholder.className = 'course-ai-thinking';
|
||
bubble.appendChild(placeholder);
|
||
bubble._courseAiThinkingEl = placeholder;
|
||
}
|
||
bubble._courseAiThinkingEl.textContent = text;
|
||
const box = document.getElementById('courseAiMessages');
|
||
box.scrollTop = box.scrollHeight;
|
||
}
|
||
|
||
function courseAiDismissThinking(bubble) {
|
||
if (bubble && bubble._courseAiThinkingEl) {
|
||
bubble._courseAiThinkingEl.remove();
|
||
bubble._courseAiThinkingEl = null;
|
||
}
|
||
}
|
||
|
||
function courseAiAppendDelta(bubble, delta) {
|
||
// 工具卡片会打断当前文字段;卡片之后的文字另起一段继续,保持发生顺序。
|
||
let segment = bubble._courseAiSegment;
|
||
if (!segment) {
|
||
segment = document.createElement('div');
|
||
segment.className = 'course-ai-markdown';
|
||
bubble.appendChild(segment);
|
||
bubble._courseAiSegment = segment;
|
||
}
|
||
segment._courseAiRaw = (segment._courseAiRaw || '') + delta;
|
||
segment.innerHTML = courseAiRenderMarkdown(segment._courseAiRaw);
|
||
}
|
||
|
||
const courseAiToolLabels = {
|
||
load_tools: '加载工具目录',
|
||
search_live_courses: '查询实时课程', search_index_courses: '搜索课程索引', browse_index_courses: '浏览课程索引',
|
||
get_course_index_status: '查看课程索引状态',
|
||
get_timetable: '读取课表', get_timetable_semester: '查询学期信息',
|
||
get_semesters: '查询学年学期', get_grades: '查询成绩', get_exam_schedule: '查询考试安排',
|
||
get_classroom_params: '读取教室筛选参数', get_classroom_filter_options: '读取教室筛选选项',
|
||
get_classroom_periods: '读取节次周次', search_available_classrooms: '查询空闲教室',
|
||
search_classroom_schedule: '查询教室课表',
|
||
search_teachers: '查询教师', get_teacher_schedule_detail: '查询教师课表',
|
||
get_academic_warning: '查询学业预警', get_academic_warning_params: '读取预警筛选项',
|
||
get_academic_status: '查询学业情况', get_academic_status_courses: '查询培养方案课程',
|
||
get_teaching_plan: '查询教学计划', get_student_info: '查询学生信息', get_personal_info: '查询学籍信息',
|
||
list_grab_tasks: '读取抢课任务', get_task_logs: '读取任务日志', list_chosen_courses: '读取已选课程',
|
||
create_grab_task: '创建抢课任务', cancel_grab_task: '取消抢课任务', drop_selected_course: '执行退课',
|
||
get_textbook_orders: '查询教材预订', get_textbook_details: '查询教材明细',
|
||
order_textbook: '预订教材', cancel_textbook_order: '退订教材',
|
||
ask_user: '向用户提问',
|
||
};
|
||
|
||
function courseAiPrettyJson(text, limit = 4000) {
|
||
const raw = String(text || '').trim();
|
||
if (!raw) return '';
|
||
let pretty = raw;
|
||
try { pretty = JSON.stringify(JSON.parse(raw), null, 2); } catch (error) { /* 非 JSON 原样展示 */ }
|
||
return pretty.length > limit ? `${pretty.slice(0, limit)}\n…(已截断,共 ${pretty.length} 字符)` : pretty;
|
||
}
|
||
|
||
function courseAiEnsureToolCard(bubble, id, name, argsJson) {
|
||
const existing = [...document.querySelectorAll('[data-tool-id]')].find(item => item.dataset.toolId === id);
|
||
if (existing) return existing;
|
||
const card = document.createElement('details');
|
||
card.className = 'course-ai-tool w-full rounded-xl px-3 py-2 text-xs text-slate-600 dark:text-slate-300';
|
||
card.dataset.toolId = id;
|
||
card.dataset.state = 'running';
|
||
// 默认收起:摘要行显示“名称 + 进度摘要 + 状态”,展开查看输入参数与输出数据。
|
||
card.innerHTML = `<summary class="flex cursor-pointer items-center gap-2"><span class="course-ai-tool-icon flex h-5 w-5 shrink-0 items-center justify-center rounded-md bg-slate-100 text-slate-500 dark:bg-neutral-800 dark:text-slate-300"><span class="h-2 w-2 rounded-full bg-current"></span></span><span class="shrink-0 font-medium text-slate-700 dark:text-slate-200">${courseAiEscapeHtml(courseAiToolLabels[name] || name || '调用站内工具')}</span><span data-tool-message class="min-w-0 flex-1 truncate text-slate-400">正在请求本站服务…</span><span data-tool-status class="shrink-0 text-slate-400">执行中</span><svg class="h-3.5 w-3.5 shrink-0 text-slate-400" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m6 9 6 6 6-6"/></svg></summary>`
|
||
+ `<div class="mt-2 border-t border-slate-100 pt-2 dark:border-neutral-800"><div class="course-ai-io">`
|
||
+ `<div><div class="course-ai-io-label">输入参数(模型提供)</div><pre data-tool-args class="course-ai-io-pre"></pre></div>`
|
||
+ `<div><div class="course-ai-io-label">输出数据(站内返回)</div><pre data-tool-result class="course-ai-io-pre">执行完成后显示</pre></div></div></div>`;
|
||
card.querySelector('[data-tool-args]').textContent = courseAiPrettyJson(argsJson) || '(无参数)';
|
||
bubble.appendChild(card);
|
||
const box = document.getElementById('courseAiMessages');
|
||
box.scrollTop = box.scrollHeight;
|
||
return card;
|
||
}
|
||
|
||
function courseAiAddConfirmation(bubble, id, name, summary, argsJson) {
|
||
const existing = [...document.querySelectorAll('[data-tool-id]')].find(item => item.dataset.toolId === id);
|
||
if (existing) return existing;
|
||
const card = document.createElement('details');
|
||
card.className = 'course-ai-tool w-full rounded-xl px-3 py-2.5 text-xs text-slate-600 dark:text-slate-300';
|
||
card.dataset.toolId = id;
|
||
card.dataset.state = 'confirm';
|
||
card.open = true;
|
||
const label = courseAiEscapeHtml(courseAiToolLabels[name] || name || '站内操作');
|
||
card.innerHTML = `<summary class="flex cursor-pointer items-center gap-2"><svg class="h-4 w-4 shrink-0 text-amber-600 dark:text-amber-300" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 20h16a2 2 0 0 0 1.73-2Z"/><path d="M12 9v4M12 17h.01"/></svg><span class="min-w-0 flex-1 font-medium text-amber-700 dark:text-amber-300">需要你确认:${label}</span><span data-tool-status class="text-amber-600 dark:text-amber-300">待确认</span><svg class="h-3.5 w-3.5 text-slate-400" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m6 9 6 6 6-6"/></svg></summary>`
|
||
+ `<div class="mt-2 space-y-2 border-t border-amber-200/70 pt-2 dark:border-amber-900/60">`
|
||
+ `<p data-tool-message class="leading-5 text-slate-500 dark:text-slate-400">${courseAiEscapeHtml(summary || '请核对以下操作内容。')}</p>`
|
||
+ `<div class="course-ai-io"><div class="course-ai-io-label">输入参数(模型提供)</div><pre data-tool-args class="course-ai-io-pre"></pre>`
|
||
+ `<div class="course-ai-io-label mt-1">输出数据(站内返回)</div><pre data-tool-result class="course-ai-io-pre">确认后执行,结果在此显示</pre></div>`
|
||
+ `<div class="flex gap-2"><button type="button" data-confirm-approve class="rounded-lg bg-slate-900 px-3 py-1.5 text-xs font-semibold text-white transition hover:bg-slate-700 dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-white">确认执行</button><button type="button" data-confirm-deny class="rounded-lg border border-slate-200 px-3 py-1.5 text-xs font-semibold text-slate-600 transition hover:bg-slate-100 dark:border-neutral-700 dark:text-slate-300 dark:hover:bg-neutral-800">拒绝</button></div>`
|
||
+ `<div data-tool-note class="hidden leading-5 text-slate-500 dark:text-slate-400"></div></div>`;
|
||
card.querySelector('[data-tool-args]').textContent = courseAiPrettyJson(argsJson) || '(无参数)';
|
||
const act = approved => {
|
||
if (card.dataset.state !== 'confirm') return;
|
||
card.dataset.state = 'pending';
|
||
card.querySelectorAll('button').forEach(button => button.remove());
|
||
const note = card.querySelector('[data-tool-note]');
|
||
note.classList.remove('hidden');
|
||
note.textContent = approved ? '已确认,正在执行…' : '已拒绝,操作未执行。';
|
||
const status = card.querySelector('[data-tool-status]');
|
||
if (status) status.textContent = approved ? '执行中' : '已拒绝';
|
||
const socket = courseAiSocket;
|
||
if (socket && socket.readyState === WebSocket.OPEN) {
|
||
try { socket.send(JSON.stringify({ type: 'confirm', call_id: id, approved })); } catch (error) { /* 连接已断开 */ }
|
||
}
|
||
};
|
||
card.querySelector('[data-confirm-approve]').addEventListener('click', () => act(true));
|
||
card.querySelector('[data-confirm-deny]').addEventListener('click', () => act(false));
|
||
bubble.appendChild(card);
|
||
const box = document.getElementById('courseAiMessages');
|
||
box.scrollTop = box.scrollHeight;
|
||
return card;
|
||
}
|
||
|
||
function courseAiAddAskCard(bubble, id, question, options, multiple) {
|
||
const existing = [...document.querySelectorAll('[data-tool-id]')].find(item => item.dataset.toolId === id);
|
||
if (existing) return existing;
|
||
const card = document.createElement('details');
|
||
card.className = 'course-ai-tool w-full rounded-xl px-3 py-2.5 text-xs text-slate-600 dark:text-slate-300';
|
||
card.dataset.toolId = id;
|
||
card.dataset.state = 'ask';
|
||
card.open = true;
|
||
const optionButtons = (options || []).map(option =>
|
||
`<button type="button" data-ask-option aria-pressed="false" class="rounded-lg border border-slate-200 bg-white px-3 py-1.5 text-left text-xs font-medium text-slate-700 transition hover:bg-slate-100 dark:border-neutral-700 dark:bg-neutral-800 dark:text-slate-200 dark:hover:bg-neutral-700">${courseAiEscapeHtml(option)}</button>`
|
||
).join('');
|
||
card.innerHTML = `<summary class="flex cursor-pointer items-center gap-2"><svg class="h-4 w-4 shrink-0 text-sky-600 dark:text-sky-300" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><path d="M12 17h.01"/></svg><span class="min-w-0 flex-1 font-medium text-sky-700 dark:text-sky-300">AI 需要你选择</span><span data-tool-status class="text-sky-600 dark:text-sky-300">待回答</span><svg class="h-3.5 w-3.5 text-slate-400" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m6 9 6 6 6-6"/></svg></summary>`
|
||
+ `<div class="mt-2 space-y-2 border-t border-sky-200/70 pt-2 dark:border-sky-900/60">`
|
||
+ `<p data-ask-question class="leading-5 text-slate-700 dark:text-slate-200">${courseAiEscapeHtml(question || '请做出选择')}</p>`
|
||
+ `<div data-ask-options class="flex flex-wrap gap-2">${optionButtons}</div>`
|
||
+ `<textarea data-ask-note rows="1" maxlength="500" placeholder="补充说明(可留空;没有合适的选项时直接在这里填写)" class="w-full resize-none rounded-lg border border-slate-200 bg-slate-50 px-2.5 py-1.5 text-xs text-slate-900 outline-none transition placeholder:text-slate-400 focus:border-slate-400 dark:border-neutral-700 dark:bg-neutral-800 dark:text-white"></textarea>`
|
||
+ `<div class="flex items-center gap-2"><button type="button" data-ask-submit class="rounded-lg bg-slate-900 px-3 py-1.5 text-xs font-semibold text-white transition hover:bg-slate-700 dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-white">提交${multiple ? '(可多选)' : ''}</button><span data-tool-note class="hidden min-w-0 flex-1 leading-5 text-slate-500 dark:text-slate-400"></span></div>`
|
||
+ `<pre data-tool-result class="course-ai-io-pre hidden"></pre></div>`;
|
||
bubble.appendChild(card);
|
||
const box = document.getElementById('courseAiMessages');
|
||
box.scrollTop = box.scrollHeight;
|
||
|
||
const input = document.getElementById('courseAiInput');
|
||
if (input) input.placeholder = '请先回答上方的问题';
|
||
const noteInput = card.querySelector('[data-ask-note]');
|
||
const selectedValues = [];
|
||
|
||
const act = selected => {
|
||
if (card.dataset.state !== 'ask') return;
|
||
card.dataset.state = 'pending';
|
||
card.querySelectorAll('[data-ask-option], [data-ask-submit]').forEach(el => el.remove());
|
||
noteInput.disabled = true;
|
||
if (input) input.placeholder = '例如:查课、看课表或管理抢课任务';
|
||
const status = card.querySelector('[data-tool-status]');
|
||
if (status) status.textContent = '已回答';
|
||
const note = card.querySelector('[data-tool-note]');
|
||
const summary = [];
|
||
if (selected.length) summary.push(`已选:${selected.join('、')}`);
|
||
if (noteInput.value.trim()) summary.push(`补充:${noteInput.value.trim()}`);
|
||
if (note && summary.length) { note.classList.remove('hidden'); note.textContent = summary.join(' · '); }
|
||
const socket = courseAiSocket;
|
||
if (socket && socket.readyState === WebSocket.OPEN) {
|
||
try { socket.send(JSON.stringify({ type: 'ask_answer', call_id: id, selected, text: noteInput.value.trim() })); } catch (error) { /* 连接已断开 */ }
|
||
}
|
||
};
|
||
|
||
card.querySelectorAll('[data-ask-option]').forEach(button => {
|
||
button.addEventListener('click', () => {
|
||
if (card.dataset.state !== 'ask') return;
|
||
if (multiple) {
|
||
const pressed = button.getAttribute('aria-pressed') === 'true';
|
||
button.setAttribute('aria-pressed', pressed ? 'false' : 'true');
|
||
} else {
|
||
act([button.textContent.trim()]);
|
||
}
|
||
});
|
||
});
|
||
card.querySelector('[data-ask-submit]').addEventListener('click', () => {
|
||
if (card.dataset.state !== 'ask') return;
|
||
const selected = multiple
|
||
? [...card.querySelectorAll('[data-ask-option][aria-pressed="true"]')].map(el => el.textContent.trim())
|
||
: [];
|
||
act(selected);
|
||
});
|
||
return card;
|
||
}
|
||
|
||
function courseAiFinishToolCard(id, success, message, resultJson) {
|
||
const card = [...document.querySelectorAll('[data-tool-id]')].find(item => item.dataset.toolId === id);
|
||
if (!card) return;
|
||
const result = card.querySelector('[data-tool-result]');
|
||
const pretty = courseAiPrettyJson(resultJson);
|
||
if (result && pretty) result.textContent = pretty;
|
||
if (card.dataset.state === 'confirm' || card.dataset.state === 'pending' || card.dataset.state === 'ask') {
|
||
const isAskCard = !!card.querySelector('[data-ask-question]');
|
||
card.dataset.state = success ? 'success' : 'error';
|
||
const status = card.querySelector('[data-tool-status]');
|
||
if (status) status.textContent = isAskCard ? (success ? '已回答' : '未回答') : (success ? '已执行' : '未执行');
|
||
const note = card.querySelector('[data-tool-note]');
|
||
if (note) {
|
||
// 提问卡片已就地展示“已选/补充”摘要,仅在没有摘要时显示服务端消息。
|
||
if (isAskCard && note.textContent.trim()) { restoreCourseAiInput(); return; }
|
||
note.classList.remove('hidden');
|
||
note.textContent = message || (success ? '已执行。' : '未执行。');
|
||
}
|
||
if (isAskCard) restoreCourseAiInput();
|
||
return;
|
||
}
|
||
card.dataset.state = success ? 'success' : 'error';
|
||
const icon = card.querySelector('.course-ai-tool-icon');
|
||
if (icon) icon.innerHTML = success
|
||
? '<svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="m5 12 4.5 4.5L19 7"/></svg>'
|
||
: '<svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="m6 6 12 12M18 6 6 18"/></svg>';
|
||
const status = card.querySelector('[data-tool-status]');
|
||
if (status) status.textContent = success ? '已完成' : '失败';
|
||
const detail = card.querySelector('[data-tool-message]');
|
||
if (detail) detail.textContent = message || (success ? '已返回站内结果。' : '工具未能完成。');
|
||
}
|
||
|
||
function restoreCourseAiInput() {
|
||
const input = document.getElementById('courseAiInput');
|
||
if (input) input.placeholder = '例如:查课、看课表或管理抢课任务';
|
||
}
|
||
|
||
function courseAiRenderMessages(messages) {
|
||
courseAiMessages = [];
|
||
const box = document.getElementById('courseAiMessages');
|
||
box.replaceChildren();
|
||
messages.forEach(item => courseAiAddMessage(item.role, item.content));
|
||
}
|
||
|
||
async function loadCourseAiConversation() {
|
||
try {
|
||
const response = await fetch('/api/ai/conversation', { credentials: 'same-origin' });
|
||
const data = await response.json();
|
||
if (data.success && Array.isArray(data.messages) && data.messages.length) {
|
||
courseAiRenderMessages(data.messages);
|
||
return;
|
||
}
|
||
} catch (e) {
|
||
// 读取历史失败时仍允许开始新对话。
|
||
}
|
||
resetCourseAi(false);
|
||
}
|
||
|
||
function courseAiSetSending(sending) {
|
||
courseAiSending = sending;
|
||
const button = document.getElementById('courseAiSend');
|
||
const input = document.getElementById('courseAiInput');
|
||
const stop = document.getElementById('courseAiStop');
|
||
button.disabled = sending || !courseAiReady;
|
||
input.disabled = sending || !courseAiReady;
|
||
stop.classList.toggle('hidden', !sending);
|
||
stop.classList.toggle('inline-flex', sending);
|
||
if (sending) {
|
||
button.innerHTML = '<span class="h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"></span>';
|
||
} else {
|
||
button.innerHTML = '<svg class="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m22 2-7 20-4-9-9-4Z"/><path d="m22 2-11 11"/></svg>';
|
||
}
|
||
}
|
||
|
||
function stopCourseAi() {
|
||
if (!courseAiSending) return;
|
||
courseAiStopRequested = true;
|
||
const bubble = courseAiActiveReply;
|
||
if (bubble && !bubble._courseAiRawText) {
|
||
// 还没有任何文字输出时,把“思考中”占位改成已停止。
|
||
if (bubble._courseAiThinkingEl) {
|
||
bubble._courseAiThinkingEl.textContent = '已停止生成。';
|
||
bubble._courseAiThinkingEl.style.animation = 'none';
|
||
} else {
|
||
courseAiAppendDelta(bubble, '已停止生成。');
|
||
}
|
||
}
|
||
const socket = courseAiSocket;
|
||
if (socket && socket.readyState === WebSocket.OPEN) {
|
||
// 先发停止帧,让服务端取消生成并跳过待执行的工具,再关闭连接。
|
||
try { socket.send(JSON.stringify({ type: 'stop' })); } catch (error) { /* 连接可能已断开 */ }
|
||
}
|
||
setTimeout(() => {
|
||
if (socket && socket.readyState === WebSocket.OPEN) {
|
||
try { socket.close(1000, 'user_stop'); } catch (error) { /* socket may already be closed */ }
|
||
}
|
||
}, 120);
|
||
}
|
||
|
||
async function loadCourseAiStatus() {
|
||
const status = document.getElementById('courseAiAvailability');
|
||
const launcher = document.getElementById('courseAiLauncher');
|
||
const panel = document.getElementById('courseAiPanel');
|
||
try {
|
||
const response = await fetch('/api/ai/status', { credentials: 'same-origin' });
|
||
const data = await response.json();
|
||
courseAiReady = !!(data.success && data.enabled && data.configured);
|
||
if (data.success && !data.enabled) {
|
||
launcher.classList.add('hidden');
|
||
panel.classList.remove('is-open');
|
||
panel.setAttribute('aria-hidden', 'true');
|
||
} else if (data.success) {
|
||
launcher.classList.remove('hidden');
|
||
}
|
||
if (courseAiReady) {
|
||
status.textContent = '可查课、创建任务、看日志与取消任务';
|
||
} else if (data.enabled && !data.configured) {
|
||
status.textContent = '管理员尚未配置 API Key';
|
||
} else {
|
||
status.textContent = '管理员尚未启用助手';
|
||
}
|
||
} catch (e) {
|
||
courseAiReady = false;
|
||
status.textContent = '服务状态暂不可用';
|
||
}
|
||
courseAiSetSending(false);
|
||
}
|
||
|
||
function toggleCourseAi(open) {
|
||
const panel = document.getElementById('courseAiPanel');
|
||
const launcher = document.getElementById('courseAiLauncher');
|
||
panel.classList.toggle('is-open', open);
|
||
panel.setAttribute('aria-hidden', open ? 'false' : 'true');
|
||
launcher.classList.toggle('hidden', open);
|
||
if (open) {
|
||
loadCourseAiStatus();
|
||
setTimeout(() => document.getElementById('courseAiInput').focus(), 100);
|
||
}
|
||
}
|
||
|
||
async function resetCourseAi(clearSaved = true) {
|
||
if (clearSaved) {
|
||
try {
|
||
await fetch('/api/ai/conversation', { method: 'DELETE', credentials: 'same-origin' });
|
||
} catch (e) {
|
||
courseAiAddMessage('assistant', '清空历史失败,请稍后重试。');
|
||
return;
|
||
}
|
||
}
|
||
courseAiMessages = [];
|
||
document.getElementById('courseAiMessages').replaceChildren();
|
||
courseAiAddMessage('assistant', '你好,我可以查询当前已开放的课程、课表、成绩、教室和教师信息,也可以创建或定时创建抢课任务、查看任务日志、取消任务,以及在你明确要求时退掉已选课程。创建任务、取消任务和退课会先弹出确认,你点击“确认执行”后才会真正执行。课程未开放时,我不会编造可选课程信息。');
|
||
}
|
||
|
||
function courseAiSocketUrl() {
|
||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||
return `${protocol}//${window.location.host}/api/ai/chat/ws`;
|
||
}
|
||
|
||
function courseAiSendOverWebSocket(content, handleEvent) {
|
||
return new Promise((resolve, reject) => {
|
||
const socket = new WebSocket(courseAiSocketUrl());
|
||
courseAiSocket = socket;
|
||
let finished = false;
|
||
let receivedDone = false;
|
||
|
||
const fail = message => {
|
||
if (finished) return;
|
||
finished = true;
|
||
if (courseAiSocket === socket) courseAiSocket = null;
|
||
try { socket.close(1000, 'client error'); } catch (error) { /* socket may already be closed */ }
|
||
reject(new Error(message || 'WebSocket 连接失败'));
|
||
};
|
||
|
||
socket.onopen = () => {
|
||
socket.send(JSON.stringify({ message: content }));
|
||
};
|
||
socket.onmessage = event => {
|
||
let payload;
|
||
try {
|
||
payload = JSON.parse(event.data);
|
||
} catch (error) {
|
||
fail('收到无法解析的 AI 事件');
|
||
return;
|
||
}
|
||
try {
|
||
handleEvent(payload);
|
||
} catch (error) {
|
||
fail(error.message || 'AI 输出处理失败');
|
||
return;
|
||
}
|
||
if (payload.type === 'error') {
|
||
fail(payload.message || 'AI 服务暂时不可用');
|
||
} else if (payload.type === 'done') {
|
||
// done 是模型流的结束,不立即关连接;等待服务端的 stream_end。
|
||
// 文本内容交给 handleEvent 统一处理,这里只做标记。
|
||
receivedDone = true;
|
||
handleEvent(payload);
|
||
} else if (payload.type === 'stream_end') {
|
||
finished = true;
|
||
if (courseAiSocket === socket) courseAiSocket = null;
|
||
resolve(payload);
|
||
// 收到应用层结束事件后再发送标准 1000 close frame。
|
||
setTimeout(() => {
|
||
if (socket.readyState === WebSocket.OPEN) socket.close(1000, 'complete');
|
||
}, 120);
|
||
}
|
||
};
|
||
socket.onerror = () => {
|
||
// 底层错误随后会由 onclose 统一判断,避免同一次断开触发两次错误处理。
|
||
};
|
||
socket.onclose = () => {
|
||
if (finished || receivedDone || courseAiStopRequested) {
|
||
if (!finished) {
|
||
finished = true;
|
||
resolve({ type: 'stream_end', reason: courseAiStopRequested ? 'user_stop' : 'done' });
|
||
}
|
||
return;
|
||
}
|
||
fail('WebSocket 连接意外断开');
|
||
};
|
||
});
|
||
}
|
||
|
||
async function sendCourseAiMessage(text) {
|
||
const content = String(text || '').trim();
|
||
if (!content || courseAiSending) return;
|
||
if (!courseAiReady) {
|
||
courseAiAddMessage('assistant', 'AI 助手尚不可用,请让管理员在管理后台启用并配置 API Key。');
|
||
return;
|
||
}
|
||
courseAiAddMessage('user', content);
|
||
document.getElementById('courseAiInput').value = '';
|
||
courseAiSetSending(true);
|
||
courseAiStopRequested = false;
|
||
// 一条回答一个复合气泡:文字分段与工具卡片按发生顺序内嵌排列。
|
||
let reply = null;
|
||
let replyText = '';
|
||
const ensureReply = () => {
|
||
if (!reply) {
|
||
reply = courseAiCreateStreamingMessage();
|
||
courseAiActiveReply = reply;
|
||
}
|
||
return reply;
|
||
};
|
||
courseAiShowThinking(ensureReply(), '思考中…');
|
||
try {
|
||
const handleEvent = event => {
|
||
if (event.type === 'heartbeat') {
|
||
// 服务端保活帧不参与回答内容,也不改变“思考中”状态。
|
||
return;
|
||
} else if (event.type === 'text_delta') {
|
||
replyText += event.delta || '';
|
||
const bubble = ensureReply();
|
||
courseAiDismissThinking(bubble);
|
||
bubble._courseAiRawText = replyText;
|
||
courseAiAppendDelta(bubble, event.delta || '');
|
||
} else if (event.type === 'done' && event.message && !replyText) {
|
||
replyText = event.message;
|
||
const bubble = ensureReply();
|
||
courseAiDismissThinking(bubble);
|
||
bubble._courseAiRawText = replyText;
|
||
courseAiAppendDelta(bubble, replyText);
|
||
} else if (event.type === 'tool_started') {
|
||
const bubble = ensureReply();
|
||
courseAiDismissThinking(bubble);
|
||
// 工具卡片内嵌在当前文字之后;其后的文字另起一段继续。
|
||
bubble._courseAiSegment = null;
|
||
courseAiEnsureToolCard(bubble, event.id, event.name, event.arguments || '');
|
||
} else if (event.type === 'tool_finished') {
|
||
courseAiFinishToolCard(event.id, event.success, event.message, event.result || '');
|
||
} else if (event.type === 'confirmation_required') {
|
||
const bubble = ensureReply();
|
||
courseAiDismissThinking(bubble);
|
||
bubble._courseAiSegment = null;
|
||
courseAiAddConfirmation(bubble, event.id, event.name, event.summary || '', event.arguments || '');
|
||
} else if (event.type === 'ask_user') {
|
||
const bubble = ensureReply();
|
||
courseAiDismissThinking(bubble);
|
||
bubble._courseAiSegment = null;
|
||
courseAiAddAskCard(bubble, event.id, event.question || '', event.options || [], !!event.multiple);
|
||
} else if (event.type === 'cancelled') {
|
||
if (reply && !replyText && reply._courseAiThinkingEl) {
|
||
reply._courseAiThinkingEl.textContent = '已停止生成。';
|
||
reply._courseAiThinkingEl.style.animation = 'none';
|
||
}
|
||
} else if (event.type === 'error') {
|
||
throw new Error(event.message || '服务暂时不可用');
|
||
}
|
||
document.getElementById('courseAiMessages').scrollTop = document.getElementById('courseAiMessages').scrollHeight;
|
||
};
|
||
await courseAiSendOverWebSocket(content, handleEvent);
|
||
if (replyText) courseAiMessages.push({ role: 'assistant', content: replyText });
|
||
} catch (e) {
|
||
if (courseAiStopRequested) return;
|
||
// 已收到正常内容时,连接收尾错误不覆盖已有输出;否则把错误作为一段文字展示。
|
||
if (!replyText) {
|
||
const bubble = ensureReply();
|
||
courseAiDismissThinking(bubble);
|
||
courseAiAppendDelta(bubble, e && e.message ? `出错了:${e.message}` : '暂时没有返回内容,请稍后重试。');
|
||
}
|
||
} finally {
|
||
if (reply && replyText) {
|
||
// 收尾:复制按钮挂在气泡末尾,复制内容只含文字部分。
|
||
reply._courseAiRawContent = replyText;
|
||
courseAiAddCopyButton(reply);
|
||
}
|
||
courseAiSetSending(false);
|
||
courseAiActiveReply = null;
|
||
courseAiStopRequested = false;
|
||
}
|
||
}
|
||
|
||
document.addEventListener('DOMContentLoaded', () => {
|
||
loadCourseAiConversation();
|
||
loadCourseAiStatus();
|
||
document.getElementById('courseAiForm').addEventListener('submit', event => {
|
||
event.preventDefault();
|
||
sendCourseAiMessage(document.getElementById('courseAiInput').value);
|
||
});
|
||
document.getElementById('courseAiInput').addEventListener('keydown', event => {
|
||
if (event.key === 'Enter' && !event.shiftKey) {
|
||
event.preventDefault();
|
||
document.getElementById('courseAiForm').requestSubmit();
|
||
}
|
||
});
|
||
document.getElementById('courseAiInput').addEventListener('input', event => {
|
||
event.target.style.height = 'auto';
|
||
event.target.style.height = Math.min(event.target.scrollHeight, 112) + 'px';
|
||
});
|
||
document.getElementById('courseAiSuggestions').addEventListener('click', event => {
|
||
const button = event.target.closest('button[data-prompt]');
|
||
if (button) sendCourseAiMessage(button.dataset.prompt);
|
||
});
|
||
document.addEventListener('keydown', event => {
|
||
if (event.key === 'Escape' && document.getElementById('courseAiPanel').classList.contains('is-open')) toggleCourseAi(false);
|
||
});
|
||
});
|
||
</script>
|
||
{% endif %}
|
||
{% block extra_js %}{% endblock %}
|
||
</body>
|
||
</html>
|