罗广辉
2025-11-17 de3edb50d18b549fc47adfc3dcc4f6833cbe04c4
src/App.vue
@@ -1,63 +1,12 @@
<script setup>
  import {onHide, onLaunch, onShow} from "@dcloudio/uni-app";
  import {useAppStore, useUserStore} from "@/store";
  import {genTestUserSig} from '@/utils/voiceCallByTX/GenerateTestUserSig.js';
import {useGlobalWS} from "@/hooks/useGlobalWS.js";
  const appStore = useAppStore();
  const userStore = useUserStore();
  const userId = computed(() => userStore?.userInfo?.user_id)
  onLaunch(() => {
    // 初始化系统信息
    appStore.initSystemInfo();
    if (!userStore.userInfo) {
      //不存在则跳转至登录页
      uni.reLaunch({
        url: "/pages/login/index",
      })
    }
  });
  // #ifdef APP-PLUS
  import TrtcCloud from '@/utils/voiceCallByTX/TrtcCloud/lib/index';
  import { TRTCAppScene } from '@/utils/voiceCallByTX/TrtcCloud/lib/TrtcDefines';
  const trtcCloud = TrtcCloud.createInstance();
  function enterRoomFun() {
    const {userSig, SDKAppID} = genTestUserSig(userId.value);
    const params = {sdkAppId: SDKAppID, userId: userId.value, roomId: 789456, userSig: userSig};
    trtcCloud.enterRoom(params, TRTCAppScene.TRTCAppSceneVideoCall)
    trtcCloud.startLocalAudio();
  }
  // #endif
  // #ifdef H5
  import TRTC from 'trtc-sdk-v5';
  const trtc = TRTC.create();
  function enterRoomFunByH5() {
    const {userSig, SDKAppID} = genTestUserSig(userId.value);
    trtc.enterRoom({ sdkAppId:SDKAppID, userId:userId.value, userSig, roomId: 789456 })
    trtc.startLocalAudio()
  }
  // #endif
  // 初始化登陆腾讯音频平台
  watch(userId, () => {
    if (!userId.value) return
    // #ifdef APP-PLUS
    // enterRoomFun()
    // #endif
    // #ifdef H5
    // enterRoomFunByH5()
    // #endif
  }, {
    immediate: true
  })
useGlobalWS()
  onShow(() => {
    console.log("App Show");
@@ -66,6 +15,17 @@
  onHide(() => {
    console.log("App Hide");
  });
onLaunch(() => {
  // 初始化系统信息
  appStore.initSystemInfo();
  if (!userStore.userInfo) {
    //不存在则跳转至登录页
    uni.reLaunch({
      url: "/pages/login/index",
    })
  }
});
</script>
<style lang="scss">