Bladeren bron

视频交互题编辑处时间转化为时分秒

natasha 2 weken geleden
bovenliggende
commit
6cbadc719b

+ 36 - 1
src/views/book/courseware/create/components/question/video_interaction/VideoInteraction.vue

@@ -34,7 +34,7 @@
           <li v-for="(file, i) in data.file_info_list" :key="i">
             <div class="file-name">
               <span>
-                <span>时间:{{ file.currentTime }}s</span>
+                <span>时间:{{ realFormatSecond(file.currentTime) }}</span>
                 <span>{{ file.file_name ?? file.name }}</span>
               </span>
             </div>
@@ -300,6 +300,41 @@ export default {
           this.$emit('handleCancale');
         });
     },
+    // 将整数转换成 时:分:秒的格式
+    realFormatSecond(value) {
+      let theTime = parseInt(value); // 秒
+      let theTime1 = 0; // 分
+      let theTime2 = 0; // 小时
+      if (theTime > 60) {
+        theTime1 = parseInt(theTime / 60);
+        theTime = parseInt(theTime % 60);
+        if (theTime1 > 60) {
+          theTime2 = parseInt(theTime1 / 60);
+          theTime1 = parseInt(theTime1 % 60);
+        }
+      }
+      let result = String(parseInt(theTime));
+      if (result < 10) {
+        result = `0${result}`;
+      }
+      if (theTime1 > 0) {
+        result = `${String(parseInt(theTime1))}:${result}`;
+        if (theTime1 < 10) {
+          result = `0${result}`;
+        }
+      } else {
+        result = `00:${result}`;
+      }
+      if (theTime2 > 0) {
+        result = `${String(parseInt(theTime2))}:${result}`;
+        if (theTime2 < 10) {
+          result = `0${result}`;
+        }
+      } else {
+        // result = "00:" + result;
+      }
+      return result;
+    },
   },
 };
 </script>