SanHQin vor 21 Stunden
Ursprung
Commit
b78a47530b

+ 1 - 1
dist/index.html

@@ -37,7 +37,7 @@
       width: 100%;
       background: #e6eaf0;
       font-family: '黑体';
-    }</style><link href=./static/css/app.e780c43c899430cb00de60a51ad949d6.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=./static/js/manifest.23ea04dc469b57e2b4f8.js></script><script type=text/javascript src=./static/js/vendor.2c492f3d5a39df08f4a3.js></script><script type=text/javascript src=./static/js/app.065a6fd44e114d797dda.js></script></body></html><script>function stopSafari() {
+    }</style><link href=./static/css/app.d644dee7e1ff6773cfdd72140f3d16fc.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=./static/js/manifest.23ea04dc469b57e2b4f8.js></script><script type=text/javascript src=./static/js/vendor.2c492f3d5a39df08f4a3.js></script><script type=text/javascript src=./static/js/app.46d98d884b3e26679c38.js></script></body></html><script>function stopSafari() {
     //阻止safari浏览器双击放大功能
     let lastTouchEnd = 0  //更新手指弹起的时间
     document.documentElement.addEventListener("touchstart", function (event) {

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/css/app.d644dee7e1ff6773cfdd72140f3d16fc.css


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/css/app.d644dee7e1ff6773cfdd72140f3d16fc.css.map


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/css/workPage.3bd38670d47d99120a88e1a42ebe9acd.css


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/css/workPage.3bd38670d47d99120a88e1a42ebe9acd.css.map


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/js/app.46d98d884b3e26679c38.js


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/js/app.46d98d884b3e26679c38.js.map


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/js/manifest.23ea04dc469b57e2b4f8.js.map


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/js/workPage-manifest.2ece51fa34be51c8610a.js.map


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/js/workPage.454015c4190d7e9065ee.js


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/js/workPage.454015c4190d7e9065ee.js.map


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/js/workPage.c578c661f45812eadff0.js


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/static/js/workPage.c578c661f45812eadff0.js.map


+ 1 - 1
dist/workPage.html

@@ -1,4 +1,4 @@
-<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>工作页面 - CocoFlow</title><link rel=icon href=../static/logo.ico><link href=./static/css/workPage.7d69de154d7ba76c6450e05c4d5f8ffd.css rel=stylesheet></head><body><noscript><strong>We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script type=text/javascript src=./static/js/workPage-manifest.2ece51fa34be51c8610a.js></script><script type=text/javascript src=./static/js/workPage-vendor.7b6275e4cf468b42a92b.js></script><script type=text/javascript src=./static/js/workPage.454015c4190d7e9065ee.js></script></body></html><script>function stopSafari() {
+<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>工作页面 - CocoFlow</title><link rel=icon href=../static/logo.ico><link href=./static/css/workPage.3bd38670d47d99120a88e1a42ebe9acd.css rel=stylesheet></head><body><noscript><strong>We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script type=text/javascript src=./static/js/workPage-manifest.2ece51fa34be51c8610a.js></script><script type=text/javascript src=./static/js/workPage-vendor.7b6275e4cf468b42a92b.js></script><script type=text/javascript src=./static/js/workPage.c578c661f45812eadff0.js></script></body></html><script>function stopSafari() {
     //阻止safari浏览器双击放大功能
     let lastTouchEnd = 0  //更新手指弹起的时间
     document.documentElement.addEventListener("touchstart", function (event) {

+ 62 - 53
src/components/pages/workPage/components/questionsAndAnswers.vue

@@ -116,6 +116,11 @@ export default {
     }
   },
   methods: {
+    // 清理 iframe 录音会话(统一清理入口)
+    _cleanupTranscriber(iframe) {
+      iframe.contentWindow.onSessionStopped = null;
+      iframe.contentWindow.window.onRecognizedResult = null;
+    },
     // 更新作业
     changeWorkData(newValue) {
       this.$emit("changeWorkData", JSON.stringify(newValue));
@@ -124,52 +129,64 @@ export default {
     changeAnswer(newValue) {
       this.work.answer = newValue;
     },
-    // 开始录音
+    // 开始录音 — 先请求权限,权限通过后再启动转录
     startRecord() {
       let iframe = this.$refs["iframeRef"];
-      if(this.lang.lang == 'com'){
-        iframe.contentWindow.window.document.getElementById(
-          "languageOptions"
-        ).selectedIndex = 8;
-      }else if(this.lang.lang == 'hk'){
-        iframe.contentWindow.window.document.getElementById(
-          "languageOptions"
-        ).selectedIndex = 4;
-      }else{
-        iframe.contentWindow.window.document.getElementById(
-          "languageOptions"
-        ).selectedIndex = 2;
-      }
+      const langMap = { com: 8, hk: 4 };
+      const idx = langMap[this.lang.lang] || 2;
+      iframe.contentWindow.window.document.getElementById("languageOptions").selectedIndex = idx;
 
-      iframe.contentWindow.window.onRecognizedResult = e => {
-        console.log("onRecognizedResult", e)
-        let privText = e.privText;
-        console.log("👇转译对象👇");
-        console.log(e);
-        console.log("👇转译结果👇");
-        console.log(privText);
-        if (!privText) {
-          return;
-        }
+      const startTranscriber = () => {
+        iframe.contentWindow.window.onRecognizedResult = e => {
+          console.log("onRecognizedResult", e)
+          let privText = e.privText;
+          console.log("👇转译对象👇");
+          console.log(e);
+          console.log("👇转译结果👇");
+          console.log(privText);
+          if (!privText) {
+            return;
+          }
 
-        // 获取wangEnduit富文本组件实例
-        const editorComponent = this.$refs.wangEnduitRef;
-        if (editorComponent && editorComponent.editor) {
-          // 获取当前光标位置并插入文本
-          editorComponent.editor.cmd.do('insertText', privText);
-          // 同步内容到work.answer
-          this.work.answer = editorComponent.editor.txt.html();
-        } else {
-          // 如果获取不到富文本实例,则直接追加
-          this.work.answer += privText;
-        }
-        console.log(privText)
+          // 获取wangEnduit富文本组件实例
+          const editorComponent = this.$refs.wangEnduitRef;
+          if (editorComponent && editorComponent.editor) {
+            // 获取当前光标位置并插入文本
+            editorComponent.editor.cmd.do('insertText', privText);
+            // 同步内容到work.answer
+            this.work.answer = editorComponent.editor.txt.html();
+          } else {
+            // 如果获取不到富文本实例,则直接追加
+            this.work.answer += privText;
+          }
+          console.log(privText)
+        };
 
+        iframe.contentWindow.ConversationTranscriber();
+        this.recordObj.status = "1"
+        this.recordObj.startTime = new Date().getTime();
       };
 
-      iframe.contentWindow.ConversationTranscriber();
-      this.recordObj.status = "1"
-      this.recordObj.startTime = new Date().getTime();
+      // 先通过 getUserMedia 主动请求麦克风权限,避免 ConversationTranscriber
+      // 在浏览器权限弹窗期间被中断导致内部状态异常
+      if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
+        navigator.mediaDevices.getUserMedia({ audio: true })
+          .then(stream => {
+            // 权限已获取,立即释放 stream,让 ConversationTranscriber 自己接管麦克风
+            stream.getTracks().forEach(t => t.stop());
+            startTranscriber();
+          })
+          .catch(() => {
+            // 用户拒绝权限
+            this._cleanupTranscriber(iframe);
+            this.$message.success(this.lang.ssNoPermStop);
+          });
+      } else {
+        // 降级:不支持 getUserMedia 的浏览器直接启动
+        startTranscriber();
+      }
+
+      // 预留 2 秒后的兜底权限检查(处理用户后续在浏览器设置中撤销权限的情况)
       setTimeout(() => {
         navigator.permissions && navigator.permissions.query({ name: 'microphone' }).then(permissionStatus => {
           if (permissionStatus.state !== "granted") {
@@ -177,7 +194,7 @@ export default {
             this.recordObj.status = "0";
             this.recordObj.loading = false;
             iframe.contentWindow.onSessionStopped = null;
-            iframe.contentWindow.window.onRecognizedResult = null;
+            this._cleanupTranscriber(iframe);
             this.$message.success(this.lang.ssNoPermStop);
             return;
           }
@@ -189,16 +206,14 @@ export default {
       if (new Date().getTime() - this.recordObj.startTime < 2000) {
         return this.$message.info(this.lang.ssRecordShort)
       }
+      const iframe = this.$refs["iframeRef"];
       // 判断浏览器是否有开启录音权限
       navigator.permissions && navigator.permissions.query({ name: 'microphone' }).then(permissionStatus => {
         if (permissionStatus.state !== "granted") {
           // 没有开启录音权限,直接确定停止录音
           this.recordObj.status = "0";
           this.recordObj.loading = false;
-          let iframe = this.$refs["iframeRef"];
-          iframe.contentWindow.onSessionStopped = null;
-          iframe.contentWindow.window.onRecognizedResult = null;
-
+          this._cleanupTranscriber(iframe);
           this.$message.success(this.lang.ssNoPermStop);
           return;
         }
@@ -206,7 +221,6 @@ export default {
         // 有权限再判断状态
         if (this.recordObj.status == '1' && !this.recordObj.loading) {
           console.log("测试测3333")
-          let iframe = this.$refs["iframeRef"];
           this.recordObj.loading = true;
           iframe.contentWindow.window.document
             .getElementById("scenarioStopButton")
@@ -216,26 +230,21 @@ export default {
             this.recordObj.loading = false;
             this.$message.success(this.lang.ssStoppedRec)
             iframe.contentWindow.onSessionStopped = null;
-            iframe.contentWindow.window.onRecognizedResult = null;
+            this._cleanupTranscriber(iframe);
           };
         } else {
           this.recordObj.status = "0";
           this.recordObj.loading = false;
-          let iframe = this.$refs["iframeRef"];
-          iframe.contentWindow.onSessionStopped = null;
-          iframe.contentWindow.window.onRecognizedResult = null;
+          this._cleanupTranscriber(iframe);
         }
       }).catch(() => {
         console.log("测试测4444试")
         // 浏览器不支持或异常,默认直接停止
         this.recordObj.status = "0";
         this.recordObj.loading = false;
-        let iframe = this.$refs["iframeRef"];
-        iframe.contentWindow.onSessionStopped = null;
-        iframe.contentWindow.window.onRecognizedResult = null;
+        this._cleanupTranscriber(this.$refs["iframeRef"]);
         this.$message.success(this.lang.ssMicCheckStop);
       });
-      // this.recordObj.status = "0"
     }
   },
   mounted() {

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.