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

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