谢杰标 2 anni fa
parent
commit
40ef2989d5
2 ha cambiato i file con 21 aggiunte e 13 eliminazioni
  1. 7 13
      pages3/polyv/detail.vue
  2. 14 0
      utils/common.js

+ 7 - 13
pages3/polyv/detail.vue

@@ -296,7 +296,7 @@ import noteBox from "@/components/course/noteBox.vue";
 import answerBox from "@/components/course/answerBox.vue";
 import { mapGetters, mapMutations } from "vuex";
 import { lockAction } from "../../utils/lock";
-import { debounce, reload } from "../../utils/common";
+import { debounce, throttle, reload } from "../../utils/common";
 export default {
   components: {
     handoutsBox,
@@ -372,6 +372,7 @@ export default {
       beforeHideIsPlaying: false,
       isLeave: false,
       text: "",
+      throttleFn: throttle(this.postStudyRecord, 15000),
     };
   },
   computed: {
@@ -459,7 +460,6 @@ export default {
       lockAction();
       this.lockTimer = setInterval(lockAction, 10000);
     }
-
     // 公众号模板消息的数据埋点
     informId && this.clickOfficial(informId);
     this.init();
@@ -1498,20 +1498,14 @@ export default {
       }).then((res) => {});
     },
     timeupdate(time) {
-      console.log("🚀 ~ file: detail.vue:1501 ~ timeupdate ~ time:", time);
       if (this.noticeShow) {
         this.refPlv.playPause();
         return;
       }
-      newRecord(time);
+      this.throttleFn();
       this.playTime = time;
       this.timeEvent(time);
     },
-    newRecord(time) {
-      return debounce(() => {
-        console.log(1123123, time);
-      }, 5000);
-    },
     playing() {
       console.log("palying");
       this.isPlaying = true;
@@ -1519,10 +1513,10 @@ export default {
         this.postStudyRecord(0);
       }
       this.clearPauseTimer();
-      this.studyTimer && clearInterval(this.studyTimer);
-      this.studyTimer = setInterval(() => {
-        this.postStudyRecord(0);
-      }, 15000);
+      // this.studyTimer && clearInterval(this.studyTimer);
+      // this.studyTimer = setInterval(() => {
+      //   this.postStudyRecord(0);
+      // }, 15000);
     },
     openCamera() {
       console.log("拍照");

+ 14 - 0
utils/common.js

@@ -1,6 +1,7 @@
 export function debounce(func, wait = 3000, immediate = true) {
   let timeout;
   return function () {
+    console.log(11112, timeout);
     const context = this;
     const args = [...arguments];
     if (timeout) clearTimeout(timeout);
@@ -18,6 +19,19 @@ export function debounce(func, wait = 3000, immediate = true) {
   };
 }
 
+export function throttle(fn, delay = 1000) {
+  let lastTime = 0;
+  return function () {
+    let _this = this;
+    let _arguments = arguments;
+    let now = new Date().getTime();
+    if (now - lastTime > delay) {
+      fn.apply(_this, _arguments);
+      lastTime = now;
+    }
+  };
+}
+
 export function reload(option = {}) {
   // #ifdef H5
   location.reload();