Browse Source

Merge branch 'master' of https://git.nanodreamtech.com/wkw/wallet_app

wkw 1 week ago
parent
commit
49fe9ebe47
1 changed files with 29 additions and 2 deletions
  1. 29 2
      src/views/im/chat/index.vue

+ 29 - 2
src/views/im/chat/index.vue

@@ -36,7 +36,7 @@
     <!-- 输入框 -->
     <div class="page-foot">
       <div class="flex-box">
-        <svg-icon class="page-icon" name="voice" />
+        <svg-icon class="page-icon" name="voice" @mousedown="startAudio" />
         <van-field
           rows="1"
           type="textarea"
@@ -80,6 +80,7 @@ import { useWalletStore } from "@/stores/modules/walletStore.js";
 import { Keyboard } from "@capacitor/keyboard";
 import { Capacitor } from "@capacitor/core";
 import { MSG_TYPE, MESSAGE_TYPE_USER } from "@/common/constant/msgType";
+import { Capacitor } from '@capacitor/core';
 
 // 路由 & store
 const router = useRouter();
@@ -100,6 +101,10 @@ const appBoxHeight = ref(210);
 const isMobile = Capacitor.getPlatform() !== "web";
 
 // 底部高度动态计算
+// 语音
+const mediaRecorder = ref(null); 
+
+// 计算当前底部总高度
 const currentBottomHeight = computed(() => {
   if (keyboardHeight.value > 0) return keyboardHeight.value;
   if (showEmoji.value || showTools.value) return appBoxHeight.value;
@@ -135,7 +140,29 @@ const toggleAppBox = async (type) => {
     showEmoji.value = false;
   }
 };
-
+const startAudio = async () => {
+    try {
+    // 请求麦克风权限
+    const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
+    
+    // 创建 MediaRecorder 实例
+    mediaRecorder.value = new MediaRecorder(stream);
+    
+    // 收集音频数据
+    mediaRecorder.value.ondataavailable = (e) => {
+      audioChunks.push(e.data);
+    };
+    
+    mediaRecorder.value.onerror = (e) => {
+      console.error('Recording error:', e.error);
+    };
+    
+    mediaRecorder.value.start();
+    console.log('Recording started');
+  } catch (error) {
+    console.error('Error accessing microphone:', error);
+  }
+}
 // 发送消息
 const sendMessage = () => {
   if (!text.value.trim()) return;