!589 【功能完善】商城: 客服动态计算消息最后发送时间距离现在过去了多久

Merge pull request !589 from puhui999/dev
pull/598/MERGE
芋道源码 2024-11-21 01:57:22 +00:00 committed by Gitee
commit fc5df39b1a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 29 additions and 10 deletions

View File

@ -26,7 +26,7 @@
<div class="flex justify-between items-center w-100%"> <div class="flex justify-between items-center w-100%">
<span class="username">{{ item.userNickname }}</span> <span class="username">{{ item.userNickname }}</span>
<span class="color-[#999]" style="font-size: 13px"> <span class="color-[#999]" style="font-size: 13px">
{{ formatPast(item.lastMessageTime, 'YYYY-MM-DD') }} {{ lastMessageTimeMap.get(item.id) ?? '计算中' }}
</span> </span>
</div> </div>
<!-- 最后聊天内容 --> <!-- 最后聊天内容 -->
@ -89,6 +89,14 @@ const { replaceEmoji } = useEmoji()
const activeConversationId = ref(-1) // const activeConversationId = ref(-1) //
const collapse = computed(() => appStore.getCollapse) // const collapse = computed(() => appStore.getCollapse) //
const lastMessageTimeMap = ref<Map<number, string>>(new Map<number, string>())
/** 计算消息最后发送时间距离现在过去了多久 */
const calculationLastMessageTime = () => {
kefuStore.getConversationList?.forEach((item) => {
lastMessageTimeMap.value.set(item.id, formatPast(item.lastMessageTime, 'YYYY-MM-DD'))
})
}
defineExpose({ calculationLastMessageTime })
/** 打开右侧的消息列表 */ /** 打开右侧的消息列表 */
const emits = defineEmits<{ const emits = defineEmits<{
(e: 'change', v: KeFuConversationRespVO): void (e: 'change', v: KeFuConversationRespVO): void
@ -177,6 +185,16 @@ watch(showRightMenu, (val) => {
document.body.removeEventListener('click', closeRightMenu) document.body.removeEventListener('click', closeRightMenu)
} }
}) })
const timer = ref<any>()
/** 初始化 */
onMounted(() => {
timer.value = setInterval(calculationLastMessageTime, 1000 * 10) //
})
/** 组件卸载前 */
onBeforeUnmount(() => {
clearInterval(timer.value)
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -414,7 +414,7 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
.kefu-message { .kefu-message {
background-color: rgb(245, 245, 245); background-color: rgb(245, 245, 245);
margin-left: 10px; margin-left: 10px;
margin-top: 18px; margin-top: 3px;
border-top-right-radius: 10px; border-top-right-radius: 10px;
border-bottom-right-radius: 10px; border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px; border-bottom-left-radius: 10px;
@ -427,7 +427,7 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
.kefu-message { .kefu-message {
background-color: rgb(206, 223, 255); background-color: rgb(206, 223, 255);
margin-right: 10px; margin-right: 10px;
margin-top: 18px; margin-top: 3px;
border-top-left-radius: 10px; border-top-left-radius: 10px;
border-bottom-right-radius: 10px; border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px; border-bottom-left-radius: 10px;
@ -454,11 +454,11 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
.date-message, .date-message,
.system-message { .system-message {
width: fit-content; width: fit-content;
border-radius: 12rpx; background-color: rgba(0, 0, 0, 0.1);
padding: 8rpx 16rpx; border-radius: 8px;
margin-bottom: 16rpx; padding: 0 5px;
color: #999; color: #999;
font-size: 24rpx; font-size: 10px;
} }
} }

View File

@ -31,7 +31,6 @@ const server = ref(
) // WebSocket ) // WebSocket
/** 发起 WebSocket 连接 */ /** 发起 WebSocket 连接 */
// TODO puhui999: websocket 🤣
const { data, close, open } = useWebSocket(server.value, { const { data, close, open } = useWebSocket(server.value, {
autoReconnect: true, autoReconnect: true,
heartbeat: true heartbeat: true
@ -49,7 +48,6 @@ watchEffect(() => {
} }
// 2.1 type // 2.1 type
const jsonMessage = JSON.parse(data.value) const jsonMessage = JSON.parse(data.value)
console.log(jsonMessage)
const type = jsonMessage.type const type = jsonMessage.type
if (!type) { if (!type) {
message.error('未知的消息类型:' + data.value) message.error('未知的消息类型:' + data.value)
@ -83,10 +81,13 @@ const handleChange = (conversation: KeFuConversationRespVO) => {
memberInfoRef.value?.initHistory(conversation) memberInfoRef.value?.initHistory(conversation)
} }
const keFuConversationRef = ref<InstanceType<typeof KeFuConversationList>>()
/** 初始化 */ /** 初始化 */
onMounted(() => { onMounted(() => {
/** 加载会话列表 */ /** 加载会话列表 */
kefuStore.setConversationList() kefuStore.setConversationList().then(() => {
keFuConversationRef.value?.calculationLastMessageTime()
})
// websocket // websocket
open() open()
}) })