2024-07-01 11:36:07 +08:00
|
|
|
<template>
|
|
|
|
<div class="kefu">
|
|
|
|
<div
|
|
|
|
v-for="(item, index) in conversationList"
|
|
|
|
:key="item.id"
|
|
|
|
:class="{ active: index === activeConversationIndex }"
|
|
|
|
class="kefu-conversation flex justify-between items-center"
|
|
|
|
@click="openRightMessage(item, index)"
|
|
|
|
>
|
2024-07-01 17:11:47 +08:00
|
|
|
<div class="flex justify-center items-center w-100%">
|
2024-07-01 11:36:07 +08:00
|
|
|
<el-avatar :src="item.userAvatar" alt="avatar" />
|
2024-07-01 17:11:47 +08:00
|
|
|
<div class="ml-10px w-100%">
|
|
|
|
<div class="flex justify-between items-center w-100%">
|
|
|
|
<span>{{ item.userNickname }}</span>
|
|
|
|
<span class="color-[#989EA6]">
|
|
|
|
{{ formatDate(item.lastMessageTime) }}
|
|
|
|
</span>
|
|
|
|
</div>
|
2024-07-02 17:31:26 +08:00
|
|
|
<!-- 文本消息 -->
|
|
|
|
<template v-if="KeFuMessageContentTypeEnum.TEXT === item.lastMessageContentType">
|
|
|
|
<div
|
|
|
|
v-dompurify-html="replaceEmoji(item.lastMessageContent)"
|
|
|
|
class="last-message flex items-center color-[#989EA6]"
|
|
|
|
></div>
|
|
|
|
</template>
|
|
|
|
<!-- 图片消息 -->
|
|
|
|
<template v-if="KeFuMessageContentTypeEnum.IMAGE === item.lastMessageContentType">
|
|
|
|
<div class="last-message flex items-center color-[#989EA6]">【图片消息】</div>
|
|
|
|
</template>
|
2024-07-01 11:36:07 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { KeFuConversationApi, KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
|
2024-07-04 15:28:34 +08:00
|
|
|
import { useEmoji } from './tools/emoji'
|
2024-07-04 16:23:11 +08:00
|
|
|
import { formatDate } from '@/utils/formatTime'
|
2024-07-04 15:28:34 +08:00
|
|
|
import { KeFuMessageContentTypeEnum } from './tools/constants'
|
2024-07-01 11:36:07 +08:00
|
|
|
|
|
|
|
defineOptions({ name: 'KeFuConversationBox' })
|
2024-07-03 17:51:58 +08:00
|
|
|
const { replaceEmoji } = useEmoji()
|
2024-07-01 17:11:47 +08:00
|
|
|
const activeConversationIndex = ref(-1) // 选中的会话
|
2024-07-01 11:36:07 +08:00
|
|
|
const conversationList = ref<KeFuConversationRespVO[]>([]) // 会话列表
|
|
|
|
const getConversationList = async () => {
|
|
|
|
conversationList.value = await KeFuConversationApi.getConversationList()
|
|
|
|
}
|
|
|
|
defineExpose({ getConversationList })
|
|
|
|
const emits = defineEmits<{
|
2024-07-01 16:15:27 +08:00
|
|
|
(e: 'change', v: KeFuConversationRespVO): void
|
2024-07-01 11:36:07 +08:00
|
|
|
}>()
|
|
|
|
// 打开右侧消息
|
|
|
|
const openRightMessage = (item: KeFuConversationRespVO, index: number) => {
|
|
|
|
activeConversationIndex.value = index
|
2024-07-01 16:15:27 +08:00
|
|
|
emits('change', item)
|
2024-07-01 11:36:07 +08:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.kefu {
|
|
|
|
&-conversation {
|
|
|
|
height: 60px;
|
|
|
|
padding: 10px;
|
|
|
|
background-color: #fff;
|
|
|
|
transition: border-left 0.05s ease-in-out; /* 设置过渡效果 */
|
|
|
|
|
2024-07-01 17:11:47 +08:00
|
|
|
.last-message {
|
|
|
|
width: 200px;
|
|
|
|
overflow: hidden; // 隐藏超出的文本
|
|
|
|
white-space: nowrap; // 禁止换行
|
|
|
|
text-overflow: ellipsis; // 添加省略号
|
2024-07-01 11:36:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.active {
|
|
|
|
border-left: 5px #3271ff solid;
|
|
|
|
background-color: #eff0f1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|