Skip to content

Commit 392603c

Browse files
YunaiVgitee-org
authored andcommitted
!478 完善 mall 客服
Merge pull request !478 from puhui999/dev-crm
2 parents e655b4d + 60d4175 commit 392603c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+155
-178
lines changed

src/views/mall/promotion/kefu/components/KeFuConversationBox.vue renamed to src/views/mall/promotion/kefu/components/KeFuConversationList.vue

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<template>
22
<div class="kefu">
33
<div
4-
v-for="(item, index) in conversationList"
4+
v-for="item in conversationList"
55
:key="item.id"
6-
:class="{ active: index === activeConversationIndex, pinned: item.adminPinned }"
6+
:class="{ active: item.id === activeConversationId, pinned: item.adminPinned }"
77
class="kefu-conversation flex items-center"
8-
@click="openRightMessage(item, index)"
8+
@click="openRightMessage(item)"
99
@contextmenu.prevent="rightClick($event as PointerEvent, item)"
1010
>
1111
<div class="flex justify-center items-center w-100%">
12-
<!-- TODO style 换成 unocss -->
13-
<div class="flex justify-center items-center" style="width: 50px; height: 50px">
12+
<div class="flex justify-center items-center w-50px h-50px">
1413
<!-- 头像 + 未读 -->
1514
<el-badge
1615
:hidden="item.adminUnreadMessageCount === 0"
@@ -27,35 +26,29 @@
2726
{{ formatDate(item.lastMessageTime) }}
2827
</span>
2928
</div>
30-
<!-- 文本消息 -->
31-
<template v-if="KeFuMessageContentTypeEnum.TEXT === item.lastMessageContentType">
32-
<div
33-
v-dompurify-html="replaceEmoji(item.lastMessageContent)"
34-
class="last-message flex items-center color-[#989EA6]"
35-
></div>
36-
</template>
37-
<!-- 图片消息 -->
38-
<template v-else>
39-
<div class="last-message flex items-center color-[#989EA6]">
40-
{{ getContentType(item.lastMessageContentType) }}
41-
</div>
42-
</template>
29+
<!-- 最后聊天内容 -->
30+
<div
31+
v-dompurify-html="
32+
getConversationDisplayText(item.lastMessageContentType, item.lastMessageContent)
33+
"
34+
class="last-message flex items-center color-[#989EA6]"
35+
></div>
4336
</div>
4437
</div>
4538
</div>
4639

4740
<!-- 右键,进行操作(类似微信) -->
4841
<ul v-show="showRightMenu" :style="rightMenuStyle" class="right-menu-ul">
4942
<li
50-
v-show="!selectedConversation.adminPinned"
43+
v-show="!rightClickConversation.adminPinned"
5144
class="flex items-center"
5245
@click.stop="updateConversationPinned(true)"
5346
>
5447
<Icon class="mr-5px" icon="ep:top" />
5548
置顶会话
5649
</li>
5750
<li
58-
v-show="selectedConversation.adminPinned"
51+
v-show="rightClickConversation.adminPinned"
5952
class="flex items-center"
6053
@click.stop="updateConversationPinned(false)"
6154
>
@@ -79,64 +72,71 @@ import { KeFuConversationApi, KeFuConversationRespVO } from '@/api/mall/promotio
7972
import { useEmoji } from './tools/emoji'
8073
import { formatDate } from '@/utils/formatTime'
8174
import { KeFuMessageContentTypeEnum } from './tools/constants'
75+
import { useAppStore } from '@/store/modules/app'
8276
83-
defineOptions({ name: 'KeFuConversationBox' })
77+
defineOptions({ name: 'KeFuConversationList' })
8478
8579
const message = useMessage() // 消息弹窗
86-
80+
const appStore = useAppStore()
8781
const { replaceEmoji } = useEmoji()
8882
const conversationList = ref<KeFuConversationRespVO[]>([]) // 会话列表
89-
const activeConversationIndex = ref(-1) // 选中的会话 index 位置 TODO @puhui999:这个可以改成 activeConversationId 么?因为一般是选中的对话编号
83+
const activeConversationId = ref(-1) // 选中的会话
84+
const collapse = computed(() => appStore.getCollapse) // 折叠菜单
9085
9186
/** 加载会话列表 */
9287
const getConversationList = async () => {
93-
conversationList.value = await KeFuConversationApi.getConversationList()
88+
const list = await KeFuConversationApi.getConversationList()
89+
list.sort((a: KeFuConversationRespVO, _) => (a.adminPinned ? -1 : 1))
90+
conversationList.value = list
9491
}
9592
defineExpose({ getConversationList })
9693
9794
/** 打开右侧的消息列表 */
9895
const emits = defineEmits<{
9996
(e: 'change', v: KeFuConversationRespVO): void
10097
}>()
101-
const openRightMessage = (item: KeFuConversationRespVO, index: number) => {
102-
activeConversationIndex.value = index
98+
const openRightMessage = (item: KeFuConversationRespVO) => {
99+
activeConversationId.value = item.id
103100
emits('change', item)
104101
}
105102
106-
// TODO @puhui999:这个,是不是改成 getConversationDisplayText,获取会话的展示文本。然后,把文本消息类型,也统一处理(包括上面的 replaceEmoji)。这样,更统一。
107103
/** 获得消息类型 */
108-
const getContentType = computed(() => (lastMessageContentType: number) => {
109-
switch (lastMessageContentType) {
110-
case KeFuMessageContentTypeEnum.SYSTEM:
111-
return '[系统消息]'
112-
case KeFuMessageContentTypeEnum.VIDEO:
113-
return '[视频消息]'
114-
case KeFuMessageContentTypeEnum.IMAGE:
115-
return '[图片消息]'
116-
case KeFuMessageContentTypeEnum.PRODUCT:
117-
return '[商品消息]'
118-
case KeFuMessageContentTypeEnum.ORDER:
119-
return '[订单消息]'
120-
case KeFuMessageContentTypeEnum.VOICE:
121-
return '[语音消息]'
122-
default:
123-
return ''
104+
const getConversationDisplayText = computed(
105+
() => (lastMessageContentType: number, lastMessageContent: string) => {
106+
switch (lastMessageContentType) {
107+
case KeFuMessageContentTypeEnum.SYSTEM:
108+
return '[系统消息]'
109+
case KeFuMessageContentTypeEnum.VIDEO:
110+
return '[视频消息]'
111+
case KeFuMessageContentTypeEnum.IMAGE:
112+
return '[图片消息]'
113+
case KeFuMessageContentTypeEnum.PRODUCT:
114+
return '[商品消息]'
115+
case KeFuMessageContentTypeEnum.ORDER:
116+
return '[订单消息]'
117+
case KeFuMessageContentTypeEnum.VOICE:
118+
return '[语音消息]'
119+
case KeFuMessageContentTypeEnum.TEXT:
120+
return replaceEmoji(lastMessageContent)
121+
default:
122+
return ''
123+
}
124124
}
125-
})
125+
)
126126
127127
//======================= 右键菜单 =======================
128128
const showRightMenu = ref(false) // 显示右键菜单
129129
const rightMenuStyle = ref<any>({}) // 右键菜单 Style
130-
const selectedConversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) // 右键选中的会话对象 TODO puhui999:这个是不是叫 rightClickConversation 会好点。因为 selected 容易和选中的对话,定义上有点重叠
130+
const rightClickConversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) // 右键选中的会话对象
131131
132132
/** 打开右键菜单 */
133133
const rightClick = (mouseEvent: PointerEvent, item: KeFuConversationRespVO) => {
134-
selectedConversation.value = item
134+
rightClickConversation.value = item
135135
// 显示右键菜单
136136
showRightMenu.value = true
137137
rightMenuStyle.value = {
138138
top: mouseEvent.clientY - 110 + 'px',
139-
left: mouseEvent.clientX - 80 + 'px'
139+
left: collapse.value ? mouseEvent.clientX - 80 + 'px' : mouseEvent.clientX - 210 + 'px'
140140
}
141141
}
142142
/** 关闭右键菜单 */
@@ -148,7 +148,7 @@ const closeRightMenu = () => {
148148
const updateConversationPinned = async (adminPinned: boolean) => {
149149
// 1. 会话置顶/取消置顶
150150
await KeFuConversationApi.updateConversationPinned({
151-
id: selectedConversation.value.id,
151+
id: rightClickConversation.value.id,
152152
adminPinned
153153
})
154154
message.notifySuccess(adminPinned ? '置顶成功' : '取消置顶成功')
@@ -161,7 +161,7 @@ const updateConversationPinned = async (adminPinned: boolean) => {
161161
const deleteConversation = async () => {
162162
// 1. 删除会话
163163
await message.confirm('您确定要删除该会话吗?')
164-
await KeFuConversationApi.deleteConversation(selectedConversation.value.id)
164+
await KeFuConversationApi.deleteConversation(rightClickConversation.value.id)
165165
// 2. 关闭右键菜单,更新会话列表
166166
closeRightMenu()
167167
await getConversationList()

0 commit comments

Comments
 (0)