diff --git a/admin/src/views/ChatRecords.vue b/admin/src/views/ChatRecords.vue index bd26297..ad55d17 100644 --- a/admin/src/views/ChatRecords.vue +++ b/admin/src/views/ChatRecords.vue @@ -70,13 +70,13 @@ {{ msg.text }} -
+
{{ (msg.nickname || '?')[0] }}
{{ msg.nickname }}
-
+
{{ msg.text }}
diff --git a/miniapp/pages/message/message.vue b/miniapp/pages/message/message.vue index e8fa0b9..772eb43 100644 --- a/miniapp/pages/message/message.vue +++ b/miniapp/pages/message/message.vue @@ -144,25 +144,41 @@ export default { async loadChatList() { try { const list = await getChatOrderList() - this.chatList = (list || []).map(item => ({ ...item, imUnread: 0 })) + let chatItems = (list || []).map(item => ({ ...item, imUnread: 0 })) // 从 IM 获取群会话未读数 + const unreadMap = {} try { await initIM() const convList = await getConversationList() - const unreadMap = {} convList.forEach(c => { unreadMap[c.groupId] = c.unreadCount || 0 }) - let totalImUnread = 0 - this.chatList.forEach(item => { - const groupId = item.imGroupId || `order_${item.orderId}` - item.imUnread = unreadMap[groupId] || 0 - totalImUnread += item.imUnread - }) - // 更新 tabBar badge(系统未读 + IM未读) - this.imUnreadTotal = totalImUnread - this.updateTabBarBadge() - } catch (e) { - // IM 未登录时静默处理 + } catch (e) {} + + // 过滤已删除的会话(有新未读消息时自动恢复) + const deleted = JSON.parse(uni.getStorageSync('deletedChats') || '{}') + let deletedChanged = false + chatItems = chatItems.filter(item => { + const groupId = item.imGroupId || `order_${item.orderId}` + item.imUnread = unreadMap[groupId] || 0 + if (deleted[groupId]) { + if (item.imUnread > 0) { + // 有新消息,恢复显示并清除删除记录 + delete deleted[groupId] + deletedChanged = true + return true + } + return false + } + return true + }) + if (deletedChanged) { + uni.setStorageSync('deletedChats', JSON.stringify(deleted)) } + + let totalImUnread = 0 + chatItems.forEach(item => { totalImUnread += item.imUnread }) + this.chatList = chatItems + this.imUnreadTotal = totalImUnread + this.updateTabBarBadge() } catch (e) { console.error('[消息页] 加载聊天列表失败:', e) } @@ -261,8 +277,13 @@ export default { item._prevX = 0 } }, - /** 删除聊天记录 */ + /** 删除聊天记录(记录到本地,有新消息时恢复) */ onDeleteChat(item) { + const groupId = item.imGroupId || `order_${item.orderId}` + // 记录删除时间,后续有新消息时自动恢复 + const deleted = JSON.parse(uni.getStorageSync('deletedChats') || '{}') + deleted[groupId] = Date.now() + uni.setStorageSync('deletedChats', JSON.stringify(deleted)) this.chatList = this.chatList.filter(c => c.orderId !== item.orderId) } } diff --git a/miniapp/utils/request.js b/miniapp/utils/request.js index b55e1e0..89073bd 100644 --- a/miniapp/utils/request.js +++ b/miniapp/utils/request.js @@ -6,8 +6,8 @@ */ // API 基础地址,按环境切换 -const BASE_URL = 'http://localhost:5099' -// const BASE_URL = 'http://api.zwz.shhmkjgs.cn' +// const BASE_URL = 'http://localhost:5099' +const BASE_URL = 'http://api.zwz.shhmkjgs.cn' /** * 获取本地存储的 token