|
|
@@ -72,17 +72,24 @@
|
|
|
>
|
|
|
<div style="display: flex; justify-content: flex-end;max-width: 70%;">
|
|
|
<div class="bubble right">
|
|
|
- <div class="read-status">
|
|
|
- <div
|
|
|
- v-if="maxReadSeq>=m.messageSeq"
|
|
|
+ <div
|
|
|
+ v-show="!sendStatusObj[m.clientSeq]"
|
|
|
+ class="read-status"
|
|
|
+ >
|
|
|
+ <!-- 已读/未读/发送失败文本 -->
|
|
|
+ <span
|
|
|
+ v-if="sendFailSeqs.includes(m.clientSeq)"
|
|
|
+ class="fail"
|
|
|
>
|
|
|
- {{ $t('chat.read') }}
|
|
|
- </div>
|
|
|
- <div
|
|
|
+ {{ $t('chat.sendFail') }}
|
|
|
+ </span>
|
|
|
+ <span
|
|
|
v-else
|
|
|
+ class="unread"
|
|
|
>
|
|
|
- {{ $t('chat.unRead') }}
|
|
|
- </div>
|
|
|
+ {{ maxReadSeq >= m.messageSeq ? $t('chat.read') : $t('chat.unRead') }}
|
|
|
+ </span>
|
|
|
+ <!-- end已读/未读/发送失败文本 -->
|
|
|
</div>
|
|
|
<div
|
|
|
v-if="m.content.text?.msgType===1"
|
|
|
@@ -618,7 +625,7 @@ const fileRef = ref(null)
|
|
|
let selectFileObj = null // 上传图片对象
|
|
|
// 发送图片
|
|
|
const toolEvent = async () => {
|
|
|
- WKSDK.shared().chatManager.removeMessageStatusListener(messageStatusListener)
|
|
|
+ sendAutoReplyInfo = null
|
|
|
if (fileRef.value.files[0]) {
|
|
|
selectFileObj = await compressImage(fileRef.value.files[0])
|
|
|
}
|
|
|
@@ -661,6 +668,9 @@ const toolEvent = async () => {
|
|
|
* 链接点击去往商品详情
|
|
|
*/
|
|
|
const toProdDetail = (prodInfo, type, orderType) => {
|
|
|
+ sendAutoReplyInfo = null
|
|
|
+ WKSDK.shared().chatManager.removeMessageListener(messageListener)
|
|
|
+ WKSDK.shared().disconnect()
|
|
|
// type 1 点击订单跳转 type
|
|
|
let routeUrl = null
|
|
|
if (Cookie.get('bbcToken')) {
|
|
|
@@ -756,6 +766,7 @@ let messageListener
|
|
|
let sendStatus = false
|
|
|
const channelInfolineStatus = ref(false)
|
|
|
const loginOtherSide = ref(false)
|
|
|
+let connectSuccess = false
|
|
|
const getWukong = () => {
|
|
|
http.post('/p/wuKongIm/registerOrLogin').then(({ data }) => {
|
|
|
// 认证信息
|
|
|
@@ -770,6 +781,7 @@ const getWukong = () => {
|
|
|
|
|
|
// 监听连接状态
|
|
|
connectStatusListener = (status) => {
|
|
|
+ connectSuccess = status === ConnectStatus.Connected
|
|
|
if (status === ConnectStatus.Connected) {
|
|
|
title.value = $t('chat.ConnectionSuccessful')
|
|
|
loginOtherSide.value = false
|
|
|
@@ -780,8 +792,39 @@ const getWukong = () => {
|
|
|
}
|
|
|
}
|
|
|
WKSDK.shared().connectManager.addConnectStatusListener(connectStatusListener)
|
|
|
+ // 监听消息发送状态
|
|
|
+ listenMsgSendStatus()
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+const sendFailSeqs = ref([])
|
|
|
+const sendStatusObj = ref({}) // clientSeq为key,value为加载状态
|
|
|
+const listenMsgSendStatus = () => {
|
|
|
+ sendFailSeqs.value = [] // 清空发送失败的seqs
|
|
|
+ sendStatusObj.value = {} // 清空发送状态对象
|
|
|
+ sendAutoReplyInfo = null // 清空自动回复信息
|
|
|
+ WKSDK.shared().chatManager.removeMessageStatusListener(messageStatusListener)
|
|
|
+ messageStatusListener = (ack) => {
|
|
|
+ if (ack.reasonCode === 1) {
|
|
|
+ // 发送自动回复
|
|
|
+ if (sendAutoReplyInfo) {
|
|
|
+ http.request({
|
|
|
+ url: '/p/wuKongIm/sendAutoReplyContent',
|
|
|
+ method: 'POST',
|
|
|
+ data: sendAutoReplyInfo
|
|
|
+ })
|
|
|
+ sendAutoReplyInfo = null
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // eslint-disable-next-line no-console
|
|
|
+ console.log('消息发送失败=>>', ack)
|
|
|
+ sendFailSeqs.value.push(ack.clientSeq)
|
|
|
+ }
|
|
|
+ sendStatusObj.value[ack.clientSeq] = false
|
|
|
+ }
|
|
|
+ WKSDK.shared().chatManager.addMessageStatusListener(messageStatusListener)
|
|
|
+}
|
|
|
+
|
|
|
const isJSON = (str) => {
|
|
|
if (typeof str == 'string') {
|
|
|
try {
|
|
|
@@ -819,7 +862,7 @@ const textMsg = ref(null) // 用户输入内容
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
const sendText = async (type, prod, orderInfo) => {
|
|
|
if (!to.value.channelID) return
|
|
|
- WKSDK.shared().chatManager.removeMessageStatusListener(messageStatusListener)
|
|
|
+ sendAutoReplyInfo = null
|
|
|
// type 1 = 发送消息 type 2 = 发送商品链接 type 3 = 右侧我的订单发送 type 4 = 发送订单号
|
|
|
if (type === 1) {
|
|
|
if (!textMsg.value || (textMsg.value && textMsg.value.match(/^\s+$/))) {
|
|
|
@@ -928,6 +971,8 @@ const onSelectChannel = (channel, shopName, id, maxSeq, status) => {
|
|
|
} else {
|
|
|
titleName.value = shopName
|
|
|
}
|
|
|
+ sendFailSeqs.value = []
|
|
|
+ sendStatusObj.value = {} // 清空发送状态对象
|
|
|
messages.value = []
|
|
|
pullLast() // 拉取最新消息
|
|
|
|
|
|
@@ -1083,6 +1128,13 @@ const pullLast = async () => {
|
|
|
} else {
|
|
|
msg.timeStr = util.tsToDate(new Date().getTime(), 'M月D日 h:m')
|
|
|
}
|
|
|
+ if (msg.clientSeq) {
|
|
|
+ if (!connectSuccess) {
|
|
|
+ sendFailSeqs.value.push(msg.clientSeq)
|
|
|
+ } else if (sendStatusObj.value[msg.clientSeq] !== false) {
|
|
|
+ sendStatusObj.value[msg.clientSeq] = true
|
|
|
+ }
|
|
|
+ }
|
|
|
messages.value.push(msg)
|
|
|
scrollBottom()
|
|
|
}
|
|
|
@@ -1113,12 +1165,14 @@ WKSDK.shared().config.provider.syncMessagesCallback = async (channel, opts) => {
|
|
|
if (messageList) {
|
|
|
messageList.forEach((msg) => {
|
|
|
const message = Convert.toMessage(msg)
|
|
|
- message.content.text = JSON.parse(message.content.text)
|
|
|
- message.timeStr = util.tsToDate(
|
|
|
- message.timestamp * 1000,
|
|
|
- 'M月D日 h:m'
|
|
|
- )
|
|
|
- resultMessages.push(message)
|
|
|
+ if (isJSON(message.content.text)) {
|
|
|
+ message.content.text = JSON.parse(message.content.text)
|
|
|
+ message.timeStr = util.tsToDate(
|
|
|
+ message.timestamp * 1000,
|
|
|
+ 'M月D日 h:m'
|
|
|
+ )
|
|
|
+ resultMessages.push(message)
|
|
|
+ }
|
|
|
})
|
|
|
resultMessages.length > 0 && resultMessages.reduce((prev, cur) => {
|
|
|
// 将时间更换为某某月某某日 要是是当天即去掉月日
|
|
|
@@ -1279,18 +1333,13 @@ const handleScroll = (e) => {
|
|
|
}
|
|
|
}
|
|
|
let messageStatusListener
|
|
|
+let sendAutoReplyInfo = null
|
|
|
const sendIssues = async (content, issues, channelId) => {
|
|
|
- WKSDK.shared().chatManager.removeMessageStatusListener(messageStatusListener)
|
|
|
const setting = Setting.fromUint8(0)
|
|
|
const msgObj = JSON.stringify({ msg: issues, msgType: 1 })
|
|
|
const sendContent = new MessageText(msgObj)
|
|
|
+ sendAutoReplyInfo = { channelId, content: JSON.stringify({ msg: content, msgType: -1 }) }
|
|
|
WKSDK.shared().chatManager.send(sendContent, to.value, setting)
|
|
|
- messageStatusListener = (ack) => {
|
|
|
- if (ack.reasonCode === 1) {
|
|
|
- http.post('/p/wuKongIm/sendAutoReplyContent', { channelId, content: JSON.stringify({ msg: content, msgType: -1 }) })
|
|
|
- }
|
|
|
- }
|
|
|
- WKSDK.shared().chatManager.addMessageStatusListener(messageStatusListener)
|
|
|
}
|
|
|
// 判断是否当天的信息
|
|
|
const isTimestampToday = (timestamp) => {
|