diff --git a/src/views/mall/promotion/kefu/components/KeFuChatBox.vue b/src/views/mall/promotion/kefu/components/KeFuChatBox.vue index da25c9d9..8c6b5b71 100644 --- a/src/views/mall/promotion/kefu/components/KeFuChatBox.vue +++ b/src/views/mall/promotion/kefu/components/KeFuChatBox.vue @@ -6,34 +6,55 @@
-
- -
- - - - +
+
+ +
+ {{ formatDate(item.createTime) }} +
+ + + {{ item.content }} + +
+
+ +
+ + + + +
+
-
@@ -69,6 +90,11 @@ import { Emoji } from './tools/emoji' import { KeFuMessageContentTypeEnum } from './tools/constants' import { isEmpty } from '@/utils/is' import { UserTypeEnum } from '@/utils/constants' +import { formatDate } from '@/utils/formatTime' +import dayjs from 'dayjs' +import relativeTime from 'dayjs/plugin/relativeTime' + +dayjs.extend(relativeTime) defineOptions({ name: 'KeFuMessageBox' }) const messageTool = useMessage() @@ -90,7 +116,7 @@ const getMessageList = async (conversation: KeFuConversationRespVO) => { if (!poller.value) { poller.value = setInterval(() => { getMessageList(conversation) - }, 1000) + }, 2000) } } defineExpose({ getMessageList }) @@ -143,7 +169,18 @@ const scrollToBottom = async () => { await nextTick() scrollbarRef.value!.setScrollTop(innerRef.value!.clientHeight) } - +/** + * 是否显示时间 + * @param {*} item - 数据 + * @param {*} index - 索引 + */ +const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => { + if (unref(messageList.value)[index + 1]) { + let dateString = dayjs(unref(messageList.value)[index + 1].createTime).fromNow() + return dateString !== dayjs(unref(item).createTime).fromNow() + } + return false +}) // TODO puhui999: 轮训相关,功能完善后移除 onBeforeUnmount(() => { if (!poller.value) { @@ -225,6 +262,17 @@ onBeforeUnmount(() => { transform: scale(1.03); } } + + .date-message, + .system-message { + width: fit-content; + border-radius: 12rpx; + padding: 8rpx 16rpx; + margin-bottom: 16rpx; + background-color: #e8e8e8; + color: #999; + font-size: 24rpx; + } } .chat-tools { diff --git a/src/views/mall/promotion/kefu/components/KeFuConversationBox.vue b/src/views/mall/promotion/kefu/components/KeFuConversationBox.vue index d45343ad..bf2d6fdd 100644 --- a/src/views/mall/promotion/kefu/components/KeFuConversationBox.vue +++ b/src/views/mall/promotion/kefu/components/KeFuConversationBox.vue @@ -36,7 +36,7 @@