From 05ead34c6489d733639f7264e3d3071737cbea64 Mon Sep 17 00:00:00 2001
From: hubian <908234780@qq.com>
Date: Sun, 26 Apr 2026 22:59:25 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E9=A1=B5=E9=87=8D=E6=9E=84=20?=
=?UTF-8?q?-=20=E5=BA=95=E9=83=A8=E5=AF=BC=E8=88=AA=E6=A0=8F=EF=BC=88?=
=?UTF-8?q?=E5=AF=B9=E8=AF=9D/=E6=99=BA=E8=83=BD=E4=BD=93/=E6=88=91?=
=?UTF-8?q?=E7=9A=84=EF=BC=89+=20=E6=99=BA=E8=83=BD=E4=BD=93=E5=88=86?=
=?UTF-8?q?=E7=B1=BB=E5=88=97=E8=A1=A8=20+=20=E6=99=BA=E8=83=BD=E4=BD=93?=
=?UTF-8?q?=E5=AF=B9=E8=AF=9D=E7=95=8C=E9=9D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
www/app.js | 591 ++++++++++++++++++++++++++++++++++++++++++++++++-
www/index.html | 6 +-
www/style.css | 297 +++++++++++++++++++++++++
3 files changed, 888 insertions(+), 6 deletions(-)
diff --git a/www/app.js b/www/app.js
index 512a8d5..06d990c 100644
--- a/www/app.js
+++ b/www/app.js
@@ -16,6 +16,35 @@ let conversations = []; // 对话列表
let currentConversation = null; // 当前对话
let isLoading = false;
+// 当前页面状态
+let currentPage = 'chats'; // chats | agents | profile
+
+// 智能体数据
+let agents = [
+ // 热门智能体
+ { id: 'assistant', name: '通用助手', avatar: '🤖', category: 'hot', desc: '能回答各类问题,帮助写作、分析、解答疑惑', systemPrompt: '你是一个智能助手,能够回答各类问题,帮助用户解决问题。' },
+ { id: 'writer', name: '写作助手', avatar: '✍️', category: 'hot', desc: '专注于文章写作、文案创作、内容润色', systemPrompt: '你是一个专业的写作助手,擅长各类文章写作、文案创作和内容润色。' },
+ { id: 'coder', name: '编程助手', avatar: '👨💻', category: 'hot', desc: '精通编程语言,解答技术问题,生成代码', systemPrompt: '你是一个专业的编程助手,精通各类编程语言,能够解答技术问题并生成高质量代码。' },
+ { id: 'translator', name: '翻译助手', avatar: '🌐', category: 'hot', desc: '多语言翻译,精准表达,文化适配', systemPrompt: '你是一个专业的翻译助手,精通多语言翻译,能够精准表达并适配文化差异。' },
+
+ // 工作助手
+ { id: 'assistant-work', name: '工作助手', avatar: '💼', category: 'work', desc: '职场问题解答,工作效率提升', systemPrompt: '你是一个工作助手,帮助解决职场问题,提升工作效率。' },
+ { id: 'ppt', name: 'PPT助手', avatar: '📊', category: 'work', desc: 'PPT内容生成,结构优化,设计建议', systemPrompt: '你是一个PPT助手,擅长PPT内容生成、结构优化和设计建议。' },
+ { id: 'excel', name: 'Excel助手', avatar: '📈', category: 'work', desc: 'Excel公式、数据分析、表格优化', systemPrompt: '你是一个Excel助手,精通Excel公式、数据分析和表格优化。' },
+
+ // 学习助手
+ { id: 'teacher', name: '学习助手', avatar: '📚', category: 'study', desc: '知识讲解,学习方法,考试辅导', systemPrompt: '你是一个学习助手,擅长知识讲解、学习方法指导和考试辅导。' },
+ { id: 'english', name: '英语助手', avatar: '🔤', category: 'study', desc: '英语学习,语法纠正,口语练习', systemPrompt: '你是一个英语助手,帮助英语学习、语法纠正和口语练习。' },
+ { id: 'math', name: '数学助手', avatar: '🔢', category: 'study', desc: '数学解题,公式推导,概念讲解', systemPrompt: '你是一个数学助手,擅长数学解题、公式推导和概念讲解。' },
+
+ // 生活助手
+ { id: 'health', name: '健康助手', avatar: '🏥', category: 'life', desc: '健康咨询,养生建议,运动指导', systemPrompt: '你是一个健康助手,提供健康咨询、养生建议和运动指导。' },
+ { id: 'travel', name: '旅行助手', avatar: '✈️', category: 'life', desc: '旅行规划,景点推荐,美食指南', systemPrompt: '你是一个旅行助手,擅长旅行规划、景点推荐和美食指南。' },
+ { id: 'food', name: '美食助手', avatar: '🍳', category: 'life', desc: '菜谱推荐,烹饪技巧,营养搭配', systemPrompt: '你是一个美食助手,提供菜谱推荐、烹饪技巧和营养搭配建议。' },
+];
+
+let currentAgent = null; // 当前选中的智能体
+
// 功能开关
let enableThinking = false; // 深度思考
let enableSearch = false; // 联网搜索
@@ -61,11 +90,567 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
- // 显示对话列表页面
- showConversationList();
+ // 加载当前页面状态
+ const savedPage = localStorage.getItem('currentPage');
+ if (savedPage) {
+ currentPage = savedPage;
+ }
+
+ // 显示主页
+ showMainPage();
});
-// ==================== 对话列表页面 ====================
+// ==================== 主页(底部导航栏) ====================
+
+function showMainPage() {
+ currentConversation = null;
+ currentAgent = null;
+
+ const mainHtml = `
+
+
+ ${renderCurrentPage()}
+
+
+
+
+
+ `;
+
+ appContainer.innerHTML = mainHtml;
+
+ // 绑定底部导航事件
+ document.querySelectorAll('.nav-item').forEach(item => {
+ item.addEventListener('click', () => {
+ const page = item.getAttribute('data-page');
+ switchPage(page);
+ });
+ });
+
+ // 根据当前页面绑定其他事件
+ bindPageEvents();
+}
+
+// 渲染当前页面内容
+function renderCurrentPage() {
+ switch (currentPage) {
+ case 'chats':
+ return renderChatsPage();
+ case 'agents':
+ return renderAgentsPage();
+ case 'profile':
+ return renderProfilePage();
+ default:
+ return renderChatsPage();
+ }
+}
+
+// 切换页面
+function switchPage(page) {
+ currentPage = page;
+ localStorage.setItem('currentPage', page);
+
+ // 更新导航栏状态
+ 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();
+ }
+
+ // 绑定页面事件
+ bindPageEvents();
+}
+
+// 绑定页面事件
+function bindPageEvents() {
+ switch (currentPage) {
+ case 'chats':
+ bindChatsPageEvents();
+ break;
+ case 'agents':
+ bindAgentsPageEvents();
+ break;
+ case 'profile':
+ bindProfilePageEvents();
+ break;
+ }
+}
+
+// ==================== 对话页面 ====================
+
+function renderChatsPage() {
+ return `
+
+
+
+
+
+ ${conversations.length === 0
+ ? '
暂无对话记录
点击右上角 + 开始新对话
'
+ : sortConversations().map(conv => `
+
+ ${conv.is_pinned ? '
📌' : ''}
+
${escapeHtml(conv.title)}
+
${conv.messages.length} 条消息 · ${formatTime(conv.updatedAt)}
+
+ `).join('')
+ }
+
+
+
+ `;
+}
+
+function bindChatsPageEvents() {
+ const newChatBtn = document.getElementById('newChatBtn');
+ if (newChatBtn) {
+ newChatBtn.addEventListener('click', createNewConversation);
+ }
+
+ const conversationList = document.getElementById('conversationList');
+ if (conversationList) {
+ conversationList.addEventListener('click', (e) => {
+ const item = e.target.closest('.conversation-item');
+ if (item) {
+ const id = item.getAttribute('data-id');
+ openConversation(id);
+ }
+ });
+
+ // 长按事件
+ setupLongPressEvents(conversationList);
+ }
+}
+
+// ==================== 智能体页面 ====================
+
+function renderAgentsPage() {
+ const hotAgents = agents.filter(a => a.category === 'hot');
+ const workAgents = agents.filter(a => a.category === 'work');
+ const studyAgents = agents.filter(a => a.category === 'study');
+ const lifeAgents = agents.filter(a => a.category === 'life');
+
+ return `
+
+
+
+
+
+
+
🔥 热门智能体
+
+ ${hotAgents.map(agent => `
+
+
${agent.avatar}
+
${agent.name}
+
${agent.desc}
+
+ `).join('')}
+
+
+
+
+
+
💼 工作助手
+
+ ${workAgents.map(agent => `
+
+
${agent.avatar}
+
${agent.name}
+
${agent.desc}
+
+ `).join('')}
+
+
+
+
+
+
📚 学习助手
+
+ ${studyAgents.map(agent => `
+
+
${agent.avatar}
+
${agent.name}
+
${agent.desc}
+
+ `).join('')}
+
+
+
+
+
+
🏠 生活助手
+
+ ${lifeAgents.map(agent => `
+
+
${agent.avatar}
+
${agent.name}
+
${agent.desc}
+
+ `).join('')}
+
+
+
+
+ `;
+}
+
+function bindAgentsPageEvents() {
+ document.querySelectorAll('.agent-card').forEach(card => {
+ card.addEventListener('click', () => {
+ const id = card.getAttribute('data-id');
+ openAgent(id);
+ });
+ });
+}
+
+// ==================== 我的页面 ====================
+
+function renderProfilePage() {
+ return `
+
+ `;
+}
+
+function bindProfilePageEvents() {
+ const clearDataBtn = document.getElementById('clearDataBtn');
+ if (clearDataBtn) {
+ clearDataBtn.addEventListener('click', () => {
+ if (confirm('确定要清除所有数据吗?这将删除所有对话记录。')) {
+ localStorage.clear();
+ conversations = [];
+ showToast('数据已清除');
+ showMainPage();
+ }
+ });
+ }
+}
+
+// 打开智能体对话
+function openAgent(agentId) {
+ currentAgent = agents.find(a => a.id === agentId);
+ if (!currentAgent) return;
+
+ // 创建新对话并设置智能体
+ createNewConversation();
+ currentConversation.agentId = agentId;
+ currentConversation.title = currentAgent.name;
+ saveConversations();
+
+ // 显示对话界面
+ showAgentChatPage();
+}
+
+// 显示智能体对话界面
+function showAgentChatPage() {
+ if (!currentAgent || !currentConversation) return;
+
+ const chatHtml = `
+
+
+
+
+
+
${currentAgent.avatar}
+
${currentAgent.name}
+
${currentAgent.desc}
+
有什么可以帮你的吗?
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `;
+
+ appContainer.innerHTML = chatHtml;
+
+ // 重新获取 DOM 元素
+ messagesContainer = document.getElementById('messagesContainer');
+ messagesDiv = document.getElementById('messages');
+ userInput = document.getElementById('userInput');
+ sendBtn = document.getElementById('sendBtn');
+ welcome = document.getElementById('welcome');
+ thinkingBtn = document.getElementById('thinkingBtn');
+ searchBtn = document.getElementById('searchBtn');
+
+ // 重置自动滚动状态
+ autoScrollEnabled = true;
+
+ // 设置滚动监听
+ setupScrollListener();
+
+ // 绑定事件
+ const backBtn = document.getElementById('backBtn');
+ if (backBtn) {
+ backBtn.addEventListener('click', () => {
+ showMainPage();
+ });
+ }
+
+ // 绑定功能开关按钮事件
+ if (thinkingBtn) {
+ thinkingBtn.addEventListener('click', () => {
+ enableThinking = !enableThinking;
+ thinkingBtn.classList.toggle('active', enableThinking);
+ });
+ }
+
+ if (searchBtn) {
+ searchBtn.addEventListener('click', () => {
+ enableSearch = !enableSearch;
+ searchBtn.classList.toggle('active', enableSearch);
+ });
+ }
+
+ // 绑定输入事件
+ userInput.addEventListener('keydown', handleKeyDown);
+ userInput.addEventListener('input', (e) => autoResize(e.target));
+ sendBtn.addEventListener('click', sendMessage);
+
+ // 绑定置顶置底按钮事件
+ const scrollTopBtn = document.getElementById('scrollTopBtn');
+ const scrollBottomBtn = document.getElementById('scrollBottomBtn');
+
+ if (scrollTopBtn) {
+ scrollTopBtn.addEventListener('click', () => {
+ if (messagesContainer) {
+ messagesContainer.scrollTo({
+ top: 0,
+ behavior: 'smooth'
+ });
+ }
+ });
+ }
+
+ if (scrollBottomBtn) {
+ scrollBottomBtn.addEventListener('click', () => {
+ if (messagesContainer) {
+ messagesContainer.scrollTo({
+ top: messagesContainer.scrollHeight,
+ behavior: 'smooth'
+ });
+ }
+ });
+ }
+
+ // 绑定上传按钮事件
+ const attachBtn = document.getElementById('attachBtn');
+ const attachPanel = document.getElementById('attachPanel');
+ const imageInput = document.getElementById('imageInput');
+ const fileInput = document.getElementById('fileInput');
+
+ if (attachBtn) {
+ attachBtn.addEventListener('click', (e) => {
+ e.stopPropagation();
+ attachPanel.classList.toggle('show');
+ });
+ }
+
+ document.addEventListener('click', (e) => {
+ if (attachPanel && attachPanel.classList.contains('show') &&
+ !attachPanel.contains(e.target) && !attachBtn.contains(e.target)) {
+ attachPanel.classList.remove('show');
+ }
+ });
+
+ attachPanel.querySelectorAll('.attach-item').forEach(item => {
+ item.addEventListener('click', () => {
+ const type = item.getAttribute('data-type');
+ attachPanel.classList.remove('show');
+ if (type === 'image') {
+ imageInput.click();
+ } else if (type === 'file') {
+ fileInput.click();
+ }
+ });
+ });
+
+ imageInput.addEventListener('change', handleImageUpload);
+ fileInput.addEventListener('change', handleFileUpload);
+
+ // 渲染消息
+ renderMessages();
+ userInput.focus();
+}
+
+// 设置长按事件
+function setupLongPressEvents(container) {
+ let longPressTimer = null;
+ let currentActionConvId = null;
+
+ container.addEventListener('touchstart', (e) => {
+ const item = e.target.closest('.conversation-item');
+ if (item) {
+ longPressTimer = setTimeout(() => {
+ currentActionConvId = item.getAttribute('data-id');
+ showActionMenu(currentActionConvId);
+ }, 500);
+ }
+ });
+
+ container.addEventListener('touchend', () => {
+ if (longPressTimer) {
+ clearTimeout(longPressTimer);
+ longPressTimer = null;
+ }
+ });
+
+ container.addEventListener('touchmove', () => {
+ if (longPressTimer) {
+ clearTimeout(longPressTimer);
+ longPressTimer = null;
+ }
+ });
+
+ container.addEventListener('mousedown', (e) => {
+ const item = e.target.closest('.conversation-item');
+ if (item) {
+ longPressTimer = setTimeout(() => {
+ currentActionConvId = item.getAttribute('data-id');
+ showActionMenu(currentActionConvId);
+ }, 500);
+ }
+ });
+
+ container.addEventListener('mouseup', () => {
+ if (longPressTimer) {
+ clearTimeout(longPressTimer);
+ longPressTimer = null;
+ }
+ });
+
+ container.addEventListener('mouseleave', () => {
+ if (longPressTimer) {
+ clearTimeout(longPressTimer);
+ longPressTimer = null;
+ }
+ });
+}
function showConversationList() {
currentConversation = null;
diff --git a/www/index.html b/www/index.html
index d0cde40..3a36bac 100644
--- a/www/index.html
+++ b/www/index.html
@@ -8,12 +8,12 @@
AI助手
-
+
-
-
+
+