no message

This commit is contained in:
wangdongbo 2026-02-09 09:18:33 +08:00
parent c53149c3d5
commit 1058af4f84
4 changed files with 34 additions and 54 deletions

View File

@ -1,6 +1,6 @@
// SCSS 变量定义
$font-size-text: 28rpx;
$font-size-tip: 24rpx;
$font-size-text: 30rpx;
$font-size-tip: 28rpx;
$font-size-title: 32rpx;
$text-color-sub: #999;
$primary-color: #0877F1;
@ -356,7 +356,7 @@ $primary-color: #0877F1;
}
.message-text {
font-size: $font-size-text;
font-size: 30rpx;
line-height: 1.4;
word-wrap: break-word;
word-break: break-all;

View File

@ -110,22 +110,12 @@ const initIM = async () => {
);
if (!isIMInitialized.value) {
uni.showLoading({
title: "连接中...",
});
console.log("开始调用 initIMAfterLogin");
const success = await initIMAfterLogin();
console.log("initIMAfterLogin 返回:", success);
uni.hideLoading();
if (!success) {
console.error("initIMAfterLogin 失败");
uni.showToast({
title: "IM连接失败请重试",
icon: "none",
});
console.log("initIMAfterLogin 失败,跳过 IM 初始化");
return false;
}
@ -141,14 +131,10 @@ const initIM = async () => {
);
} else if (globalTimChatManager && !globalTimChatManager.isLoggedIn) {
console.log("IM 已初始化但未登录,尝试重连");
uni.showLoading({
title: "重连中...",
});
const reconnected = await globalTimChatManager.ensureIMConnection();
uni.hideLoading();
if (!reconnected) {
console.error("重连失败");
console.log("重连失败");
return false;
}
}
@ -167,19 +153,22 @@ const loadConversationList = async () => {
// IM TIM
if (!globalTimChatManager) {
throw new Error("IM管理器未初始化");
console.log("IM管理器未初始化跳过加载");
return;
}
if (!globalTimChatManager.tim) {
console.error("TIM实例不存在尝试重新初始化");
console.log("TIM实例不存在尝试重新初始化");
const imReady = await initIM();
if (!imReady || !globalTimChatManager.tim) {
throw new Error("TIM实例初始化失败");
console.log("TIM实例初始化失败跳过加载");
return;
}
}
if (!globalTimChatManager.getGroupList) {
throw new Error("getGroupList 方法不存在");
console.log("getGroupList 方法不存在,跳过加载");
return;
}
// getGroupListSDK
@ -198,18 +187,10 @@ const loadConversationList = async () => {
//
await loadGroupAvatars(conversationList.value);
} else {
console.error("加载群聊列表失败:", result);
uni.showToast({
title: "加载失败,请重试",
icon: "none",
});
console.log("加载群聊列表失败或返回数据为空");
}
} catch (error) {
console.error("加载会话列表失败:", error);
uni.showToast({
title: error.message || "加载失败,请重试",
icon: "none",
});
console.log("加载会话列表异常:", error.message);
} finally {
loading.value = false;
}
@ -466,17 +447,15 @@ onShow(async () => {
// IM
const imReady = await initIM();
if (!imReady) initIMAfterLogin();
if (!imReady) {
console.log("IM初始化失败继续加载列表");
}
//
await loadConversationList();
//
setupConversationListener();
} catch (error) {
console.error("页面初始化失败:", error);
uni.showToast({
title: error.message || "初始化失败,请重试",
icon: "none",
});
console.log("页面初始化异常:", error.message);
}
});

View File

@ -58,7 +58,7 @@ export default defineStore("accountStore", () => {
// 使用 openid 作为 userID 初始化 IM
const userID = openid.value || uni.getStorageSync('openid');
if (!userID) {
console.error('无法获取 openidIM 初始化失败');
console.log('未获取到有效的 userId跳过 IM 初始化');
return false;
}
@ -66,13 +66,13 @@ export default defineStore("accountStore", () => {
const success = await initGlobalTIM(userID);
if (!success) {
console.error('initGlobalTIM 返回失败');
console.log('initGlobalTIM 返回失败,跳过 IM 初始化');
return false;
}
// 验证 TIM 实例是否真正创建成功
if (!globalTimChatManager || !globalTimChatManager.tim) {
console.error('IM 初始化后 TIM 实例不存在');
console.log('IM 初始化后 TIM 实例不存在,跳过 IM 初始化');
return false;
}
@ -80,7 +80,7 @@ export default defineStore("accountStore", () => {
console.log('IM 初始化成功');
return true;
} catch (error) {
console.error('IM初始化失败:', error);
console.log('IM初始化异常跳过 IM 初始化:', error.message);
return false;
}
}

View File

@ -193,7 +193,12 @@ class TimChatManager {
// 获取用户信息并登录
console.log('开始获取用户信息并登录...')
await this.getUserInfoAndLogin(userID)
const loginSuccess = await this.getUserInfoAndLogin(userID)
if (!loginSuccess) {
console.log('获取用户信息失败,跳过 IM 初始化')
await this.cleanupOldInstance()
return false
}
console.log('用户信息获取并登录成功')
// 等待SDK Ready
@ -206,11 +211,7 @@ class TimChatManager {
return true
} catch (error) {
console.error('=== IM初始化失败 ===', error)
console.error('错误详情:', error.message || error)
console.error('错误堆栈:', error.stack)
this.triggerCallback('onError', `初始化失败: ${error.message || error}`)
console.log('=== IM初始化异常 ===', error.message)
// 初始化失败时清理资源
console.log('初始化失败,开始清理资源...')
await this.cleanupOldInstance()
@ -390,7 +391,8 @@ class TimChatManager {
console.log('本地存储的 userInfo:', userInfo)
if (!userInfo?.userID) {
throw new Error('未找到用户信息,请先登录')
console.log('未找到用户信息,跳过 IM 初始化')
return false
}
this.currentUserID = userInfo.userID
console.log('从本地存储获取到 userID:', this.currentUserID)
@ -403,11 +405,10 @@ class TimChatManager {
console.log('开始登录 TIM...')
await this.loginTIM()
console.log('TIM 登录成功')
return true
} catch (error) {
console.error('获取用户信息失败:', error)
console.error('错误详情:', error.message || error)
this.triggerCallback('onError', `登录失败: ${error.message || error}`)
throw error // 重新抛出错误,让调用者知道登录失败
console.log('获取用户信息异常:', error.message)
return false
}
}