From 05d2a0dd704260183012d50201887ed21631481e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E8=82=96=E7=A3=8A?= <18851179580@163.com> Date: Thu, 12 Mar 2026 13:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A7=86=E9=A2=91=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/plugins/video/detail/detail.nvue | 103 ++++++++++++++----------- pages/plugins/video/detail/detail.vue | 12 ++- 2 files changed, 68 insertions(+), 47 deletions(-) diff --git a/pages/plugins/video/detail/detail.nvue b/pages/plugins/video/detail/detail.nvue index 861b5cb3..13a5e874 100644 --- a/pages/plugins/video/detail/detail.nvue +++ b/pages/plugins/video/detail/detail.nvue @@ -2,7 +2,7 @@ - + @@ -649,24 +649,25 @@ setTimeout(() => { // 更新显示数据数据信息 this.update_display_data(); - - if (this.display_video_list && this.display_video_list.length > 0) { - // 更新分享信息 - this.update_share_info(this.display_video_list[this.current_index]); - - this.display_video_list.forEach((item, index) => { - // this.create_video_contexts[index] = uni.createVideoContext(`video_${index}`, this); - this.$set(this.create_video_contexts, index, uni.createVideoContext(`video_${index}`, this)); - //#ifdef H5 - if (document.getElementById(`video_${index}`) != null && this.video_contexts) { - // this.video_contexts[index] = document.getElementById(`video_${index}`).querySelector('video'); - this.$set(this.video_contexts, index, document.getElementById(`video_${index}`).querySelector('video')); - } - //#endif - }); - } setTimeout(() => { + + if (this.display_video_list && this.display_video_list.length > 0) { + // 更新分享信息 + this.update_share_info(this.display_video_list[this.current_index]); + console.log(this.display_video_list.length); + this.display_video_list.forEach((item, index) => { + // this.create_video_contexts[index] = uni.createVideoContext(`video_${index}`, this); + this.$set(this.create_video_contexts, index, uni.createVideoContext(`video_${index}`, this)); + //#ifdef H5 + if (document.getElementById(`video_${index}`) != null && this.video_contexts) { + // this.video_contexts[index] = document.getElementById(`video_${index}`).querySelector('video'); + this.$set(this.video_contexts, index, document.getElementById(`video_${index}`).querySelector('video')); + } + //#endif + }); + } + //#ifdef H5 if (this.video_contexts && this.video_contexts[this.current_index]) { // 当前播放的视频索引为 0 this.video_play_event(this.video_contexts[this.current_index], true); @@ -678,7 +679,7 @@ } //#endif }, 200); - }, 0); + }, 100); } } } @@ -806,7 +807,7 @@ app.globalData.showToast('已经是第一个视频了'); return; } else { - new_index = (this.current_index - 1 + this.video_data_list.length) % this.video_data_list.length; + new_index = this.current_index - 1 < 0 ? 2 : (this.current_index - 1); } } else if (direction === 'next') { // 向上滑动,切换到下一个 @@ -814,9 +815,11 @@ app.globalData.showToast('已经是最后一个视频了'); return; } else { - new_index = (this.current_index + 1 + this.video_data_list.length) % this.video_data_list.length; + console.log('new_index', this.current_index); + new_index = this.current_index + 1 > 2 ? 0 : (this.current_index + 1); } } + console.log('new_index', new_index); // 创建模拟的 event 对象 const mockEvent = { detail: { @@ -838,10 +841,9 @@ if (this.video_switch_debounce_timer) { clearTimeout(this.video_switch_debounce_timer); } - this.video_switch_debounce_timer = setTimeout(() => { this.process_swiper_change(current); - }, 50); // 50ms 防抖延迟 + }, 100); // 100ms 防抖延迟 } catch (error) { console.error('handle_swiper_change error:', error); } @@ -886,23 +888,24 @@ const list = this.update_video_list([0, 1, 2]); this.is_slide_start = false; - this.current_index = 0; - this.swiper_key = get_math(); + this.current_index = 0; + // this.swiper_key = get_math(); // 刷新数据 this.update_display_video_list(list); } else if (this.current_video_index == this.video_data_list.length - 1) { const list = this.update_video_list([-2, -1, 0]); - this.current_index = list.length - 1; - this.swiper_key = get_math(); + this.current_index = list.length - 1; + // this.swiper_key = get_math(); // 刷新数据 this.update_display_video_list(list); } else { - this.is_slide_start = true; - this.swiper_key = get_math(); + this.is_slide_start = true; + // this.swiper_key = get_math(); this.update_display_data(); } // 更新分享信息 - this.update_share_info(this.display_video_list[current]); + this.update_share_info(this.display_video_list[current]); + this.swiper_key = get_math(); // 延迟播放当前视频,确保DOM更新完成 setTimeout(() => { this.play_current_video_safely(this.current_index); @@ -995,18 +998,20 @@ update_display_video_list(list) { try { // 不理解为什么这里时undefined的 - // 根据 weex 的通用做法,需要同时改变“引用”和“长度”两个维度才能被识别数组更新。 - // 1. 先清空原数组(触发长度变化) - if (this.display_video_list && this.display_video_list.length > 0) { - this.display_video_list.splice(0, this.display_video_list.length) - } else { - this.display_video_list = []; + // 根据 weex 的通用做法,需要同时改变“引用”和“长度”两个维度才能被识别数组更新。 + // 1. 先清空原数组(触发长度变化) + if (this.display_video_list && this.display_video_list.length > 0) { + this.display_video_list.splice(0, this.display_video_list.length) + } else { + this.display_video_list = []; } - // this.$nextTick(() => { - // setTimeout(() => { - // 2. 再把新数据 push 进去(触发内容变化) - list.forEach(item => this.display_video_list.push(item)) - // }, 0); + // this.display_video_list.splice(0, this.display_video_list.length, ...list); + + // this.$nextTick(() => { + // setTimeout(() => { + // 2. 再把新数据 push 进去(触发内容变化) + list.forEach(item => this.display_video_list.push(item)) + // }, 0); // }); } catch (e) { console.log('update_display_video_list', e); @@ -1017,8 +1022,8 @@ update_share_info(data) { try { const info = { - title: data.title || '', - desc: data.desc || '', + title: data?.title || '', + desc: data?.desc || '', path: '/pages/plugins/video/detail/detail', query: 'id=' + this.current_video_id, img: data.cover || '' @@ -1098,11 +1103,19 @@ let list = []; // 如果当前索引为0,只显示当前元素和下一个元素 if (this.current_index == 0) { - list = this.update_video_list([0, 1, -1]); + if (this.current_video_index == 0) { + list = this.update_video_list([0, 1, 2]); + } else { + list = this.update_video_list([0, 1, -1]); + } } else if (this.current_index == 1) { // 索引为1时,为确保无限轮播正常,需要改变数据插入顺序 list = this.update_video_list([-1, 0, 1]); - } else { - list = this.update_video_list([1, -1, 0]); + } else { + if (this.current_video_index == this.video_data_list.length - 1) { + list = this.update_video_list([-2, -1, 0]); + } else { + list = this.update_video_list([1, -1, 0]); + } } // 刷新数据 this.update_display_video_list(list); diff --git a/pages/plugins/video/detail/detail.vue b/pages/plugins/video/detail/detail.vue index f23427c6..943206fd 100644 --- a/pages/plugins/video/detail/detail.vue +++ b/pages/plugins/video/detail/detail.vue @@ -929,11 +929,19 @@ let list = []; // 如果当前索引为0,只显示当前元素和下一个元素 if (this.current_index == 0) { - list = this.update_video_list([0, 1, -1]); + if (this.current_video_index == 0) { + list = this.update_video_list([0, 1, 2]); + } else { + list = this.update_video_list([0, 1, -1]); + } } else if (this.current_index == 1) { // 索引为1时,为确保无限轮播正常,需要改变数据插入顺序 list = this.update_video_list([-1, 0, 1]); } else { - list = this.update_video_list([1, -1, 0]); + if (this.current_video_index == this.video_data_list.length - 1) { + list = this.update_video_list([-2, -1, 0]); + } else { + list = this.update_video_list([1, -1, 0]); + } } this.setData({ display_video_list: list