Commit 9d794137 authored by yaya's avatar yaya

feat: 添加数量展示

parent a618a14c
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
<el-container v-loading="loading" style="width: 100%;height: 100%; border: 1px solid #eee"> <el-container v-loading="loading" style="width: 100%;height: 100%; border: 1px solid #eee">
<el-aside style="width: 25%;background-color: white;padding: 0"> <el-aside style="width: 25%;background-color: white;padding: 0">
<el-tabs style="padding: 10px 10px 0;" @tab-click="handleClick"> <el-tabs style="padding: 10px 10px 0;" @tab-click="handleClick">
<el-tab-pane v-for="(item, indexNum) in customerList" :key="item.code" > <el-tab-pane v-for="(item) in customerList" :key="item.code" >
<div slot="label"> <div slot="label">
<div class="span-box"> <div class="span-box">
<span>{{ item.name }}</span> <span>{{ item.name }}</span>
<div v-if="indexNum === currentCustomerIndex && totalUnreadMessageCount > 0" class="span-box__num"/> <div v-if="item.unReadMessageCount > 0" class="span-box__num"/>
</div> </div>
</div> </div>
</el-tab-pane> </el-tab-pane>
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
</div> </div>
</el-main> </el-main>
<el-aside style="width: 25%;background-color: white;padding: 10px"> <el-aside style="width: 25%;background-color: white;padding: 10px">
<ChatUserInfo :chat-user-info="chatUserInfo"/> <ChatUserInfo v-if="chatUserInfo && chatUserInfo.user" :chat-user-info="chatUserInfo"/>
</el-aside> </el-aside>
</el-container> </el-container>
...@@ -125,9 +125,6 @@ export default { ...@@ -125,9 +125,6 @@ export default {
if (this.customerList && this.customerList.length > 0 && this.currentCustomerIndex <= this.customerList.length - 1) { if (this.customerList && this.customerList.length > 0 && this.currentCustomerIndex <= this.customerList.length - 1) {
return this.customerList[this.currentCustomerIndex] return this.customerList[this.currentCustomerIndex]
} }
},
isShowTotalUnRead(index) {
return index === this.currentCustomerIndex && this.totalUnreadMessageCount
} }
}, },
...@@ -135,7 +132,6 @@ export default { ...@@ -135,7 +132,6 @@ export default {
}, },
created() { created() {
console.log('==环境==', process.env.NODE_ENV) console.log('==环境==', process.env.NODE_ENV)
chat.on(TencentCloudChat.EVENT.SDK_READY, this.onSdkReady)
this.handleGetUserInfo() this.handleGetUserInfo()
this.handleGetChatList() this.handleGetChatList()
}, },
...@@ -199,7 +195,13 @@ export default { ...@@ -199,7 +195,13 @@ export default {
this.nextReqMessageID = '' this.nextReqMessageID = ''
this.messageList = [] this.messageList = []
this.messageContent = '' this.messageContent = ''
this.totalUnreadMessageCount = 0 this.totalUnreadMessageCount = -1
this.customerList = this.customerList.map((item) => {
return {
...item,
unReadMessageCount: 0
}
})
}, },
/** /**
* 获取客服列表 * 获取客服列表
...@@ -265,6 +267,8 @@ export default { ...@@ -265,6 +267,8 @@ export default {
* IM 登录 * IM 登录
*/ */
handleImLoin(userId, userSign) { handleImLoin(userId, userSign) {
chat.on(TencentCloudChat.EVENT.SDK_READY, this.onSdkReady)
chat.on(TencentCloudChat.EVENT.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED, this.onTotalUnreadMessageCountUpdated)
console.log('====用户信息===', userId, userSign) // 登录成功 console.log('====用户信息===', userId, userSign) // 登录成功
this.closeLoading() this.closeLoading()
const promise = chat.login({ userID: this.envText + userId, userSig: userSign }) const promise = chat.login({ userID: this.envText + userId, userSig: userSign })
...@@ -273,9 +277,7 @@ export default { ...@@ -273,9 +277,7 @@ export default {
console.log('====登录成功===', imResponse.data) // 登录成功 console.log('====登录成功===', imResponse.data) // 登录成功
chat.on(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED, this.onConversationListUpdated) chat.on(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED, this.onConversationListUpdated)
chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, this.onMessageReceived) chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, this.onMessageReceived)
chat.on(TencentCloudChat.EVENT.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED, this.onTotalUnreadMessageCountUpdated)
this.handleGetConversationList() this.handleGetConversationList()
if (imResponse.data.repeatLogin === true) { if (imResponse.data.repeatLogin === true) {
// 标识账号已登录,本次登录操作为重复登录。 // 标识账号已登录,本次登录操作为重复登录。
console.log(imResponse.data.errorInfo) console.log(imResponse.data.errorInfo)
...@@ -345,7 +347,7 @@ export default { ...@@ -345,7 +347,7 @@ export default {
* */ * */
onTotalUnreadMessageCountUpdated(event) { onTotalUnreadMessageCountUpdated(event) {
console.log('====会话未读总数', event.data) // 当前单聊和群聊会话的未读总数 console.log('====会话未读总数', event.data) // 当前单聊和群聊会话的未读总数
this.totalUnreadMessageCount = event.data // this.totalUnreadMessageCount = event.data
}, },
/** /**
* 获取会话列表 * 获取会话列表
...@@ -355,7 +357,6 @@ export default { ...@@ -355,7 +357,6 @@ export default {
promise.then((imResponse) => { promise.then((imResponse) => {
// 全量的会话列表,用该列表覆盖原有的会话列表 // 全量的会话列表,用该列表覆盖原有的会话列表
const conversationList = imResponse.data.conversationList const conversationList = imResponse.data.conversationList
this.totalUnreadMessageCount = chat.getTotalUnreadMessageCount()
this.setConversationList(conversationList) this.setConversationList(conversationList)
}).catch((imError) => { }).catch((imError) => {
// 获取会话列表失败的相关信息 // 获取会话列表失败的相关信息
...@@ -377,6 +378,7 @@ export default { ...@@ -377,6 +378,7 @@ export default {
this.conversationList = [] this.conversationList = []
} else { } else {
const newList = [] const newList = []
let num = 0
list.map((item) => { list.map((item) => {
const object = { const object = {
conversationID: item.conversationID || '', conversationID: item.conversationID || '',
...@@ -388,8 +390,12 @@ export default { ...@@ -388,8 +390,12 @@ export default {
isPinned: item.isPinned, isPinned: item.isPinned,
unreadCount: item.unreadCount || 0 unreadCount: item.unreadCount || 0
} }
num = num + (item.unreadCount || 0)
newList.push(object) newList.push(object)
}) })
this.customerList[this.currentCustomerIndex].unReadMessageCount = num
this.totalUnreadMessageCount = num
console.log('=====数量, ', this.totalUnreadMessageCount)
this.conversationList = newList this.conversationList = newList
} }
}, },
......
...@@ -42,17 +42,24 @@ export default { ...@@ -42,17 +42,24 @@ export default {
props: { props: {
chatUserInfo: { chatUserInfo: {
type: Object, type: Object,
required: true required: true,
default: () => {
return {
user: {
remark: ''
}
}
}
} }
}, },
data() { data() {
return { return {
preRemark: this.chatUserInfo.user && this.chatUserInfo.user.remark || '' preRemark: this.chatUserInfo && this.chatUserInfo.user && this.chatUserInfo.user.remark || ''
} }
}, },
methods: { methods: {
handleBlur() { handleBlur() {
if (this.chatUserInfo.user.remark && this.chatUserInfo.user.remark !== this.preRemark) { if (this.chatUserInfo && this.chatUserInfo.user && this.chatUserInfo.user.remark && this.chatUserInfo.user.remark !== this.preRemark) {
const params = { const params = {
user: this.chatUserInfo.user.id, user: this.chatUserInfo.user.id,
remark: this.chatUserInfo.user.remark remark: this.chatUserInfo.user.remark
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment