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) +})