From 440aaabacad16b2f86e5ea0a5423b476c1f6a072 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期五, 27 六月 2025 10:11:43 +0800
Subject: [PATCH] 活动样式调整
---
pages/tabbar/index/home.vue | 179 ++++++++++++++++++++++-------------------------------------
1 files changed, 67 insertions(+), 112 deletions(-)
diff --git a/pages/tabbar/index/home.vue b/pages/tabbar/index/home.vue
index 1c56703..9aebf49 100644
--- a/pages/tabbar/index/home.vue
+++ b/pages/tabbar/index/home.vue
@@ -1,11 +1,15 @@
<template>
<view class="video-container">
+ <top-bar selectedTitleIndex="home" textColor="white" @changeTab="topBarChange" class="topBar"></top-bar>
+ <!-- 瑙嗛鍔犺浇 -->
+ <zero-loading v-show="videoLoading" type="circle" color="#0ebd57" text=""></zero-loading>
<!-- 瑙嗛鍒楄〃 -->
<swiper
class="video-swiper"
vertical
:current="currentIndex"
@change="onSwiperChange"
+ :duration="250"
easing-function="linear"
>
<swiper-item
@@ -25,14 +29,16 @@
<image src="/static/video/play.png" style="width: 45px;height: 45px" mode="aspectFit"></image>
</view>
<video
+ v-if="index >= currentIndex - videoLiveOffset && index <= currentIndex + videoLiveOffset"
:id="'video'+index"
:ref="'video'+index"
:src="item.videoUrl"
- :autoplay="false"
+ :autoplay="index === currentIndex"
:controls="false"
:loop="true"
:object-fit="item.objectFit"
:enable-progress-gesture="false"
+ :show-center-play-btn="false"
class="video-item"
@play="onPlay(item.id, index)"
@pause="onPause(index)"
@@ -40,12 +46,13 @@
@click="togglePlay(index)"
@timeupdate="onTimeUpdate($event)"
@loadedmetadata="onLoadedMetadata($event)"
+ @waiting="videoWaiting(index)"
></video>
<!-- 鑷畾涔夋帶鍒舵潯 -->
<view
- @touchstart="handleTouchStart"
- @touchmove="handleTouchMove"
- @touchend="handleTouchEnd"
+ @touchstart.stop="handleTouchStart"
+ @touchmove.stop="handleTouchMove"
+ @touchend.stop="handleTouchEnd"
class="container">
<!-- 杩涘害鏉� - 鏁翠釜鍖哄煙鍙嫋鍔� -->
<view class="process-warp" :style="{ opacity: showProcess ? 1 : 0 }">
@@ -241,7 +248,10 @@
import { silentLogin } from "@/api/connect.js";
import { getUserInfo } from "@/api/members";
import storage from "@/utils/storage.js";
+import TopBar from "@/components/TopBar.vue";
+
export default {
+ components: {TopBar},
computed: {
hasPlayTime() {
return this.sliderFormatTime(this.progress > 0 ? this.duration * this.progress / 100 : 0);
@@ -300,13 +310,11 @@
startPlayTime: 0 // 杩欎釜瑙嗛浠庝粈涔堟椂鍊欏紑濮嬫挱鏀剧殑
},
currentVideoIsPlaying: true, // 褰撳墠瑙嗛鏄惁姝e湪鎾斁
- isFullScreen: false,
- windowHeight: 0,
currentIndex: 0, // 褰撳墠鎾斁鐨勮棰戠储寮�
+ videoLoading: false, // 瑙嗛缂撳啿涓�
videoList: [], // 瑙嗛鍒楄〃鏁版嵁
- videoContexts: [], // 瑙嗛涓婁笅鏂囧璞¢泦鍚�
videoBufferOffset: 0.1 ,// 瑙嗛棰勫姞杞藉弬鏁�
- videoLiveOffset: 5, // 淇濈暀褰撳墠瑙嗛鍓嶅悗鍚勫灏戜釜瑙嗛涓婁笅鏂�
+ videoLiveOffset: 2, // 淇濈暀褰撳墠瑙嗛鍓嶅悗鍚勫灏戜釜瑙嗛涓婁笅鏂�
touchXY: { // 鐩戝惉宸︽粦鍙虫粦
startX: 0,
endX: 0,
@@ -375,6 +383,17 @@
}
},
methods: {
+ topBarChange(titleObj) {
+ if (titleObj.index === 'home') {
+ uni.switchTab({
+ url: titleObj.pagePath
+ });
+ } else {
+ uni.redirectTo({
+ url: titleObj.pagePath
+ });
+ }
+ },
// 闈欓粯鐧诲綍
wxSilentLogin(callback) {
//鑾峰彇code
@@ -662,56 +681,6 @@
}
})
},
- // 鍒濆鍖栬棰戜笂涓嬫枃
- initVideoContexts() {
- const start = Math.max(0, this.currentIndex - this.videoLiveOffset);
- const end = Math.min(this.currentIndex + this.videoLiveOffset, this.videoList.length - 1);
- let contextsLength = this.videoContexts.length;
- if (contextsLength === 0) {
- // 绗竴娆″垵濮嬪寲
- for (let i = 0; i < this.videoList.length; i++) {
- if (i < start || i > end) {
- this.videoContexts.push(null)
- } else {
- let videoContent = uni.createVideoContext(`video${i}`, this);
- videoContent.seek(this.videoBufferOffset);
- videoContent.pause();
- this.videoContexts.push(videoContent);
- }
- }
- } else {
- for (let i = 0; i < this.videoList.length; i++) {
- contextsLength = this.videoContexts.length
- if (contextsLength - 1 >= i) {
- // 濡傛灉宸茬粡鏄痭ull浜嗗氨涓嶇敤绠★紝鍥犱负瑙嗛鍔犺浇鍙細鍦ㄥ悗闈ush锛屽墠闈㈠凡缁忚缃负null鍒欐棤闇�澶勭悊
- if (this.videoContexts[i] == null) {
- continue
- }
- // 瓒呭嚭鍙鍖栬寖鍥寸殑瑙嗛鐩存帴閲婃斁璧勬簮锛屽苟缃负null
- if (i < start || i > end) {
- if (this.videoContexts[i]) {
- this.videoContexts[i].stop();
- this.videoContexts[i] = null
- }
- }
- } else {
- if (i < start || i > end) {
- this.videoContexts.push(null);
- } else {
- let videoContent = uni.createVideoContext(`video${i}`, this);
- videoContent.seek(this.videoBufferOffset);
- videoContent.pause();
- this.videoContexts.push(videoContent);
- }
- }
- }
- }
- // 灏嗗綋鍓嶈棰戣缃负鎾斁
- if (this.videoContexts[this.currentIndex]) {
- this.videoContexts[this.currentIndex].play()
- }
-
- },
// 鍔犺浇瑙嗛鏁版嵁
async loadVideos() {
@@ -730,9 +699,6 @@
),
];
}
- this.$nextTick(() => {
- this.initVideoContexts();
- });
this.loading = false;
if(res.data.data.length < this.videoQuery.pageSize) {
this.videoNoMore = true;
@@ -745,6 +711,7 @@
// 婊戝姩鍒囨崲瑙嗛
onSwiperChange(e) {
+ this.videoLoading = false
// 濡傛灉瑙嗛澶勪簬鏆傚仠鐘舵�佸線涓嬪埛瑙嗛锛岄偅涔堥渶瑕佸啀璁$畻涓�娆℃殏鍋滄椂闂�
if(!this.currentVideoIsPlaying) {
if(this.startPauseTime !== 0) {
@@ -756,49 +723,23 @@
this.savePlayRecord()
const oldIndex = this.currentIndex;
this.currentIndex = e.detail.current;
-
+ const videoContext = uni.createVideoContext(`video${oldIndex}`, this);
// 鏆傚仠涓婁竴涓棰�
- if (this.videoContexts[oldIndex]) {
- this.videoContexts[oldIndex].pause();
- }
-
+ videoContext.pause();
this.startPauseTime = 0;
// 璁剧疆褰撳墠鎾斁瑙嗛鐨勬�绘椂闀�
this.duration = this.videoList[this.currentIndex].videoDuration;
this.formartDuration = this.sliderFormatTime(this.duration);
- // 鎾斁褰撳墠瑙嗛
- if (this.videoContexts[this.currentIndex]) {
- this.videoContexts[this.currentIndex].play();
- }
- this.clearVideoContext()
- },
- // 娓呴櫎瓒呭嚭瑙嗛鍙鍖栧尯鍩熺殑瑙嗛涓婁笅鏂�
- async clearVideoContext() {
- // 瀵硅秴鍑哄彲瑙嗗寲鍖哄煙鐨勮棰戜笂涓嬫枃鍋氶攢姣佸鐞�
- const start = Math.max(0, this.currentIndex - this.videoLiveOffset);
- const end = Math.min(this.currentIndex + this.videoLiveOffset, this.videoList.length - 1);
- for (let i = 0; i < this.videoContexts.length; i++) {
- if (i < start || i > end) {
- if (this.videoContexts[i]) {
- this.videoContexts[i].stop();
- this.videoContexts[i] = null
- }
- } else {
- if (this.videoContexts[i] == null) {
- let videoContent = uni.createVideoContext(`video${i}`, this);
- videoContent.seek(this.videoBufferOffset);
- videoContent.pause();
- this.videoContexts[i] = videoContent;
- }
- }
- }
+ // 鎾斁褰撳墠瑙嗛
+ const videoContext1 = uni.createVideoContext(`video${this.currentIndex}`, this);
+ videoContext1.play()
// 濡傛灉鍓╀綑瑙嗛涓嶈冻锛岃Е鍙戣姹傝幏鍙栨洿澶氳棰�
if (this.videoList.length - 1 < this.currentIndex + this.videoLiveOffset) {
this.loadVideos()
}
- },
+ },
// 寮�濮嬭Е鎽�
handleSwiperStart(e) {
@@ -808,12 +749,15 @@
},
// 瑙︽懜涓�
handleSwiperMove(e) {
- console.log("瑙︽懜涓�", e);
this.touchXY.endX = e.touches[0].pageX
this.touchXY.endY = e.touches[0].pageY
},
// 缁撴潫瑙︽懜
handleSwiperEnd(item) {
+ // 闃叉婊戝姩婊氬姩鏉′篃瑙﹀彂璺宠浆
+ if (this.showProcess) {
+ return
+ }
const diffX = this.touchXY.endX - this.touchXY.startX
const diffY = this.touchXY.endY - this.touchXY.startY
@@ -861,18 +805,16 @@
},
// 鍗曞嚮灞忓箷锛氭殏鍋滄垨缁х画鎾斁
togglePlay(index) {
- console.log("鍗曞嚮瑙嗛", index, this.videoContexts);
+ console.log("鍗曞嚮瑙嗛", index);
+ const videoContext = uni.createVideoContext(`video${index}`, this);
if(this.currentVideoIsPlaying) {
- this.videoContexts[index].pause();
+ videoContext.pause();
} else {
- this.videoContexts[index].play();
+ videoContext.play();
}
},
// 瑙嗛鎾斁浜嬩欢
onPlay(id, index) {
- this.getBarRect()
- this.progress = 0
- console.log(id, index, "瑙﹀彂鎾斁");
if(index === this.currentIndex) {
this.currentVideoIsPlaying = true;
if(! this.duration) {
@@ -881,9 +823,11 @@
this.formartDuration = this.sliderFormatTime(this.duration);
}
} else {
- this.currentVideoIsPlaying = false;
return
}
+ this.getBarRect()
+ this.progress = 0
+ console.log(id, index, "瑙﹀彂鎾斁");
this.playRecord.videoId = id;
// 娌″垵濮嬪寲鎵嶈祴鍊硷紝鍥犱负涓�涓棰戦噸澶嶆挱鏀緊nPlay浼氶噸澶嶈Е鍙�
if(this.playRecord.startPlayTime === 0) {
@@ -893,7 +837,7 @@
const duration = Date.now() - this.startPauseTime
this.totalPauseTime += duration
}
-
+ this.videoLoading = false
},
// 瑙嗛鏆傚仠浜嬩欢
@@ -901,11 +845,8 @@
console.log(index, "瑙﹀彂鏆傚仠");
if(index === this.currentIndex) {
this.currentVideoIsPlaying = false;
- } else {
- this.currentVideoIsPlaying = true;
- return
+ this.startPauseTime = Date.now()
}
- this.startPauseTime = Date.now()
},
// 瑙嗛缁撴潫浜嬩欢
onEnded(index) {
@@ -914,6 +855,7 @@
// 璁板綍鎾斁鏃堕暱
onTimeUpdate(e) {
+ this.videoLoading = false
this.playRecord.playAt = e.detail.currentTime;
this.currentTime = e.detail.currentTime;
@@ -926,7 +868,8 @@
this.startProgress = this.progress; // 璁板綍寮�濮嬫椂鐨勮繘搴�
this.startX = e.touches[0].pageX;
console.log("璁板綍寮�濮嬫椂鐨勮繘搴�", this.startProgress);
- this.videoContexts[this.currentIndex].pause()
+ const videoContext = uni.createVideoContext(`video${this.currentIndex}`, this);
+ videoContext.pause()
// this.updateProgress(e);
},
@@ -934,7 +877,6 @@
handleTouchMove(e) {
if (!this.isDragging || !this.barWidth) return;
clearTimeout(this.processHidenTimer)
- this.videoContexts[this.currentIndex].pause()
this.updateProgress(e);
},
@@ -942,8 +884,9 @@
handleTouchEnd() {
this.isDragging = false;
console.log("婊戝姩缁撴潫", this.duration * this.progress);
- this.videoContexts[this.currentIndex].seek(this.duration * this.progress / 100)
- this.videoContexts[this.currentIndex].play()
+ const videoContext = uni.createVideoContext(`video${this.currentIndex}`, this);
+ videoContext.seek(this.duration * this.progress / 100)
+ videoContext.play()
this.processHidenTimer = setTimeout(() => {
this.showProcess = false;
}, 1000);
@@ -959,7 +902,6 @@
// 灏嗗儚绱犺窛绂昏浆鎹负杩涘害澧為噺
const deltaProgress = (deltaX / this.barWidth) * 100;
- console.log("杩涘害澧為噺", deltaProgress);
// 璁$畻鏂拌繘搴� = 寮�濮嬫椂鐨勮繘搴� + 婊戝姩澧為噺
let newProgress = this.startProgress + deltaProgress;
@@ -967,6 +909,13 @@
newProgress = Math.max(0, Math.min(100, newProgress));
this.progress = newProgress;
+ },
+ // 瑙嗛缂撳啿
+ videoWaiting(index) {
+ if (index === this.currentIndex) {
+ console.log("瑙嗛缂撳啿涓�傘�傘��");
+ this.videoLoading = true;
+ }
},
// 鑾峰彇瑙嗛鎬绘椂闀�
onLoadedMetadata(e) {
@@ -1015,7 +964,7 @@
.video-item {
width: 100%;
height: 100%;
- object-fit: cover;
+ /* object-fit: cover; */
}
.play-icon {
position: absolute;
@@ -1427,4 +1376,10 @@
.custom-share-btn::after {
border: none;
}
+ .topBar {
+ position: fixed;
+ top: 20rpx;
+ left: 20rpx;
+ z-index: 1000
+ }
</style>
--
Gitblit v1.8.0