【新增】:mall 客服使用轮训模拟 websocket

pull/468/head
puhui999 2024-07-02 17:10:53 +08:00
parent 9c05ff35db
commit 91c262fb24
2 changed files with 33 additions and 2 deletions

View File

@ -23,7 +23,7 @@
:src="keFuConversation.userAvatar"
alt="avatar"
/>
<div class="kefu-message flex items-center p-10px">
<div class="kefu-message p-10px">
<!-- 文本消息 -->
<template v-if="KeFuMessageContentTypeEnum.TEXT === item.contentType">
<div
@ -35,6 +35,7 @@
? `mr-10px`
: ''
]"
class="flex items-center"
></div>
</template>
<template v-else>
@ -80,7 +81,7 @@ const messageTool = useMessage()
const message = ref('') //
const messageList = ref<KeFuMessageRespVO[]>([]) //
const keFuConversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) //
const poller = ref<any>(null) // TODO puhui999: websocket
// TODO puhui999:
const getMessageList = async (conversation: KeFuConversationRespVO) => {
keFuConversation.value = conversation
@ -91,6 +92,12 @@ const getMessageList = async (conversation: KeFuConversationRespVO) => {
messageList.value = list.reverse()
// TODO puhui999:
await scrollToBottom()
// TODO puhui999:
if (!poller.value) {
poller.value = setInterval(() => {
getMessageList(conversation)
}, 1000)
}
}
defineExpose({ getMessageList })
//
@ -126,6 +133,14 @@ const scrollToBottom = async () => {
await nextTick()
scrollbarRef.value!.setScrollTop(innerRef.value!.clientHeight)
}
// TODO puhui999:
onBeforeUnmount(() => {
if (!poller.value) {
return
}
clearInterval(poller.value)
})
</script>
<style lang="scss" scoped>

View File

@ -64,6 +64,22 @@ const openRightMessage = (item: KeFuConversationRespVO, index: number) => {
activeConversationIndex.value = index
emits('change', item)
}
const poller = ref<any>(null) // TODO puhui999: websocket
onMounted(() => {
// TODO puhui999:
if (!poller.value) {
poller.value = setInterval(() => {
getConversationList()
}, 1000)
}
})
// TODO puhui999:
onBeforeUnmount(() => {
if (!poller.value) {
return
}
clearInterval(poller.value)
})
</script>
<style lang="scss" scoped>