1
1
<template >
2
2
<div class =" kefu" >
3
+ <!-- TODO @puhui999:item => conversation 会不会更容易理解 -->
3
4
<div
4
5
v-for =" (item, index) in conversationList"
5
6
:key =" item.id"
9
10
@contextmenu.prevent =" rightClick($event as PointerEvent, item)"
10
11
>
11
12
<div class =" flex justify-center items-center w-100%" >
13
+ <!-- TODO style 换成 unocss -->
12
14
<div class =" flex justify-center items-center" style =" width : 50px ; height : 50px " >
15
+ <!-- 头像 + 未读 -->
13
16
<el-badge
14
17
:hidden =" item.adminUnreadMessageCount === 0"
15
18
:max =" 99"
41
44
</div >
42
45
</div >
43
46
</div >
44
- <!-- 通过右击获取到的坐标定位 -->
47
+
48
+ <!-- 右键,进行操作(类似微信) -->
45
49
<ul v-show =" showRightMenu" :style =" rightMenuStyle" class =" right-menu-ul" >
46
50
<li
47
51
v-show =" !selectedConversation.adminPinned"
@@ -78,23 +82,30 @@ import { formatDate } from '@/utils/formatTime'
78
82
import { KeFuMessageContentTypeEnum } from ' ./tools/constants'
79
83
80
84
defineOptions ({ name: ' KeFuConversationBox' })
81
- const message = useMessage ()
85
+
86
+ const message = useMessage () // 消息弹窗
87
+
82
88
const { replaceEmoji } = useEmoji ()
83
- const activeConversationIndex = ref (- 1 ) // 选中的会话
84
89
const conversationList = ref <KeFuConversationRespVO []>([]) // 会话列表
90
+ const activeConversationIndex = ref (- 1 ) // 选中的会话 index 位置 TODO @puhui999:这个可以改成 activeConversationId 么?因为一般是选中的对话编号
91
+
92
+ /** 加载会话列表 */
85
93
const getConversationList = async () => {
86
94
conversationList .value = await KeFuConversationApi .getConversationList ()
87
95
}
88
96
defineExpose ({ getConversationList })
97
+
98
+ /** 打开右侧的消息列表 */
89
99
const emits = defineEmits <{
90
100
(e : ' change' , v : KeFuConversationRespVO ): void
91
101
}>()
92
- // 打开右侧消息
93
102
const openRightMessage = (item : KeFuConversationRespVO , index : number ) => {
94
103
activeConversationIndex .value = index
95
104
emits (' change' , item )
96
105
}
97
- // 获得消息类型
106
+
107
+ // TODO @puhui999:这个,是不是改成 getConversationDisplayText,获取会话的展示文本。然后,把文本消息类型,也统一处理(包括上面的 replaceEmoji)。这样,更统一。
108
+ /** 获得消息类型 */
98
109
const getContentType = computed (() => (lastMessageContentType : number ) => {
99
110
switch (lastMessageContentType ) {
100
111
case KeFuMessageContentTypeEnum .SYSTEM :
@@ -117,8 +128,9 @@ const getContentType = computed(() => (lastMessageContentType: number) => {
117
128
// ======================= 右键菜单 =======================
118
129
const showRightMenu = ref (false ) // 显示右键菜单
119
130
const rightMenuStyle = ref <any >({}) // 右键菜单 Style
120
- const selectedConversation = ref <KeFuConversationRespVO >({} as KeFuConversationRespVO ) // 右键选中的会话对象
121
- // 右键菜单
131
+ const selectedConversation = ref <KeFuConversationRespVO >({} as KeFuConversationRespVO ) // 右键选中的会话对象 TODO puhui999:这个是不是叫 rightClickConversation 会好点。因为 selected 容易和选中的对话,定义上有点重叠
132
+
133
+ /** 打开右键菜单 */
122
134
const rightClick = (mouseEvent : PointerEvent , item : KeFuConversationRespVO ) => {
123
135
selectedConversation .value = item
124
136
// 显示右键菜单
@@ -128,11 +140,12 @@ const rightClick = (mouseEvent: PointerEvent, item: KeFuConversationRespVO) => {
128
140
left: mouseEvent .clientX - 80 + ' px'
129
141
}
130
142
}
131
- // 关闭菜单
143
+ /** 关闭右键菜单 */
132
144
const closeRightMenu = () => {
133
145
showRightMenu .value = false
134
146
}
135
- // 置顶会话
147
+
148
+ /** 置顶会话 */
136
149
const updateConversationPinned = async (adminPinned : boolean ) => {
137
150
// 1. 会话置顶/取消置顶
138
151
await KeFuConversationApi .updateConversationPinned ({
@@ -144,7 +157,8 @@ const updateConversationPinned = async (adminPinned: boolean) => {
144
157
closeRightMenu ()
145
158
await getConversationList ()
146
159
}
147
- // 删除会话
160
+
161
+ /** 删除会话 */
148
162
const deleteConversation = async () => {
149
163
// 1. 删除会话
150
164
await message .confirm (' 您确定要删除该会话吗?' )
@@ -153,6 +167,8 @@ const deleteConversation = async () => {
153
167
closeRightMenu ()
154
168
await getConversationList ()
155
169
}
170
+
171
+ /** 监听右键菜单的显示状态,添加点击事件监听器 */
156
172
watch (showRightMenu , (val ) => {
157
173
if (val ) {
158
174
document .body .addEventListener (' click' , closeRightMenu )
0 commit comments