From 07a5f956f2ea9f475b33373c5b858eb2330e60ea Mon Sep 17 00:00:00 2001 From: yindongqi Date: Fri, 15 Aug 2025 15:52:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(study):=20=E4=BF=AE=E5=A4=8D=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=92=AD=E6=94=BE=E7=BB=93=E6=9D=9F=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=92=8C=E5=AE=9A=E6=97=B6=E5=99=A8=E6=B8=85=E7=90=86=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复视频播放结束判断条件,增加对播放进度的验证 添加定时器清理逻辑防止内存泄漏 --- src/components/study/courseDetail.vue | 28 ++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/components/study/courseDetail.vue b/src/components/study/courseDetail.vue index f180b0f..ef6990c 100644 --- a/src/components/study/courseDetail.vue +++ b/src/components/study/courseDetail.vue @@ -413,7 +413,9 @@ export default { //最后2s调用结束接口 // 获取视频总时长 let duration = document.getElementById("video").duration; - if (curTime >= (duration - 2)) { + // console.log(curTime, _this.current_sign, duration, "-----") + if (curTime >= (duration - 2) && _this.current_sign >= (duration - 10)) { + if (_this.last30sTimer && _this.section[_this.choose_section_index].is_end != 1) { // console.log("最后2秒我运行了11111111111111111"); _this.last30sTimer = false; @@ -433,14 +435,24 @@ export default { _this.current_sign = _this.record; Toast("从上次记录的地方开始播放"); setTimeout(function () { + // 先清除旧定时器 + if (_this.video_timer) { + clearInterval(_this.video_timer); + } _this.video_timer = setInterval(timer, 100); }, 1000); } function onPlayerEnded() { - document - .getElementById("video") - .removeEventListener("ended", onPlayerEnded, false); - _this.onPlayerEnded(); + const duration = document.getElementById("video").duration; + // console.log(duration, "视频播放完啦,真的吗?"); + + if (_this.current_sign >= duration - 10) { + document + .getElementById("video") + .removeEventListener("ended", onPlayerEnded, false); + _this.onPlayerEnded(); + } + } console.log("视频播放进度:", _this.record); @@ -449,6 +461,10 @@ export default { document.getElementById("video").addEventListener("play", plays, false); } else { // vd.play(); + // 先清除旧定时器 + if (_this.video_timer) { + clearInterval(_this.video_timer); + } _this.video_timer = setInterval(timer, 100); } // 监听视频播放完成 @@ -856,6 +872,8 @@ export default { }, beforeRouteLeave(to, from, next) { // 确保离开路由时清除定时器 + // console.log("离开路由时清除定时器:", this.video_timer); + if (this.video_timer) { clearInterval(this.video_timer); this.video_timer = null; // 重置定时器变量