Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
893cd5d8
authored
Jul 04, 2024
by
puhui999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【优化】:mall 客服优化消息样式,增加消息时间段显示
parent
e89b274e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
53 deletions
+81
-53
src/views/mall/promotion/kefu/components/KeFuChatBox.vue
+77
-29
src/views/mall/promotion/kefu/components/KeFuConversationBox.vue
+1
-19
src/views/mall/promotion/kefu/components/message/ImageMessageItem.vue
+1
-2
src/views/mall/promotion/kefu/components/tools/PictureSelectUpload.vue
+2
-3
No files found.
src/views/mall/promotion/kefu/components/KeFuChatBox.vue
View file @
893cd5d8
...
@@ -6,34 +6,55 @@
...
@@ -6,34 +6,55 @@
<el-main
class=
"kefu-content"
style=
"overflow: visible"
>
<el-main
class=
"kefu-content"
style=
"overflow: visible"
>
<el-scrollbar
ref=
"scrollbarRef"
always
height=
"calc(100vh - 495px)"
>
<el-scrollbar
ref=
"scrollbarRef"
always
height=
"calc(100vh - 495px)"
>
<div
ref=
"innerRef"
class=
"w-[100%] pb-3px"
>
<div
ref=
"innerRef"
class=
"w-[100%] pb-3px"
>
<div
<div
v-for=
"(item, index) in messageList"
:key=
"item.id"
class=
"w-[100%]"
>
v-for=
"item in messageList"
<div
class=
"flex justify-center items-center mb-20px"
>
:key=
"item.id"
<!-- 日期 -->
:class=
"[
<div
item.senderType === UserTypeEnum.MEMBER
v-if=
"
? `ss-row-left`
item.contentType !== KeFuMessageContentTypeEnum.SYSTEM && showTime(item, index)
: item.senderType === UserTypeEnum.ADMIN
"
? `ss-row-right`
class=
"date-message"
: ''
>
]"
{{
formatDate
(
item
.
createTime
)
}}
class=
"flex mb-20px w-[100%]"
</div>
>
<!-- 系统消息 -->
<el-avatar
<view
v-if=
"item.senderType === UserTypeEnum.MEMBER"
v-if=
"item.contentType === KeFuMessageContentTypeEnum.SYSTEM"
:src=
"keFuConversation.userAvatar"
class=
"system-message"
alt=
"avatar"
>
/>
{{
item
.
content
}}
<div
class=
"kefu-message p-10px"
>
</view>
<!-- 文本消息 -->
</div>
<TextMessageItem
:message=
"item"
/>
<div
<!-- 图片消息 -->
:class=
"[
<ImageMessageItem
:message=
"item"
/>
item.senderType === UserTypeEnum.MEMBER
? `ss-row-left`
: item.senderType === UserTypeEnum.ADMIN
? `ss-row-right`
: ''
]"
class=
"flex mb-20px w-[100%]"
>
<el-avatar
v-if=
"item.senderType === UserTypeEnum.MEMBER"
:src=
"keFuConversation.userAvatar"
alt=
"avatar"
/>
<div
:class=
"
{ 'kefu-message': KeFuMessageContentTypeEnum.TEXT === item.contentType }"
class="p-10px"
>
<!-- 文本消息 -->
<TextMessageItem
:message=
"item"
/>
<!-- 图片消息 -->
<ImageMessageItem
:message=
"item"
/>
</div>
<el-avatar
v-if=
"item.senderType === UserTypeEnum.ADMIN"
:src=
"item.senderAvatar"
alt=
"avatar"
/>
</div>
</div>
<el-avatar
v-if=
"item.senderType === UserTypeEnum.ADMIN"
:src=
"item.senderAvatar"
alt=
"avatar"
/>
</div>
</div>
</div>
</div>
</el-scrollbar>
</el-scrollbar>
...
@@ -69,6 +90,11 @@ import { Emoji } from './tools/emoji'
...
@@ -69,6 +90,11 @@ import { Emoji } from './tools/emoji'
import
{
KeFuMessageContentTypeEnum
}
from
'./tools/constants'
import
{
KeFuMessageContentTypeEnum
}
from
'./tools/constants'
import
{
isEmpty
}
from
'@/utils/is'
import
{
isEmpty
}
from
'@/utils/is'
import
{
UserTypeEnum
}
from
'@/utils/constants'
import
{
UserTypeEnum
}
from
'@/utils/constants'
import
{
formatDate
}
from
'@/utils/formatTime'
import
dayjs
from
'dayjs'
import
relativeTime
from
'dayjs/plugin/relativeTime'
dayjs
.
extend
(
relativeTime
)
defineOptions
({
name
:
'KeFuMessageBox'
})
defineOptions
({
name
:
'KeFuMessageBox'
})
const
messageTool
=
useMessage
()
const
messageTool
=
useMessage
()
...
@@ -90,7 +116,7 @@ const getMessageList = async (conversation: KeFuConversationRespVO) => {
...
@@ -90,7 +116,7 @@ const getMessageList = async (conversation: KeFuConversationRespVO) => {
if
(
!
poller
.
value
)
{
if
(
!
poller
.
value
)
{
poller
.
value
=
setInterval
(()
=>
{
poller
.
value
=
setInterval
(()
=>
{
getMessageList
(
conversation
)
getMessageList
(
conversation
)
},
1
000
)
},
2
000
)
}
}
}
}
defineExpose
({
getMessageList
})
defineExpose
({
getMessageList
})
...
@@ -143,7 +169,18 @@ const scrollToBottom = async () => {
...
@@ -143,7 +169,18 @@ const scrollToBottom = async () => {
await
nextTick
()
await
nextTick
()
scrollbarRef
.
value
!
.
setScrollTop
(
innerRef
.
value
!
.
clientHeight
)
scrollbarRef
.
value
!
.
setScrollTop
(
innerRef
.
value
!
.
clientHeight
)
}
}
/**
* 是否显示时间
* @param {*} item - 数据
* @param {*} index - 索引
*/
const
showTime
=
computed
(()
=>
(
item
:
KeFuMessageRespVO
,
index
:
number
)
=>
{
if
(
unref
(
messageList
.
value
)[
index
+
1
])
{
let
dateString
=
dayjs
(
unref
(
messageList
.
value
)[
index
+
1
].
createTime
).
fromNow
()
return
dateString
!==
dayjs
(
unref
(
item
).
createTime
).
fromNow
()
}
return
false
})
// TODO puhui999: 轮训相关,功能完善后移除
// TODO puhui999: 轮训相关,功能完善后移除
onBeforeUnmount
(()
=>
{
onBeforeUnmount
(()
=>
{
if
(
!
poller
.
value
)
{
if
(
!
poller
.
value
)
{
...
@@ -225,6 +262,17 @@ onBeforeUnmount(() => {
...
@@ -225,6 +262,17 @@ onBeforeUnmount(() => {
transform
:
scale
(
1.03
);
transform
:
scale
(
1.03
);
}
}
}
}
.date-message
,
.system-message
{
width
:
fit-content
;
border-radius
:
12
rpx
;
padding
:
8
rpx
16
rpx
;
margin-bottom
:
16
rpx
;
background-color
:
#e8e8e8
;
color
:
#999
;
font-size
:
24
rpx
;
}
}
}
.chat-tools
{
.chat-tools
{
...
...
src/views/mall/promotion/kefu/components/KeFuConversationBox.vue
View file @
893cd5d8
...
@@ -36,7 +36,7 @@
...
@@ -36,7 +36,7 @@
<
script
lang=
"ts"
setup
>
<
script
lang=
"ts"
setup
>
import
{
KeFuConversationApi
,
KeFuConversationRespVO
}
from
'@/api/mall/promotion/kefu/conversation'
import
{
KeFuConversationApi
,
KeFuConversationRespVO
}
from
'@/api/mall/promotion/kefu/conversation'
import
{
useEmoji
}
from
'./tools/emoji'
import
{
useEmoji
}
from
'./tools/emoji'
import
{
formatDate
,
getNowDateTime
}
from
'@/utils/formatTime'
import
{
formatDate
}
from
'@/utils/formatTime'
import
{
KeFuMessageContentTypeEnum
}
from
'./tools/constants'
import
{
KeFuMessageContentTypeEnum
}
from
'./tools/constants'
defineOptions
({
name
:
'KeFuConversationBox'
})
defineOptions
({
name
:
'KeFuConversationBox'
})
...
@@ -45,24 +45,6 @@ const activeConversationIndex = ref(-1) // 选中的会话
...
@@ -45,24 +45,6 @@ const activeConversationIndex = ref(-1) // 选中的会话
const
conversationList
=
ref
<
KeFuConversationRespVO
[]
>
([])
// 会话列表
const
conversationList
=
ref
<
KeFuConversationRespVO
[]
>
([])
// 会话列表
const
getConversationList
=
async
()
=>
{
const
getConversationList
=
async
()
=>
{
conversationList
.
value
=
await
KeFuConversationApi
.
getConversationList
()
conversationList
.
value
=
await
KeFuConversationApi
.
getConversationList
()
// 测试数据
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
conversationList
.
value
.
push
({
id
:
1
,
userId
:
283
,
userAvatar
:
'https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKMezSxtOImrC9lbhwHiazYwck3xwrEcO7VJfG6WQo260whaeVNoByE5RreiaGsGfOMlIiaDhSaA991w/132'
,
userNickname
:
'辉辉鸭'
+
i
,
lastMessageTime
:
getNowDateTime
(),
lastMessageContent
:
'[爱心][爱心]你好哇你好哇你好哇你好哇你好哇你好哇你好哇你好哇你好哇你好哇你好哇你好哇你好哇你好哇你好哇你好哇你好哇你好哇'
,
lastMessageContentType
:
1
,
adminPinned
:
false
,
userDeleted
:
false
,
adminDeleted
:
false
,
adminUnreadMessageCount
:
19
})
}
}
}
defineExpose
({
getConversationList
})
defineExpose
({
getConversationList
})
const
emits
=
defineEmits
<
{
const
emits
=
defineEmits
<
{
...
...
src/views/mall/promotion/kefu/components/message/ImageMessageItem.vue
View file @
893cd5d8
...
@@ -9,12 +9,11 @@
...
@@ -9,12 +9,11 @@
? `mr-10px`
? `mr-10px`
: ''
: ''
]"
]"
class=
"flex messages-center"
>
>
<el-image
<el-image
:src=
"message.content"
:src=
"message.content"
fit=
"contain"
fit=
"contain"
style=
"width: 200px
; height: 200px
"
style=
"width: 200px"
@
click=
"imagePreview(message.content)"
@
click=
"imagePreview(message.content)"
/>
/>
</div>
</div>
...
...
src/views/mall/promotion/kefu/components/tools/PictureSelectUpload.vue
View file @
893cd5d8
...
@@ -16,9 +16,8 @@ const emits = defineEmits<{
...
@@ -16,9 +16,8 @@ const emits = defineEmits<{
// 选择并上传文件
// 选择并上传文件
const
selectAndUpload
=
async
()
=>
{
const
selectAndUpload
=
async
()
=>
{
const
files
:
any
=
await
getFiles
()
const
files
:
any
=
await
getFiles
()
message
.
success
(
'图片发送请稍等。。。'
)
message
.
success
(
'图片发送
中
请稍等。。。'
)
const
res
=
await
FileApi
.
updateFile
({
file
:
files
[
0
].
file
})
const
res
=
await
FileApi
.
updateFile
({
file
:
files
[
0
].
file
})
message
.
success
(
'图片发送成功!'
)
emits
(
'send-picture'
,
res
.
data
)
emits
(
'send-picture'
,
res
.
data
)
}
}
...
@@ -34,7 +33,7 @@ const selectAndUpload = async () => {
...
@@ -34,7 +33,7 @@ const selectAndUpload = async () => {
async
function
getFiles
(
options
=
{})
{
async
function
getFiles
(
options
=
{})
{
const
{
multiple
,
accept
,
limit
,
fileSize
}
=
{
const
{
multiple
,
accept
,
limit
,
fileSize
}
=
{
multiple
:
true
,
multiple
:
true
,
accept
:
'image/jpeg, image/png, image/gif'
,
accept
:
'image/jpeg, image/png, image/gif'
,
// 默认选择图片
limit
:
1
,
limit
:
1
,
fileSize
:
500
,
fileSize
:
500
,
...
options
...
options
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment