Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3417709a79 | |||
| 3f72306e78 | |||
| f06260cf78 | |||
| e1ab11c007 | |||
| 386fa20c84 |
@@ -1,5 +1,5 @@
|
|||||||
// AI助手 - 前端应用
|
// AI助手 - 前端应用
|
||||||
// 使用智谱 GLM-4.5-Air 模型(流式输出)
|
// 使用智谱 GLM-4.5-Air 模型(流式输出 + 多对话管理)
|
||||||
|
|
||||||
const CONFIG = {
|
const CONFIG = {
|
||||||
apiUrl: 'https://open.bigmodel.cn/api/paas/v4/chat/completions',
|
apiUrl: 'https://open.bigmodel.cn/api/paas/v4/chat/completions',
|
||||||
@@ -8,11 +8,13 @@ const CONFIG = {
|
|||||||
maxTokens: 2048
|
maxTokens: 2048
|
||||||
};
|
};
|
||||||
|
|
||||||
// 对话历史
|
// 数据结构
|
||||||
let messages = [];
|
let conversations = []; // 对话列表
|
||||||
|
let currentConversation = null; // 当前对话
|
||||||
let isLoading = false;
|
let isLoading = false;
|
||||||
|
|
||||||
// DOM 元素
|
// DOM 元素
|
||||||
|
const appContainer = document.getElementById('app');
|
||||||
const messagesContainer = document.getElementById('messagesContainer');
|
const messagesContainer = document.getElementById('messagesContainer');
|
||||||
const messagesDiv = document.getElementById('messages');
|
const messagesDiv = document.getElementById('messages');
|
||||||
const userInput = document.getElementById('userInput');
|
const userInput = document.getElementById('userInput');
|
||||||
@@ -21,20 +23,151 @@ const welcome = document.getElementById('welcome');
|
|||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
// 从本地存储恢复对话
|
// 从本地存储加载对话列表
|
||||||
const saved = localStorage.getItem('chat_history');
|
const saved = localStorage.getItem('conversations');
|
||||||
if (saved) {
|
if (saved) {
|
||||||
messages = JSON.parse(saved);
|
conversations = JSON.parse(saved);
|
||||||
renderMessages();
|
|
||||||
if (messages.length > 0) {
|
|
||||||
welcome.style.display = 'none';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 聚焦输入框
|
// 显示对话列表页面
|
||||||
userInput.focus();
|
showConversationList();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ==================== 对话列表页面 ====================
|
||||||
|
|
||||||
|
function showConversationList() {
|
||||||
|
currentConversation = null;
|
||||||
|
|
||||||
|
// 渲染对话列表
|
||||||
|
const listHtml = `
|
||||||
|
<div class="conversation-list-page">
|
||||||
|
<header class="list-header">
|
||||||
|
<div class="header-title">
|
||||||
|
<span class="logo">🤖</span>
|
||||||
|
<h1>AI助手</h1>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="list-content">
|
||||||
|
<button class="new-chat-btn" onclick="createNewConversation()">
|
||||||
|
<svg viewBox="0 0 24 24" width="20" height="20"><path fill="currentColor" d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></svg>
|
||||||
|
新建对话
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="conversation-list">
|
||||||
|
${conversations.length === 0
|
||||||
|
? '<div class="empty-list">暂无对话记录</div>'
|
||||||
|
: conversations.map(conv => `
|
||||||
|
<div class="conversation-item" onclick="openConversation('${conv.id}')">
|
||||||
|
<div class="conv-title">${escapeHtml(conv.title)}</div>
|
||||||
|
<div class="conv-meta">${conv.messages.length} 条消息 · ${formatTime(conv.updatedAt)}</div>
|
||||||
|
<button class="conv-delete-btn" onclick="event.stopPropagation(); deleteConversation('${conv.id}')" title="删除对话">
|
||||||
|
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/></svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
`).join('')
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
appContainer.innerHTML = listHtml;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建新对话
|
||||||
|
function createNewConversation() {
|
||||||
|
const newConv = {
|
||||||
|
id: Date.now().toString(),
|
||||||
|
title: '新对话',
|
||||||
|
messages: [],
|
||||||
|
createdAt: Date.now(),
|
||||||
|
updatedAt: Date.now()
|
||||||
|
};
|
||||||
|
|
||||||
|
conversations.unshift(newConv);
|
||||||
|
saveConversations();
|
||||||
|
openConversation(newConv.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打开对话
|
||||||
|
function openConversation(id) {
|
||||||
|
currentConversation = conversations.find(c => c.id === id);
|
||||||
|
if (!currentConversation) {
|
||||||
|
showConversationList();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染对话页面
|
||||||
|
const chatHtml = `
|
||||||
|
<div id="chatPage">
|
||||||
|
<header class="header">
|
||||||
|
<button class="back-btn" onclick="showConversationList()">
|
||||||
|
<svg viewBox="0 0 24 24" width="24" height="24"><path fill="currentColor" d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/></svg>
|
||||||
|
</button>
|
||||||
|
<div class="header-title">
|
||||||
|
<span class="logo">🤖</span>
|
||||||
|
<h1>${escapeHtml(currentConversation.title)}</h1>
|
||||||
|
</div>
|
||||||
|
<button class="clear-btn" onclick="clearCurrentChat()" title="清空对话">
|
||||||
|
<svg viewBox="0 0 24 24" width="20" height="20"><path fill="currentColor" d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="messages-container" id="messagesContainer">
|
||||||
|
<div class="welcome" id="welcome" style="${currentConversation.messages.length > 0 ? 'display:none' : ''}">
|
||||||
|
<div class="welcome-icon">👋</div>
|
||||||
|
<h2>你好!我是AI助手</h2>
|
||||||
|
<p>有什么可以帮助你的吗?</p>
|
||||||
|
<div class="quick-actions">
|
||||||
|
<button onclick="sendQuickMessage('介绍一下你自己')">介绍一下你自己</button>
|
||||||
|
<button onclick="sendQuickMessage('帮我写一段代码')">帮我写代码</button>
|
||||||
|
<button onclick="sendQuickMessage('解释一个概念')">解释概念</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="messages" id="messages"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-area">
|
||||||
|
<textarea
|
||||||
|
id="userInput"
|
||||||
|
placeholder="输入消息..."
|
||||||
|
rows="1"
|
||||||
|
onkeydown="handleKeyDown(event)"
|
||||||
|
oninput="autoResize(this)"
|
||||||
|
></textarea>
|
||||||
|
<button class="send-btn" onclick="sendMessage()" 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>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
appContainer.innerHTML = chatHtml;
|
||||||
|
|
||||||
|
// 重新获取 DOM 元素
|
||||||
|
messagesContainer = document.getElementById('messagesContainer');
|
||||||
|
messagesDiv = document.getElementById('messages');
|
||||||
|
userInput = document.getElementById('userInput');
|
||||||
|
sendBtn = document.getElementById('sendBtn');
|
||||||
|
welcome = document.getElementById('welcome');
|
||||||
|
|
||||||
|
// 渲染消息
|
||||||
|
renderMessages();
|
||||||
|
userInput.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除对话
|
||||||
|
function deleteConversation(id) {
|
||||||
|
if (!confirm('确定要删除这个对话吗?')) return;
|
||||||
|
|
||||||
|
conversations = conversations.filter(c => c.id !== id);
|
||||||
|
saveConversations();
|
||||||
|
showConversationList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 对话页面 ====================
|
||||||
|
|
||||||
// 自动调整输入框高度
|
// 自动调整输入框高度
|
||||||
function autoResize(textarea) {
|
function autoResize(textarea) {
|
||||||
textarea.style.height = 'auto';
|
textarea.style.height = 'auto';
|
||||||
@@ -57,6 +190,8 @@ function sendQuickMessage(text) {
|
|||||||
|
|
||||||
// 发送消息(流式输出)
|
// 发送消息(流式输出)
|
||||||
async function sendMessage() {
|
async function sendMessage() {
|
||||||
|
if (!currentConversation) return;
|
||||||
|
|
||||||
const text = userInput.value.trim();
|
const text = userInput.value.trim();
|
||||||
if (!text || isLoading) return;
|
if (!text || isLoading) return;
|
||||||
|
|
||||||
@@ -64,27 +199,43 @@ async function sendMessage() {
|
|||||||
welcome.style.display = 'none';
|
welcome.style.display = 'none';
|
||||||
|
|
||||||
// 添加用户消息
|
// 添加用户消息
|
||||||
messages.push({ role: 'user', content: text });
|
currentConversation.messages.push({ role: 'user', content: text });
|
||||||
|
|
||||||
|
// 更新对话标题(第一条用户消息)
|
||||||
|
if (currentConversation.title === '新对话') {
|
||||||
|
currentConversation.title = text.slice(0, 30) + (text.length > 30 ? '...' : '');
|
||||||
|
// 更新标题显示
|
||||||
|
const titleEl = document.querySelector('.header h1');
|
||||||
|
if (titleEl) {
|
||||||
|
titleEl.textContent = currentConversation.title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentConversation.updatedAt = Date.now();
|
||||||
|
saveConversations();
|
||||||
|
|
||||||
renderMessages();
|
renderMessages();
|
||||||
userInput.value = '';
|
userInput.value = '';
|
||||||
autoResize(userInput);
|
autoResize(userInput);
|
||||||
|
|
||||||
// 显示加载状态
|
// 调用流式生成
|
||||||
|
await streamGenerate(currentConversation.messages.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 流式生成 AI 回复
|
||||||
|
async function streamGenerate(userMsgIndex) {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
sendBtn.disabled = true;
|
sendBtn.disabled = true;
|
||||||
|
|
||||||
// 创建 AI 消息容器(流式填充)
|
const aiMessageIndex = currentConversation.messages.length;
|
||||||
const aiMessageIndex = messages.length;
|
currentConversation.messages.push({ role: 'assistant', content: '' });
|
||||||
messages.push({ role: 'assistant', content: '' });
|
|
||||||
renderMessages();
|
renderMessages();
|
||||||
|
|
||||||
// 获取最后一条消息的 DOM 元素
|
|
||||||
const lastMessageEl = messagesDiv.lastElementChild;
|
const lastMessageEl = messagesDiv.lastElementChild;
|
||||||
const contentEl = lastMessageEl.querySelector('.message-content');
|
const contentEl = lastMessageEl.querySelector('.message-content');
|
||||||
contentEl.innerHTML = '<span class="streaming-cursor">▌</span>';
|
contentEl.innerHTML = '<span class="streaming-cursor">▌</span>';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 调用 API(流式)
|
|
||||||
const response = await fetch(CONFIG.apiUrl, {
|
const response = await fetch(CONFIG.apiUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -93,12 +244,12 @@ async function sendMessage() {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: CONFIG.model,
|
model: CONFIG.model,
|
||||||
messages: messages.slice(0, aiMessageIndex).map(m => ({
|
messages: currentConversation.messages.slice(0, aiMessageIndex).map(m => ({
|
||||||
role: m.role,
|
role: m.role,
|
||||||
content: m.content
|
content: m.content
|
||||||
})),
|
})),
|
||||||
max_tokens: CONFIG.maxTokens,
|
max_tokens: CONFIG.maxTokens,
|
||||||
stream: true // 开启流式输出
|
stream: true
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -106,7 +257,6 @@ async function sendMessage() {
|
|||||||
throw new Error(`API 错误: ${response.status}`);
|
throw new Error(`API 错误: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理流式响应
|
|
||||||
const reader = response.body.getReader();
|
const reader = response.body.getReader();
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
let buffer = '';
|
let buffer = '';
|
||||||
@@ -116,10 +266,8 @@ async function sendMessage() {
|
|||||||
if (done) break;
|
if (done) break;
|
||||||
|
|
||||||
buffer += decoder.decode(value, { stream: true });
|
buffer += decoder.decode(value, { stream: true });
|
||||||
|
|
||||||
// 解析 SSE 数据
|
|
||||||
const lines = buffer.split('\n');
|
const lines = buffer.split('\n');
|
||||||
buffer = lines.pop() || ''; // 保留未完成的行
|
buffer = lines.pop() || '';
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (line.startsWith('data: ')) {
|
if (line.startsWith('data: ')) {
|
||||||
@@ -129,86 +277,210 @@ async function sendMessage() {
|
|||||||
try {
|
try {
|
||||||
const data = JSON.parse(jsonStr);
|
const data = JSON.parse(jsonStr);
|
||||||
if (data.choices && data.choices[0]?.delta?.content) {
|
if (data.choices && data.choices[0]?.delta?.content) {
|
||||||
// 追加内容
|
currentConversation.messages[aiMessageIndex].content += data.choices[0].delta.content;
|
||||||
messages[aiMessageIndex].content += data.choices[0].delta.content;
|
contentEl.innerHTML = renderMarkdown(currentConversation.messages[aiMessageIndex].content) + '<span class="streaming-cursor">▌</span>';
|
||||||
|
|
||||||
// 更新显示(带光标)
|
|
||||||
contentEl.innerHTML = formatContent(messages[aiMessageIndex].content) + '<span class="streaming-cursor">▌</span>';
|
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
// 忽略解析错误
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 完成,移除光标
|
contentEl.innerHTML = renderMarkdown(currentConversation.messages[aiMessageIndex].content);
|
||||||
contentEl.innerHTML = formatContent(messages[aiMessageIndex].content);
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
messages[aiMessageIndex].content = `抱歉,出现了错误:${error.message}\n\n请检查网络连接后重试。`;
|
currentConversation.messages[aiMessageIndex].content = `抱歉,出现了错误:${error.message}\n\n请检查网络连接后重试。`;
|
||||||
contentEl.innerHTML = formatContent(messages[aiMessageIndex].content);
|
contentEl.innerHTML = renderMarkdown(currentConversation.messages[aiMessageIndex].content);
|
||||||
} finally {
|
} finally {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
sendBtn.disabled = false;
|
sendBtn.disabled = false;
|
||||||
saveHistory();
|
currentConversation.updatedAt = Date.now();
|
||||||
|
saveConversations();
|
||||||
|
renderMessages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新生成 AI 回复
|
||||||
|
async function regenerate(index) {
|
||||||
|
if (!currentConversation || isLoading || index < 1) return;
|
||||||
|
|
||||||
|
const userMsgIndex = index - 1;
|
||||||
|
if (currentConversation.messages[userMsgIndex].role !== 'user') return;
|
||||||
|
|
||||||
|
currentConversation.messages.splice(index, 1);
|
||||||
|
currentConversation.updatedAt = Date.now();
|
||||||
|
saveConversations();
|
||||||
|
|
||||||
|
await streamGenerate(userMsgIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除消息
|
||||||
|
function deleteMessage(index) {
|
||||||
|
if (!currentConversation || isLoading) return;
|
||||||
|
|
||||||
|
const msg = currentConversation.messages[index];
|
||||||
|
|
||||||
|
if (msg.role === 'assistant') {
|
||||||
|
if (index > 0 && currentConversation.messages[index - 1].role === 'user') {
|
||||||
|
currentConversation.messages.splice(index - 1, 2);
|
||||||
|
} else {
|
||||||
|
currentConversation.messages.splice(index, 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (index < currentConversation.messages.length - 1 && currentConversation.messages[index + 1].role === 'assistant') {
|
||||||
|
currentConversation.messages.splice(index, 2);
|
||||||
|
} else {
|
||||||
|
currentConversation.messages.splice(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentConversation.updatedAt = Date.now();
|
||||||
|
saveConversations();
|
||||||
|
renderMessages();
|
||||||
|
|
||||||
|
if (currentConversation.messages.length === 0) {
|
||||||
|
welcome.style.display = 'block';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 复制消息(复制原文)
|
||||||
|
function copyMessage(index) {
|
||||||
|
if (!currentConversation) return;
|
||||||
|
|
||||||
|
const content = currentConversation.messages[index].content;
|
||||||
|
|
||||||
|
navigator.clipboard.writeText(content).then(() => {
|
||||||
|
showToast('已复制到剪贴板');
|
||||||
|
}).catch(err => {
|
||||||
|
const textarea = document.createElement('textarea');
|
||||||
|
textarea.value = content;
|
||||||
|
textarea.style.position = 'fixed';
|
||||||
|
textarea.style.opacity = '0';
|
||||||
|
document.body.appendChild(textarea);
|
||||||
|
textarea.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(textarea);
|
||||||
|
showToast('已复制到剪贴板');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清空当前对话
|
||||||
|
function clearCurrentChat() {
|
||||||
|
if (!currentConversation) return;
|
||||||
|
|
||||||
|
if (confirm('确定要清空当前对话吗?')) {
|
||||||
|
currentConversation.messages = [];
|
||||||
|
currentConversation.updatedAt = Date.now();
|
||||||
|
saveConversations();
|
||||||
|
renderMessages();
|
||||||
|
welcome.style.display = 'block';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 渲染消息
|
// 渲染消息
|
||||||
function renderMessages() {
|
function renderMessages() {
|
||||||
messagesDiv.innerHTML = messages.map(msg => {
|
if (!currentConversation) return;
|
||||||
|
|
||||||
|
messagesDiv.innerHTML = currentConversation.messages.map((msg, index) => {
|
||||||
const isUser = msg.role === 'user';
|
const isUser = msg.role === 'user';
|
||||||
const avatar = isUser ? '👤' : '🤖';
|
const avatar = isUser ? '👤' : '🤖';
|
||||||
const content = formatContent(msg.content);
|
const content = renderMarkdown(msg.content);
|
||||||
|
|
||||||
|
const copyIcon = `<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>`;
|
||||||
|
|
||||||
|
const actions = isUser
|
||||||
|
? `<div class="message-actions">
|
||||||
|
<button class="action-btn copy-btn" onclick="copyMessage(${index})" title="复制">${copyIcon}</button>
|
||||||
|
<button class="action-btn delete-btn" onclick="deleteMessage(${index})" title="删除">
|
||||||
|
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/></svg>
|
||||||
|
</button>
|
||||||
|
</div>`
|
||||||
|
: `<div class="message-actions">
|
||||||
|
<button class="action-btn copy-btn" onclick="copyMessage(${index})" title="复制">${copyIcon}</button>
|
||||||
|
<button class="action-btn regenerate-btn" onclick="regenerate(${index})" title="重新生成">
|
||||||
|
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/></svg>
|
||||||
|
</button>
|
||||||
|
<button class="action-btn delete-btn" onclick="deleteMessage(${index})" title="删除">
|
||||||
|
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/></svg>
|
||||||
|
</button>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<div class="message ${msg.role}">
|
<div class="message ${msg.role}" data-index="${index}">
|
||||||
<div class="message-avatar">${avatar}</div>
|
<div class="message-avatar">${avatar}</div>
|
||||||
<div class="message-content">${content}</div>
|
<div class="message-body">
|
||||||
|
<div class="message-content">${content}</div>
|
||||||
|
${actions}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}).join('');
|
}).join('');
|
||||||
|
|
||||||
// 滚动到底部
|
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化内容(简单处理代码块)
|
// ==================== 工具函数 ====================
|
||||||
function formatContent(text) {
|
|
||||||
|
// 渲染 Markdown
|
||||||
|
function renderMarkdown(text) {
|
||||||
if (!text) return '';
|
if (!text) return '';
|
||||||
|
|
||||||
// 处理代码块
|
marked.setOptions({
|
||||||
text = text.replace(/```(\w+)?\n([\s\S]*?)```/g, '<pre><code>$2</code></pre>');
|
breaks: true,
|
||||||
// 处理行内代码
|
gfm: true
|
||||||
text = text.replace(/`([^`]+)`/g, '<code>$1</code>');
|
});
|
||||||
// 处理换行
|
|
||||||
text = text.replace(/\n/g, '<br>');
|
return marked.parse(text);
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 滚动到底部
|
// 滚动到底部
|
||||||
function scrollToBottom() {
|
function scrollToBottom() {
|
||||||
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
if (messagesContainer) {
|
||||||
}
|
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
||||||
|
|
||||||
// 保存历史
|
|
||||||
function saveHistory() {
|
|
||||||
localStorage.setItem('chat_history', JSON.stringify(messages));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清空对话
|
|
||||||
function clearChat() {
|
|
||||||
if (confirm('确定要清空所有对话记录吗?')) {
|
|
||||||
messages = [];
|
|
||||||
messagesDiv.innerHTML = '';
|
|
||||||
welcome.style.display = 'block';
|
|
||||||
localStorage.removeItem('chat_history');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存对话列表
|
||||||
|
function saveConversations() {
|
||||||
|
localStorage.setItem('conversations', JSON.stringify(conversations));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示提示
|
||||||
|
function showToast(message) {
|
||||||
|
const toast = document.createElement('div');
|
||||||
|
toast.className = 'toast';
|
||||||
|
toast.textContent = message;
|
||||||
|
document.body.appendChild(toast);
|
||||||
|
|
||||||
|
setTimeout(() => toast.classList.add('show'), 10);
|
||||||
|
setTimeout(() => {
|
||||||
|
toast.classList.remove('show');
|
||||||
|
setTimeout(() => document.body.removeChild(toast), 300);
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTML转义
|
||||||
|
function escapeHtml(text) {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.textContent = text;
|
||||||
|
return div.innerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化时间
|
||||||
|
function formatTime(timestamp) {
|
||||||
|
const date = new Date(timestamp);
|
||||||
|
const now = new Date();
|
||||||
|
const diff = now - date;
|
||||||
|
|
||||||
|
if (diff < 60000) return '刚刚';
|
||||||
|
if (diff < 3600000) return Math.floor(diff / 60000) + '分钟前';
|
||||||
|
if (diff < 86400000) return Math.floor(diff / 3600000) + '小时前';
|
||||||
|
if (diff < 604800000) return Math.floor(diff / 86400000) + '天前';
|
||||||
|
|
||||||
|
return date.toLocaleDateString('zh-CN');
|
||||||
|
}
|
||||||
|
|
||||||
// PWA 注册
|
// PWA 注册
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.register('sw.js').catch(() => {});
|
navigator.serviceWorker.register('sw.js').catch(() => {});
|
||||||
|
|||||||
@@ -9,52 +9,8 @@
|
|||||||
<link rel="manifest" href="manifest.json">
|
<link rel="manifest" href="manifest.json">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app"></div>
|
||||||
<!-- 头部 -->
|
<script src="marked.min.js"></script>
|
||||||
<header class="header">
|
|
||||||
<div class="header-title">
|
|
||||||
<span class="logo">🤖</span>
|
|
||||||
<h1>AI助手</h1>
|
|
||||||
</div>
|
|
||||||
<button class="clear-btn" onclick="clearChat()" title="清空对话">
|
|
||||||
<svg viewBox="0 0 24 24" width="20" height="20">
|
|
||||||
<path fill="currentColor" d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<!-- 消息区域 -->
|
|
||||||
<div class="messages-container" id="messagesContainer">
|
|
||||||
<div class="welcome" id="welcome">
|
|
||||||
<div class="welcome-icon">👋</div>
|
|
||||||
<h2>你好!我是AI助手</h2>
|
|
||||||
<p>有什么可以帮助你的吗?</p>
|
|
||||||
<div class="quick-actions">
|
|
||||||
<button onclick="sendQuickMessage('介绍一下你自己')">介绍一下你自己</button>
|
|
||||||
<button onclick="sendQuickMessage('帮我写一段代码')">帮我写代码</button>
|
|
||||||
<button onclick="sendQuickMessage('解释一个概念')">解释概念</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="messages" id="messages"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 输入区域 -->
|
|
||||||
<div class="input-area">
|
|
||||||
<textarea
|
|
||||||
id="userInput"
|
|
||||||
placeholder="输入消息..."
|
|
||||||
rows="1"
|
|
||||||
onkeydown="handleKeyDown(event)"
|
|
||||||
oninput="autoResize(this)"
|
|
||||||
></textarea>
|
|
||||||
<button class="send-btn" onclick="sendMessage()" 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>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="app.js"></script>
|
<script src="app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
69
works/ai-chat-app/www/marked.min.js
vendored
Normal file
69
works/ai-chat-app/www/marked.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -25,17 +25,155 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#app {
|
#app {
|
||||||
|
min-height: 100vh;
|
||||||
|
min-height: 100dvh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==================== 对话列表页面 ==================== */
|
||||||
|
|
||||||
|
.conversation-list-page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-height: 100vh;
|
||||||
|
min-height: 100dvh;
|
||||||
|
background: var(--card-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 12px 16px;
|
||||||
|
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
|
||||||
|
color: white;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-header .header-title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-header .logo {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-header h1 {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-content {
|
||||||
|
flex: 1;
|
||||||
|
padding: 16px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.new-chat-btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 12px 20px;
|
||||||
|
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 12px;
|
||||||
|
font-size: 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
transition: transform 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.new-chat-btn:active {
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
|
|
||||||
|
.conversation-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-list {
|
||||||
|
text-align: center;
|
||||||
|
padding: 40px;
|
||||||
|
color: var(--text-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.conversation-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 12px 16px;
|
||||||
|
background: white;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.conversation-item:hover {
|
||||||
|
border-color: var(--primary);
|
||||||
|
background: rgba(102, 126, 234, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.conversation-item:active {
|
||||||
|
background: rgba(102, 126, 234, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.conv-title {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-color);
|
||||||
|
margin-bottom: 4px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.conv-meta {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.conv-delete-btn {
|
||||||
|
position: absolute;
|
||||||
|
right: 12px;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
color: var(--text-light);
|
||||||
|
padding: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
opacity: 0;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.conversation-item:hover .conv-delete-btn {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.conv-delete-btn:hover {
|
||||||
|
color: #e53e3e;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==================== 对话页面 ==================== */
|
||||||
|
|
||||||
|
#chatPage {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
height: 100dvh; /* 移动端动态视口高度 */
|
height: 100dvh;
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
background: var(--card-bg);
|
background: var(--card-bg);
|
||||||
box-shadow: var(--shadow);
|
box-shadow: var(--shadow);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 头部 */
|
|
||||||
.header {
|
.header {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
@@ -48,19 +186,38 @@ body {
|
|||||||
z-index: 100;
|
z-index: 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.back-btn {
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
padding: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.back-btn:active {
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
.header-title {
|
.header-title {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
|
flex: 1;
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-title h1 {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo {
|
.logo {
|
||||||
font-size: 24px;
|
font-size: 20px;
|
||||||
}
|
|
||||||
|
|
||||||
.header h1 {
|
|
||||||
font-size: 18px;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.clear-btn {
|
.clear-btn {
|
||||||
@@ -70,14 +227,12 @@ body {
|
|||||||
padding: 8px;
|
padding: 8px;
|
||||||
color: white;
|
color: white;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background 0.2s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.clear-btn:active {
|
.clear-btn:active {
|
||||||
background: rgba(255,255,255,0.3);
|
background: rgba(255,255,255,0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 消息区域 */
|
|
||||||
.messages-container {
|
.messages-container {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
@@ -98,7 +253,6 @@ body {
|
|||||||
.welcome h2 {
|
.welcome h2 {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
color: var(--text-color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome p {
|
.welcome p {
|
||||||
@@ -121,7 +275,6 @@ body {
|
|||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: all 0.2s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.quick-actions button:active {
|
.quick-actions button:active {
|
||||||
@@ -172,11 +325,9 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.message-content {
|
.message-content {
|
||||||
max-width: 75%;
|
|
||||||
padding: 12px 16px;
|
padding: 12px 16px;
|
||||||
border-radius: 18px;
|
border-radius: 18px;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
white-space: pre-wrap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.message.user .message-content {
|
.message.user .message-content {
|
||||||
@@ -214,27 +365,139 @@ body {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 加载动画 */
|
.message.user .message-content pre {
|
||||||
.typing-indicator {
|
background: rgba(0,0,0,0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 流式输出光标 */
|
||||||
|
.streaming-cursor {
|
||||||
|
animation: blink 1s infinite;
|
||||||
|
color: var(--primary);
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes blink {
|
||||||
|
0%, 50% { opacity: 1; }
|
||||||
|
51%, 100% { opacity: 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 消息结构 */
|
||||||
|
.message-body {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 4px;
|
flex-direction: column;
|
||||||
padding: 8px 0;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.typing-indicator span {
|
.message.user .message-body {
|
||||||
width: 8px;
|
max-width: 85%;
|
||||||
height: 8px;
|
|
||||||
background: var(--text-light);
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: typing 1.4s infinite ease-in-out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
|
.message.assistant .message-body {
|
||||||
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
|
max-width: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes typing {
|
/* 消息操作按钮 */
|
||||||
0%, 60%, 100% { transform: translateY(0); }
|
.message-actions {
|
||||||
30% { transform: translateY(-8px); }
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message:hover .message-actions {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn {
|
||||||
|
background: transparent;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 4px 6px;
|
||||||
|
color: var(--text-light);
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn:hover {
|
||||||
|
background: var(--border-color);
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn.copy-btn:hover {
|
||||||
|
background: #dbeafe;
|
||||||
|
border-color: var(--primary);
|
||||||
|
color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn.delete-btn:hover {
|
||||||
|
background: #fee2e2;
|
||||||
|
border-color: #e53e3e;
|
||||||
|
color: #e53e3e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn.regenerate-btn:hover {
|
||||||
|
background: #dbeafe;
|
||||||
|
border-color: var(--primary);
|
||||||
|
color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Markdown 内容样式 */
|
||||||
|
.message-content h1, .message-content h2, .message-content h3 {
|
||||||
|
margin: 12px 0 8px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-content h1 { font-size: 1.3em; }
|
||||||
|
.message-content h2 { font-size: 1.2em; }
|
||||||
|
.message-content h3 { font-size: 1.1em; }
|
||||||
|
|
||||||
|
.message-content ul, .message-content ol {
|
||||||
|
margin: 8px 0;
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-content li {
|
||||||
|
margin: 4px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-content strong {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-content em {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-content a {
|
||||||
|
color: var(--primary);
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-content blockquote {
|
||||||
|
margin: 8px 0;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-left: 3px solid var(--primary);
|
||||||
|
background: rgba(102, 126, 234, 0.1);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-content table {
|
||||||
|
margin: 8px 0;
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-content th, .message-content td {
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
padding: 6px 10px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-content th {
|
||||||
|
background: var(--bg-color);
|
||||||
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 输入区域 */
|
/* 输入区域 */
|
||||||
@@ -289,31 +552,26 @@ body {
|
|||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 错误提示 */
|
/* Toast 提示 */
|
||||||
.error-msg {
|
.toast {
|
||||||
color: #e53e3e;
|
position: fixed;
|
||||||
|
top: 80px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%) translateY(-20px);
|
||||||
|
background: var(--text-color);
|
||||||
|
color: white;
|
||||||
|
padding: 12px 24px;
|
||||||
|
border-radius: 8px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
text-align: center;
|
opacity: 0;
|
||||||
padding: 8px;
|
transition: all 0.3s ease;
|
||||||
|
z-index: 1000;
|
||||||
|
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 流式输出光标 */
|
.toast.show {
|
||||||
.streaming-cursor {
|
opacity: 1;
|
||||||
animation: blink 1s infinite;
|
transform: translateX(-50%) translateY(0);
|
||||||
color: var(--primary);
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes blink {
|
|
||||||
0%, 50% { opacity: 1; }
|
|
||||||
51%, 100% { opacity: 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 响应式 */
|
|
||||||
@media (min-width: 768px) {
|
|
||||||
.message-content {
|
|
||||||
max-width: 60%;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 安全区域适配(刘海屏) */
|
/* 安全区域适配(刘海屏) */
|
||||||
|
|||||||
Reference in New Issue
Block a user