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
df34f65d
authored
Nov 09, 2024
by
puhui999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【功能完善】商城: 客服会话消息缓存
parent
e342e91f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
12 deletions
+22
-12
src/store/modules/mall/kefu.ts
+8
-3
src/views/mall/promotion/kefu/components/KeFuConversationList.vue
+4
-0
src/views/mall/promotion/kefu/components/KeFuMessageList.vue
+10
-9
No files found.
src/store/modules/mall/kefu.ts
View file @
df34f65d
...
@@ -4,7 +4,6 @@ import { KeFuConversationApi, KeFuConversationRespVO } from '@/api/mall/promotio
...
@@ -4,7 +4,6 @@ import { KeFuConversationApi, KeFuConversationRespVO } from '@/api/mall/promotio
import
{
KeFuMessageRespVO
}
from
'@/api/mall/promotion/kefu/message'
import
{
KeFuMessageRespVO
}
from
'@/api/mall/promotion/kefu/message'
import
{
isEmpty
}
from
'@/utils/is'
import
{
isEmpty
}
from
'@/utils/is'
// TODO puhui999: 待优化完善
interface
MallKefuInfoVO
{
interface
MallKefuInfoVO
{
conversationList
:
KeFuConversationRespVO
[]
// 会话列表
conversationList
:
KeFuConversationRespVO
[]
// 会话列表
conversationMessageList
:
Map
<
number
,
KeFuMessageRespVO
[]
>
// 会话消息
conversationMessageList
:
Map
<
number
,
KeFuMessageRespVO
[]
>
// 会话消息
...
@@ -19,11 +18,17 @@ export const useMallKefuStore = defineStore('mall-kefu', {
...
@@ -19,11 +18,17 @@ export const useMallKefuStore = defineStore('mall-kefu', {
getConversationList
():
KeFuConversationRespVO
[]
{
getConversationList
():
KeFuConversationRespVO
[]
{
return
this
.
conversationList
return
this
.
conversationList
},
},
getConversationMessageList
():
Map
<
number
,
KeFuMessageRespVO
[]
>
{
getConversationMessageList
():
(
conversationId
:
number
)
=>
KeFuMessageRespVO
[]
|
undefined
{
return
this
.
conversationMessageList
return
(
conversationId
:
number
)
=>
this
.
conversationMessageList
.
get
(
conversationId
)
}
}
},
},
actions
:
{
actions
:
{
//======================= 会话消息相关 =======================
/** 缓存历史消息 */
saveMessageList
(
conversationId
:
number
,
messageList
:
KeFuMessageRespVO
[])
{
this
.
conversationMessageList
.
set
(
conversationId
,
messageList
)
},
//======================= 会话相关 =======================
/** 加载会话缓存列表 */
/** 加载会话缓存列表 */
async
setConversationList
()
{
async
setConversationList
()
{
this
.
conversationList
=
await
KeFuConversationApi
.
getConversationList
()
this
.
conversationList
=
await
KeFuConversationApi
.
getConversationList
()
...
...
src/views/mall/promotion/kefu/components/KeFuConversationList.vue
View file @
df34f65d
...
@@ -93,6 +93,10 @@ const emits = defineEmits<{
...
@@ -93,6 +93,10 @@ const emits = defineEmits<{
(
e
:
'change'
,
v
:
KeFuConversationRespVO
):
void
(
e
:
'change'
,
v
:
KeFuConversationRespVO
):
void
}
>
()
}
>
()
const
openRightMessage
=
(
item
:
KeFuConversationRespVO
)
=>
{
const
openRightMessage
=
(
item
:
KeFuConversationRespVO
)
=>
{
// 同一个会话则不处理
if
(
activeConversationId
.
value
===
item
.
id
)
{
return
}
activeConversationId
.
value
=
item
.
id
activeConversationId
.
value
=
item
.
id
emits
(
'change'
,
item
)
emits
(
'change'
,
item
)
}
}
...
...
src/views/mall/promotion/kefu/components/KeFuMessageList.vue
View file @
df34f65d
...
@@ -236,19 +236,20 @@ const refreshMessageList = async (message?: any) => {
...
@@ -236,19 +236,20 @@ const refreshMessageList = async (message?: any) => {
}
}
}
}
/** 获得新会话的消息列表 */
/** 获得新会话的消息列表, 点击切换时,读取缓存;然后异步获取新消息,merge 下; */
// TODO @puhui999:可优化:可以考虑本地做每个会话的消息 list 缓存;然后点击切换时,读取缓存;然后异步获取新消息,merge 下;
const
getNewMessageList
=
async
(
val
:
KeFuConversationRespVO
)
=>
{
const
getNewMessageList
=
async
(
val
:
KeFuConversationRespVO
)
=>
{
// 会话切换,重置相关参数
// 1. 缓存当前会话消息列表
messageList
.
value
=
[]
kefuStore
.
saveMessageList
(
conversation
.
value
.
id
,
messageList
.
value
)
total
.
value
=
0
// 2.1 会话切换,重置相关参数
messageList
.
value
=
kefuStore
.
getConversationMessageList
(
val
.
id
)
||
[]
total
.
value
=
messageList
.
value
.
length
||
0
loadHistory
.
value
=
false
loadHistory
.
value
=
false
refreshContent
.
value
=
false
refreshContent
.
value
=
false
// 设置会话相关属性
//
2.2
设置会话相关属性
conversation
.
value
=
val
conversation
.
value
=
val
queryParams
.
conversationId
=
val
.
id
queryParams
.
conversationId
=
val
.
id
queryParams
.
createTime
=
undefined
queryParams
.
createTime
=
undefined
// 获取消息
//
3.
获取消息
await
refreshMessageList
()
await
refreshMessageList
()
}
}
defineExpose
({
getNewMessageList
,
refreshMessageList
})
defineExpose
({
getNewMessageList
,
refreshMessageList
})
...
@@ -299,8 +300,8 @@ const sendMessage = async (msg: any) => {
...
@@ -299,8 +300,8 @@ const sendMessage = async (msg: any) => {
message
.
value
=
''
message
.
value
=
''
// 加载消息列表
// 加载消息列表
await
refreshMessageList
()
await
refreshMessageList
()
//
异步刷新
//
更新会话缓存
kefuStore
.
updateConversation
(
conversation
.
value
.
id
)
await
kefuStore
.
updateConversation
(
conversation
.
value
.
id
)
}
}
/** 滚动到底部 */
/** 滚动到底部 */
...
...
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