!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%">
<span class="username">{{ item.userNickname }}</span>
<span class="color-[#999]" style="font-size: 13px">
{{ formatPast(item.lastMessageTime, 'YYYY-MM-DD') }}
{{ lastMessageTimeMap.get(item.id) ?? '计算中' }}
</span>
</div>
<!-- 最后聊天内容 -->
@ -89,6 +89,14 @@ const { replaceEmoji } = useEmoji()
const activeConversationId = ref(-1) //
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<{
(e: 'change', v: KeFuConversationRespVO): void
@ -177,6 +185,16 @@ watch(showRightMenu, (val) => {
document.body.removeEventListener('click', closeRightMenu)
}
})
const timer = ref<any>()
/** 初始化 */
onMounted(() => {
timer.value = setInterval(calculationLastMessageTime, 1000 * 10) //
})
/** 组件卸载前 */
onBeforeUnmount(() => {
clearInterval(timer.value)
})
</script>
<style lang="scss" scoped>

View File

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

View File

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