吉安感知网项目-前端
张含笑
2026-01-15 3c19d8e89a48137bdabee24e9bb1187e748618fc
feat:语音通话更新
4 files modified
78 ■■■■ changed files
applications/mobile-web-view/src/appPages/voiceCallDetail/index.vue 50 ●●●● patch | view | raw | blame | history
uniapps/work-app/src/hooks/useGlobalWS.js 24 ●●●● patch | view | raw | blame | history
uniapps/work-app/src/subPackages/voiceCallDetail/index.vue 2 ●●● patch | view | raw | blame | history
uniapps/work-app/src/utils/common/index.js 2 ●●● patch | view | raw | blame | history
applications/mobile-web-view/src/appPages/voiceCallDetail/index.vue
@@ -62,17 +62,51 @@
// 解析URL参数
const parseUrlParams = () => {
    const url = new URL(window.location.href)
    const paramsStr = url.searchParams.get('params')
    if (paramsStr) {
    // 1. 优先从route.query.voiceparams获取参数
    if (route.query && route.query.voiceparams) {
        console.log('从route.query.voiceparams获取参数:', route.query.voiceparams);
        try {
            const params = JSON.parse(decodeURIComponent(paramsStr))
            // 解码并解析voiceparams参数
            const params = JSON.parse(decodeURIComponent(route.query.voiceparams));
            console.log('解析后的voiceparams:', params);
            if (params.peerUid) {
                peerUid.value = String(params.peerUid)
                log('🔗 从URL参数获取peerUid:', params.peerUid)
                peerUid.value = String(params.peerUid);
                log('🔗 从voiceparams获取peerUid:', params.peerUid);
            }
            // 如果是来电类型,直接触发来电状态
            if (params.type === 'incoming') {
                log('📞 voiceparams检测到来电,直接进入来电状态');
                incomingFrom = String(params.from);
                peerUid.value = incomingFrom;
                acceptedByMe = false;
                offeredByPeer = false;
                state.value = 'ringing';
                log('📞 收到来电 call,来自', incomingFrom);
                // 开始来电提示(铃声和震动)
                playRingtone();
                startVibration();
            }
        } catch (e) {
            log('❌ 解析URL参数失败:', String(e))
            log('❌ 解析voiceparams参数失败:', String(e));
        }
    }
    // 2. 同时保留原有的URL参数解析逻辑,作为备选
    const url = new URL(window.location.href);
    const paramsStr = url.searchParams.get('params');
    if (paramsStr) {
        try {
            const params = JSON.parse(decodeURIComponent(paramsStr));
            if (params.peerUid) {
                peerUid.value = String(params.peerUid);
                log('🔗 从URL参数获取peerUid:', params.peerUid);
            }
        } catch (e) {
            log('❌ 解析URL参数失败:', String(e));
        }
    }
}
@@ -600,6 +634,8 @@
}
onMounted(() => {
console.log('收拾收拾',route.query.voiceparams);
    const receiveParameters = route.query.contact
    console.log('接收参数', receiveParameters)
uniapps/work-app/src/hooks/useGlobalWS.js
@@ -6,7 +6,7 @@
export function useGlobalWS() {
    const userStore = useUserStore();
  const appStore = useAppStore();
  // 设置默认用户ID为3
  const defaultUserId = '3';
  // WebSocket基础URL
@@ -30,20 +30,20 @@
        from: payload.from,
        type: 'incoming'
      };
      // 转义参数以便在URL中传递
      const encodedParams = encodeURIComponent(JSON.stringify(callParams));
      // 跳转到mobile-web-view应用中的语音通话页面
      const voiceCallUrl = `http://localhost:9527/work-app/#/subPackages/voiceCallDetail/index?params=${encodedParams}`;
      const voiceCallUrl = `http://localhost:9527/work-app/#/subPackages/voiceCallDetail/index?voiceparams=${encodedParams}`;
      console.log('🔗 准备导航到:', voiceCallUrl)
      try {
        // 优先使用uni-app的导航API(适用于uni-app环境)
        if (typeof uni !== 'undefined' && uni.navigateTo) {
          console.log('使用uni-app导航API跳转到语音通话页面');
          // 检查是否是跳转到应用内页面
          if (voiceCallUrl.includes('/subPackages/voiceCallDetail/')) {
            // 应用内页面跳转
@@ -62,7 +62,7 @@
            // 外部页面跳转
            fallbackToExternalNavigation();
          }
        }
        }
        // 否则尝试使用window.location跳转(适用于Web环境)
        else if (typeof window !== 'undefined' && window.location) {
          console.log('使用window.location跳转到语音通话页面');
@@ -75,7 +75,7 @@
        // 尝试使用外部跳转作为最后的补救措施
        fallbackToExternalNavigation();
      }
      // 外部页面跳转的回调函数
      function fallbackToExternalNavigation() {
        console.log('尝试使用外部导航跳转到语音通话页面');
@@ -98,7 +98,7 @@
                }
              }
            });
          }
          }
          // 或者使用plus.runtime.openURL(适用于App环境)
          else if (typeof plus !== 'undefined' && plus.runtime) {
            plus.runtime.openURL(voiceCallUrl);
@@ -145,16 +145,16 @@
      // 使用默认用户ID初始化WebSocket连接
      websocketService.init(defaultUserId, WS_BASE);
      console.log('🌐 全局WebSocket初始化成功,默认用户ID:', defaultUserId);
      // 设置全局消息处理回调
      websocketService.setOnMessageCallback(messageHandler);
      console.log('✅ 全局WebSocket消息处理器已设置');
    } catch (error) {
      console.error('❌ 全局WebSocket初始化失败:', error);
    }
  }
  // 监听用户信息变化,初始化WebSocket
  watch(
    () => userStore.userInfo,
uniapps/work-app/src/subPackages/voiceCallDetail/index.vue
@@ -21,7 +21,7 @@
  // 构建viewUrl,将contact参数拼接到URL中
  const contactParam = contact ? encodeURIComponent(JSON.stringify(contact)) : '';
  // viewUrl.value = `https://192.168.1.157:5176/mobile-web-view/#/webViewWrapper/voiceCallDetail?params=${encodeURIComponent(userParams)}&contact=${contactParam}`;
  viewUrl.value = getWebViewUrl("/voiceCallDetail", { contact: options.contact });
  viewUrl.value = getWebViewUrl("/voiceCallDetail", { contact: options.contact ,voiceparams: options.voiceparams});
});
function onPostMessage(data) {}
// #ifdef APP-PLUS
uniapps/work-app/src/utils/common/index.js
@@ -90,4 +90,4 @@
export function getAssetsImage (targetUrl) {
  const url = getEnvObj().VITE_APP_ASSETS_URL
  return `${url}${targetUrl}`
}
}