|
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
|
|
<title>学生端门户 - 教育AI助手平台</title>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
|
|
<style>
|
|
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
|
|
|
:root {
|
|
|
|
--primary-color: #0f2d49;
|
|
--primary-light: #234a70;
|
|
--secondary-color: #4a6cfd;
|
|
--secondary-light: #7b91ff;
|
|
--tertiary-color: #f7f9fe;
|
|
--success-color: #10b981;
|
|
--success-light: rgba(16, 185, 129, 0.1);
|
|
--warning-color: #f59e0b;
|
|
--warning-light: rgba(245, 158, 11, 0.1);
|
|
--info-color: #0ea5e9;
|
|
--info-light: rgba(14, 165, 233, 0.1);
|
|
--danger-color: #ef4444;
|
|
--danger-light: rgba(239, 68, 68, 0.1);
|
|
--neutral-50: #f9fafb;
|
|
--neutral-100: #f3f4f6;
|
|
--neutral-200: #e5e7eb;
|
|
--neutral-300: #d1d5db;
|
|
--neutral-400: #9ca3af;
|
|
--neutral-500: #6b7280;
|
|
--neutral-600: #4b5563;
|
|
--neutral-700: #374151;
|
|
--neutral-800: #1f2937;
|
|
--neutral-900: #111827;
|
|
|
|
|
|
--border-radius-sm: 0.25rem;
|
|
--border-radius: 0.375rem;
|
|
--border-radius-lg: 0.5rem;
|
|
--border-radius-xl: 0.75rem;
|
|
--border-radius-2xl: 1rem;
|
|
--card-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.1);
|
|
--card-shadow-hover: 0 10px 20px rgba(0, 0, 0, 0.05), 0 6px 6px rgba(0, 0, 0, 0.1);
|
|
--card-shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
|
--transition-base: all 0.2s ease-in-out;
|
|
--transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
--font-family: 'Inter', 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', sans-serif;
|
|
}
|
|
|
|
|
|
body {
|
|
font-family: var(--font-family);
|
|
background-color: var(--neutral-50);
|
|
color: var(--neutral-800);
|
|
margin: 0;
|
|
padding: 0;
|
|
min-height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
-webkit-font-smoothing: antialiased;
|
|
-moz-osx-font-smoothing: grayscale;
|
|
}
|
|
|
|
h1, h2, h3, h4, h5, h6 {
|
|
font-weight: 600;
|
|
color: var(--neutral-900);
|
|
}
|
|
|
|
.text-gradient {
|
|
background: linear-gradient(135deg, var(--secondary-color), var(--secondary-light));
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
background-clip: text;
|
|
color: transparent;
|
|
}
|
|
|
|
|
|
::-webkit-scrollbar {
|
|
width: 6px;
|
|
height: 6px;
|
|
}
|
|
|
|
::-webkit-scrollbar-track {
|
|
background: var(--neutral-100);
|
|
border-radius: 10px;
|
|
}
|
|
|
|
::-webkit-scrollbar-thumb {
|
|
background: var(--neutral-300);
|
|
border-radius: 10px;
|
|
}
|
|
|
|
::-webkit-scrollbar-thumb:hover {
|
|
background: var(--neutral-400);
|
|
}
|
|
|
|
|
|
.header {
|
|
background-color: white;
|
|
border-bottom: 1px solid var(--neutral-200);
|
|
padding: 1rem 1.5rem;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 100;
|
|
}
|
|
|
|
.header-content {
|
|
max-width: 1400px;
|
|
margin: 0 auto;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
.header h1 {
|
|
margin: 0;
|
|
font-size: 1.5rem;
|
|
font-weight: 700;
|
|
background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
letter-spacing: -0.01em;
|
|
}
|
|
|
|
.user-info {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
}
|
|
|
|
.user-info .badge {
|
|
font-size: 0.85rem;
|
|
padding: 0.4rem 0.75rem;
|
|
border-radius: var(--border-radius-lg);
|
|
background: linear-gradient(to right, var(--secondary-color), var(--secondary-light));
|
|
color: white;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.user-info button {
|
|
color: var(--neutral-600);
|
|
text-decoration: none;
|
|
font-size: 0.9rem;
|
|
transition: var(--transition-base);
|
|
}
|
|
|
|
.user-info button:hover {
|
|
color: var(--secondary-color);
|
|
}
|
|
|
|
|
|
.main-container {
|
|
flex: 1;
|
|
max-width: 1400px;
|
|
margin: 2rem auto;
|
|
padding: 0 1.5rem;
|
|
width: 100%;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
|
|
.welcome-message {
|
|
background-color: white;
|
|
border-radius: var(--border-radius-xl);
|
|
box-shadow: var(--card-shadow);
|
|
padding: 2rem;
|
|
margin-bottom: 2.5rem;
|
|
position: relative;
|
|
overflow: hidden;
|
|
border: none;
|
|
transition: var(--transition-smooth);
|
|
}
|
|
|
|
.welcome-message:hover {
|
|
box-shadow: var(--card-shadow-hover);
|
|
transform: translateY(-3px);
|
|
}
|
|
|
|
.welcome-message::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
bottom: 0;
|
|
left: 0;
|
|
width: 4px;
|
|
background: linear-gradient(to bottom, var(--info-color), var(--secondary-light));
|
|
border-radius: 4px 0 0 4px;
|
|
}
|
|
|
|
.welcome-message h2 {
|
|
margin-top: 0;
|
|
margin-bottom: 1rem;
|
|
font-size: 1.6rem;
|
|
font-weight: 700;
|
|
color: var(--primary-color);
|
|
}
|
|
|
|
.welcome-message p {
|
|
color: var(--neutral-600);
|
|
margin-bottom: 0.75rem;
|
|
font-size: 0.95rem;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.welcome-message p:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
|
|
.token-input {
|
|
background-color: white;
|
|
border-radius: var(--border-radius-xl);
|
|
box-shadow: var(--card-shadow);
|
|
padding: 2rem;
|
|
margin-bottom: 2.5rem;
|
|
position: relative;
|
|
overflow: hidden;
|
|
transition: var(--transition-smooth);
|
|
}
|
|
|
|
.token-input:hover {
|
|
box-shadow: var(--card-shadow-hover);
|
|
transform: translateY(-3px);
|
|
}
|
|
|
|
.token-input::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
bottom: 0;
|
|
left: 0;
|
|
width: 4px;
|
|
background: linear-gradient(to bottom, var(--warning-color), var(--secondary-light));
|
|
border-radius: 4px 0 0 4px;
|
|
}
|
|
|
|
.token-input h3 {
|
|
margin-top: 0;
|
|
margin-bottom: 1rem;
|
|
font-size: 1.35rem;
|
|
font-weight: 600;
|
|
color: var(--neutral-900);
|
|
}
|
|
|
|
.token-input p {
|
|
color: var(--neutral-600);
|
|
margin-bottom: 1.25rem;
|
|
}
|
|
|
|
.token-input .input-group {
|
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
|
|
border-radius: var(--border-radius-lg);
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.token-input .form-control {
|
|
border-radius: var(--border-radius-lg) 0 0 var(--border-radius-lg);
|
|
border: 1px solid var(--neutral-200);
|
|
padding: 0.75rem 1rem;
|
|
font-size: 0.95rem;
|
|
}
|
|
|
|
.token-input .form-control:focus {
|
|
box-shadow: none;
|
|
border-color: var(--secondary-color);
|
|
}
|
|
|
|
.token-input .btn {
|
|
background: linear-gradient(to right, var(--secondary-color), var(--secondary-light));
|
|
color: white;
|
|
border: none;
|
|
border-radius: 0 var(--border-radius-lg) var(--border-radius-lg) 0;
|
|
padding: 0.75rem 1.25rem;
|
|
transition: var(--transition-base);
|
|
}
|
|
|
|
.token-input .btn:hover {
|
|
background: linear-gradient(to right, var(--secondary-light), var(--secondary-color));
|
|
box-shadow: 0 4px 10px rgba(74, 108, 253, 0.2);
|
|
}
|
|
|
|
|
|
.section-header {
|
|
margin-bottom: 1.5rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.section-header h2 {
|
|
margin: 0;
|
|
font-size: 1.5rem;
|
|
font-weight: 700;
|
|
color: var(--primary-color);
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.section-header p {
|
|
color: var(--neutral-600);
|
|
margin: 0;
|
|
font-size: 0.95rem;
|
|
}
|
|
|
|
|
|
.agent-card {
|
|
background-color: white;
|
|
border-radius: var(--border-radius-xl);
|
|
margin-bottom: 1.5rem;
|
|
box-shadow: var(--card-shadow);
|
|
overflow: hidden;
|
|
transition: var(--transition-smooth);
|
|
position: relative;
|
|
border: none;
|
|
}
|
|
|
|
.agent-card:hover {
|
|
transform: translateY(-5px);
|
|
box-shadow: var(--card-shadow-hover);
|
|
}
|
|
|
|
.agent-card::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
bottom: 0;
|
|
left: 0;
|
|
width: 4px;
|
|
background: linear-gradient(to bottom, var(--secondary-color), var(--secondary-light));
|
|
border-radius: 4px 0 0 4px;
|
|
}
|
|
|
|
.agent-card-header {
|
|
padding: 1.5rem;
|
|
background-color: rgba(74, 108, 253, 0.03);
|
|
border-bottom: 1px solid var(--neutral-100);
|
|
}
|
|
|
|
.agent-card-title {
|
|
margin: 0;
|
|
font-size: 1.25rem;
|
|
font-weight: 600;
|
|
color: var(--primary-color);
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.agent-card-title i {
|
|
margin-right: 0.75rem;
|
|
font-size: 1.2rem;
|
|
color: var(--secondary-color);
|
|
}
|
|
|
|
.agent-card-content {
|
|
padding: 1.5rem;
|
|
}
|
|
|
|
.agent-card-description {
|
|
margin-bottom: 1.25rem;
|
|
color: var(--neutral-700);
|
|
font-size: 0.95rem;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.agent-meta {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
margin-bottom: 1.25rem;
|
|
gap: 1.5rem;
|
|
}
|
|
|
|
.agent-meta-item {
|
|
display: flex;
|
|
align-items: center;
|
|
font-size: 0.9rem;
|
|
color: var(--neutral-600);
|
|
}
|
|
|
|
.agent-meta-item i {
|
|
margin-right: 0.5rem;
|
|
font-size: 0.95rem;
|
|
color: var(--secondary-color);
|
|
}
|
|
|
|
.agent-tags {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 0.5rem;
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
|
|
.agent-tag {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
padding: 0.35em 0.75em;
|
|
background-color: rgba(74, 108, 253, 0.1);
|
|
color: var(--secondary-color);
|
|
border-radius: 20px;
|
|
font-size: 0.85rem;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.agent-tag i {
|
|
margin-right: 0.4rem;
|
|
}
|
|
|
|
.agent-actions {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.agent-actions .btn {
|
|
padding: 0.65em 1.25em;
|
|
font-weight: 500;
|
|
background: linear-gradient(to right, var(--secondary-color), var(--secondary-light));
|
|
border: none;
|
|
color: white;
|
|
border-radius: var(--border-radius-lg);
|
|
transition: var(--transition-base);
|
|
}
|
|
|
|
.agent-actions .btn:hover {
|
|
background: linear-gradient(to right, var(--secondary-light), var(--secondary-color));
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 10px rgba(74, 108, 253, 0.2);
|
|
}
|
|
|
|
.agent-actions .btn i {
|
|
margin-right: 0.5rem;
|
|
}
|
|
|
|
|
|
.recent-activity {
|
|
background-color: white;
|
|
border-radius: var(--border-radius-xl);
|
|
box-shadow: var(--card-shadow);
|
|
padding: 1.5rem;
|
|
margin-bottom: 2rem;
|
|
position: relative;
|
|
overflow: hidden;
|
|
transition: var(--transition-smooth);
|
|
}
|
|
|
|
.recent-activity:hover {
|
|
box-shadow: var(--card-shadow-hover);
|
|
transform: translateY(-3px);
|
|
}
|
|
|
|
.recent-activity::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
bottom: 0;
|
|
left: 0;
|
|
width: 4px;
|
|
background: linear-gradient(to bottom, var(--success-color), var(--secondary-light));
|
|
border-radius: 4px 0 0 4px;
|
|
}
|
|
|
|
.recent-activity h3 {
|
|
margin-top: 0;
|
|
margin-bottom: 1.5rem;
|
|
font-size: 1.35rem;
|
|
font-weight: 600;
|
|
color: var(--neutral-900);
|
|
}
|
|
|
|
.activity-list {
|
|
list-style: none;
|
|
padding: 0;
|
|
margin: 0;
|
|
}
|
|
|
|
.activity-item {
|
|
display: flex;
|
|
padding: 1rem 0;
|
|
border-bottom: 1px solid var(--neutral-100);
|
|
align-items: center;
|
|
}
|
|
|
|
.activity-item:last-child {
|
|
border-bottom: none;
|
|
padding-bottom: 0;
|
|
}
|
|
|
|
.activity-icon {
|
|
width: 40px;
|
|
height: 40px;
|
|
border-radius: 50%;
|
|
background-color: rgba(74, 108, 253, 0.1);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin-right: 1rem;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.activity-icon i {
|
|
color: var(--secondary-color);
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.activity-content {
|
|
flex: 1;
|
|
}
|
|
|
|
.activity-title {
|
|
margin: 0;
|
|
margin-bottom: 0.35rem;
|
|
font-size: 0.95rem;
|
|
font-weight: 500;
|
|
color: var(--neutral-800);
|
|
}
|
|
|
|
.activity-time {
|
|
font-size: 0.85rem;
|
|
color: var(--neutral-500);
|
|
}
|
|
|
|
|
|
@keyframes fadeIn {
|
|
from { opacity: 0; transform: translateY(10px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
|
|
.fade-in {
|
|
opacity: 0;
|
|
animation: fadeIn 0.4s ease-out forwards;
|
|
}
|
|
|
|
.animate-delay-1 { animation-delay: 0.1s; }
|
|
.animate-delay-2 { animation-delay: 0.2s; }
|
|
.animate-delay-3 { animation-delay: 0.3s; }
|
|
.animate-delay-4 { animation-delay: 0.4s; }
|
|
.animate-delay-5 { animation-delay: 0.5s; }
|
|
|
|
|
|
@media (max-width: 992px) {
|
|
.main-container {
|
|
padding: 0 1rem;
|
|
}
|
|
|
|
.agent-meta {
|
|
flex-direction: column;
|
|
gap: 0.75rem;
|
|
}
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.header h1 {
|
|
font-size: 1.25rem;
|
|
}
|
|
|
|
.welcome-message h2 {
|
|
font-size: 1.35rem;
|
|
}
|
|
|
|
.agent-card-title {
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.section-header h2 {
|
|
font-size: 1.3rem;
|
|
}
|
|
|
|
.recent-activity h3,
|
|
.token-input h3 {
|
|
font-size: 1.2rem;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<header class="header">
|
|
<div class="header-content">
|
|
<h1>教育AI助手平台 - 学生端</h1>
|
|
<div class="user-info">
|
|
<span class="badge" id="user-name">张三</span>
|
|
<button class="btn btn-sm btn-link text-decoration-none" id="logout-btn">登出</button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="main-container">
|
|
<div class="welcome-message fade-in">
|
|
<h2>欢迎回来,<span id="welcome-name">张三</span>!</h2>
|
|
<p>教育AI助手平台为您提供智能学习辅助工具,帮助您更高效地学习和解决问题。</p>
|
|
<p>下方是您的教师分享给您的AI助手,点击"开始对话"与它们互动。</p>
|
|
</div>
|
|
|
|
<div class="token-input fade-in animate-delay-1">
|
|
<h3>访问新的AI助手</h3>
|
|
<p>输入教师分享的访问令牌,即可使用新的AI助手。</p>
|
|
<div class="input-group">
|
|
<input type="text" class="form-control" id="access-token" placeholder="输入访问令牌">
|
|
<button class="btn" id="access-button">
|
|
<i class="bi bi-arrow-right-circle me-1"></i> 访问
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="section-header fade-in animate-delay-2">
|
|
<h2>我的AI助手</h2>
|
|
<p>教师分享给您的智能学习助手</p>
|
|
</div>
|
|
|
|
<div class="row" id="agents-container">
|
|
|
|
</div>
|
|
|
|
<div class="recent-activity fade-in animate-delay-4">
|
|
<h3>最近活动</h3>
|
|
<ul class="activity-list" id="activity-list">
|
|
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
|
|
const userNameElement = document.getElementById('user-name');
|
|
const welcomeNameElement = document.getElementById('welcome-name');
|
|
const logoutBtn = document.getElementById('logout-btn');
|
|
const accessButton = document.getElementById('access-button');
|
|
const agentsContainer = document.getElementById('agents-container');
|
|
const activityList = document.getElementById('activity-list');
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
checkAuthStatus();
|
|
|
|
|
|
loadAgents();
|
|
|
|
|
|
logoutBtn.addEventListener('click', logout);
|
|
|
|
|
|
accessButton.addEventListener('click', accessWithToken);
|
|
});
|
|
|
|
|
|
async function checkAuthStatus() {
|
|
try {
|
|
const response = await fetch('/api/auth/check');
|
|
const data = await response.json();
|
|
|
|
if (!data.success) {
|
|
|
|
window.location.href = '/login.html';
|
|
return;
|
|
}
|
|
|
|
|
|
userNameElement.textContent = data.user.name;
|
|
welcomeNameElement.textContent = data.user.name;
|
|
|
|
|
|
if (data.user.type !== 'student') {
|
|
window.location.href = '/index.html';
|
|
}
|
|
} catch (error) {
|
|
console.error('验证登录状态出错:', error);
|
|
window.location.href = '/login.html';
|
|
}
|
|
}
|
|
|
|
|
|
async function logout() {
|
|
try {
|
|
const response = await fetch('/api/auth/logout', {
|
|
method: 'POST'
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
window.location.href = '/login.html';
|
|
}
|
|
} catch (error) {
|
|
console.error('登出出错:', error);
|
|
alert('登出失败,请重试');
|
|
}
|
|
}
|
|
|
|
|
|
async function loadAgents() {
|
|
try {
|
|
|
|
agentsContainer.innerHTML = `
|
|
<div class="col-12 text-center py-4">
|
|
<div class="spinner-border text-primary" role="status">
|
|
<span class="visually-hidden">加载中...</span>
|
|
</div>
|
|
<p class="mt-3">正在加载AI助手列表...</p>
|
|
</div>
|
|
`;
|
|
|
|
|
|
const response = await fetch('/api/student/agents');
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
const agents = result.agents || [];
|
|
|
|
if (agents.length === 0) {
|
|
agentsContainer.innerHTML = `
|
|
<div class="col-12">
|
|
<div class="alert alert-info">
|
|
<i class="bi bi-info-circle me-2"></i>
|
|
您还没有可用的AI助手。请向您的教师获取访问令牌。
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
|
|
activityList.innerHTML = `
|
|
<li class="text-center py-3 text-muted">
|
|
暂无活动记录
|
|
</li>
|
|
`;
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
agentsContainer.innerHTML = '';
|
|
|
|
agents.forEach(agent => {
|
|
const col = document.createElement('div');
|
|
col.className = 'col-lg-6 col-12 fade-in';
|
|
|
|
|
|
let lastUsedText = '从未使用';
|
|
if (agent.last_used) {
|
|
const lastUsedDate = new Date(agent.last_used * 1000);
|
|
lastUsedText = lastUsedDate.toLocaleString();
|
|
}
|
|
|
|
|
|
let pluginsHtml = '';
|
|
if (agent.plugins && agent.plugins.length > 0) {
|
|
pluginsHtml = '<div class="agent-tags">';
|
|
|
|
agent.plugins.forEach(plugin => {
|
|
let pluginName = '未知插件';
|
|
let pluginIcon = 'puzzle';
|
|
|
|
if (plugin === 'code') {
|
|
pluginName = '代码执行';
|
|
pluginIcon = 'code-square';
|
|
} else if (plugin === 'visualization') {
|
|
pluginName = '3D可视化';
|
|
pluginIcon = 'bar-chart';
|
|
} else if (plugin === 'mindmap') {
|
|
pluginName = '思维导图';
|
|
pluginIcon = 'diagram-3';
|
|
}
|
|
|
|
pluginsHtml += `
|
|
<span class="agent-tag">
|
|
<i class="bi bi-${pluginIcon}"></i> ${pluginName}
|
|
</span>
|
|
`;
|
|
});
|
|
|
|
pluginsHtml += '</div>';
|
|
}
|
|
|
|
|
|
let metaHtml = '<div class="agent-meta">';
|
|
|
|
if (agent.subject) {
|
|
metaHtml += `
|
|
<div class="agent-meta-item">
|
|
<i class="bi bi-book"></i> ${agent.subject}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
if (agent.instructor) {
|
|
metaHtml += `
|
|
<div class="agent-meta-item">
|
|
<i class="bi bi-person"></i> ${agent.instructor}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
metaHtml += `
|
|
<div class="agent-meta-item">
|
|
<i class="bi bi-clock"></i> 最后使用: ${lastUsedText}
|
|
</div>
|
|
</div>`;
|
|
|
|
|
|
col.innerHTML = `
|
|
<div class="agent-card">
|
|
<div class="agent-card-header">
|
|
<h3 class="agent-card-title">
|
|
<i class="bi bi-robot"></i> ${agent.name}
|
|
</h3>
|
|
</div>
|
|
<div class="agent-card-content">
|
|
<div class="agent-card-description">
|
|
${agent.description || '暂无描述'}
|
|
</div>
|
|
${metaHtml}
|
|
${pluginsHtml}
|
|
<div class="agent-actions">
|
|
<a href="/student/${agent.id}?token=${agent.token}" class="btn">
|
|
<i class="bi bi-chat-dots me-1"></i> 开始对话
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
agentsContainer.appendChild(col);
|
|
});
|
|
|
|
|
|
loadActivityRecords();
|
|
} else {
|
|
agentsContainer.innerHTML = `
|
|
<div class="col-12">
|
|
<div class="alert alert-danger">
|
|
<i class="bi bi-exclamation-triangle me-2"></i>
|
|
加载Agent列表失败: ${result.message}
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
|
|
activityList.innerHTML = `
|
|
<li class="text-center py-3 text-muted">
|
|
暂无活动记录
|
|
</li>
|
|
`;
|
|
}
|
|
} catch (error) {
|
|
console.error('加载Agent列表出错:', error);
|
|
agentsContainer.innerHTML = `
|
|
<div class="col-12">
|
|
<div class="alert alert-danger">
|
|
<i class="bi bi-exclamation-triangle me-2"></i>
|
|
加载Agent列表时发生错误,请刷新页面重试
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function loadActivityRecords() {
|
|
try {
|
|
|
|
const response = await fetch('/api/student/activities');
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
const activities = result.activities || [];
|
|
|
|
if (activities.length === 0) {
|
|
activityList.innerHTML = `
|
|
<li class="text-center py-3 text-muted">
|
|
暂无活动记录
|
|
</li>
|
|
`;
|
|
return;
|
|
}
|
|
|
|
|
|
activityList.innerHTML = '';
|
|
|
|
activities.forEach(activity => {
|
|
let iconClass = 'bi-activity';
|
|
|
|
switch (activity.type) {
|
|
case 'chat':
|
|
iconClass = 'bi-chat-dots';
|
|
break;
|
|
case 'code':
|
|
iconClass = 'bi-code-square';
|
|
break;
|
|
case 'viz':
|
|
iconClass = 'bi-bar-chart';
|
|
break;
|
|
case 'mindmap':
|
|
iconClass = 'bi-diagram-3';
|
|
break;
|
|
}
|
|
|
|
const li = document.createElement('li');
|
|
li.className = 'activity-item';
|
|
|
|
|
|
let titleHtml = `<h4 class="activity-title">${activity.title}</h4>`;
|
|
if (activity.agent_id) {
|
|
|
|
const agent = agents.find(a => a.id === activity.agent_id);
|
|
if (agent && agent.token) {
|
|
titleHtml = `
|
|
<h4 class="activity-title">
|
|
<a href="/student/${activity.agent_id}?token=${agent.token}">${activity.title}</a>
|
|
</h4>
|
|
`;
|
|
}
|
|
}
|
|
|
|
li.innerHTML = `
|
|
<div class="activity-icon">
|
|
<i class="bi ${iconClass}"></i>
|
|
</div>
|
|
<div class="activity-content">
|
|
${titleHtml}
|
|
<div class="activity-time">${activity.time}</div>
|
|
</div>
|
|
`;
|
|
|
|
activityList.appendChild(li);
|
|
});
|
|
} else {
|
|
activityList.innerHTML = `
|
|
<li class="text-center py-3 text-muted">
|
|
<i class="bi bi-exclamation-circle me-2"></i>
|
|
无法加载活动记录
|
|
</li>
|
|
`;
|
|
}
|
|
} catch (error) {
|
|
console.error('加载活动记录出错:', error);
|
|
activityList.innerHTML = `
|
|
<li class="text-center py-3 text-muted">
|
|
<i class="bi bi-exclamation-circle me-2"></i>
|
|
加载活动记录时出错
|
|
</li>
|
|
`;
|
|
}
|
|
}
|
|
|
|
async function accessWithToken() {
|
|
const token = document.getElementById('access-token').value.trim();
|
|
|
|
if (!token) {
|
|
showMessage('请输入访问令牌', 'warning');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
|
|
const response = await fetch('/api/verify_token', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ token })
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
|
|
const agent = result.agent;
|
|
window.location.href = `/student/${agent.id}?token=${token}`;
|
|
} else {
|
|
showMessage(result.message || '无效的访问令牌', 'danger');
|
|
}
|
|
} catch (error) {
|
|
console.error('验证令牌出错:', error);
|
|
showMessage('验证令牌时发生错误,请重试', 'danger');
|
|
}
|
|
}
|
|
|
|
|
|
function showMessage(message, type) {
|
|
|
|
const existingAlert = document.querySelector('.token-input .alert');
|
|
if (existingAlert) {
|
|
existingAlert.remove();
|
|
}
|
|
|
|
|
|
const alertDiv = document.createElement('div');
|
|
alertDiv.className = `alert alert-${type} mt-3`;
|
|
alertDiv.innerHTML = `
|
|
<i class="bi ${type === 'danger' ? 'bi-exclamation-triangle' : 'bi-info-circle'} me-2"></i>
|
|
${message}
|
|
`;
|
|
|
|
|
|
document.querySelector('.token-input .input-group').insertAdjacentElement('afterend', alertDiv);
|
|
|
|
|
|
setTimeout(() => {
|
|
alertDiv.style.opacity = '0';
|
|
setTimeout(() => alertDiv.remove(), 300);
|
|
}, 3000);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |