吉安感知网项目-前端
罗广辉
2026-02-27 e00da17ae2adaecf1cdf2d5128e357a50607bc90
uniapps/work-app/src/hooks/useGlobalWS.js
@@ -2,7 +2,7 @@
import useAppStore from "../store/modules/app/index.js";
import websocketService from "@/utils/websocket.js";
// #ifdef APP-PLUS
import { openDialog, allowFloat, getBatteryCapacity } from '@/uni_modules/lgh-dialog'
import { openDialog, allowFloat, getBatteryCapacity, showIncomingCallNotification, cancelIncomingCallNotification } from '@/uni_modules/lgh-dialog'
// #endif
export function useGlobalWS() {
   const userStore = useUserStore();
@@ -27,8 +27,6 @@
    // 处理语音通话请求
    if (t === 'call') {
      console.log('📞 全局收到来电 call,来自', payload.from)
      // 播放铃声
      // playRingtone();
      // 触发震动
      triggerVibration();
      // 构建来电参数
@@ -37,7 +35,10 @@
        from: payload.from,
        type: 'incoming'
      };
// #ifdef APP-PLUS
      // #ifdef APP-PLUS
      // 发送来电通知(锁屏/后台都会弹出 + 亮屏)
      showIncomingCallNotification(payload.from || '未知来电')
      // 拉起应用到前台
         openDialog()
      // #endif
      // 转义参数以便在URL中传递
@@ -57,6 +58,12 @@
      }
      return
    }
    // 通话接听或结束时,取消来电通知
    if (t === 'accept' || t === 'reject' || t === 'hangup' || t === 'cancel') {
      // #ifdef APP-PLUS
      cancelIncomingCallNotification()
      // #endif
    }
  }
  // 播放来电铃声 - 定义在 messageHandler 外部