diff --git a/frontend/src/pages/cloud-law/video-call.vue b/frontend/src/pages/cloud-law/video-call.vue index fa217d5..35117bf 100644 --- a/frontend/src/pages/cloud-law/video-call.vue +++ b/frontend/src/pages/cloud-law/video-call.vue @@ -162,12 +162,11 @@ import { MEETING_ENDED_REASON_LABEL } from '@/constants/meeting' import VideoTile from '@/components/meeting/VideoTile.vue' -import { minimizeCloudLawMeeting, notifyCloudLawCallEnded, getMiniProgram } from '@/utils/cloudLawMiniProgram' +import { minimizeCloudLawMeeting } from '@/utils/cloudLawMiniProgram' import { notifyCloudLawBackendEnd, notifyCloudLawParentCallEnded, - isCloudLawPcIframe, - notifyNativeMiniProgramHangup + isCloudLawPcIframe } from '@/utils/cloudLawVoiceCall' import bgImage from '@/static/bg.png' import hangupIcon from '@/static/cacel.png' @@ -524,29 +523,37 @@ let miniProgramRedirected = false let miniProgramEndNotified = false let miniProgramRedirectRetryTimer = null +const getMiniProgram = () => { + return typeof window !== 'undefined' && window.wx && window.wx.miniProgram ? window.wx.miniProgram : null +} + const navigateMiniProgramToReturnUrl = (returnUrl) => { const mp = getMiniProgram() - console.log('[CloudLawVideoCall] navigateToReturnUrl', { hasMiniProgram: !!mp, returnUrl, consultId: consultId.value }) if (!mp) return false const url = String(returnUrl || '').trim() - // 拿不到咨询详情地址时返回 false:交给 URL 桥接让原生页用本地 consultId 跳转, - // 切勿 navigateBack——那会退出整个视频页且误标记"已跳转",导致停不到咨询详情。 - if (!url) { - return false - } - const attempts = [ - () => mp.reLaunch && mp.reLaunch({ url }), - () => mp.redirectTo && mp.redirectTo({ url }), - () => mp.navigateTo && mp.navigateTo({ url }) - ] - for (let i = 0; i < attempts.length; i++) { - try { - attempts[i]() - return true - } catch (e) { - console.warn('[CloudLawVideoCall] miniProgram navigate failed', e) + if (url) { + const attempts = [ + () => mp.reLaunch && mp.reLaunch({ url }), + () => mp.redirectTo && mp.redirectTo({ url }), + () => mp.navigateTo && mp.navigateTo({ url }) + ] + for (let i = 0; i < attempts.length; i++) { + try { + attempts[i]() + return true + } catch (e) { + console.warn('[CloudLawVideoCall] miniProgram navigate failed', e) + } } } + try { + if (typeof mp.navigateBack === 'function') { + mp.navigateBack({ delta: 1 }) + return true + } + } catch (e) { + console.warn('[CloudLawVideoCall] miniProgram navigateBack failed', e) + } return false } @@ -1043,16 +1050,14 @@ const hangup = async () => { } finally { ended.value = true leaving.value = false + // 用户端:优先尝试跳转小程序咨询详情;失败则依赖小程序页轮询 /end 状态兜底 + notifyMiniProgramCallEndedOnce() if (!isLawRole.value) { - // 挂断流程完成后再通知小程序:避免提前 reload web-view 中断 endMeeting - notifyMiniProgramCallEndedOnce() setTimeout(() => { - // web-view 内(经 SSO 重定向)常拿不到 consultId 而无法直跳, - // 此时用 URL 桥接触发原生页 @load,由原生页用本地 consultId 跳转咨询详情。 - if (!miniProgramRedirected) { - notifyNativeMiniProgramHangup() + if (ended.value && !miniProgramRedirected) { + goToConsultDetail() } - }, 400) + }, 600) } } } @@ -1120,16 +1125,8 @@ onMounted(() => { // 对方挂断或会议结束时,通知云律后端 + 父页面(PC 律师浮窗)+ 小程序 notifyCloudLawEnd().finally(() => { if (isLawRole.value) { - if (isCloudLawPcIframe()) { - notifyCloudLawParentCallEnded(callId.value) - return - } - if (getMiniProgram()) { - notifyCloudLawCallEnded(callId.value) - return - } notifyCloudLawParentCallEnded(callId.value) - return + if (isCloudLawPcIframe()) return } notifyMiniProgramCallEndedOnce() scheduleEndedRedirect()