From 751cc8dc24bc15c5a312875315ef7cadb9885f4f Mon Sep 17 00:00:00 2001 From: limuxi <1251316345@qq.com> Date: Tue, 10 Mar 2026 13:19:48 +0800 Subject: [PATCH] mobile chat themes --- templates/chat.html | 66 ++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/templates/chat.html b/templates/chat.html index f410423..1a0e98d 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -375,7 +375,7 @@ function switchTab(tab) { notifPanel.classList.remove('hidden'); tabChat.className = 'flex-1 px-3 py-2.5 text-sm font-medium text-slate-400 border-b-2 border-transparent hover:text-slate-600'; tabNotif.className = 'flex-1 px-3 py-2.5 text-sm font-medium text-primary border-b-2 border-primary relative'; - loadNotifications(); + loadChatNotifications(); // Mark all notifications as read when switching to the notification tab fetch('/api/notifications/read-all', { method: 'POST' }).then(() => { @@ -388,7 +388,7 @@ function switchTab(tab) { } } -async function loadNotifications() { +async function loadChatNotifications() { const res = await fetch('/api/notifications'); const data = await res.json(); if (data.success) { @@ -428,20 +428,20 @@ function renderNotifications() { let actionsHtml = ''; if (isPendingContest && currentUser.role === 'admin') { actionsHtml = `
- - + +
`; } if (isPendingTeacher && currentUser.role === 'admin' && n.application_id) { actionsHtml = `
- - + +
`; } if (isPendingFriend && n.friend_request_id) { actionsHtml = `
- - + +
`; } return `
@@ -470,65 +470,65 @@ async function markNotifRead(nid, el) { } } -async function approveContest(appId) { +async function chatApproveContest(appId) { if (!confirm('确定批准该杯赛申请?')) return; const res = await fetch(`/api/contest-applications/${appId}/approve`, { method: 'POST' }); const data = await res.json(); if (data.success) { - loadNotifications(); + loadChatNotifications(); } else { alert(data.message || '操作失败'); } } -async function rejectContest(appId) { +async function chatRejectContest(appId) { if (!confirm('确定拒绝该杯赛申请?')) return; const res = await fetch(`/api/contest-applications/${appId}/reject`, { method: 'POST' }); const data = await res.json(); if (data.success) { - loadNotifications(); + loadChatNotifications(); } else { alert(data.message || '操作失败'); } } -async function approveTeacher(appId) { +async function chatApproveTeacher(appId) { if (!confirm('确定批准该教师申请?')) return; const res = await fetch(`/api/teacher-applications/${appId}/approve`, { method: 'POST' }); const data = await res.json(); if (data.success) { - loadNotifications(); + loadChatNotifications(); } else { alert(data.message || '操作失败'); } } -async function rejectTeacher(appId) { +async function chatRejectTeacher(appId) { if (!confirm('确定拒绝该教师申请?')) return; const res = await fetch(`/api/teacher-applications/${appId}/reject`, { method: 'POST' }); const data = await res.json(); if (data.success) { - loadNotifications(); + loadChatNotifications(); } else { alert(data.message || '操作失败'); } } -async function acceptFriendReq(reqId, notifId) { +async function chatAcceptFriendReq(reqId, notifId) { const res = await fetch(`/api/friend/accept/${reqId}`, { method: 'POST' }); const data = await res.json(); if (data.success) { - loadNotifications(); + loadChatNotifications(); } else { alert(data.message || '操作失败'); } } -async function rejectFriendReq(reqId, notifId) { +async function chatRejectFriendReq(reqId, notifId) { const res = await fetch(`/api/friend/reject/${reqId}`, { method: 'POST' }); const data = await res.json(); if (data.success) { - loadNotifications(); + loadChatNotifications(); } else { alert(data.message || '操作失败'); } @@ -606,13 +606,13 @@ function showNotifDetail(nid) { let actHtml = ''; if (n.type === 'contest_application' && n.application_status === 'pending' && n.post_id && currentUser.role === 'admin') { actHtml = `
- - + +
`; } else if (n.type === 'teacher_application' && n.application_status === 'pending' && n.application_id && currentUser.role === 'admin') { actHtml = `
- - + +
`; } else if (n.type === 'exam_submission' && n.exam_id && n.submission_id) { actHtml = ` @@ -623,8 +623,8 @@ function showNotifDetail(nid) { actHtml = `查看考试`; } else if (n.type === 'friend_request' && n.application_status === 'pending' && n.friend_request_id) { actHtml = `
- - + +
`; } else if (n.type === 'friend_request' && n.application_status === 'accepted') { actHtml = '✅ 已同意'; @@ -674,14 +674,14 @@ function renderRooms() { list.innerHTML = filtered.map(r => { const peerInExam = r.type === 'private' && r.peer_id && peerExamStatus[r.peer_id]?.in_exam; return ` -
-
+
+
${r.avatar ? `` : - `${(r.name || '?')[0]}`} + `${(r.name || '?')[0]}`}
- ${escHtml(r.name || '未命名')} + ${escHtml(r.name || '未命名')} ${peerInExam ? '考试中' : ''} ${r.last_message ? formatTime(r.last_message.created_at) : ''}
@@ -710,7 +710,7 @@ function filterRooms() { renderRooms(); } async function selectRoom(roomId) { currentRoomId = roomId; oldestMsgId = null; - markRead(roomId); // 立即标记已读,使聊天气泡消失 + markChatRead(roomId); // 立即标记已读,使聊天气泡消失 document.getElementById('emptyState').classList.add('hidden'); // 隐藏通知详情 const nd = document.getElementById('notifDetailView'); @@ -988,7 +988,7 @@ function previewImage(url) { } // ========== 标记已读 ========== -function markRead(roomId) { +function markChatRead(roomId) { fetch(`/api/chat/rooms/${roomId}/read`, { method: 'POST' }); socket.emit('mark_read', { room_id: roomId }); const room = rooms.find(r => r.id === roomId); @@ -1425,7 +1425,7 @@ socket.on('new_message', (msg) => { area.scrollTop = area.scrollHeight; }, 50); } - markRead(currentRoomId); + markChatRead(currentRoomId); } // 更新会话列表 const room = rooms.find(r => r.id === msg.room_id);