From 9807721a3d9cf299e08cef721524c1f21cb3d860 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Tue, 11 Nov 2025 16:46:46 +0800
Subject: [PATCH] feat: 腾讯语音接入

---
 src/App.vue |   69 +++++++++++++++++++++++++++++-----
 1 files changed, 58 insertions(+), 11 deletions(-)

diff --git a/src/App.vue b/src/App.vue
index bb5c52a..26d39bf 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,13 +1,13 @@
-
 <script setup>
-import { onHide, onLaunch, onShow } from "@dcloudio/uni-app";
-import { useAppStore } from "@/store";
+import {onHide, onLaunch, onShow} from "@dcloudio/uni-app";
+import {useAppStore, useUserStore} from "@/store";
 import {mpUpdate} from "@/utils/index";
-
+import {genTestUserSig} from '@/utils/voiceCallByTX/GenerateTestUserSig.js';
+import { TUICallKit, TUICallKitAPI, CallMediaType } from '@trtc/calls-uikit-vue'
 const appStore = useAppStore();
-onLaunch(() => {
-  console.log("App Launch");
+const userStore = useUserStore();
 
+onLaunch(() => {
   // 初始化系统信息
   appStore.initSystemInfo();
 
@@ -15,6 +15,41 @@
   mpUpdate();
   // #endif
 });
+
+const userId = computed(() => userStore?.userInfo?.user_id)
+
+function initVoiceCallFromApp() {
+  const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');
+  const {userSig, SDKAppID} = genTestUserSig(userId.value);
+  uni.$TUICallKit = TUICallKit;
+  uni.$TUICallKit.login({
+    SDKAppID,
+    userID: userId.value,
+    userSig: userSig,
+  })
+}
+
+async function initVoiceCallFromH5() {
+  const {userSig, SDKAppID} = genTestUserSig(userId.value)
+  await TUICallKitAPI.init({
+    userID: userId.value,
+    userSig,
+    SDKAppID,
+  })
+}
+
+// 初始化登陆腾讯音频平台
+watch(userId, () => {
+  if (!userId.value) return
+  // #ifdef H5
+  initVoiceCallFromH5()
+  console.log(userId.value)
+  // #endif
+
+  // #ifdef APP-PLUS
+  initVoiceCallFromApp()
+  // #endif
+}, {immediate: true})
 
 onShow(() => {
   console.log("App Show");
@@ -29,6 +64,14 @@
 /* 每个页面公共css */
 @import "uview-plus/index.scss";
 @import "@/static/styles/common.scss";
+
+.TUICallKit-mobile{
+  position: fixed;
+  left: 0;
+  top: 0;
+  z-index: 9999;
+}
+
 page {
   background-image: url('~@/static/images/user/bg.png');
   background-size: cover;
@@ -37,6 +80,7 @@
   background-attachment: fixed;
   // min-height: 10vh;
 }
+
 .uni-tabbar__item:nth-child(4) {
   .uni-tabbar__bd {
     .uni-tabbar__icon {
@@ -46,15 +90,18 @@
     }
   }
 }
-.uni-tabbar-border{
+
+.uni-tabbar-border {
   background-color: #f6f6f6 !important;
 }
+
 .uni-page-head__title {
- font-family: Source Han Sans CN, Source Han Sans CN !important;
- font-weight: 400 !important;
- font-size: 17px !important;
- color: #222324 !important;
+  font-family: Source Han Sans CN, Source Han Sans CN !important;
+  font-weight: 400 !important;
+  font-size: 17px !important;
+  color: #222324 !important;
 }
+
 .uni-page-head {
   background: transparent !important;
 }

--
Gitblit v1.9.3