From 4d2c038972602271d700c78d88095b9b689a7199 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 20 Nov 2024 23:44:25 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E3=80=91=E5=95=86=E5=9F=8E:=20=E5=AE=A2=E6=9C=8D=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E8=AE=A1=E7=AE=97=E6=B6=88=E6=81=AF=E6=9C=80=E5=90=8E?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4=E8=B7=9D=E7=A6=BB=E7=8E=B0?= =?UTF-8?q?=E5=9C=A8=E8=BF=87=E5=8E=BB=E4=BA=86=E5=A4=9A=E4=B9=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kefu/components/KeFuConversationList.vue | 20 ++++++++++++++++++- .../kefu/components/KeFuMessageList.vue | 12 +++++------ src/views/mall/promotion/kefu/index.vue | 7 ++++--- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/views/mall/promotion/kefu/components/KeFuConversationList.vue b/src/views/mall/promotion/kefu/components/KeFuConversationList.vue index 3f28f9c2..042a29fd 100644 --- a/src/views/mall/promotion/kefu/components/KeFuConversationList.vue +++ b/src/views/mall/promotion/kefu/components/KeFuConversationList.vue @@ -26,7 +26,7 @@
{{ item.userNickname }} - {{ formatPast(item.lastMessageTime, 'YYYY-MM-DD') }} + {{ lastMessageTimeMap.get(item.id) ?? '计算中' }}
@@ -89,6 +89,14 @@ const { replaceEmoji } = useEmoji() const activeConversationId = ref(-1) // 选中的会话 const collapse = computed(() => appStore.getCollapse) // 折叠菜单 +const lastMessageTimeMap = ref>(new Map()) +/** 计算消息最后发送时间距离现在过去了多久 */ +const calculationLastMessageTime = () => { + kefuStore.getConversationList?.forEach((item) => { + lastMessageTimeMap.value.set(item.id, formatPast(item.lastMessageTime, 'YYYY-MM-DD')) + }) +} +defineExpose({ calculationLastMessageTime }) /** 打开右侧的消息列表 */ const emits = defineEmits<{ (e: 'change', v: KeFuConversationRespVO): void @@ -177,6 +185,16 @@ watch(showRightMenu, (val) => { document.body.removeEventListener('click', closeRightMenu) } }) + +const timer = ref() +/** 初始化 */ +onMounted(() => { + timer.value = setInterval(calculationLastMessageTime, 1000 * 10) // 十秒计算一次 +}) +/** 组件卸载前 */ +onBeforeUnmount(() => { + clearInterval(timer.value) +})