优化
This commit is contained in:
@@ -33,54 +33,26 @@
|
||||
import NewAddedPk from "../../pages/NewAddedPk/NewAddedPk.vue";
|
||||
import VerifyLogin from "../VerifyLogin.js";
|
||||
import { getCurrentInstance, defineProps, onMounted,onUnmounted,reactive, ref } from "vue";
|
||||
import { TUIStore,StoreName } from '@tencentcloud/chat-uikit-engine';
|
||||
require.async('../../TUIKit/components/TUIConversation/entry.js');
|
||||
let showMiddleButton = ref(false);
|
||||
const conversationList = ref([]);
|
||||
let Unread = ref(0);
|
||||
// 监听会话列表变化
|
||||
onMounted(() => {
|
||||
TUIStore.watch(StoreName.CONV, {
|
||||
conversationList: onConversationListUpdated,
|
||||
});
|
||||
});
|
||||
//conversationList[0].unreadCount
|
||||
// 组件销毁时取消监听
|
||||
onUnmounted(() => {
|
||||
TUIStore.unwatch(StoreName.CONV, {
|
||||
conversationList: onConversationListUpdated,
|
||||
});
|
||||
});
|
||||
// 监听会话列表变化
|
||||
function onConversationListUpdated(list) {
|
||||
conversationList.value = list;
|
||||
Unread.value = calculateUnreadCount(list);
|
||||
|
||||
}
|
||||
const emit = defineEmits(['publishSucces']);
|
||||
function publishSuccesss() {
|
||||
emit('publishSucces');
|
||||
}
|
||||
// 计算未读消息总数
|
||||
function calculateUnreadCount(arr) {
|
||||
let total = 0;
|
||||
for (const item of arr) {
|
||||
// 检查对象是否包含 unreadCount 属性
|
||||
if (!item.hasOwnProperty('unreadCount')) {
|
||||
return null;
|
||||
}
|
||||
const count = item.unreadCount;
|
||||
// 检查值是否为有效数值类型
|
||||
if (typeof count !== 'number' || !Number.isFinite(count)) {
|
||||
return null;
|
||||
}
|
||||
total += count;
|
||||
}
|
||||
return total;
|
||||
import GoEasy from 'goeasy'
|
||||
import {
|
||||
getConversationList,
|
||||
} from "../../components/goEasyTool/tool.js";
|
||||
const instance = getCurrentInstance();
|
||||
const $goeasy = instance.appContext.config.globalProperties.$goeasy;
|
||||
|
||||
const Unread = ref(0);
|
||||
var im = $goeasy.im;
|
||||
|
||||
function onConversationsUpdated(conversations) {
|
||||
console.log("监听会话列表", conversations);
|
||||
Unread.value = conversations.unreadTotal;
|
||||
}
|
||||
|
||||
|
||||
let showMiddleButton = ref(false);
|
||||
|
||||
const props = defineProps({
|
||||
tabIndex: Number,
|
||||
tabIndex: Number,//当前tab索引
|
||||
});
|
||||
let tabList = reactive([
|
||||
{
|
||||
@@ -108,6 +80,8 @@ let tabList = reactive([
|
||||
iconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Message.png",
|
||||
selectedIconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Messageclick.png",
|
||||
text: "消息",
|
||||
pagePath: "/pages/index/index",
|
||||
middleClass: "",
|
||||
},
|
||||
{
|
||||
iconPath: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Mine.png",
|
||||
@@ -119,7 +93,12 @@ let tabList = reactive([
|
||||
]);
|
||||
onMounted(() => {
|
||||
setTabBar();
|
||||
// getSystemInfo()
|
||||
setTimeout(() => {
|
||||
getConversationList($goeasy).then((conversations) => {
|
||||
Unread.value = conversations.unreadTotal;
|
||||
});
|
||||
im.on(GoEasy.IM_EVENT.CONVERSATIONS_UPDATED,onConversationsUpdated);
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
uni.getSystemInfo({
|
||||
@@ -153,16 +132,7 @@ const disabledScroll = () => {
|
||||
};
|
||||
//tab点击事件
|
||||
function handlePush(item, index) {
|
||||
if (index === 3) {
|
||||
VerifyLogin().then((res) => {
|
||||
if (res) {
|
||||
uni.redirectTo({
|
||||
url: "/TUIKit/components/TUIConversation/index",
|
||||
animationType: "none",
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (index === 2) {
|
||||
if (index === 2) {
|
||||
//打开弹窗
|
||||
VerifyLogin().then((res) => {
|
||||
if (res) {
|
||||
|
||||
Reference in New Issue
Block a user