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
91c262fb
authored
Jul 02, 2024
by
puhui999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【新增】:mall 客服使用轮训模拟 websocket
parent
9c05ff35
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
src/views/mall/promotion/kefu/components/KeFuChatBox.vue
+17
-2
src/views/mall/promotion/kefu/components/KeFuConversationBox.vue
+16
-0
No files found.
src/views/mall/promotion/kefu/components/KeFuChatBox.vue
View file @
91c262fb
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
:src=
"keFuConversation.userAvatar"
:src=
"keFuConversation.userAvatar"
alt=
"avatar"
alt=
"avatar"
/>
/>
<div
class=
"kefu-message
flex items-center
p-10px"
>
<div
class=
"kefu-message p-10px"
>
<!-- 文本消息 -->
<!-- 文本消息 -->
<template
v-if=
"KeFuMessageContentTypeEnum.TEXT === item.contentType"
>
<template
v-if=
"KeFuMessageContentTypeEnum.TEXT === item.contentType"
>
<div
<div
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
? `mr-10px`
? `mr-10px`
: ''
: ''
]"
]"
class=
"flex items-center"
></div>
></div>
</
template
>
</
template
>
<
template
v-else
>
<
template
v-else
>
...
@@ -80,7 +81,7 @@ const messageTool = useMessage()
...
@@ -80,7 +81,7 @@ const messageTool = useMessage()
const
message
=
ref
(
''
)
// 消息
const
message
=
ref
(
''
)
// 消息
const
messageList
=
ref
<
KeFuMessageRespVO
[]
>
([])
// 消息列表
const
messageList
=
ref
<
KeFuMessageRespVO
[]
>
([])
// 消息列表
const
keFuConversation
=
ref
<
KeFuConversationRespVO
>
({}
as
KeFuConversationRespVO
)
// 用户会话
const
keFuConversation
=
ref
<
KeFuConversationRespVO
>
({}
as
KeFuConversationRespVO
)
// 用户会话
const
poller
=
ref
<
any
>
(
null
)
// TODO puhui999: 轮训定时器,暂时模拟 websocket
// 获得消息 TODO puhui999: 先不考虑下拉加载历史消息
// 获得消息 TODO puhui999: 先不考虑下拉加载历史消息
const
getMessageList
=
async
(
conversation
:
KeFuConversationRespVO
)
=>
{
const
getMessageList
=
async
(
conversation
:
KeFuConversationRespVO
)
=>
{
keFuConversation
.
value
=
conversation
keFuConversation
.
value
=
conversation
...
@@ -91,6 +92,12 @@ const getMessageList = async (conversation: KeFuConversationRespVO) => {
...
@@ -91,6 +92,12 @@ const getMessageList = async (conversation: KeFuConversationRespVO) => {
messageList
.
value
=
list
.
reverse
()
messageList
.
value
=
list
.
reverse
()
// TODO puhui999: 首次加载时滚动到最新消息,如果加载的是历史消息则不滚动
// TODO puhui999: 首次加载时滚动到最新消息,如果加载的是历史消息则不滚动
await
scrollToBottom
()
await
scrollToBottom
()
// TODO puhui999: 轮训相关,功能完善后移除
if
(
!
poller
.
value
)
{
poller
.
value
=
setInterval
(()
=>
{
getMessageList
(
conversation
)
},
1000
)
}
}
}
defineExpose
({
getMessageList
})
defineExpose
({
getMessageList
})
// 是否显示聊天区域
// 是否显示聊天区域
...
@@ -126,6 +133,14 @@ const scrollToBottom = async () => {
...
@@ -126,6 +133,14 @@ const scrollToBottom = async () => {
await
nextTick
()
await
nextTick
()
scrollbarRef
.
value
!
.
setScrollTop
(
innerRef
.
value
!
.
clientHeight
)
scrollbarRef
.
value
!
.
setScrollTop
(
innerRef
.
value
!
.
clientHeight
)
}
}
// TODO puhui999: 轮训相关,功能完善后移除
onBeforeUnmount
(()
=>
{
if
(
!
poller
.
value
)
{
return
}
clearInterval
(
poller
.
value
)
})
</
script
>
</
script
>
<
style
lang=
"scss"
scoped
>
<
style
lang=
"scss"
scoped
>
...
...
src/views/mall/promotion/kefu/components/KeFuConversationBox.vue
View file @
91c262fb
...
@@ -64,6 +64,22 @@ const openRightMessage = (item: KeFuConversationRespVO, index: number) => {
...
@@ -64,6 +64,22 @@ const openRightMessage = (item: KeFuConversationRespVO, index: number) => {
activeConversationIndex
.
value
=
index
activeConversationIndex
.
value
=
index
emits
(
'change'
,
item
)
emits
(
'change'
,
item
)
}
}
const
poller
=
ref
<
any
>
(
null
)
// TODO puhui999: 轮训定时器,暂时模拟 websocket
onMounted
(()
=>
{
// TODO puhui999: 轮训相关,功能完善后移除
if
(
!
poller
.
value
)
{
poller
.
value
=
setInterval
(()
=>
{
getConversationList
()
},
1000
)
}
})
// TODO puhui999: 轮训相关,功能完善后移除
onBeforeUnmount
(()
=>
{
if
(
!
poller
.
value
)
{
return
}
clearInterval
(
poller
.
value
)
})
</
script
>
</
script
>
<
style
lang=
"scss"
scoped
>
<
style
lang=
"scss"
scoped
>
...
...
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