diff --git a/jiuyi2/App.vue b/jiuyi2/App.vue index 15aedb1b..08f887c5 100644 --- a/jiuyi2/App.vue +++ b/jiuyi2/App.vue @@ -9,6 +9,8 @@ import api from '@/api/index.js' // vuex import store from '@/store/index.js' + // 腾讯云聊天 + import TencentCloudChat from '@tencentcloud/chat'; // #ifdef APP // 引入各种权限配置 import { @@ -40,6 +42,9 @@ // #ifdef APP unregisterRequestPermissionTipsListener(null) // #endif + + // 关闭未读消息提示 + removeListenerUnreadCount() }) /** @@ -58,7 +63,6 @@ onConfirm: (e) => { console.log(e) }, - // onComplete onComplete: (e) => { // 华为手机在权限禁止之后,再次申请权限不会出现权限申请框。此时应该引导用户去系统设置开启此权限,不应该频繁申请。 if (brand.toLowerCase() == "huawei") { @@ -103,9 +107,29 @@ util.loginTencent(userinfo) } }) + + // 开启未读消息监听 + addListenerUnreadCount() } } + // 开启未读消息监听 + function addListenerUnreadCount() { + let onTotalUnreadMessageCountUpdated = function(event) { + // 设置未读消息条数 + store.commit('setUnreadCount', event.data) + }; + + uni.$chat.on(TencentCloudChat.EVENT.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED, onTotalUnreadMessageCountUpdated); + } + + // 关闭未读消息更新 + function removeListenerUnreadCount() { + let onTotalUnreadMessageCountUpdated = (event) => {}; + // + uni.$chat.off(TencentCloudChat.EVENT.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED, onTotalUnreadMessageCountUpdated); + } + // 获取系统配置 function getConfig() { api.getConfig().then(rs => { diff --git a/jiuyi2/common/js/util.js b/jiuyi2/common/js/util.js index 12b72bd9..93b4251a 100644 --- a/jiuyi2/common/js/util.js +++ b/jiuyi2/common/js/util.js @@ -1220,11 +1220,31 @@ const util = { userSig: imSig, }).then(rs => { util.updateMyProfile(userinfo) + // 获取未读消息条数 + util.getUnread(userinfo) console.log('im login success', rs) }) }) }, + // 获取未读消息条数 + getUnread(userinfo) { + if (userinfo.isRealName) { + // 验证sdk是否准备完毕 + let isReady = uni.$chat.isReady(); + if (!isReady) { + setTimeout(function() { + util.getUnread(userinfo) + }, 800); + return + } + // 未读条数 + let unreadCount = uni.$chat.getTotalUnreadMessageCount(); + // 设置未读消息条数 + store.commit('setUnreadCount', unreadCount) + } + }, + // 更新im个人资料 updateMyProfile(userinfo) { // 验证sdk是否准备完毕 diff --git a/jiuyi2/components/footerMenu/footerMenu.vue b/jiuyi2/components/footerMenu/footerMenu.vue index ec3926cf..38707058 100644 --- a/jiuyi2/components/footerMenu/footerMenu.vue +++ b/jiuyi2/components/footerMenu/footerMenu.vue @@ -112,14 +112,6 @@ url: '/pages/release/video', }) } - // 1是商家 - // if(userinfo.value.isShop == 1) { - // result.push({ - // name: '发布商品', - // img: '/static/footerMenu1.png', - // url: '/pages/release/commodity', - // }) - // } // 追加 // result.push({ // name: '打车', @@ -134,13 +126,8 @@ // }) return result }) - // 未读数量 - const noReadNum = ref(0) - - const getReadNum = () => { - getNoReadNum() - } + const noReadNum = computed(() => uni.$store.state.unreadCount) // 加载完成之后 onMounted(() => { @@ -152,8 +139,6 @@ uni.getSystemInfo().then(rs => { safeHeight.value = rs.safeArea + 'px' }) - // 获取未读消息数量 - getNoReadNum() // // proxy.$refs.alert.open() @@ -189,7 +174,6 @@ else uni.navigateTo({ url: `/${item.pagePath}`, }) - getNoReadNum() return } // @@ -217,29 +201,6 @@ // proxy.$refs.alert.close() } - - // 获取未读消息数量 - function getNoReadNum() { - if (userinfo.value.isRealName) { - // 验证sdk是否准备完毕 - let isReady = uni.$chat.isReady(); - if (!isReady) { - setTimeout(function() { - getNoReadNum(); - }, 800); - return - } - - // #ifdef APP - const unreadCount = uni.$chat.getTotalUnreadMessageCount(); - noReadNum.value = +unreadCount > 99 ? '99+' : unreadCount; - // #endif - } - } - - defineExpose({ - getReadNum - })