修改界面为左右布局、修改聊天框样式、添加部分动效

This commit is contained in:
Cx330 committed 2025-04-05 22:17:52 +08:00
1 parent 0ff8fc158f
commit df0830a2ad
9 files changed
+279 -68

No files matched your search

+2 -8
View File
@@ -1,3 +1,4 @@
// Ai模型接口
const API_KEY = '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';
const API_URL = 'https://openrouter.ai/api/v1/chat/completions';
let messages = [];
@@ -47,11 +48,4 @@ async function sendMessage() {
console.error('请求错误:', error);
appendMessage('请求出错:' + error.message, 'bot');
}
}
// 监听回车键事件
document.getElementById('userInput').addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
sendMessage();
}
});
}
+43
View File
@@ -0,0 +1,43 @@
// 监听回车键事件
document.getElementById('userInput').addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
sendMessage();
}
});
// 控制聊天框显示和隐藏
function toggleChat(show) {
const chatBox = document.getElementById('chatContainer');
if (show) {
// 如果已经显示就不重复处理
if (chatBox.classList.contains('show')) return;
chatBox.style.display = 'block'; // 确保先显示再动画
chatBox.classList.remove('hide');
chatBox.classList.add('show');
document.addEventListener('click', outsideClickListener);
} else {
if (!chatBox.classList.contains('show')) return;
chatBox.classList.remove('show');
chatBox.classList.add('hide');
chatBox.addEventListener('animationend', function handler() {
chatBox.style.display = 'none';
chatBox.removeEventListener('animationend', handler);
});
document.removeEventListener('click', outsideClickListener);
}
}
function outsideClickListener(event) {
const chatBox = document.getElementById('chatContainer');
const inputBox = document.getElementById('userInput');
if (!chatBox.contains(event.target) && !inputBox.contains(event.target)) {
toggleChat(false);
}
}
+10
View File
@@ -0,0 +1,10 @@
// 移动端切换
function showLeft() {
document.querySelector('.left-panel').style.display = 'block';
document.querySelector('.right-panel').style.display = 'none';
}
function showRight() {
document.querySelector('.right-panel').style.display = 'block';
document.querySelector('.left-panel').style.display = 'none';
}
+20 -3
View File
@@ -1,9 +1,26 @@
//获取计算机的时间信息
function updateLocalTime() {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const now = new Date().toLocaleString('zh-CN', { timeZone: timezone });
document.getElementById('timeDisplay').innerText = `当前时间 (${timezone}): ${now}`;
const now = new Date();
// 获取时间(24小时制)
const timeStr = now.toLocaleTimeString('zh-CN', {
timeZone: timezone,
hour12: false
});
// 获取日期
const dateStr = now.toLocaleDateString('zh-CN', {
timeZone: timezone,
year: 'numeric',
month: 'long',
day: 'numeric',
weekday: 'long'
});
document.getElementById('timeDisplay').innerText = timeStr;
document.getElementById('dateDisplay').innerText = dateStr;
}
setInterval(updateLocalTime, 1000); // 每秒更新时间
setInterval(updateLocalTime, 1000);
window.onload = updateLocalTime;