【功能完善】商城: 客服会话消息缓存

This commit is contained in:
puhui999 2024-11-09 17:29:49 +08:00
parent e342e91f79
commit df34f65df8
3 changed files with 22 additions and 12 deletions

View File

@ -4,7 +4,6 @@ import { KeFuConversationApi, KeFuConversationRespVO } from '@/api/mall/promotio
import { KeFuMessageRespVO } from '@/api/mall/promotion/kefu/message'
import { isEmpty } from '@/utils/is'
// TODO puhui999: 待优化完善
interface MallKefuInfoVO {
conversationList: KeFuConversationRespVO[] // 会话列表
conversationMessageList: Map<number, KeFuMessageRespVO[]> // 会话消息
@ -19,11 +18,17 @@ export const useMallKefuStore = defineStore('mall-kefu', {
getConversationList(): KeFuConversationRespVO[] {
return this.conversationList
},
getConversationMessageList(): Map<number, KeFuMessageRespVO[]> {
return this.conversationMessageList
getConversationMessageList(): (conversationId: number) => KeFuMessageRespVO[] | undefined {
return (conversationId: number) => this.conversationMessageList.get(conversationId)
}
},
actions: {
//======================= 会话消息相关 =======================
/** 缓存历史消息 */
saveMessageList(conversationId: number, messageList: KeFuMessageRespVO[]) {
this.conversationMessageList.set(conversationId, messageList)
},
//======================= 会话相关 =======================
/** 加载会话缓存列表 */
async setConversationList() {
this.conversationList = await KeFuConversationApi.getConversationList()

View File

@ -93,6 +93,10 @@ const emits = defineEmits<{
(e: 'change', v: KeFuConversationRespVO): void
}>()
const openRightMessage = (item: KeFuConversationRespVO) => {
//
if (activeConversationId.value === item.id) {
return
}
activeConversationId.value = item.id
emits('change', item)
}

View File

@ -236,19 +236,20 @@ const refreshMessageList = async (message?: any) => {
}
}
/** 获得新会话的消息列表 */
// TODO @puhui999 list merge
/** 获得新会话的消息列表, 点击切换时读取缓存然后异步获取新消息merge 下; */
const getNewMessageList = async (val: KeFuConversationRespVO) => {
// ,
messageList.value = []
total.value = 0
// 1.
kefuStore.saveMessageList(conversation.value.id, messageList.value)
// 2.1 ,
messageList.value = kefuStore.getConversationMessageList(val.id) || []
total.value = messageList.value.length || 0
loadHistory.value = false
refreshContent.value = false
//
// 2.2
conversation.value = val
queryParams.conversationId = val.id
queryParams.createTime = undefined
//
// 3.
await refreshMessageList()
}
defineExpose({ getNewMessageList, refreshMessageList })
@ -299,8 +300,8 @@ const sendMessage = async (msg: any) => {
message.value = ''
//
await refreshMessageList()
//
kefuStore.updateConversation(conversation.value.id)
//
await kefuStore.updateConversation(conversation.value.id)
}
/** 滚动到底部 */