新增功能

This commit is contained in:
Your Name
2026-04-01 09:46:25 +08:00
parent 099bc1dd22
commit a780356908
332 changed files with 7845 additions and 866 deletions
+54 -1
View File
@@ -241,6 +241,8 @@
import groupPlugin from '@tencentcloud/lite-chat/plugins/group';
import * as GenerateTestUserSig from "@/debug/GenerateTestUserSig-es.js";
import { TUICallKitAPI } from '@/TUICallKit/src/TUICallService/index';
import { TUIStore } from '@/TUICallKit/src/TUICallService/CallService/index';
import { StoreName, NAME, CallStatus } from '@/TUICallKit/src/TUICallService/const/index';
// CallManager 在 App.vue 已挂载到 uni.CallManager,勿在此重复 new,否则会丢失通话状态
const { proxy } = getCurrentInstance()
const messages = ref([]);
@@ -271,6 +273,10 @@ const { proxy } = getCurrentInstance()
let targetUserID = '';
let currentUserID = ''; // 当前登录用户ID
let scrollTimer = null; // 滚动定时器
/** 微信小程序:从系统后台回前台时刷新 IM/TUICall,避免无法接通视频 */
let unsubscribeWxAppShow = null;
let allowChatForegroundRelogin = false;
let foregroundReloginTimer = null;
const CONFIRMATION_MESSAGE = `我已确认以下信息:
1、本人确认已在线下确诊;
@@ -730,6 +736,22 @@ const { proxy } = getCurrentInstance()
uni.$on('TUICall:callEnd', onVideoCallEnd);
//uni.showToast({ title: '聊天已就绪', icon: 'success' });
// #ifdef MP-WEIXIN
// 系统级前后台切换时页面 onShow 不一定等价于「回前台」,用 wx.onAppShow 刷新音视频信令链路
if (typeof wx !== 'undefined' && wx.onAppShow) {
unsubscribeWxAppShow = wx.onAppShow(() => {
if (!allowChatForegroundRelogin) return;
const pages = getCurrentPages();
const top = pages[pages.length - 1];
if (!(top?.route || '').includes('pages/chat/chat')) return;
reloginAfterMiniProgramForeground();
});
}
setTimeout(() => {
allowChatForegroundRelogin = true;
}, 800);
// #endif
// 监听键盘高度变化
uni.onKeyboardHeightChange((res) => {
keyboardHeight.value = res.height;
@@ -765,6 +787,17 @@ const { proxy } = getCurrentInstance()
});
onUnload(() => {
allowChatForegroundRelogin = false;
// #ifdef MP-WEIXIN
if (typeof unsubscribeWxAppShow === 'function') {
unsubscribeWxAppShow();
unsubscribeWxAppShow = null;
}
// #endif
if (foregroundReloginTimer) {
clearTimeout(foregroundReloginTimer);
foregroundReloginTimer = null;
}
uni.$off('TUICall:callStart', onVideoCallStart);
uni.$off('TUICall:callEnd', onVideoCallEnd);
stopDoctorWaitTimer();
@@ -1039,6 +1072,26 @@ const { proxy } = getCurrentInstance()
chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived);
await initTUICallKitWithTim(chat);
}
/** 小程序切后台再回前台:拉取新 UserSig 并重登 IM、重绑 TUICallEngine(与发消息失败时的 relogin 一致) */
async function reloginAfterMiniProgramForeground() {
if (!chat || !currentUserID) return;
if (foregroundReloginTimer) clearTimeout(foregroundReloginTimer);
foregroundReloginTimer = setTimeout(async () => {
foregroundReloginTimer = null;
// reloginIMChat 会先 IM logout 再 initTUICallKit;若非 IDLEdestroyed 会失败且 IM 已断开,故仅 IDLE 时刷新
try {
const status = TUIStore?.getData?.(StoreName.CALL, NAME.CALL_STATUS);
if (status != null && status !== CallStatus.IDLE) {
console.warn('前台恢复: 通话未结束,跳过 IM/TUICall 重绑');
return;
}
await reloginIMChat();
} catch (e) {
console.warn('前台恢复后 IM/TUICall 刷新失败:', e);
}
}, 400);
}
async function sendTextMessage() {
if (!inputText.value.trim()) return;
@@ -1353,7 +1406,7 @@ const { proxy } = getCurrentInstance()
hideDoctorCardByCall();
}
function onVideoCallEnd() {
async function onVideoCallEnd() {
hideDoctorCardByCall();
uni.showToast({ title: '视频通话已结束', icon: 'success' });
}