【功能完善】商城客服: 消息获取改为游标查询

pull/576/head
puhui999 2024-11-04 17:59:30 +08:00
parent ce3380fa3f
commit 70abc5fc17
3 changed files with 56 additions and 20 deletions

View File

@ -29,8 +29,8 @@ export const KeFuMessageApi = {
url: '/promotion/kefu-message/update-read-status?conversationId=' + conversationId
})
},
// 获得消息分页数据
getKeFuMessagePage: async (params: any) => {
return await request.get({ url: '/promotion/kefu-message/page', params })
// 获得消息数据
getKeFuMessageList: async (params: any) => {
return await request.get({ url: '/promotion/kefu-message/list', params })
}
}

View File

@ -0,0 +1,37 @@
import { store } from '@/store'
import { defineStore } from 'pinia'
import { KeFuConversationApi, KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
import { KeFuMessageRespVO } from '@/api/mall/promotion/kefu/message'
// TODO puhui999: 待优化完善
interface MallKefuInfoVO {
conversationList: KeFuConversationRespVO[] // 会话列表
conversationMessageList: Map<number, KeFuMessageRespVO[]> // 会话消息
}
export const useMallKefuStore = defineStore('mall-kefu', {
state: (): MallKefuInfoVO => ({
conversationList: [],
conversationMessageList: new Map<number, KeFuMessageRespVO[]>() // key 会话value 会话消息列表
}),
getters: {
getConversationList(): KeFuConversationRespVO[] {
return this.conversationList
},
getConversationMessageList(): Map<number, KeFuMessageRespVO[]> {
return this.conversationMessageList
}
},
actions: {
async setConversationList() {
const list = await KeFuConversationApi.getConversationList()
list.sort((a: KeFuConversationRespVO, _) => (a.adminPinned ? -1 : 1))
this.conversationList = list
}
// async setConversationMessageList(conversationId: number) {}
}
})
export const useUserStoreWithOut = () => {
return useMallKefuStore(store)
}

View File

@ -164,9 +164,8 @@ const messageList = ref<KeFuMessageRespVO[]>([]) // 消息列表
const conversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) //
const showNewMessageTip = ref(false) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
conversationId: 0
conversationId: 0,
createTime: undefined
})
const total = ref(0) //
const refreshContent = ref(false) // ,
@ -175,14 +174,20 @@ const refreshContent = ref(false) // 内容刷新,主要解决会话消息页面
const getMessageContent = computed(() => (item: any) => jsonParse(item.content))
/** 获得消息列表 */
const getMessageList = async () => {
const res = await KeFuMessageApi.getKeFuMessagePage(queryParams)
total.value = res.total
const res = await KeFuMessageApi.getKeFuMessageList(queryParams)
if (isEmpty(res)) {
//
skipGetMessageList.value = true
return
}
queryParams.createTime = formatDate(res.at(-1).createTime) as any
//
if (queryParams.pageNo === 1) {
messageList.value = res.list
if (!queryParams.createTime) {
messageList.value = res
} else {
//
for (const item of res.list) {
for (const item of res) {
pushMessage(item)
}
}
@ -216,8 +221,7 @@ const refreshMessageList = async (message?: any) => {
}
pushMessage(message)
} else {
// TODO @puhui999 page createTime
queryParams.pageNo = 1
queryParams.createTime = undefined
await getMessageList()
}
@ -234,7 +238,6 @@ const refreshMessageList = async (message?: any) => {
// TODO @puhui999 list merge
const getNewMessageList = async (val: KeFuConversationRespVO) => {
// ,
queryParams.pageNo = 1
messageList.value = []
total.value = 0
loadHistory.value = false
@ -242,16 +245,14 @@ const getNewMessageList = async (val: KeFuConversationRespVO) => {
//
conversation.value = val
queryParams.conversationId = val.id
queryParams.createTime = undefined
//
await refreshMessageList()
}
defineExpose({ getNewMessageList, refreshMessageList })
const showKeFuMessageList = computed(() => !isEmpty(conversation.value)) //
const skipGetMessageList = computed(() => {
//
return total.value > 0 && Math.ceil(total.value / queryParams.pageSize) === queryParams.pageNo
}) //
const skipGetMessageList = ref(false) //
/** 处理表情选择 */
const handleEmojiSelect = (item: Emoji) => {
@ -345,8 +346,6 @@ const handleOldMessage = async () => {
return
}
loadHistory.value = true
//
queryParams.pageNo += 1
await getMessageList()
//
scrollbarRef.value!.setScrollTop(innerRef.value!.clientHeight - oldPageHeight)