Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c439842bb2 | |||
| d4b1f3dfff | |||
| dc2e822ea9 | |||
| 53db607b8d | |||
| c346418d68 | |||
| 7de13ffc6d | |||
| 60db170c0d | |||
| 336e3cd12f | |||
| f0d9ca09aa | |||
| 36801e9266 | |||
| 5acd9f08f1 | |||
| 31732a6303 | |||
| 7f576827b0 | |||
| 8287be10ea | |||
| a56bad11f1 | |||
| 92c187d576 | |||
| 9eeeace88c | |||
| ba5d49005b | |||
| c71f27072a | |||
| 22a109d6c0 | |||
| 0244715a8a | |||
| 1c3f7604c9 | |||
| 0086eaa1d6 | |||
| 8e17ef5e15 | |||
| 773fb89b01 | |||
| 8199773ef6 | |||
| d153986f3d | |||
| e9357577cb | |||
| 24ba04b3e3 | |||
| d1ddd340c0 | |||
| 6ab58cb363 | |||
| ba8d0ae679 | |||
| 52d98e88c6 | |||
| 25dff98583 | |||
| 6452e4c976 | |||
| f85991064f | |||
| c725aeb192 | |||
| 423f3aa717 | |||
| 2f60e30169 | |||
| 4442d5056a | |||
| 3411de1612 | |||
| f24cefb2ab |
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
.Python
|
||||
*.so
|
||||
*.egg-info/
|
||||
dist/
|
||||
build/
|
||||
*.db
|
||||
data.db
|
||||
node_modules/
|
||||
1011
backend/app.py
Normal file
1011
backend/app.py
Normal file
File diff suppressed because it is too large
Load Diff
2
backend/requirements.txt
Normal file
2
backend/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
flask>=2.0.0
|
||||
flask-cors>=3.0.0
|
||||
4
backend/start.sh
Executable file
4
backend/start.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
cd "$(dirname "$0")"
|
||||
pip install -r requirements.txt -q
|
||||
python app.py
|
||||
482
www/admin.html
Normal file
482
www/admin.html
Normal file
@@ -0,0 +1,482 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>AI助手 - 后台管理</title>
|
||||
<link rel="stylesheet" href="admin.css?v=3.6.6">
|
||||
<style>
|
||||
:root {
|
||||
--primary: #667eea;
|
||||
--primary-dark: #5a67d8;
|
||||
--bg-color: #f5f7fa;
|
||||
--card-bg: #ffffff;
|
||||
--text-color: #2d3748;
|
||||
--text-light: #718096;
|
||||
--border-color: #e2e8f0;
|
||||
--danger: #e53e3e;
|
||||
--success: #22c55e;
|
||||
--warning: #f59e0b;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: var(--bg-color);
|
||||
color: var(--text-color);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* 登录页面 */
|
||||
.login-page {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
|
||||
}
|
||||
|
||||
.login-card {
|
||||
background: white;
|
||||
padding: 40px;
|
||||
border-radius: 16px;
|
||||
width: 350px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.login-logo {
|
||||
font-size: 48px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.login-title {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.login-input {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
border: 2px solid var(--border-color);
|
||||
border-radius: 10px;
|
||||
font-size: 16px;
|
||||
margin-bottom: 16px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.login-input:focus {
|
||||
border-color: var(--primary);
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.login-btn:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* 主页面 */
|
||||
.admin-page {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16px 24px;
|
||||
background: white;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.admin-logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.admin-logo span {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.admin-header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.admin-logout {
|
||||
padding: 8px 16px;
|
||||
background: var(--danger);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* 侧边栏 */
|
||||
.admin-container {
|
||||
display: flex;
|
||||
height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.admin-sidebar {
|
||||
width: 220px;
|
||||
background: white;
|
||||
border-right: 1px solid var(--border-color);
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.sidebar-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.sidebar-item:hover {
|
||||
background: rgba(102, 126, 234, 0.1);
|
||||
}
|
||||
|
||||
.sidebar-item.active {
|
||||
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.sidebar-icon {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
/* 内容区 */
|
||||
.admin-content {
|
||||
flex: 1;
|
||||
padding: 24px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.content-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.content-title {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
padding: 10px 20px;
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* 数据卡片 */
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 16px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
font-size: 32px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 14px;
|
||||
color: var(--text-light);
|
||||
}
|
||||
|
||||
/* 数据表格 */
|
||||
.data-table {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.data-table table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.data-table th, .data-table td {
|
||||
padding: 14px 16px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.data-table th {
|
||||
background: var(--bg-color);
|
||||
font-weight: 600;
|
||||
color: var(--text-light);
|
||||
}
|
||||
|
||||
.data-table tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.data-table tr:hover td {
|
||||
background: rgba(102, 126, 234, 0.05);
|
||||
}
|
||||
|
||||
/* 操作按钮 */
|
||||
.action-btns {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.action-btn.edit {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-btn.delete {
|
||||
background: var(--danger);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-btn.default {
|
||||
background: var(--success);
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* 默认标记 */
|
||||
.default-badge {
|
||||
padding: 4px 8px;
|
||||
background: var(--success);
|
||||
color: white;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* 模态框 */
|
||||
.modal {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0,0,0,0.5);
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal.show {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: white;
|
||||
padding: 24px;
|
||||
border-radius: 16px;
|
||||
max-width: 500px;
|
||||
width: 90%;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
color: var(--text-light);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.form-input, .form-select, .form-textarea {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.form-input:focus, .form-select:focus, .form-textarea:focus {
|
||||
border-color: var(--primary);
|
||||
}
|
||||
|
||||
.form-textarea {
|
||||
resize: vertical;
|
||||
min-height: 100px;
|
||||
}
|
||||
|
||||
.form-submit {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
/* Toast */
|
||||
.toast {
|
||||
position: fixed;
|
||||
top: 80px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: var(--text-color);
|
||||
color: white;
|
||||
padding: 12px 24px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s;
|
||||
z-index: 2000;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
opacity: 1;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 登录页面 -->
|
||||
<div class="login-page" id="loginPage">
|
||||
<div class="login-card">
|
||||
<div class="login-logo">🤖</div>
|
||||
<h1 class="login-title">后台管理系统</h1>
|
||||
<input type="text" class="login-input" id="loginUsername" placeholder="用户名">
|
||||
<input type="password" class="login-input" id="loginPassword" placeholder="密码">
|
||||
<button class="login-btn" id="loginBtn">登录</button>
|
||||
<p style="margin-top: 16px; color: #999; font-size: 12px;">默认: admin / admin123</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 管理页面 -->
|
||||
<div class="admin-page" id="adminPage">
|
||||
<header class="admin-header">
|
||||
<div class="admin-logo">
|
||||
<span>🤖</span>
|
||||
AI助手 - 后台管理
|
||||
</div>
|
||||
<div class="admin-header-right">
|
||||
<span id="adminName">管理员</span>
|
||||
<button class="admin-logout" id="logoutBtn">退出</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="admin-container">
|
||||
<aside class="admin-sidebar">
|
||||
<div class="sidebar-item active" data-page="stats">
|
||||
<span class="sidebar-icon">📊</span>
|
||||
<span>统计信息</span>
|
||||
</div>
|
||||
<div class="sidebar-item" data-page="users">
|
||||
<span class="sidebar-icon">👥</span>
|
||||
<span>用户管理</span>
|
||||
</div>
|
||||
<div class="sidebar-item" data-page="llm">
|
||||
<span class="sidebar-icon">🧠</span>
|
||||
<span>大模型配置</span>
|
||||
</div>
|
||||
<div class="sidebar-item" data-page="agents">
|
||||
<span class="sidebar-icon">🤖</span>
|
||||
<span>智能体管理</span>
|
||||
</div>
|
||||
<div class="sidebar-item" data-page="chat">
|
||||
<span class="sidebar-icon">💬</span>
|
||||
<span>对话配置</span>
|
||||
</div>
|
||||
<div class="sidebar-item" data-page="tools">
|
||||
<span class="sidebar-icon">🔧</span>
|
||||
<span>工具配置</span>
|
||||
</div>
|
||||
<div class="sidebar-item" data-page="system">
|
||||
<span class="sidebar-icon">⚙️</span>
|
||||
<span>系统设置</span>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<main class="admin-content" id="mainContent">
|
||||
<!-- 内容区动态加载 -->
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Toast -->
|
||||
<div class="toast" id="toast"></div>
|
||||
|
||||
<!-- 模态框 -->
|
||||
<div class="modal" id="modal">
|
||||
<div class="modal-content" id="modalContent">
|
||||
<!-- 动态内容 -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="admin.js?v=3.6.6"></script>
|
||||
</body>
|
||||
</html>
|
||||
1342
www/admin.js
Normal file
1342
www/admin.js
Normal file
File diff suppressed because it is too large
Load Diff
384
www/app.js
384
www/app.js
@@ -19,39 +19,18 @@ let isLoading = false;
|
||||
// 当前页面状态
|
||||
let currentPage = 'chats'; // chats | agents | profile
|
||||
|
||||
// 系统智能体数据(完整列表)
|
||||
let systemAgents = [
|
||||
// 热门智能体
|
||||
{ id: 'assistant', name: '通用助手', avatar: '🤖', category: 'hot', desc: '能回答各类问题,帮助写作、分析、解答疑惑', systemPrompt: '你是一个智能助手,能够回答各类问题,帮助用户解决问题。', heat: 9500 },
|
||||
{ id: 'writer', name: '写作助手', avatar: '✍️', category: 'hot', desc: '专注于文章写作、文案创作、内容润色', systemPrompt: '你是一个专业的写作助手,擅长各类文章写作、文案创作和内容润色。', heat: 8800 },
|
||||
{ id: 'coder', name: '编程助手', avatar: '👨💻', category: 'hot', desc: '精通编程语言,解答技术问题,生成代码', systemPrompt: '你是一个专业的编程助手,精通各类编程语言,能够解答技术问题并生成高质量代码。', heat: 8500 },
|
||||
{ id: 'translator', name: '翻译助手', avatar: '🌐', category: 'hot', desc: '多语言翻译,精准表达,文化适配', systemPrompt: '你是一个专业的翻译助手,精通多语言翻译,能够精准表达并适配文化差异。', heat: 7200 },
|
||||
|
||||
// 工作助手
|
||||
{ id: 'assistant-work', name: '工作助手', avatar: '💼', category: 'work', desc: '职场问题解答,工作效率提升', systemPrompt: '你是一个工作助手,帮助解决职场问题,提升工作效率。', heat: 5000 },
|
||||
{ id: 'ppt', name: 'PPT助手', avatar: '📊', category: 'work', desc: 'PPT内容生成,结构优化,设计建议', systemPrompt: '你是一个PPT助手,擅长PPT内容生成、结构优化和设计建议。', heat: 4500 },
|
||||
{ id: 'excel', name: 'Excel助手', avatar: '📈', category: 'work', desc: 'Excel公式、数据分析、表格优化', systemPrompt: '你是一个Excel助手,精通Excel公式、数据分析和表格优化。', heat: 4000 },
|
||||
|
||||
// 学习助手
|
||||
{ id: 'teacher', name: '学习助手', avatar: '📚', category: 'study', desc: '知识讲解,学习方法,考试辅导', systemPrompt: '你是一个学习助手,擅长知识讲解、学习方法指导和考试辅导。', heat: 5500 },
|
||||
{ id: 'english', name: '英语助手', avatar: '🔤', category: 'study', desc: '英语学习,语法纠正,口语练习', systemPrompt: '你是一个英语助手,帮助英语学习、语法纠正和口语练习。', heat: 5000 },
|
||||
{ id: 'math', name: '数学助手', avatar: '🔢', category: 'study', desc: '数学解题,公式推导,概念讲解', systemPrompt: '你是一个数学助手,擅长数学解题、公式推导和概念讲解。', heat: 4500 },
|
||||
|
||||
// 生活助手
|
||||
{ id: 'health', name: '健康助手', avatar: '🏥', category: 'life', desc: '健康咨询,养生建议,运动指导', systemPrompt: '你是一个健康助手,提供健康咨询、养生建议和运动指导。', heat: 3500 },
|
||||
{ id: 'travel', name: '旅行助手', avatar: '✈️', category: 'life', desc: '旅行规划,景点推荐,美食指南', systemPrompt: '你是一个旅行助手,擅长旅行规划、景点推荐和美食指南。', heat: 3200 },
|
||||
{ id: 'food', name: '美食助手', avatar: '🍳', category: 'life', desc: '菜谱推荐,烹饪技巧,营养搭配', systemPrompt: '你是一个美食助手,提供菜谱推荐、烹饪技巧和营养搭配建议。', heat: 3000 },
|
||||
];
|
||||
// 系统智能体数据(从后台API加载)
|
||||
let systemAgents = [];
|
||||
|
||||
// 用户智能体界面显示的智能体(默认显示热门智能体)
|
||||
// 用户智能体界面显示的智能体
|
||||
let agents = [];
|
||||
|
||||
// 用户添加的智能体(按类别分组)
|
||||
let myAgents = {
|
||||
hot: ['assistant', 'writer', 'coder', 'translator'],
|
||||
work: ['assistant-work', 'ppt', 'excel'],
|
||||
study: ['teacher', 'english', 'math'],
|
||||
life: ['health', 'travel', 'food']
|
||||
basic: [],
|
||||
work: [],
|
||||
study: [],
|
||||
life: []
|
||||
};
|
||||
|
||||
// 收藏的智能体列表
|
||||
@@ -59,7 +38,7 @@ let favoriteAgents = [];
|
||||
|
||||
// 置顶的智能体列表(按类别)
|
||||
let pinnedAgents = {
|
||||
hot: [],
|
||||
basic: [],
|
||||
work: [],
|
||||
study: [],
|
||||
life: []
|
||||
@@ -67,6 +46,9 @@ let pinnedAgents = {
|
||||
|
||||
let currentAgent = null; // 当前选中的智能体
|
||||
|
||||
// 后台配置
|
||||
let backendConfig = null; // 从API获取的配置
|
||||
|
||||
// 用户状态
|
||||
let currentUser = null; // 当前登录用户 { username, password, registeredAt }
|
||||
|
||||
@@ -79,12 +61,12 @@ let dailyUsage = {
|
||||
agentMessages: 0 // 智能体消息数
|
||||
};
|
||||
|
||||
// 未登录用户限制
|
||||
const GUEST_LIMITS = {
|
||||
maxChatSessionsPerDay: 1, // 每天最多1个对话会话
|
||||
maxChatMessagesPerDay: 20, // 每天最多20条对话消息
|
||||
maxAgentPerDay: 1, // 每天只能用1个智能体(通用助手)
|
||||
maxAgentMessagesPerDay: 20 // 每天最多20条智能体消息
|
||||
// 未登录用户限制(从后台配置加载)
|
||||
let GUEST_LIMITS = {
|
||||
maxChatSessionsPerDay: 1,
|
||||
maxChatMessagesPerDay: 20,
|
||||
maxAgentPerDay: 1,
|
||||
maxAgentMessagesPerDay: 20
|
||||
};
|
||||
|
||||
// 获取今日日期字符串
|
||||
@@ -93,6 +75,66 @@ function getTodayDate() {
|
||||
return `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
// 从后台API加载配置
|
||||
async function loadBackendConfig() {
|
||||
try {
|
||||
// 使用相对路径,自动适当前域名
|
||||
const API_BASE = window.location.origin;
|
||||
const res = await fetch(`${API_BASE}/api/config`);
|
||||
backendConfig = await res.json();
|
||||
|
||||
// 加载智能体列表
|
||||
if (backendConfig.agents) {
|
||||
systemAgents = backendConfig.agents.map(a => ({
|
||||
id: a.agent_id,
|
||||
name: a.name,
|
||||
avatar: a.avatar,
|
||||
category: a.category,
|
||||
desc: a.description,
|
||||
systemPrompt: a.system_prompt,
|
||||
heat: a.heat || 0,
|
||||
tags: a.tags || '',
|
||||
enable_tools: a.enable_tools || ''
|
||||
}));
|
||||
|
||||
// 初始化用户智能体列表(按类别)
|
||||
systemAgents.forEach(agent => {
|
||||
if (!myAgents[agent.category]) {
|
||||
myAgents[agent.category] = [];
|
||||
}
|
||||
myAgents[agent.category].push(agent.id);
|
||||
});
|
||||
}
|
||||
|
||||
// 加载游客限制配置
|
||||
if (backendConfig.system?.guestLimits) {
|
||||
GUEST_LIMITS = {
|
||||
maxChatSessionsPerDay: backendConfig.system.guestLimits.chatSessions || 1,
|
||||
maxChatMessagesPerDay: backendConfig.system.guestLimits.chatMessages || 20,
|
||||
maxAgentPerDay: 1, // 游客只能用通用助手
|
||||
maxAgentMessagesPerDay: backendConfig.system.guestLimits.agentMessages || 20
|
||||
};
|
||||
}
|
||||
|
||||
// 加载LLM能力配置(思考模式、视觉能力)
|
||||
if (backendConfig.llm) {
|
||||
llmCapabilities.thinking = backendConfig.llm.enable_thinking === 1;
|
||||
llmCapabilities.vision = backendConfig.llm.enable_vision === 1;
|
||||
console.log('LLM能力: 思考模式=', llmCapabilities.thinking, '视觉=', llmCapabilities.vision);
|
||||
}
|
||||
|
||||
updateAgentsDisplay();
|
||||
console.log('后台配置已加载', backendConfig);
|
||||
} catch (e) {
|
||||
console.error('加载后台配置失败', e);
|
||||
// 使用默认配置
|
||||
systemAgents = [
|
||||
{ id: 'assistant', name: '通用助手', avatar: '🤖', category: 'basic', desc: '能回答各类问题,帮助写作、分析、解答疑惑', systemPrompt: '你是一个智能助手,能够回答各类问题,帮助用户解决问题。', heat: 9500, tags: 'hot' },
|
||||
];
|
||||
updateAgentsDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
// 检查并重置每日使用统计
|
||||
function checkDailyUsage() {
|
||||
const today = getTodayDate();
|
||||
@@ -228,9 +270,10 @@ function getRemainingQuota() {
|
||||
}
|
||||
|
||||
// 获取使用智能体的对话列表(按时间倒序)
|
||||
// 只返回真正有对话消息的记录(messages.length > 0)
|
||||
function getAgentConversationHistory(limit = 5) {
|
||||
return conversations
|
||||
.filter(conv => conv.agentId) // 筛选有智能体的对话
|
||||
.filter(conv => conv.agentId && conv.messages && conv.messages.length > 0) // 筛选有智能体且有消息的对话
|
||||
.sort((a, b) => b.updatedAt - a.updatedAt) // 按更新时间倒序
|
||||
.slice(0, limit)
|
||||
.map(conv => {
|
||||
@@ -247,6 +290,12 @@ let enableThinking = false; // 深度思考
|
||||
let enableSearch = false; // 联网搜索
|
||||
let autoScrollEnabled = true; // 自动滚动(用户滚动后可关闭)
|
||||
|
||||
// LLM 能力标志(从后台配置加载)
|
||||
let llmCapabilities = {
|
||||
thinking: false, // 是否支持思考模式
|
||||
vision: false // 是否支持视觉能力
|
||||
};
|
||||
|
||||
// DOM 元素(初始为 null,在 openConversation 时重新获取)
|
||||
let appContainer = null;
|
||||
let messagesContainer = null;
|
||||
@@ -321,7 +370,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
checkDailyUsage();
|
||||
|
||||
// 根据用户配置更新显示的智能体
|
||||
updateAgentsDisplay();
|
||||
// updateAgentsDisplay(); // 先不调用,等后台配置加载后再更新
|
||||
|
||||
// 加载当前页面状态
|
||||
const savedPage = localStorage.getItem('currentPage');
|
||||
@@ -329,8 +378,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
currentPage = savedPage;
|
||||
}
|
||||
|
||||
// 显示主页
|
||||
showMainPage();
|
||||
// 加载后台配置并显示主页
|
||||
loadBackendConfig().then(() => {
|
||||
showMainPage();
|
||||
}).catch(() => {
|
||||
// 即使加载失败也显示主页
|
||||
showMainPage();
|
||||
});
|
||||
});
|
||||
|
||||
// 根据用户配置更新显示的智能体
|
||||
@@ -429,16 +483,21 @@ function switchPage(page) {
|
||||
currentPage = page;
|
||||
localStorage.setItem('currentPage', page);
|
||||
|
||||
// 先确保页面结构正确(如果当前不在主页结构)
|
||||
const mainContent = document.getElementById('mainContent');
|
||||
if (!mainContent) {
|
||||
// 重新渲染主页结构
|
||||
showMainPage();
|
||||
return; // showMainPage 会自动调用 renderCurrentPage
|
||||
}
|
||||
|
||||
// 更新导航栏状态
|
||||
document.querySelectorAll('.nav-item').forEach(item => {
|
||||
item.classList.toggle('active', item.getAttribute('data-page') === page);
|
||||
});
|
||||
|
||||
// 更新内容区
|
||||
const mainContent = document.getElementById('mainContent');
|
||||
if (mainContent) {
|
||||
mainContent.innerHTML = renderCurrentPage();
|
||||
}
|
||||
mainContent.innerHTML = renderCurrentPage();
|
||||
|
||||
// 绑定页面事件
|
||||
bindPageEvents();
|
||||
@@ -639,8 +698,11 @@ function bindChatsPageEvents() {
|
||||
// ==================== 智能体页面 ====================
|
||||
|
||||
function renderAgentsPage() {
|
||||
// 根据用户配置筛选智能体
|
||||
const hotAgents = agents.filter(a => a.category === 'hot');
|
||||
// 根据后台配置筛选智能体
|
||||
// 热门智能体 = 标签中包含 "hot"
|
||||
const hotAgents = agents.filter(a => a.tags && a.tags.split(',').includes('hot'));
|
||||
// 其他类别 = 根据 category 字段分类
|
||||
const basicAgents = agents.filter(a => a.category === 'basic');
|
||||
const workAgents = agents.filter(a => a.category === 'work');
|
||||
const studyAgents = agents.filter(a => a.category === 'study');
|
||||
const lifeAgents = agents.filter(a => a.category === 'life');
|
||||
@@ -693,7 +755,7 @@ function renderAgentsPage() {
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
<!-- 热门智能体 -->
|
||||
<!-- 热门智能体(标签为hot) -->
|
||||
${hotAgents.length > 0 ? `
|
||||
<div class="agents-section">
|
||||
<div class="section-title">🔥 热门智能体</div>
|
||||
@@ -1027,7 +1089,10 @@ function showAgentDiscoverPage() {
|
||||
const sortedAgents = [...systemAgents].sort((a, b) => b.heat - a.heat);
|
||||
|
||||
// 分类显示
|
||||
const hotAgents = systemAgents.filter(a => a.category === 'hot');
|
||||
// 热门智能体 = 标签中包含 "hot"
|
||||
const hotAgents = systemAgents.filter(a => a.tags && a.tags.split(',').includes('hot'));
|
||||
// 其他类别
|
||||
const basicAgents = systemAgents.filter(a => a.category === 'basic');
|
||||
const workAgents = systemAgents.filter(a => a.category === 'work');
|
||||
const studyAgents = systemAgents.filter(a => a.category === 'study');
|
||||
const lifeAgents = systemAgents.filter(a => a.category === 'life');
|
||||
@@ -1048,37 +1113,55 @@ function showAgentDiscoverPage() {
|
||||
<input type="text" id="discoverSearchInput" placeholder="搜索智能体名称或描述...">
|
||||
</div>
|
||||
|
||||
<!-- 热门智能体 -->
|
||||
<!-- 热门智能体(标签为hot) -->
|
||||
${hotAgents.length > 0 ? `
|
||||
<div class="discover-section">
|
||||
<div class="discover-section-title">🔥 热门智能体</div>
|
||||
<div class="discover-grid" id="discoverHotGrid">
|
||||
${hotAgents.map(agent => renderDiscoverCard(agent)).join('')}
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
<!-- 基础智能体 -->
|
||||
${basicAgents.length > 0 ? `
|
||||
<div class="discover-section">
|
||||
<div class="discover-section-title">⭐ 基础智能体</div>
|
||||
<div class="discover-grid" id="discoverBasicGrid">
|
||||
${basicAgents.map(agent => renderDiscoverCard(agent)).join('')}
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
<!-- 工作助手 -->
|
||||
${workAgents.length > 0 ? `
|
||||
<div class="discover-section">
|
||||
<div class="discover-section-title">💼 工作助手</div>
|
||||
<div class="discover-grid" id="discoverWorkGrid">
|
||||
${workAgents.map(agent => renderDiscoverCard(agent)).join('')}
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
<!-- 学习助手 -->
|
||||
${studyAgents.length > 0 ? `
|
||||
<div class="discover-section">
|
||||
<div class="discover-section-title">📚 学习助手</div>
|
||||
<div class="discover-grid" id="discoverStudyGrid">
|
||||
${studyAgents.map(agent => renderDiscoverCard(agent)).join('')}
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
<!-- 生活助手 -->
|
||||
${lifeAgents.length > 0 ? `
|
||||
<div class="discover-section">
|
||||
<div class="discover-section-title">🏠 生活助手</div>
|
||||
<div class="discover-grid" id="discoverLifeGrid">
|
||||
${lifeAgents.map(agent => renderDiscoverCard(agent)).join('')}
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
@@ -1440,7 +1523,7 @@ function renderProfilePage() {
|
||||
</div>
|
||||
|
||||
<div class="profile-footer">
|
||||
<p>AI助手 v3.5.0</p>
|
||||
<p>AI助手 v3.6.0</p>
|
||||
<p>基于智谱 GLM-4.5-Air</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2377,18 +2460,34 @@ function handleLogin() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查本地存储的用户
|
||||
const users = JSON.parse(localStorage.getItem('registeredUsers') || '[]');
|
||||
const user = users.find(u => u.username === username && u.password === password);
|
||||
|
||||
if (user) {
|
||||
currentUser = { username: user.username, registeredAt: user.registeredAt };
|
||||
saveCurrentUser();
|
||||
showToast('登录成功');
|
||||
showMainPage();
|
||||
} else {
|
||||
showToast('用户名或密码错误');
|
||||
}
|
||||
// 调用后台登录API
|
||||
fetch('/api/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password })
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
currentUser = {
|
||||
id: data.user.id,
|
||||
username: data.user.username,
|
||||
phone: data.user.phone,
|
||||
email: data.user.email || '',
|
||||
avatar: data.user.avatar || '👤',
|
||||
signature: data.user.signature || '',
|
||||
registeredAt: Date.now()
|
||||
};
|
||||
saveCurrentUser();
|
||||
showToast('登录成功');
|
||||
showMainPage();
|
||||
} else {
|
||||
showToast(data.error || '用户名或密码错误');
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
showToast('网络错误,请重试');
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 注册页面 ====================
|
||||
@@ -2407,12 +2506,21 @@ function showRegisterPage() {
|
||||
<div class="auth-form">
|
||||
<div class="auth-input-group">
|
||||
<label>用户名</label>
|
||||
<input type="text" id="registerUsername" placeholder="请输入用户名(3-20字符)" autocomplete="username">
|
||||
<input type="text" id="registerUsername" placeholder="请输入用户名(2-20字符)" autocomplete="username">
|
||||
</div>
|
||||
<div class="auth-input-group">
|
||||
<label>手机号 <span class="required">*</span></label>
|
||||
<input type="tel" id="registerPhone" placeholder="请输入手机号" maxlength="11" autocomplete="tel">
|
||||
</div>
|
||||
<div class="auth-input-group" style="display: flex; gap: 8px;">
|
||||
<div style="flex: 1;">
|
||||
<label>验证码 <span class="required">*</span></label>
|
||||
<input type="text" id="registerCode" placeholder="请输入验证码" maxlength="6">
|
||||
</div>
|
||||
<div style="flex-shrink: 0; align-self: flex-end;">
|
||||
<button class="send-code-btn" id="getCodeBtn">获取验证码</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="auth-input-group">
|
||||
<label>邮箱 <span class="optional">(可选)</span></label>
|
||||
<input type="email" id="registerEmail" placeholder="请输入邮箱(可选)" autocomplete="email">
|
||||
@@ -2457,6 +2565,12 @@ function showRegisterPage() {
|
||||
});
|
||||
}
|
||||
|
||||
// 获取验证码按钮
|
||||
const getCodeBtn = document.getElementById('getCodeBtn');
|
||||
if (getCodeBtn) {
|
||||
getCodeBtn.addEventListener('click', handleGetCode);
|
||||
}
|
||||
|
||||
// 回车注册
|
||||
document.getElementById('registerPasswordConfirm')?.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter') handleRegister();
|
||||
@@ -2469,6 +2583,50 @@ function showRegisterPage() {
|
||||
e.target.value = e.target.value.replace(/\D/g, '');
|
||||
});
|
||||
}
|
||||
|
||||
// 验证码输入限制(只允许数字)
|
||||
const codeInput = document.getElementById('registerCode');
|
||||
if (codeInput) {
|
||||
codeInput.addEventListener('input', (e) => {
|
||||
e.target.value = e.target.value.replace(/\D/g, '');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 获取验证码(模拟)
|
||||
let verifyCode = '';
|
||||
let codeExpireTime = 0;
|
||||
|
||||
function handleGetCode() {
|
||||
const phone = document.getElementById('registerPhone')?.value.trim();
|
||||
|
||||
if (!validatePhone(phone)) {
|
||||
showToast('请先输入正确的手机号');
|
||||
return;
|
||||
}
|
||||
|
||||
// 生成6位随机验证码
|
||||
verifyCode = Math.floor(100000 + Math.random() * 900000).toString();
|
||||
codeExpireTime = Date.now() + 5 * 60 * 1000; // 5分钟有效
|
||||
|
||||
// 模拟发送(实际项目中应调用短信API)
|
||||
showToast(`验证码已发送: ${verifyCode}(演示)`);
|
||||
|
||||
// 60秒倒计时
|
||||
const getCodeBtn = document.getElementById('getCodeBtn');
|
||||
if (getCodeBtn) {
|
||||
getCodeBtn.disabled = true;
|
||||
let countdown = 60;
|
||||
const timer = setInterval(() => {
|
||||
getCodeBtn.textContent = `${countdown}s`;
|
||||
countdown--;
|
||||
if (countdown <= 0) {
|
||||
clearInterval(timer);
|
||||
getCodeBtn.disabled = false;
|
||||
getCodeBtn.textContent = '获取验证码';
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// 验证手机号格式
|
||||
@@ -2489,12 +2647,13 @@ function handleRegister() {
|
||||
const username = document.getElementById('registerUsername')?.value.trim();
|
||||
const phone = document.getElementById('registerPhone')?.value.trim();
|
||||
const email = document.getElementById('registerEmail')?.value.trim();
|
||||
const code = document.getElementById('registerCode')?.value.trim();
|
||||
const password = document.getElementById('registerPassword')?.value;
|
||||
const passwordConfirm = document.getElementById('registerPasswordConfirm')?.value;
|
||||
|
||||
// 验证用户名
|
||||
if (!username || username.length < 3 || username.length > 20) {
|
||||
showToast('用户名需要3-20个字符');
|
||||
if (!username || username.length < 2 || username.length > 20) {
|
||||
showToast('用户名需要2-20个字符');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2504,8 +2663,20 @@ function handleRegister() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证验证码
|
||||
if (!code || code.length !== 6) {
|
||||
showToast('请输入6位验证码');
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查验证码是否正确(模拟)
|
||||
if (code !== verifyCode || Date.now() > codeExpireTime) {
|
||||
showToast('验证码不正确或已过期');
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证邮箱(可选)
|
||||
if (!validateEmail(email)) {
|
||||
if (email && !validateEmail(email)) {
|
||||
showToast('请输入正确的邮箱格式');
|
||||
return;
|
||||
}
|
||||
@@ -2521,37 +2692,39 @@ function handleRegister() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查用户名是否已存在
|
||||
const users = JSON.parse(localStorage.getItem('registeredUsers') || '[]');
|
||||
if (users.find(u => u.username === username)) {
|
||||
showToast('用户名已存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查手机号是否已注册
|
||||
if (users.find(u => u.phone === phone)) {
|
||||
showToast('该手机号已注册');
|
||||
return;
|
||||
}
|
||||
|
||||
// 注册新用户
|
||||
const newUser = {
|
||||
username,
|
||||
phone,
|
||||
email: email || '',
|
||||
password,
|
||||
registeredAt: Date.now()
|
||||
};
|
||||
|
||||
users.push(newUser);
|
||||
localStorage.setItem('registeredUsers', JSON.stringify(users));
|
||||
|
||||
// 自动登录
|
||||
currentUser = { username: newUser.username, phone: newUser.phone, registeredAt: newUser.registeredAt };
|
||||
saveCurrentUser();
|
||||
|
||||
showToast('注册成功');
|
||||
showMainPage();
|
||||
// 调用后台注册API
|
||||
fetch('/api/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
username,
|
||||
phone,
|
||||
email: email || '',
|
||||
password,
|
||||
code
|
||||
})
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
// 注册成功,自动登录
|
||||
currentUser = {
|
||||
id: data.user_id,
|
||||
username: username,
|
||||
phone: phone,
|
||||
email: email || '',
|
||||
registeredAt: Date.now()
|
||||
};
|
||||
saveCurrentUser();
|
||||
showToast('注册成功');
|
||||
showMainPage();
|
||||
} else {
|
||||
showToast(data.error || '注册失败');
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
showToast('网络错误,请重试');
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 限制提示 ====================
|
||||
@@ -2757,10 +2930,12 @@ function showAgentChatPage() {
|
||||
<!-- 功能开关栏 -->
|
||||
<div class="feature-bar" id="featureBar">
|
||||
<div class="feature-left">
|
||||
${llmCapabilities.thinking ? `
|
||||
<button class="feature-btn thinking-btn" id="thinkingBtn">
|
||||
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>
|
||||
<span>深度思考</span>
|
||||
</button>
|
||||
` : ''}
|
||||
<button class="feature-btn search-btn" id="searchBtn">
|
||||
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 7 9.5 7 14 9.01 14 9.5 11.99 14 9.5 14z"/></svg>
|
||||
<span>联网搜索</span>
|
||||
@@ -2780,7 +2955,7 @@ function showAgentChatPage() {
|
||||
<button class="attach-btn" id="attachBtn" title="上传文件">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24"><path fill="currentColor" d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></svg>
|
||||
</button>
|
||||
<textarea id="userInput" placeholder="输入消息..." rows="1"></textarea>
|
||||
<textarea id="userInput" placeholder="${llmCapabilities.vision ? '输入消息或上传图片...' : '输入消息...'}" rows="1"></textarea>
|
||||
<button class="send-btn" id="sendBtn">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24"><path fill="currentColor" d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/></svg>
|
||||
</button>
|
||||
@@ -2789,10 +2964,12 @@ function showAgentChatPage() {
|
||||
<!-- 上传选项弹窗 -->
|
||||
<div class="attach-panel" id="attachPanel">
|
||||
<div class="attach-panel-content">
|
||||
${llmCapabilities.vision ? `
|
||||
<div class="attach-item" data-type="image">
|
||||
<div class="attach-icon">📷</div>
|
||||
<div class="attach-label">上传图片</div>
|
||||
</div>
|
||||
` : ''}
|
||||
<div class="attach-item" data-type="file">
|
||||
<div class="attach-icon">📄</div>
|
||||
<div class="attach-label">上传文件</div>
|
||||
@@ -3225,10 +3402,12 @@ function openConversation(id) {
|
||||
<!-- 功能开关栏 -->
|
||||
<div class="feature-bar">
|
||||
<div class="feature-left">
|
||||
${llmCapabilities.thinking ? `
|
||||
<button class="feature-btn thinking-btn ${enableThinking ? 'active' : ''}" id="thinkingBtn">
|
||||
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>
|
||||
<span>深度思考</span>
|
||||
</button>
|
||||
` : ''}
|
||||
<button class="feature-btn search-btn ${enableSearch ? 'active' : ''}" id="searchBtn">
|
||||
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 7 9.5 7 14 9.01 14 9.5 11.99 14 9.5 14z"/></svg>
|
||||
<span>联网搜索</span>
|
||||
@@ -3250,7 +3429,7 @@ function openConversation(id) {
|
||||
</button>
|
||||
<textarea
|
||||
id="userInput"
|
||||
placeholder="输入消息..."
|
||||
placeholder="${llmCapabilities.vision ? '输入消息或上传图片...' : '输入消息...'}"
|
||||
rows="1"
|
||||
></textarea>
|
||||
<button class="send-btn" id="sendBtn">
|
||||
@@ -3261,10 +3440,12 @@ function openConversation(id) {
|
||||
<!-- 上传选项弹窗 -->
|
||||
<div class="attach-panel" id="attachPanel">
|
||||
<div class="attach-panel-content">
|
||||
${llmCapabilities.vision ? `
|
||||
<div class="attach-item" data-type="image">
|
||||
<div class="attach-icon">📷</div>
|
||||
<div class="attach-label">上传图片</div>
|
||||
</div>
|
||||
` : ''}
|
||||
<div class="attach-item" data-type="file">
|
||||
<div class="attach-icon">📄</div>
|
||||
<div class="attach-label">上传文件</div>
|
||||
@@ -4126,6 +4307,13 @@ async function handleImageUpload(e) {
|
||||
const file = e.target.files[0];
|
||||
if (!file) return;
|
||||
|
||||
// 检查是否支持视觉能力
|
||||
if (!llmCapabilities.vision) {
|
||||
showToast('当前大模型不支持图片分析功能,请等待后期升级');
|
||||
e.target.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
// 读取图片为base64
|
||||
const reader = new FileReader();
|
||||
reader.onload = async (event) => {
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
<meta http-equiv="Pragma" content="no-cache">
|
||||
<meta http-equiv="Expires" content="0">
|
||||
<title>AI助手</title>
|
||||
<link rel="stylesheet" href="style.css?v=3.5.0">
|
||||
<link rel="stylesheet" href="style.css?v=3.5.1">
|
||||
<link rel="manifest" href="manifest.json">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="marked.min.js?v=3.5.0"></script>
|
||||
<script src="app.js?v=3.5.0"></script>
|
||||
<script src="marked.min.js?v=3.5.1"></script>
|
||||
<script src="app.js?v=3.5.1"></script>
|
||||
</body>
|
||||
</html>
|
||||
247
www/style.css
247
www/style.css
@@ -1049,6 +1049,31 @@ body {
|
||||
box-shadow: 0 0 8px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.avatar-upload-section {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.avatar-upload-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 12px 24px;
|
||||
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.avatar-upload-btn:hover {
|
||||
transform: scale(1.02);
|
||||
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.edit-input-group {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
@@ -1705,6 +1730,16 @@ body {
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.recent-agent-title {
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
max-width: 120px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.recent-agent-agent-name {
|
||||
font-size: 12px;
|
||||
color: var(--primary);
|
||||
@@ -1782,7 +1817,17 @@ body {
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.agent-history-agent {
|
||||
.agent-history-title {
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
max-width: 150px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.agent-history-agent-name {
|
||||
font-size: 12px;
|
||||
color: var(--primary);
|
||||
background: rgba(102, 126, 234, 0.1);
|
||||
@@ -2350,7 +2395,8 @@ body {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
/* TTS 语音播放按钮 */
|
||||
.tts-btn {
|
||||
background: rgba(255,255,255,0.2);
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
@@ -2359,10 +2405,18 @@ body {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.clear-btn:active {
|
||||
.tts-btn:hover {
|
||||
background: rgba(255,255,255,0.3);
|
||||
}
|
||||
|
||||
.tts-btn.active {
|
||||
background: rgba(255,255,255,0.4);
|
||||
}
|
||||
|
||||
.tts-btn svg {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.messages-container {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
@@ -2715,6 +2769,193 @@ body {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* 更多工具按钮 */
|
||||
.tools-btn {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tools-count {
|
||||
position: absolute;
|
||||
top: -4px;
|
||||
right: -4px;
|
||||
min-width: 16px;
|
||||
height: 16px;
|
||||
padding: 0 4px;
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* 工具选择弹窗 */
|
||||
.tools-popup {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.tools-popup-content {
|
||||
width: 90%;
|
||||
max-width: 400px;
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.tools-popup-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 20px;
|
||||
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.tools-popup-header h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.tools-popup-close {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border: none;
|
||||
border-radius: 14px;
|
||||
color: white;
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.tools-popup-close:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.tools-popup-body {
|
||||
padding: 16px 20px;
|
||||
}
|
||||
|
||||
.tools-popup-tip {
|
||||
color: #718096;
|
||||
font-size: 13px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.tools-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.tool-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
background: #f5f7fa;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.tool-option:hover {
|
||||
background: #e8ecf1;
|
||||
}
|
||||
|
||||
.tool-option.selected {
|
||||
background: rgba(102, 126, 234, 0.1);
|
||||
border-color: var(--primary);
|
||||
}
|
||||
|
||||
.tool-checkbox {
|
||||
flex-shrink: 0;
|
||||
color: #718096;
|
||||
}
|
||||
|
||||
.tool-option.selected .tool-checkbox {
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.tool-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.tool-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.tool-name {
|
||||
font-weight: 500;
|
||||
color: #2d3748;
|
||||
}
|
||||
|
||||
.tool-type {
|
||||
font-size: 12px;
|
||||
color: #718096;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.tools-popup-footer {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding: 16px 20px;
|
||||
background: #f5f7fa;
|
||||
}
|
||||
|
||||
.tools-popup-btn {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.tools-popup-btn.cancel {
|
||||
background: #e2e8f0;
|
||||
color: #4a5568;
|
||||
}
|
||||
|
||||
.tools-popup-btn.cancel:hover {
|
||||
background: #cbd5e0;
|
||||
}
|
||||
|
||||
.tools-popup-btn.confirm {
|
||||
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.tools-popup-btn.confirm:hover {
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
/* 导航按钮样式 */
|
||||
.nav-btn {
|
||||
padding: 6px 8px;
|
||||
|
||||
Reference in New Issue
Block a user