基本功能完成
This commit is contained in:
@@ -61,7 +61,7 @@
|
||||
.msg-bubble code { background: #f0f0f0; padding: 2px 4px; border-radius: 3px; font-size: 14px; }
|
||||
|
||||
.input-area { padding: 8px 12px; border-top: 1px solid #eee; display: flex; align-items: center; background: #fff; gap: 8px; }
|
||||
.input-area textarea { flex: 1; border: 1px solid #ddd; border-radius: 12px; padding: 10px 12px; font-size: 16px; outline: none; resize: none; height: 40px; line-height: 1.4; }
|
||||
.input-area textarea { flex: 1; border: 1px solid #ddd; border-radius: 12px; padding: 10px 12px; font-size: 16px; outline: none; resize: none; min-height: 40px; max-height: 120px; overflow-y: hidden; line-height: 1.4; }
|
||||
.file-upload-btn { background: none; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 4px; }
|
||||
.file-upload-btn svg { width: 24px; height: 24px; stroke: #666; fill: none; stroke-width: 2; }
|
||||
.send-btn { background: #3b82f6; border: none; color: #fff; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
|
||||
@@ -124,7 +124,7 @@
|
||||
<input type="password" id="login-pass" placeholder="密码">
|
||||
<button class="primary-btn" onclick="login()" style="width:100%;">登录</button>
|
||||
<p id="login-error" style="color:red; margin-top:8px;"></p>
|
||||
<div class="version">v2.4</div>
|
||||
<div class="version">v2.5</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -235,6 +235,7 @@
|
||||
let pendingUploads = [];
|
||||
const messagesContainer = document.getElementById('messages-container');
|
||||
let messageCache = [];
|
||||
let tempBubbleTimer = null;
|
||||
|
||||
function getToken() { return localStorage.getItem('token'); }
|
||||
function saveAuth(data) {
|
||||
@@ -248,9 +249,7 @@
|
||||
localStorage.removeItem('isAdmin');
|
||||
}
|
||||
|
||||
if (typeof marked !== 'undefined') {
|
||||
marked.setOptions({ breaks: true, gfm: true, sanitize: false });
|
||||
}
|
||||
if (typeof marked !== 'undefined') marked.setOptions({ breaks: true, gfm: true, sanitize: false });
|
||||
|
||||
function compressImage(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -317,6 +316,7 @@
|
||||
messagesContainer.insertAdjacentHTML('beforeend', renderMessageHTML(msg));
|
||||
scrollToBottom();
|
||||
bindMessageEvents();
|
||||
clearTempBubble(); // 收到新消息时移除气泡
|
||||
}
|
||||
|
||||
function replaceMessage(msgId, newMsg) {
|
||||
@@ -367,6 +367,24 @@
|
||||
document.body.appendChild(overlay);
|
||||
}
|
||||
|
||||
// 临时“输入中...”气泡
|
||||
function insertTempBubble() {
|
||||
clearTempBubble();
|
||||
const tempId = 'temp_' + Date.now();
|
||||
const tempMsg = { id: tempId, user: '小财', text: '输入中...', attachments: [], timestamp: '', isTemp: true };
|
||||
messageCache.push(tempMsg);
|
||||
messagesContainer.insertAdjacentHTML('beforeend', renderMessageHTML(tempMsg));
|
||||
scrollToBottom();
|
||||
tempBubbleTimer = setTimeout(() => { clearTempBubble(); }, 8000);
|
||||
}
|
||||
|
||||
function clearTempBubble() {
|
||||
if (tempBubbleTimer) { clearTimeout(tempBubbleTimer); tempBubbleTimer = null; }
|
||||
messageCache = messageCache.filter(m => !m.isTemp);
|
||||
const tempEls = messagesContainer.querySelectorAll('[data-msg-id^="temp_"]');
|
||||
tempEls.forEach(el => el.remove());
|
||||
}
|
||||
|
||||
// WebSocket 重连
|
||||
let wsReconnectTimer = null;
|
||||
let reconnectAttempts = 0;
|
||||
@@ -386,7 +404,9 @@
|
||||
const data = JSON.parse(e.data);
|
||||
if (data.type === 'new_message') {
|
||||
const msg = data.message;
|
||||
if (currentRoom === msg.room_id) appendMessage(msg);
|
||||
if (currentRoom === msg.room_id) {
|
||||
appendMessage(msg);
|
||||
}
|
||||
if (data.room_preview) {
|
||||
const room = rooms.find(r => r.id === data.room_preview.room_id);
|
||||
if (room) { room.last_message = data.room_preview.last_message; room.last_time = data.room_preview.last_time; renderChatList(); }
|
||||
@@ -565,6 +585,7 @@
|
||||
|
||||
async function openChat(roomId, autoOpenPurchase = false) {
|
||||
currentRoom = roomId;
|
||||
clearTempBubble();
|
||||
document.getElementById('list-page').classList.add('hidden');
|
||||
document.getElementById('chat-page').classList.remove('hidden');
|
||||
const room = rooms.find(r => r.id === roomId);
|
||||
@@ -579,6 +600,7 @@
|
||||
}
|
||||
|
||||
function showList() {
|
||||
clearTempBubble();
|
||||
document.getElementById('chat-page').classList.add('hidden');
|
||||
document.getElementById('list-page').classList.remove('hidden');
|
||||
currentRoom = null;
|
||||
@@ -602,6 +624,7 @@
|
||||
appendMessage(newMsg);
|
||||
input.value = '';
|
||||
pendingUploads = [];
|
||||
insertTempBubble(); // 显示“输入中...”
|
||||
} catch(e) { alert('发送失败,请重试'); }
|
||||
}
|
||||
|
||||
@@ -778,6 +801,13 @@
|
||||
} else { const err = await res.json(); alert(err.error || '删除失败'); }
|
||||
}
|
||||
|
||||
document.addEventListener('input', function(e) {
|
||||
if (e.target.id === 'msg-input') {
|
||||
e.target.style.height = 'auto';
|
||||
e.target.style.height = e.target.scrollHeight + 'px';
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.target.id === 'msg-input' && e.key === 'Enter' && !e.ctrlKey) { e.preventDefault(); sendMessage(); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user