main
parent
e08f5aa532
commit
74027cfc7b
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,299 @@
|
||||
// 全局变量
|
||||
let ws = null;
|
||||
let username = null;
|
||||
let currentChat = null;
|
||||
let serverAddress = 'localhost:8080';
|
||||
|
||||
// 登录函数
|
||||
function login() {
|
||||
const usernameInput = document.getElementById('usernameInput');
|
||||
const serverInput = document.getElementById('serverInput');
|
||||
|
||||
username = usernameInput.value.trim();
|
||||
if (!username) {
|
||||
alert('请输入用户名');
|
||||
usernameInput.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取服务器地址
|
||||
const serverValue = serverInput.value.trim();
|
||||
if (serverValue) {
|
||||
serverAddress = serverValue;
|
||||
}
|
||||
|
||||
// 连接WebSocket
|
||||
connectWebSocket();
|
||||
}
|
||||
|
||||
// 连接WebSocket
|
||||
function connectWebSocket() {
|
||||
try {
|
||||
// 构建WebSocket URL
|
||||
const wsUrl = `ws://${serverAddress}`;
|
||||
console.log('连接到:', wsUrl);
|
||||
|
||||
ws = new WebSocket(wsUrl);
|
||||
|
||||
ws.onopen = () => {
|
||||
console.log('WebSocket连接成功');
|
||||
|
||||
// 发送登录消息
|
||||
const loginMsg = {
|
||||
type: 'LOGIN',
|
||||
sender: username
|
||||
};
|
||||
ws.send(JSON.stringify(loginMsg));
|
||||
|
||||
// 切换到聊天界面
|
||||
document.getElementById('loginModal').classList.add('hidden');
|
||||
document.getElementById('chatContainer').classList.remove('hidden');
|
||||
document.getElementById('currentUser').textContent = username;
|
||||
};
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
console.log('收到消息:', event.data);
|
||||
try {
|
||||
const message = JSON.parse(event.data);
|
||||
handleMessage(message);
|
||||
} catch (e) {
|
||||
console.error('解析消息失败:', e);
|
||||
}
|
||||
};
|
||||
|
||||
ws.onerror = (error) => {
|
||||
console.error('WebSocket错误:', error);
|
||||
alert('连接失败,请检查服务器地址是否正确');
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
console.log('WebSocket连接关闭');
|
||||
if (document.getElementById('chatContainer').classList.contains('hidden')) {
|
||||
alert('无法连接到服务器');
|
||||
} else {
|
||||
alert('连接已断开');
|
||||
logout();
|
||||
}
|
||||
};
|
||||
} catch (e) {
|
||||
console.error('创建WebSocket失败:', e);
|
||||
alert('连接失败: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理接收到的消息
|
||||
function handleMessage(message) {
|
||||
switch (message.type) {
|
||||
case 'ACK':
|
||||
console.log('服务器确认:', message.content);
|
||||
break;
|
||||
|
||||
case 'USER_LIST':
|
||||
updateUserList(message.users);
|
||||
break;
|
||||
|
||||
case 'PRIVATE_MSG':
|
||||
displayMessage(message, false);
|
||||
break;
|
||||
|
||||
case 'ERROR':
|
||||
alert('错误: ' + message.content);
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log('未知消息类型:', message.type);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新用户列表
|
||||
function updateUserList(users) {
|
||||
const userList = document.getElementById('userList');
|
||||
userList.innerHTML = '';
|
||||
|
||||
// 过滤掉自己
|
||||
const otherUsers = users.filter(u => u !== username);
|
||||
|
||||
if (otherUsers.length === 0) {
|
||||
userList.innerHTML = '<div class="empty-users">暂无其他用户在线</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
otherUsers.forEach(user => {
|
||||
const userItem = document.createElement('div');
|
||||
userItem.className = 'user-item';
|
||||
if (user === currentChat) {
|
||||
userItem.classList.add('active');
|
||||
}
|
||||
|
||||
userItem.innerHTML = `
|
||||
<span class="status"></span>
|
||||
<span>${escapeHtml(user)}</span>
|
||||
`;
|
||||
|
||||
userItem.onclick = () => selectUser(user);
|
||||
userList.appendChild(userItem);
|
||||
});
|
||||
}
|
||||
|
||||
// 选择聊天用户
|
||||
function selectUser(user) {
|
||||
currentChat = user;
|
||||
|
||||
// 更新标题
|
||||
document.getElementById('chatTitle').textContent = `与 ${user} 聊天`;
|
||||
|
||||
// 启用输入框
|
||||
const messageInput = document.getElementById('messageInput');
|
||||
const sendBtn = document.getElementById('sendBtn');
|
||||
messageInput.disabled = false;
|
||||
sendBtn.disabled = false;
|
||||
messageInput.focus();
|
||||
|
||||
// 更新用户列表选中状态
|
||||
document.querySelectorAll('.user-item').forEach(item => {
|
||||
const itemText = item.textContent.trim();
|
||||
item.classList.toggle('active', itemText === user);
|
||||
});
|
||||
|
||||
// 移除欢迎屏幕
|
||||
const welcomeScreen = document.querySelector('.welcome-screen');
|
||||
if (welcomeScreen) {
|
||||
welcomeScreen.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// 发送消息
|
||||
function sendMessage() {
|
||||
const messageInput = document.getElementById('messageInput');
|
||||
const content = messageInput.value.trim();
|
||||
|
||||
if (!content) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentChat) {
|
||||
alert('请先选择聊天对象');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
||||
alert('连接已断开,请重新登录');
|
||||
return;
|
||||
}
|
||||
|
||||
// 发送消息到服务器
|
||||
const message = {
|
||||
type: 'PRIVATE_MSG',
|
||||
sender: username,
|
||||
receiver: currentChat,
|
||||
content: content
|
||||
};
|
||||
|
||||
ws.send(JSON.stringify(message));
|
||||
|
||||
// 显示发送的消息
|
||||
displayMessage({
|
||||
sender: username,
|
||||
content: content,
|
||||
timestamp: Date.now()
|
||||
}, true);
|
||||
|
||||
// 清空输入框
|
||||
messageInput.value = '';
|
||||
messageInput.focus();
|
||||
}
|
||||
|
||||
// 显示消息
|
||||
function displayMessage(message, isSent) {
|
||||
// 只显示与当前聊天对象相关的消息
|
||||
if (!isSent && message.sender !== currentChat && message.receiver !== currentChat) {
|
||||
return;
|
||||
}
|
||||
|
||||
const messagesDiv = document.getElementById('messages');
|
||||
|
||||
// 创建消息元素
|
||||
const messageDiv = document.createElement('div');
|
||||
messageDiv.className = `message ${isSent ? 'sent' : 'received'}`;
|
||||
|
||||
const time = new Date(message.timestamp).toLocaleTimeString('zh-CN', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
|
||||
messageDiv.innerHTML = `
|
||||
<div class="message-content">
|
||||
<div class="message-text">${escapeHtml(message.content)}</div>
|
||||
<div class="message-info">${time}</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
messagesDiv.appendChild(messageDiv);
|
||||
|
||||
// 滚动到底部
|
||||
messageDiv.scrollIntoView({ behavior: 'smooth', block: 'end' });
|
||||
}
|
||||
|
||||
// 退出登录
|
||||
function logout() {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
const logoutMsg = {
|
||||
type: 'LOGOUT',
|
||||
sender: username
|
||||
};
|
||||
ws.send(JSON.stringify(logoutMsg));
|
||||
ws.close();
|
||||
}
|
||||
|
||||
// 重置状态
|
||||
ws = null;
|
||||
username = null;
|
||||
currentChat = null;
|
||||
|
||||
// 切换到登录界面
|
||||
document.getElementById('chatContainer').classList.add('hidden');
|
||||
document.getElementById('loginModal').classList.remove('hidden');
|
||||
|
||||
// 清空输入
|
||||
document.getElementById('usernameInput').value = '';
|
||||
document.getElementById('messageInput').value = '';
|
||||
|
||||
// 清空消息
|
||||
const messagesDiv = document.getElementById('messages');
|
||||
messagesDiv.innerHTML = `
|
||||
<div class="welcome-screen">
|
||||
<div class="welcome-icon">💬</div>
|
||||
<p>选择左侧用户开始聊天</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// HTML转义函数
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// 回车发送消息
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const messageInput = document.getElementById('messageInput');
|
||||
const usernameInput = document.getElementById('usernameInput');
|
||||
|
||||
messageInput.addEventListener('keypress', (e) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
sendMessage();
|
||||
}
|
||||
});
|
||||
|
||||
usernameInput.addEventListener('keypress', (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
login();
|
||||
}
|
||||
});
|
||||
|
||||
// 自动聚焦用户名输入框
|
||||
usernameInput.focus();
|
||||
});
|
||||
@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>TCP点对点聊天系统</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 登录界面 -->
|
||||
<div class="login-modal" id="loginModal">
|
||||
<div class="login-box">
|
||||
<h2>🚀 欢迎使用聊天系统</h2>
|
||||
<p class="login-desc">请输入您的用户名开始聊天</p>
|
||||
<input type="text" id="usernameInput" placeholder="请输入用户名" maxlength="20" autocomplete="off">
|
||||
<input type="text" id="serverInput" placeholder="服务器地址 (默认: localhost:8080)" autocomplete="off">
|
||||
<button onclick="login()">登录</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 聊天主界面 -->
|
||||
<div class="container hidden" id="chatContainer">
|
||||
<div class="sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h2>💬 在线用户</h2>
|
||||
<div class="current-user">
|
||||
<span class="status-dot"></span>
|
||||
<span id="currentUser"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="user-list" id="userList">
|
||||
<div class="empty-users">暂无其他用户在线</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chat-area">
|
||||
<div class="chat-header">
|
||||
<h3 id="chatTitle">选择用户开始聊天</h3>
|
||||
<button class="logout-btn" onclick="logout()">退出</button>
|
||||
</div>
|
||||
|
||||
<div class="messages" id="messages">
|
||||
<div class="welcome-screen">
|
||||
<div class="welcome-icon">💬</div>
|
||||
<p>选择左侧用户开始聊天</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-area">
|
||||
<input
|
||||
type="text"
|
||||
id="messageInput"
|
||||
placeholder="输入消息..."
|
||||
disabled
|
||||
autocomplete="off"
|
||||
maxlength="500">
|
||||
<button onclick="sendMessage()" id="sendBtn" disabled>
|
||||
<span>发送</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,505 @@
|
||||
/* 全局样式 */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
/* 登录界面 */
|
||||
.login-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
backdrop-filter: blur(5px);
|
||||
}
|
||||
|
||||
.login-box {
|
||||
background: white;
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
text-align: center;
|
||||
min-width: 350px;
|
||||
max-width: 90%;
|
||||
animation: fadeInUp 0.5s;
|
||||
}
|
||||
|
||||
.login-box h2 {
|
||||
margin-bottom: 10px;
|
||||
color: #333;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.login-desc {
|
||||
color: #666;
|
||||
margin-bottom: 30px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.login-box input {
|
||||
width: 100%;
|
||||
padding: 14px 16px;
|
||||
margin: 10px 0;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 10px;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.login-box input:focus {
|
||||
border-color: #667eea;
|
||||
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
||||
}
|
||||
|
||||
.login-box button {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
margin-top: 20px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.login-box button:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.login-box button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
/* 主容器 */
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: 1400px;
|
||||
height: 85vh;
|
||||
min-height: 600px;
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
animation: fadeIn 0.5s;
|
||||
}
|
||||
|
||||
/* 侧边栏 */
|
||||
.sidebar {
|
||||
width: 300px;
|
||||
background: #f8f9fa;
|
||||
border-right: 1px solid #e0e0e0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 25px 20px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.sidebar-header h2 {
|
||||
font-size: 18px;
|
||||
margin-bottom: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.current-user {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 14px;
|
||||
opacity: 0.95;
|
||||
padding: 8px 12px;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
background: #4caf50;
|
||||
border-radius: 50%;
|
||||
margin-right: 10px;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
/* 用户列表 */
|
||||
.user-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.empty-users {
|
||||
text-align: center;
|
||||
color: #999;
|
||||
padding: 40px 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.user-item {
|
||||
padding: 14px 16px;
|
||||
margin: 8px 0;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.user-item:hover {
|
||||
background: #e3f2fd;
|
||||
transform: translateX(5px);
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.user-item.active {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.user-item .status {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
background: #4caf50;
|
||||
border-radius: 50%;
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
.user-item.active .status {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
/* 聊天区域 */
|
||||
.chat-area {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.chat-header {
|
||||
padding: 20px 25px;
|
||||
background: white;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.chat-header h3 {
|
||||
font-size: 18px;
|
||||
color: #333;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
padding: 8px 20px;
|
||||
background: #f44336;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.logout-btn:hover {
|
||||
background: #d32f2f;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
/* 消息区域 */
|
||||
.messages {
|
||||
flex: 1;
|
||||
padding: 25px;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.welcome-screen {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.welcome-icon {
|
||||
font-size: 80px;
|
||||
margin-bottom: 20px;
|
||||
animation: bounce 2s infinite;
|
||||
}
|
||||
|
||||
.welcome-screen p {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
/* 消息样式 */
|
||||
.message {
|
||||
margin: 12px 0;
|
||||
display: flex;
|
||||
animation: slideIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
.message.sent {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.message.received {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
max-width: 65%;
|
||||
padding: 12px 16px;
|
||||
border-radius: 18px;
|
||||
word-wrap: break-word;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.message.received .message-content {
|
||||
background: white;
|
||||
color: #333;
|
||||
border-bottom-left-radius: 4px;
|
||||
}
|
||||
|
||||
.message.sent .message-content {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
|
||||
.message-text {
|
||||
font-size: 15px;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.message-info {
|
||||
font-size: 11px;
|
||||
opacity: 0.7;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* 输入区域 */
|
||||
.input-area {
|
||||
padding: 20px 25px;
|
||||
background: white;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.input-area input {
|
||||
flex: 1;
|
||||
padding: 14px 18px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 25px;
|
||||
font-size: 15px;
|
||||
outline: none;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.input-area input:focus {
|
||||
border-color: #667eea;
|
||||
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
||||
}
|
||||
|
||||
.input-area input:disabled {
|
||||
background: #f5f5f5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.input-area button {
|
||||
padding: 14px 32px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
transition: all 0.3s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.input-area button:hover:not(:disabled) {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 8px 16px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.input-area button:active:not(:disabled) {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.input-area button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* 滚动条样式 */
|
||||
.user-list::-webkit-scrollbar,
|
||||
.messages::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.user-list::-webkit-scrollbar-track,
|
||||
.messages::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.user-list::-webkit-scrollbar-thumb,
|
||||
.messages::-webkit-scrollbar-thumb {
|
||||
background: #ccc;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.user-list::-webkit-scrollbar-thumb:hover,
|
||||
.messages::-webkit-scrollbar-thumb:hover {
|
||||
background: #999;
|
||||
}
|
||||
|
||||
/* 工具类 */
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* 动画 */
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(0.95);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeInUp {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(20px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes bounce {
|
||||
0%, 100% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
body {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
height: 100vh;
|
||||
border-radius: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
.login-box {
|
||||
min-width: 300px;
|
||||
padding: 30px 25px;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
max-width: 80%;
|
||||
}
|
||||
|
||||
.input-area {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.input-area button {
|
||||
padding: 14px 24px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.sidebar {
|
||||
position: absolute;
|
||||
left: -250px;
|
||||
height: 100%;
|
||||
z-index: 100;
|
||||
transition: left 0.3s;
|
||||
}
|
||||
|
||||
.sidebar.show {
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.chat-header h3 {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
padding: 6px 16px;
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue