فهرست منبع

fix(pptEasyClass): 统一使用服务器时间替代本地时间处理录音时长

1.  将toggleRecording和onStartRecordWithMicrosoft改为async函数以支持异步调用
2.  替换本地new Date()为await getServerTime()获取准确时间
3.  将硬编码的警告文案替换为多语言配置项
4.  添加调试日志辅助排查问题
lsc 13 ساعت پیش
والد
کامیت
d8ed4893a1
2فایلهای تغییر یافته به همراه20 افزوده شده و 20 حذف شده
  1. 9 10
      src/components/pptEasyClass/index.vue
  2. 11 10
      src/components/pptEasyClass/indexPS.vue

+ 9 - 10
src/components/pptEasyClass/index.vue

@@ -272,11 +272,11 @@ export default {
     audioStart() {
       this.onStartRecordWithMicrosoft();
     },
-    toggleRecording() {
-      return new Promise(resolve => {
+    async toggleRecording() {
+      return new Promise(async resolve => {
         if (this.recordedForm.status == 1) {
           // 检查录音时间是否至少为5秒
-          const now = new Date();
+          const now = new Date(await this.getServerTime());
           const duration = (now - new Date(this.recordingStartTime)) / 1000;
           if (duration < 5) {
             this.$message.warning(this.lang.ssRecordingTimeAtLeast5Seconds);
@@ -321,10 +321,12 @@ export default {
           // });
 
         } else {
-          const now = new Date();
+          console.log('recordingEndTime',this.recordingEndTime)
+          const now = new Date(await this.getServerTime());
+          console.log('now', now)
           const duration = (now - new Date(this.recordingEndTime)) / 1000;
           if (duration < 5) {
-            this.$message.warning('录音时间至少间距5秒');
+            this.$message.warning(this.lang.ssRecordingTimeAtLeast5Seconds);
             return;
           }
           this.onStartRecordWithMicrosoft();
@@ -334,7 +336,7 @@ export default {
       // })
     },
     // ============ start 微软录音转译
-    onStartRecordWithMicrosoft() {
+    async onStartRecordWithMicrosoft() {
       let iiframe = this.$refs["iiframe"];
       iiframe.contentWindow.window.document.getElementById(
         "languageOptions"
@@ -345,10 +347,7 @@ export default {
       console.log("开始录音", iiframe);
       this.recordedForm.status = 1;
       // 记录开始录音时间
-      this.recordingStartTime = new Date().toLocaleString("zh-CN", {
-        hour12: false,
-        timeZone: "Asia/Shanghai"
-      }).replace(/\//g, "-");
+      this.recordingStartTime = await this.getServerTime();
       iiframe.contentWindow.window.onRecognizedResult = e => {
         console.log("onRecognizedResult", e);
         this.recordedForm.endTime = this.recordedForm.timeDuration;

+ 11 - 10
src/components/pptEasyClass/indexPS.vue

@@ -272,11 +272,13 @@ export default {
     audioStart() {
       this.onStartRecordWithMicrosoft();
     },
-    toggleRecording() {
-      return new Promise(resolve => {
+    async toggleRecording() {
+      return new Promise(async resolve => {
         if (this.recordedForm.status == 1) {
           // 检查录音时间是否至少为5秒
-          const now = new Date();
+          const now = new Date(await this.getServerTime());
+          console.log('now', now)
+          console.log('recordingStartTime',this.recordingStartTime)
           const duration = (now - new Date(this.recordingStartTime)) / 1000;
           if (duration < 5) {
             this.$message.warning(this.lang.ssRecordingTimeAtLeast5Seconds);
@@ -321,10 +323,12 @@ export default {
           // });
 
         } else {
-          const now = new Date();
+          console.log('recordingEndTime',this.recordingEndTime)
+          const now = new Date(await this.getServerTime());
+          console.log('now', now)
           const duration = (now - new Date(this.recordingEndTime)) / 1000;
           if (duration < 5) {
-            this.$message.warning('录音时间至少间距5秒');
+            this.$message.warning(this.lang.ssRecordingTimeAtLeast5Seconds);
             return;
           }
           this.onStartRecordWithMicrosoft();
@@ -334,7 +338,7 @@ export default {
       // })
     },
     // ============ start 微软录音转译
-    onStartRecordWithMicrosoft() {
+    async onStartRecordWithMicrosoft() {
       let iiframe = this.$refs["iiframe"];
       iiframe.contentWindow.window.document.getElementById(
         "languageOptions"
@@ -345,10 +349,7 @@ export default {
       console.log("开始录音", iiframe);
       this.recordedForm.status = 1;
       // 记录开始录音时间
-      this.recordingStartTime = new Date().toLocaleString("zh-CN", {
-        hour12: false,
-        timeZone: "Asia/Shanghai"
-      }).replace(/\//g, "-");
+      this.recordingStartTime = await this.getServerTime();
       iiframe.contentWindow.window.onRecognizedResult = e => {
         console.log("onRecognizedResult", e);
         this.recordedForm.endTime = this.recordedForm.timeDuration;