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
Unverified
Commit
fc5df39b
authored
Nov 21, 2024
by
芋道源码
Committed by
Gitee
Nov 21, 2024
Browse files
Options
Browse Files
Download
Plain Diff
!589 【功能完善】商城: 客服动态计算消息最后发送时间距离现在过去了多久
Merge pull request !589 from puhui999/dev
parents
3b49f7de
4d2c0389
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
10 deletions
+29
-10
src/views/mall/promotion/kefu/components/KeFuConversationList.vue
+19
-1
src/views/mall/promotion/kefu/components/KeFuMessageList.vue
+6
-6
src/views/mall/promotion/kefu/index.vue
+4
-3
No files found.
src/views/mall/promotion/kefu/components/KeFuConversationList.vue
View file @
fc5df39b
...
...
@@ -26,7 +26,7 @@
<div
class=
"flex justify-between items-center w-100%"
>
<span
class=
"username"
>
{{
item
.
userNickname
}}
</span>
<span
class=
"color-[#999]"
style=
"font-size: 13px"
>
{{
formatPast
(
item
.
lastMessageTime
,
'YYYY-MM-DD'
)
}}
{{
lastMessageTimeMap
.
get
(
item
.
id
)
??
'计算中'
}}
</span>
</div>
<!-- 最后聊天内容 -->
...
...
@@ -89,6 +89,14 @@ const { replaceEmoji } = useEmoji()
const
activeConversationId
=
ref
(
-
1
)
// 选中的会话
const
collapse
=
computed
(()
=>
appStore
.
getCollapse
)
// 折叠菜单
const
lastMessageTimeMap
=
ref
<
Map
<
number
,
string
>>
(
new
Map
<
number
,
string
>
())
/** 计算消息最后发送时间距离现在过去了多久 */
const
calculationLastMessageTime
=
()
=>
{
kefuStore
.
getConversationList
?.
forEach
((
item
)
=>
{
lastMessageTimeMap
.
value
.
set
(
item
.
id
,
formatPast
(
item
.
lastMessageTime
,
'YYYY-MM-DD'
))
})
}
defineExpose
({
calculationLastMessageTime
})
/** 打开右侧的消息列表 */
const
emits
=
defineEmits
<
{
(
e
:
'change'
,
v
:
KeFuConversationRespVO
):
void
...
...
@@ -177,6 +185,16 @@ watch(showRightMenu, (val) => {
document
.
body
.
removeEventListener
(
'click'
,
closeRightMenu
)
}
})
const
timer
=
ref
<
any
>
()
/** 初始化 */
onMounted
(()
=>
{
timer
.
value
=
setInterval
(
calculationLastMessageTime
,
1000
*
10
)
// 十秒计算一次
})
/** 组件卸载前 */
onBeforeUnmount
(()
=>
{
clearInterval
(
timer
.
value
)
})
</
script
>
<
style
lang=
"scss"
scoped
>
...
...
src/views/mall/promotion/kefu/components/KeFuMessageList.vue
View file @
fc5df39b
...
...
@@ -414,7 +414,7 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
.kefu-message
{
background-color
:
rgb
(
245
,
245
,
245
);
margin-left
:
10px
;
margin-top
:
18
px
;
margin-top
:
3
px
;
border-top-right-radius
:
10px
;
border-bottom-right-radius
:
10px
;
border-bottom-left-radius
:
10px
;
...
...
@@ -427,7 +427,7 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
.kefu-message
{
background-color
:
rgb
(
206
,
223
,
255
);
margin-right
:
10px
;
margin-top
:
18
px
;
margin-top
:
3
px
;
border-top-left-radius
:
10px
;
border-bottom-right-radius
:
10px
;
border-bottom-left-radius
:
10px
;
...
...
@@ -454,11 +454,11 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
.date-message
,
.system-message
{
width
:
fit-content
;
b
order-radius
:
12
rpx
;
padding
:
8
rpx
16
r
px
;
margin-bottom
:
16
r
px
;
b
ackground-color
:
rgba
(
0
,
0
,
0
,
0.1
)
;
border-radius
:
8
px
;
padding
:
0
5
px
;
color
:
#999
;
font-size
:
24
r
px
;
font-size
:
10
px
;
}
}
...
...
src/views/mall/promotion/kefu/index.vue
View file @
fc5df39b
...
...
@@ -31,7 +31,6 @@ const server = ref(
)
// WebSocket 服务地址
/** 发起 WebSocket 连接 */
// TODO puhui999: websocket 连接有点问题收不到消息 🤣
const
{
data
,
close
,
open
}
=
useWebSocket
(
server
.
value
,
{
autoReconnect
:
true
,
heartbeat
:
true
...
...
@@ -49,7 +48,6 @@ watchEffect(() => {
}
// 2.1 解析 type 消息类型
const
jsonMessage
=
JSON
.
parse
(
data
.
value
)
console
.
log
(
jsonMessage
)
const
type
=
jsonMessage
.
type
if
(
!
type
)
{
message
.
error
(
'未知的消息类型:'
+
data
.
value
)
...
...
@@ -83,10 +81,13 @@ const handleChange = (conversation: KeFuConversationRespVO) => {
memberInfoRef
.
value
?.
initHistory
(
conversation
)
}
const
keFuConversationRef
=
ref
<
InstanceType
<
typeof
KeFuConversationList
>>
()
/** 初始化 */
onMounted
(()
=>
{
/** 加载会话列表 */
kefuStore
.
setConversationList
()
kefuStore
.
setConversationList
().
then
(()
=>
{
keFuConversationRef
.
value
?.
calculationLastMessageTime
()
})
// 打开 websocket 连接
open
()
})
...
...
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