聊天记录
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
18631081161 2026-04-02 17:18:57 +08:00
parent 681d2b5fe8
commit bc1a8e6b3f
3 changed files with 39 additions and 18 deletions

View File

@ -70,13 +70,13 @@
<span>{{ msg.text }}</span>
</div>
<!-- 普通消息 -->
<div v-else :class="['chat-bubble-row', msg.isOwner ? 'chat-right' : 'chat-left']">
<div v-else :class="['chat-bubble-row', msg.isOwner ? 'chat-left' : 'chat-right']">
<el-avatar :size="32" :src="msg.avatar || undefined" class="chat-avatar-item">
<span style="font-size: 12px">{{ (msg.nickname || '?')[0] }}</span>
</el-avatar>
<div class="chat-bubble-wrap">
<div class="chat-nickname">{{ msg.nickname }}</div>
<div :class="['chat-bubble', msg.isOwner ? 'bubble-right' : 'bubble-left']">
<div :class="['chat-bubble', msg.isOwner ? 'bubble-left' : 'bubble-right']">
<img v-if="msg.type === 'image'" :src="msg.text" class="chat-img" @click="previewImage(msg.text)" />
<span v-else>{{ msg.text }}</span>
</div>

View File

@ -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)
}
}

View File

@ -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