Skip to content

Commit e89b274

Browse files
author
puhui999
committed
【优化】:mall 客服消息组件抽离
1 parent e45cade commit e89b274

File tree

3 files changed

+76
-45
lines changed

3 files changed

+76
-45
lines changed

src/views/mall/promotion/kefu/components/KeFuChatBox.vue

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,18 @@
1919
class="flex mb-20px w-[100%]"
2020
>
2121
<el-avatar
22-
v-show="item.senderType === UserTypeEnum.MEMBER"
22+
v-if="item.senderType === UserTypeEnum.MEMBER"
2323
:src="keFuConversation.userAvatar"
2424
alt="avatar"
2525
/>
2626
<div class="kefu-message p-10px">
27-
<!-- TODO puhui999: 消息相关等后续完成后统一抽离封装 -->
2827
<!-- 文本消息 -->
29-
<template v-if="KeFuMessageContentTypeEnum.TEXT === item.contentType">
30-
<div
31-
v-dompurify-html="replaceEmoji(item.content)"
32-
:class="[
33-
item.senderType === UserTypeEnum.MEMBER
34-
? `ml-10px`
35-
: item.senderType === UserTypeEnum.ADMIN
36-
? `mr-10px`
37-
: ''
38-
]"
39-
class="flex items-center"
40-
></div>
41-
</template>
28+
<TextMessageItem :message="item" />
4229
<!-- 图片消息 -->
43-
<template v-if="KeFuMessageContentTypeEnum.IMAGE === item.contentType">
44-
<div
45-
:class="[
46-
item.senderType === UserTypeEnum.MEMBER
47-
? `ml-10px`
48-
: item.senderType === UserTypeEnum.ADMIN
49-
? `mr-10px`
50-
: ''
51-
]"
52-
class="flex items-center"
53-
>
54-
<el-image
55-
:src="item.content"
56-
fit="contain"
57-
style="width: 200px; height: 200px"
58-
@click="imagePreview(item.content)"
59-
/>
60-
</div>
61-
</template>
30+
<ImageMessageItem :message="item" />
6231
</div>
6332
<el-avatar
64-
v-show="item.senderType === UserTypeEnum.ADMIN"
33+
v-if="item.senderType === UserTypeEnum.ADMIN"
6534
:src="item.senderAvatar"
6635
alt="avatar"
6736
/>
@@ -94,14 +63,14 @@ import { KeFuMessageApi, KeFuMessageRespVO } from '@/api/mall/promotion/kefu/mes
9463
import { KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
9564
import EmojiSelectPopover from './tools/EmojiSelectPopover.vue'
9665
import PictureSelectUpload from './tools/PictureSelectUpload.vue'
97-
import { Emoji, useEmoji } from './tools/emoji'
66+
import TextMessageItem from './message/TextMessageItem.vue'
67+
import ImageMessageItem from './message/ImageMessageItem.vue'
68+
import { Emoji } from './tools/emoji'
9869
import { KeFuMessageContentTypeEnum } from './tools/constants'
9970
import { isEmpty } from '@/utils/is'
10071
import { UserTypeEnum } from '@/utils/constants'
101-
import { createImageViewer } from '@/components/ImageViewer'
10272
10373
defineOptions({ name: 'KeFuMessageBox' })
104-
const { replaceEmoji } = useEmoji()
10574
const messageTool = useMessage()
10675
const message = ref('') // 消息
10776
const messageList = ref<KeFuMessageRespVO[]>([]) // 消息列表
@@ -175,13 +144,6 @@ const scrollToBottom = async () => {
175144
scrollbarRef.value!.setScrollTop(innerRef.value!.clientHeight)
176145
}
177146
178-
/** 图预览 */
179-
const imagePreview = (imgUrl: string) => {
180-
createImageViewer({
181-
urlList: [imgUrl]
182-
})
183-
}
184-
185147
// TODO puhui999: 轮训相关,功能完善后移除
186148
onBeforeUnmount(() => {
187149
if (!poller.value) {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<!-- 图片消息 -->
3+
<template v-if="KeFuMessageContentTypeEnum.IMAGE === message.contentType">
4+
<div
5+
:class="[
6+
message.senderType === UserTypeEnum.MEMBER
7+
? `ml-10px`
8+
: message.senderType === UserTypeEnum.ADMIN
9+
? `mr-10px`
10+
: ''
11+
]"
12+
class="flex messages-center"
13+
>
14+
<el-image
15+
:src="message.content"
16+
fit="contain"
17+
style="width: 200px; height: 200px"
18+
@click="imagePreview(message.content)"
19+
/>
20+
</div>
21+
</template>
22+
</template>
23+
24+
<script lang="ts" setup>
25+
import { KeFuMessageContentTypeEnum } from '../tools/constants'
26+
import { UserTypeEnum } from '@/utils/constants'
27+
import { KeFuMessageRespVO } from '@/api/mall/promotion/kefu/message'
28+
import { createImageViewer } from '@/components/ImageViewer'
29+
30+
defineOptions({ name: 'ImageMessageItem' })
31+
defineProps<{
32+
message: KeFuMessageRespVO
33+
}>()
34+
/** 图预览 */
35+
const imagePreview = (imgUrl: string) => {
36+
createImageViewer({
37+
urlList: [imgUrl]
38+
})
39+
}
40+
</script>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<template>
2+
<!-- 文本消息 -->
3+
<template v-if="KeFuMessageContentTypeEnum.TEXT === message.contentType">
4+
<div
5+
v-dompurify-html="replaceEmoji(message.content)"
6+
:class="[
7+
message.senderType === UserTypeEnum.MEMBER
8+
? `ml-10px`
9+
: message.senderType === UserTypeEnum.ADMIN
10+
? `mr-10px`
11+
: ''
12+
]"
13+
class="flex items-center"
14+
></div>
15+
</template>
16+
</template>
17+
18+
<script lang="ts" setup>
19+
import { KeFuMessageContentTypeEnum } from '../tools/constants'
20+
import { UserTypeEnum } from '@/utils/constants'
21+
import { useEmoji } from '../tools/emoji'
22+
import { KeFuMessageRespVO } from '@/api/mall/promotion/kefu/message'
23+
24+
defineOptions({ name: 'TextMessageItem' })
25+
defineProps<{
26+
message: KeFuMessageRespVO
27+
}>()
28+
const { replaceEmoji } = useEmoji()
29+
</script>

0 commit comments

Comments
 (0)