|
@@ -1,16 +1,15 @@
|
|
<template>
|
|
<template>
|
|
<div class="kefu">
|
|
<div class="kefu">
|
|
<div
|
|
<div
|
|
- v-for="(item, index) in conversationList"
|
|
|
|
|
|
+ v-for="item in conversationList"
|
|
:key="item.id"
|
|
:key="item.id"
|
|
- :class="{ active: index === activeConversationIndex, pinned: item.adminPinned }"
|
|
|
|
|
|
+ :class="{ active: item.id === activeConversationId, pinned: item.adminPinned }"
|
|
class="kefu-conversation flex items-center"
|
|
class="kefu-conversation flex items-center"
|
|
- @click="openRightMessage(item, index)"
|
|
|
|
|
|
+ @click="openRightMessage(item)"
|
|
@contextmenu.prevent="rightClick($event as PointerEvent, item)"
|
|
@contextmenu.prevent="rightClick($event as PointerEvent, item)"
|
|
>
|
|
>
|
|
<div class="flex justify-center items-center w-100%">
|
|
<div class="flex justify-center items-center w-100%">
|
|
- <!-- TODO style 换成 unocss -->
|
|
|
|
- <div class="flex justify-center items-center" style="width: 50px; height: 50px">
|
|
|
|
|
|
+ <div class="flex justify-center items-center w-50px h-50px">
|
|
<!-- 头像 + 未读 -->
|
|
<!-- 头像 + 未读 -->
|
|
<el-badge
|
|
<el-badge
|
|
:hidden="item.adminUnreadMessageCount === 0"
|
|
:hidden="item.adminUnreadMessageCount === 0"
|
|
@@ -27,19 +26,13 @@
|
|
{{ formatDate(item.lastMessageTime) }}
|
|
{{ formatDate(item.lastMessageTime) }}
|
|
</span>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
- <!-- 文本消息 -->
|
|
|
|
- <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-else>
|
|
|
|
- <div class="last-message flex items-center color-[#989EA6]">
|
|
|
|
- {{ getContentType(item.lastMessageContentType) }}
|
|
|
|
- </div>
|
|
|
|
- </template>
|
|
|
|
|
|
+ <!-- 最后聊天内容 -->
|
|
|
|
+ <div
|
|
|
|
+ v-dompurify-html="
|
|
|
|
+ getConversationDisplayText(item.lastMessageContentType, item.lastMessageContent)
|
|
|
|
+ "
|
|
|
|
+ class="last-message flex items-center color-[#989EA6]"
|
|
|
|
+ ></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -47,7 +40,7 @@
|
|
<!-- 右键,进行操作(类似微信) -->
|
|
<!-- 右键,进行操作(类似微信) -->
|
|
<ul v-show="showRightMenu" :style="rightMenuStyle" class="right-menu-ul">
|
|
<ul v-show="showRightMenu" :style="rightMenuStyle" class="right-menu-ul">
|
|
<li
|
|
<li
|
|
- v-show="!selectedConversation.adminPinned"
|
|
|
|
|
|
+ v-show="!rightClickConversation.adminPinned"
|
|
class="flex items-center"
|
|
class="flex items-center"
|
|
@click.stop="updateConversationPinned(true)"
|
|
@click.stop="updateConversationPinned(true)"
|
|
>
|
|
>
|
|
@@ -55,7 +48,7 @@
|
|
置顶会话
|
|
置顶会话
|
|
</li>
|
|
</li>
|
|
<li
|
|
<li
|
|
- v-show="selectedConversation.adminPinned"
|
|
|
|
|
|
+ v-show="rightClickConversation.adminPinned"
|
|
class="flex items-center"
|
|
class="flex items-center"
|
|
@click.stop="updateConversationPinned(false)"
|
|
@click.stop="updateConversationPinned(false)"
|
|
>
|
|
>
|
|
@@ -79,18 +72,22 @@ import { KeFuConversationApi, KeFuConversationRespVO } from '@/api/mall/promotio
|
|
import { useEmoji } from './tools/emoji'
|
|
import { useEmoji } from './tools/emoji'
|
|
import { formatDate } from '@/utils/formatTime'
|
|
import { formatDate } from '@/utils/formatTime'
|
|
import { KeFuMessageContentTypeEnum } from './tools/constants'
|
|
import { KeFuMessageContentTypeEnum } from './tools/constants'
|
|
|
|
+import { useAppStore } from '@/store/modules/app'
|
|
|
|
|
|
-defineOptions({ name: 'KeFuConversationBox' })
|
|
|
|
|
|
+defineOptions({ name: 'KeFuConversationList' })
|
|
|
|
|
|
const message = useMessage() // 消息弹窗
|
|
const message = useMessage() // 消息弹窗
|
|
-
|
|
|
|
|
|
+const appStore = useAppStore()
|
|
const { replaceEmoji } = useEmoji()
|
|
const { replaceEmoji } = useEmoji()
|
|
const conversationList = ref<KeFuConversationRespVO[]>([]) // 会话列表
|
|
const conversationList = ref<KeFuConversationRespVO[]>([]) // 会话列表
|
|
-const activeConversationIndex = ref(-1) // 选中的会话 index 位置 TODO @puhui999:这个可以改成 activeConversationId 么?因为一般是选中的对话编号
|
|
|
|
|
|
+const activeConversationId = ref(-1) // 选中的会话
|
|
|
|
+const collapse = computed(() => appStore.getCollapse) // 折叠菜单
|
|
|
|
|
|
/** 加载会话列表 */
|
|
/** 加载会话列表 */
|
|
const getConversationList = async () => {
|
|
const getConversationList = async () => {
|
|
- conversationList.value = await KeFuConversationApi.getConversationList()
|
|
|
|
|
|
+ const list = await KeFuConversationApi.getConversationList()
|
|
|
|
+ list.sort((a: KeFuConversationRespVO, _) => (a.adminPinned ? -1 : 1))
|
|
|
|
+ conversationList.value = list
|
|
}
|
|
}
|
|
defineExpose({ getConversationList })
|
|
defineExpose({ getConversationList })
|
|
|
|
|
|
@@ -98,45 +95,48 @@ defineExpose({ getConversationList })
|
|
const emits = defineEmits<{
|
|
const emits = defineEmits<{
|
|
(e: 'change', v: KeFuConversationRespVO): void
|
|
(e: 'change', v: KeFuConversationRespVO): void
|
|
}>()
|
|
}>()
|
|
-const openRightMessage = (item: KeFuConversationRespVO, index: number) => {
|
|
|
|
- activeConversationIndex.value = index
|
|
|
|
|
|
+const openRightMessage = (item: KeFuConversationRespVO) => {
|
|
|
|
+ activeConversationId.value = item.id
|
|
emits('change', item)
|
|
emits('change', item)
|
|
}
|
|
}
|
|
|
|
|
|
-// TODO @puhui999:这个,是不是改成 getConversationDisplayText,获取会话的展示文本。然后,把文本消息类型,也统一处理(包括上面的 replaceEmoji)。这样,更统一。
|
|
|
|
/** 获得消息类型 */
|
|
/** 获得消息类型 */
|
|
-const getContentType = computed(() => (lastMessageContentType: number) => {
|
|
|
|
- switch (lastMessageContentType) {
|
|
|
|
- case KeFuMessageContentTypeEnum.SYSTEM:
|
|
|
|
- return '[系统消息]'
|
|
|
|
- case KeFuMessageContentTypeEnum.VIDEO:
|
|
|
|
- return '[视频消息]'
|
|
|
|
- case KeFuMessageContentTypeEnum.IMAGE:
|
|
|
|
- return '[图片消息]'
|
|
|
|
- case KeFuMessageContentTypeEnum.PRODUCT:
|
|
|
|
- return '[商品消息]'
|
|
|
|
- case KeFuMessageContentTypeEnum.ORDER:
|
|
|
|
- return '[订单消息]'
|
|
|
|
- case KeFuMessageContentTypeEnum.VOICE:
|
|
|
|
- return '[语音消息]'
|
|
|
|
- default:
|
|
|
|
- return ''
|
|
|
|
|
|
+const getConversationDisplayText = computed(
|
|
|
|
+ () => (lastMessageContentType: number, lastMessageContent: string) => {
|
|
|
|
+ switch (lastMessageContentType) {
|
|
|
|
+ case KeFuMessageContentTypeEnum.SYSTEM:
|
|
|
|
+ return '[系统消息]'
|
|
|
|
+ case KeFuMessageContentTypeEnum.VIDEO:
|
|
|
|
+ return '[视频消息]'
|
|
|
|
+ case KeFuMessageContentTypeEnum.IMAGE:
|
|
|
|
+ return '[图片消息]'
|
|
|
|
+ case KeFuMessageContentTypeEnum.PRODUCT:
|
|
|
|
+ return '[商品消息]'
|
|
|
|
+ case KeFuMessageContentTypeEnum.ORDER:
|
|
|
|
+ return '[订单消息]'
|
|
|
|
+ case KeFuMessageContentTypeEnum.VOICE:
|
|
|
|
+ return '[语音消息]'
|
|
|
|
+ case KeFuMessageContentTypeEnum.TEXT:
|
|
|
|
+ return replaceEmoji(lastMessageContent)
|
|
|
|
+ default:
|
|
|
|
+ return ''
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-})
|
|
|
|
|
|
+)
|
|
|
|
|
|
//======================= 右键菜单 =======================
|
|
//======================= 右键菜单 =======================
|
|
const showRightMenu = ref(false) // 显示右键菜单
|
|
const showRightMenu = ref(false) // 显示右键菜单
|
|
const rightMenuStyle = ref<any>({}) // 右键菜单 Style
|
|
const rightMenuStyle = ref<any>({}) // 右键菜单 Style
|
|
-const selectedConversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) // 右键选中的会话对象 TODO puhui999:这个是不是叫 rightClickConversation 会好点。因为 selected 容易和选中的对话,定义上有点重叠
|
|
|
|
|
|
+const rightClickConversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) // 右键选中的会话对象
|
|
|
|
|
|
/** 打开右键菜单 */
|
|
/** 打开右键菜单 */
|
|
const rightClick = (mouseEvent: PointerEvent, item: KeFuConversationRespVO) => {
|
|
const rightClick = (mouseEvent: PointerEvent, item: KeFuConversationRespVO) => {
|
|
- selectedConversation.value = item
|
|
|
|
|
|
+ rightClickConversation.value = item
|
|
// 显示右键菜单
|
|
// 显示右键菜单
|
|
showRightMenu.value = true
|
|
showRightMenu.value = true
|
|
rightMenuStyle.value = {
|
|
rightMenuStyle.value = {
|
|
top: mouseEvent.clientY - 110 + 'px',
|
|
top: mouseEvent.clientY - 110 + 'px',
|
|
- left: mouseEvent.clientX - 80 + 'px'
|
|
|
|
|
|
+ left: collapse.value ? mouseEvent.clientX - 80 + 'px' : mouseEvent.clientX - 210 + 'px'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/** 关闭右键菜单 */
|
|
/** 关闭右键菜单 */
|
|
@@ -148,7 +148,7 @@ const closeRightMenu = () => {
|
|
const updateConversationPinned = async (adminPinned: boolean) => {
|
|
const updateConversationPinned = async (adminPinned: boolean) => {
|
|
// 1. 会话置顶/取消置顶
|
|
// 1. 会话置顶/取消置顶
|
|
await KeFuConversationApi.updateConversationPinned({
|
|
await KeFuConversationApi.updateConversationPinned({
|
|
- id: selectedConversation.value.id,
|
|
|
|
|
|
+ id: rightClickConversation.value.id,
|
|
adminPinned
|
|
adminPinned
|
|
})
|
|
})
|
|
message.notifySuccess(adminPinned ? '置顶成功' : '取消置顶成功')
|
|
message.notifySuccess(adminPinned ? '置顶成功' : '取消置顶成功')
|
|
@@ -161,7 +161,7 @@ const updateConversationPinned = async (adminPinned: boolean) => {
|
|
const deleteConversation = async () => {
|
|
const deleteConversation = async () => {
|
|
// 1. 删除会话
|
|
// 1. 删除会话
|
|
await message.confirm('您确定要删除该会话吗?')
|
|
await message.confirm('您确定要删除该会话吗?')
|
|
- await KeFuConversationApi.deleteConversation(selectedConversation.value.id)
|
|
|
|
|
|
+ await KeFuConversationApi.deleteConversation(rightClickConversation.value.id)
|
|
// 2. 关闭右键菜单,更新会话列表
|
|
// 2. 关闭右键菜单,更新会话列表
|
|
closeRightMenu()
|
|
closeRightMenu()
|
|
await getConversationList()
|
|
await getConversationList()
|