|
@@ -60,7 +60,7 @@ import MessageList from '@/components/MessageList'
|
|
|
import SearchFilter from '@/components/search/'
|
|
|
import AsideView from '@/components/aside/'
|
|
|
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
|
|
|
-import { getUserList, getMessageCount, createChatSession, findMessage, getServiceInfo, getWebSocketNode } from '@/api/modules/'
|
|
|
+import { getUserList, getMessageCount, findMessage, getServiceInfo, getWebSocketNode } from '@/api/modules/'
|
|
|
import { dateFormatter, isJSON, isHyperlink, momentTime, imgReg } from '@/utils/'
|
|
|
|
|
|
export default {
|
|
@@ -152,8 +152,14 @@ export default {
|
|
|
const result = list.sort((a, b) => {
|
|
|
return new Date(a?.create_time.replace(/-/g, '/')).getTime() - new Date(b?.create_time.replace(/-/g, '/')).getTime()
|
|
|
})
|
|
|
- console.log(result)
|
|
|
- return result
|
|
|
+ // console.log(result)
|
|
|
+ const obj = {}
|
|
|
+ const newResult = result.reduce((item, next) => {
|
|
|
+ // eslint-disable-next-line
|
|
|
+ obj[next.messageId] ? '' : obj[next.messageId] = true && item.push(next)
|
|
|
+ return item
|
|
|
+ }, [])
|
|
|
+ return newResult
|
|
|
},
|
|
|
// 获取已结束列表
|
|
|
getEndList () {
|
|
@@ -164,6 +170,7 @@ export default {
|
|
|
return u.userId
|
|
|
})
|
|
|
const result = tList.filter(v => {
|
|
|
+ v.badge = 0
|
|
|
return mergeList.indexOf(v.userId) === -1
|
|
|
})
|
|
|
return result
|
|
@@ -307,8 +314,8 @@ export default {
|
|
|
} else if (data.type === 6) {
|
|
|
// 接收到的消息 认领成功存储会话id
|
|
|
const { rUserId, sessionId } = data.data
|
|
|
- Object.assign(this.kfSessionBadge, { [rUserId]: sessionId })
|
|
|
- this.setKfSessionBadge(this.kfSessionBadge)
|
|
|
+ // Object.assign(this.kfSessionBadge, { [rUserId]: sessionId })
|
|
|
+ // this.setKfSessionBadge(this.kfSessionBadge)
|
|
|
if (this.other.userId === rUserId) {
|
|
|
this.other.sessionId = sessionId
|
|
|
this.showMsgBox = true
|
|
@@ -328,6 +335,7 @@ export default {
|
|
|
create_time: connectTime
|
|
|
}
|
|
|
this.saveMessageAction(params).then(res => {
|
|
|
+ params.messageId = res.data.messageId
|
|
|
this.msgList.push(params)
|
|
|
})
|
|
|
const resetSession = this.resetSession // 客服端重新加入会话所存的消息参数
|
|
@@ -346,6 +354,7 @@ export default {
|
|
|
this.selectItem = '会话'
|
|
|
// 客服发起聊天后
|
|
|
this.onSendCommon({ apiParams, socketParams })
|
|
|
+ this.other.sessionId = sessionId
|
|
|
this.showInfo = true
|
|
|
this.tabIndex = 0
|
|
|
}
|
|
@@ -359,10 +368,7 @@ export default {
|
|
|
// })
|
|
|
}
|
|
|
} else if (data.type === 7) {
|
|
|
- // 认领失败 更新排队列表
|
|
|
- // this.webSocketSend({
|
|
|
- // type: 9
|
|
|
- // })
|
|
|
+ // 认领失败
|
|
|
this.$toast('已被其他客户认领')
|
|
|
} else if (data.type === 8) {
|
|
|
// 正常双方通话接收的消息
|
|
@@ -374,7 +380,16 @@ export default {
|
|
|
v.msgType = contentType
|
|
|
v.message = content
|
|
|
v.lastTime = momentTime(new Date().getTime(), 'HH:mm:ss')
|
|
|
- v.badge++
|
|
|
+ if (sUserId !== this.other.userId) {
|
|
|
+ v.badge++
|
|
|
+ } else {
|
|
|
+ v.badge = 0
|
|
|
+ // 未读消息变已读
|
|
|
+ const paramId = {
|
|
|
+ messageId: id
|
|
|
+ }
|
|
|
+ this.modifyMessageAction(paramId)
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
// 更新排队列表中的最后一条消息内容
|
|
@@ -388,26 +403,23 @@ export default {
|
|
|
})
|
|
|
if (sUserId === this.other.userId) {
|
|
|
this.msgList.push({
|
|
|
+ messageId: id,
|
|
|
fool: 2,
|
|
|
type: contentType,
|
|
|
content: contentType !== 1 ? JSON.parse(content) : content,
|
|
|
create_time: dateFormatter(new Date().getTime())
|
|
|
})
|
|
|
- // 未读消息变已读
|
|
|
- const paramId = {
|
|
|
- messageId: id
|
|
|
- }
|
|
|
- this.modifyMessageAction(paramId)
|
|
|
this.$nextTick(() => {
|
|
|
this.$refs.userSide?.setScrollTop()
|
|
|
})
|
|
|
}
|
|
|
} else if (data.type === 9) {
|
|
|
// 系统消息 人工客服自动回复语
|
|
|
- const { rUserId, content } = data.data
|
|
|
+ const { rUserId, content, id } = data.data
|
|
|
if (rUserId === this.other.userId) {
|
|
|
setTimeout(() => {
|
|
|
this.msgList.push({
|
|
|
+ messageId: id,
|
|
|
fool: 1,
|
|
|
type: 1,
|
|
|
content: content,
|
|
@@ -420,10 +432,11 @@ export default {
|
|
|
}
|
|
|
} else if (data.type === 10) {
|
|
|
// 接收结束的会话消息
|
|
|
- const { rUserId, content } = data.data
|
|
|
+ const { rUserId, content, id } = data.data
|
|
|
if (rUserId === this.other.userId) {
|
|
|
// this.showMsgBox = false
|
|
|
const params = {
|
|
|
+ messageId: id,
|
|
|
type: 1,
|
|
|
title: '结束会话',
|
|
|
content: content,
|
|
@@ -487,7 +500,7 @@ export default {
|
|
|
if (e === '结束') {
|
|
|
this.showInfo = false
|
|
|
this.showMsgBox = true
|
|
|
- this.getUserListFn()
|
|
|
+ this.getUserListFn({})
|
|
|
// 点已结束 发送一句话即加入会话列表
|
|
|
} else {
|
|
|
if (e === '排队') {
|
|
@@ -546,56 +559,6 @@ export default {
|
|
|
this.userList = []
|
|
|
}
|
|
|
},
|
|
|
- /**
|
|
|
- * 创建会话
|
|
|
- */
|
|
|
- async createSessionFn (msgType = 5) {
|
|
|
- const storageInfo = this.kfSessionBadge
|
|
|
- if (storageInfo && Object.keys(storageInfo).length > 0) {
|
|
|
- for (const key in storageInfo) {
|
|
|
- if (key === this.other.userId && storageInfo[key]) {
|
|
|
- this.other.sessionId = storageInfo[key]
|
|
|
- this.getFindMessage()
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- const { data } = await createChatSession({
|
|
|
- userType: 1,
|
|
|
- msgType: msgType, // 消息类型 ;1:站内信消息 2:点对点消息 3:群消息 4:机器人消息 5:客服消息
|
|
|
- receiveId: this.other.userId,
|
|
|
- customerserviceName: this.login.nickName
|
|
|
- })
|
|
|
- if (data) {
|
|
|
- this.other.sessionId = data
|
|
|
- const kfStorage = {
|
|
|
- [this.other.userId]: data
|
|
|
- }
|
|
|
- Object.assign(this.kfSessionBadge, kfStorage)
|
|
|
- // 存储会话标识
|
|
|
- this.setKfSessionBadge(this.kfSessionBadge)
|
|
|
- // 设置首次建立连接时间
|
|
|
- const connectTime = dateFormatter(new Date().getTime())
|
|
|
- // 保存建立会话时间
|
|
|
- const params = {
|
|
|
- ownType: 2,
|
|
|
- title: '建立会话',
|
|
|
- content: `${connectTime}您和${this.other.nickName}建立了会话`,
|
|
|
- item: 8,
|
|
|
- itemType: 6,
|
|
|
- receiveId: this.other.userId,
|
|
|
- sendId: data,
|
|
|
- type: 1,
|
|
|
- link: ''
|
|
|
- }
|
|
|
- this.saveMessageAction(params).then(res => {
|
|
|
- params.fool = 2
|
|
|
- params.create_time = dateFormatter(new Date().getTime())
|
|
|
- this.msgList.push(params)
|
|
|
- })
|
|
|
- this.loadingMsg = false
|
|
|
- }
|
|
|
- },
|
|
|
/**
|
|
|
* 分页查询聊天内容
|
|
|
*/
|