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

This commit is contained in:
张梦南 2025-04-05 22:17:52 +08:00
parent 0ff8fc158f
commit df0830a2ad
9 changed files with 279 additions and 68 deletions

View File

@ -1,32 +1,43 @@
/* 基本样式重置 */ body {
body, html {
margin: 0; margin: 0;
padding: 0; font-family: "Arial", sans-serif;
font-family: Arial, sans-serif; /* 默认字体 */
background-color:#f4f4f4;
} }
/*主内容区test*/ .main-layout {
.container { display: flex;
width: 60%; flex-direction: row;
margin: 4% auto 0; height: calc(100vh - 100px);
background-color: #f0f0f0; padding-bottom: 100px;
padding: 2% 5%;
border-radius: 10px
} }
ul { .left-panel, .right-panel {
padding-left: 20px; width: 50%;
display: flex;
justify-content: center; /* 水平居中 */
align-items: center; /* 垂直居中 */
flex-direction: column; /* 内容垂直排列 */
padding: 20px;
box-sizing: border-box;
height: 100%;
} }
ul li { .logo {
line-height: 2.3 margin-top: 40px;
} font-size: 32px;
}
a { .intro a {
color: #20a53a display: block;
margin: 5px 0;
} }
.logo { .logo {
font-family: 'Pacifico', cursive; font-family: 'Pacifico', cursive;
} }
/* 默认隐藏 */
.mobile-toggle {
display: none;
margin: 10px;
text-align: center;
}

View File

@ -1,27 +1,84 @@
/* 简单样式,仅用于展示 */ .chat-container {
#chatContainer { position: fixed;
border: 1px solid #ccc; bottom: 50px;
left: 0;
width: 100%;
background: #fff;
padding: 10px; padding: 10px;
height: 50px; box-shadow: 0 -2px 5px #fff;
display: flex;
flex-direction: column;
align-items: center;
}
.chat-box {
width: 90%;
max-height: 50vh;
overflow-y: auto; overflow-y: auto;
background: #f5f5f5;
margin-bottom: 10px; margin-bottom: 10px;
padding: 10px;
border-radius: 8px;
position: relative;
z-index: 10;
} }
.message { .chat-box.show {
margin: 5px 0; animation: slideUp 0.3s ease-out forwards;
padding: 5px;
} }
.user { .chat-box.hide {
color: blue; animation: slideDown 0.3s ease-in forwards;
text-align: right;
} }
.bot {
color: green; .input-row {
text-align: left; display: flex;
justify-content: center;
width: 90%;
gap: 10px;
} }
#userInput { #userInput {
width: 93%; flex: 1;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 6px;
}
button {
padding: 10px 16px;
font-size: 16px;
border: none;
background-color: #007BFF;
color: white;
border-radius: 6px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
@keyframes slideUp {
from {
transform: translateY(100%);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
@keyframes slideDown {
from {
transform: translateY(0);
opacity: 1;
}
to {
transform: translateY(100%);
opacity: 0;
}
} }

View File

@ -0,0 +1,37 @@
@media screen and (max-width: 768px) {
.main-layout {
flex-direction: column;
}
.left-panel, .right-panel {
width: 100%;
display: none;
}
.chat-container {
bottom: 0;
}
footer {
padding-bottom: 60px;
}
.mobile-toggle {
display: block;
}
.mobile-toggle button {
margin: 0 5px;
padding: 8px 16px;
font-size: 14px;
border: none;
background-color: #007BFF;
color: white;
border-radius: 4px;
cursor: pointer;
}
.mobile-toggle button:hover {
background-color: #0056b3;
}
}

16
css/time.css Normal file
View File

@ -0,0 +1,16 @@
.datetime {
text-align: center;
margin-bottom: 20px;
}
.time {
font-size: 36px;
font-weight: bold;
color: #333;
}
.date {
font-size: 16px;
color: #666;
margin-top: 5px;
}

View File

@ -8,30 +8,54 @@
<link rel="stylesheet" href="css/body.css"> <link rel="stylesheet" href="css/body.css">
<link rel="stylesheet" href="css/chat.css"> <link rel="stylesheet" href="css/chat.css">
<link rel="stylesheet" href="css/font.css"> <link rel="stylesheet" href="css/font.css">
<link rel="stylesheet" href="css/time.css">
<link rel="stylesheet" href="css/max_width.css">
</head> </head>
<body> <body>
<div class="main-layout">
<!-- 左侧内容 -->
<div class="left-panel">
<h1 class="logo">DreamLife</h1>
<div class="intro">
<h3>这是我的网站首页,主页代码正在完善中</h3>
<ul>
<li>此网站将用于个人经历展示,个人技术分析</li>
<li>目前网站工具箱以基本完善</li>
<li>工具箱网站dreamlife.top/toolbox</li>
</ul>
<a href="http://dreamlife.top/toolbox/">ToolBox</a>
<a href="http://dreamlife.top:8080/">博客|WordPress</a>
<a href="http://dreamlife.top:13000/explore/">Gitea</a>
</div>
</div>
<div class="container"> <!-- 右侧内容 -->
<h1 class="logo">DreamLife</h1> <div class="right-panel">
<h3>这是我的网站首页,主页代码正在完善中</h3> <div class="datetime">
<ul> <div id="timeDisplay" class="time">--:--:--</div>
<li>此网站将用于个人经历展示,个人技术分析</li> <div id="dateDisplay" class="date">加载中...</div>
<li>目前网站工具箱以基本完善</li> </div>
<li>工具箱网站dreamlife.top/toolbox</li> <div class="future-content">
</ul> <p>此处预留未来内容</p>
</div>
</div>
</div>
<a href="http://dreamlife.top/toolbox/">ToolBox</a> <!-- 移动端切换按钮 -->
<a href="http://dreamlife.top:8080/">博客|WordPress</a> <div class="mobile-toggle">
<a href="http://dreamlife.top:13000/explore/">Gitea</a> <button onclick="showLeft()">显示左侧</button>
<button onclick="showRight()">显示右侧</button>
</div>
<h2>您的当前区域时间</h2> <!-- DeepSeek 聊天输入 -->
<p id="timeDisplay">加载中...</p> <div class="chat-container">
<div id="chatContainer" class="chat-box hide"></div>
<h1>DeepSeek 聊天界面</h1> <div class="input-row">
<div id="chatContainer"></div> <input type="text" id="userInput" placeholder="输入你的消息..." onfocus="toggleChat(true)">
<input type="text" id="userInput" placeholder="输入你的消息..."> <button onclick="sendMessage()">发送</button>
<button onclick="sendMessage()">发送</button> </div>
</div> </div>
<footer> <footer>
@ -40,6 +64,8 @@
<script src="javascape/time.js"></script> <script src="javascape/time.js"></script>
<script src="javascape/ai_api.js"></script> <script src="javascape/ai_api.js"></script>
<script src="javascape/chat.js"></script>
<script src="javascape/max_width.js"></script>
</body> </body>
</html> </html>

View File

@ -1,3 +1,4 @@
// Ai模型接口
const API_KEY = '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'; const API_KEY = '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';
const API_URL = 'https://openrouter.ai/api/v1/chat/completions'; const API_URL = 'https://openrouter.ai/api/v1/chat/completions';
let messages = []; let messages = [];
@ -48,10 +49,3 @@ async function sendMessage() {
appendMessage('请求出错:' + error.message, 'bot'); appendMessage('请求出错:' + error.message, 'bot');
} }
} }
// 监听回车键事件
document.getElementById('userInput').addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
sendMessage();
}
});

43
javascape/chat.js Normal file
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
javascape/max_width.js Normal file
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';
}

View File

@ -1,9 +1,26 @@
//获取计算机的时间信息 //获取计算机的时间信息
function updateLocalTime() { function updateLocalTime() {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const now = new Date().toLocaleString('zh-CN', { timeZone: timezone }); const now = new Date();
document.getElementById('timeDisplay').innerText = `当前时间 (${timezone}): ${now}`;
// 获取时间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; window.onload = updateLocalTime;