fix: 首屏视频出现播放按钮

This commit is contained in:
liulujian 2026-06-05 14:34:51 +08:00
parent 8449757995
commit d43b4b17e2
2 changed files with 58 additions and 25 deletions

View File

@ -70,11 +70,10 @@ docker buildx build --platform linux/arm64 -t txw-all:1.0.0 -f devops/Dockerfile
代码变更后,重新构建并启动: 代码变更后,重新构建并启动:
```bash ```bash
# 1. 重新构建镜像 # 1. 加载新镜像
bash build.sh 1.0.0-BETA docker load -i txw-all-1.0.0-time.tar
# 2. 重启业务服务(使用新镜像) # 2. 重启业务服务(使用新镜像)
docker-compose -f docker-compose.svc.yml up -d --build docker-compose -f docker-compose.svc.yml up -d --force-recreate
``` ```
### 查看镜像 ### 查看镜像

View File

@ -6,18 +6,29 @@
<div class="container"> <div class="container">
<!-- 顶部背景轮播 --> <!-- 顶部背景轮播 -->
<div class="top-box snap-section" id="section-hero" :style="{ minHeight: topBannerHeight + 'px' }"> <div class="top-box snap-section" id="section-hero" :style="{ minHeight: topBannerHeight + 'px' }">
<t-swiper class="top-banner-swiper" animation="fade" :height="topBannerHeight" :interval="10000" :duration="500" <t-swiper
:loop="true" :autoplay="true" theme="dark" :navigation="{ showSlideBtn: 'never' }"> class="top-banner-swiper"
animation="fade"
:height="topBannerHeight"
:interval="10000"
:duration="500"
:loop="true"
:autoplay="true"
theme="dark"
:navigation="{ showSlideBtn: 'never' }"
:current="currentBannerIndex"
@change="onBannerChange"
>
<t-swiper-item v-for="(video, idx) in topBannerVideos" :key="idx"> <t-swiper-item v-for="(video, idx) in topBannerVideos" :key="idx">
<video <video
ref="bannerVideoRefs"
class="banner-video" class="banner-video"
:src="video" :src="video"
autoplay
muted muted
loop loop
playsinline playsinline
webkit-playsinline
preload="auto" preload="auto"
@loadeddata="onBannerVideoReady"
/> />
</t-swiper-item> </t-swiper-item>
</t-swiper> </t-swiper>
@ -355,6 +366,7 @@ export default {
inputValue: '', inputValue: '',
activeTab: 0, activeTab: 0,
topBannerHeight: 686, topBannerHeight: 686,
currentBannerIndex: 0,
newsLoading: true, newsLoading: true,
scrollRoot: null, scrollRoot: null,
sectionOffsets: [], sectionOffsets: [],
@ -530,6 +542,17 @@ export default {
if (window.visualViewport) { if (window.visualViewport) {
window.visualViewport.addEventListener('resize', this.onViewportResize); window.visualViewport.addEventListener('resize', this.onViewportResize);
} }
// Mac Safari
//
this._unlockBannerOnce = () => {
this.onUserInteractUnlockBanner();
['click', 'touchstart', 'keydown', 'scroll'].forEach((evt) => {
window.removeEventListener(evt, this._unlockBannerOnce);
});
};
['click', 'touchstart', 'keydown', 'scroll'].forEach((evt) => {
window.addEventListener(evt, this._unlockBannerOnce, { once: true, passive: true });
});
this.loadHotSearch(); this.loadHotSearch();
this.fetchNewsData(); this.fetchNewsData();
this.getTfwzxUrl(); this.getTfwzxUrl();
@ -553,7 +576,7 @@ export default {
this._scrollRootResizeObserver.observe(this.scrollRoot); this._scrollRootResizeObserver.observe(this.scrollRoot);
} }
} }
this.ensureBannerVideosPlay(); this.playActiveBannerVideo();
this.jumpToSectionFromRoute(this.$route.query.section, false); this.jumpToSectionFromRoute(this.$route.query.section, false);
}); });
}, },
@ -564,6 +587,12 @@ export default {
window.visualViewport.removeEventListener('resize', this.onViewportResize); window.visualViewport.removeEventListener('resize', this.onViewportResize);
} }
} }
if (this._unlockBannerOnce) {
['click', 'touchstart', 'keydown', 'scroll'].forEach((evt) => {
window.removeEventListener(evt, this._unlockBannerOnce);
});
this._unlockBannerOnce = null;
}
if (this._scrollRootResizeObserver) { if (this._scrollRootResizeObserver) {
this._scrollRootResizeObserver.disconnect(); this._scrollRootResizeObserver.disconnect();
this._scrollRootResizeObserver = null; this._scrollRootResizeObserver = null;
@ -712,28 +741,33 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.syncPortalFigmaStageLayout(); this.syncPortalFigmaStageLayout();
this.refreshSectionOffsets(); this.refreshSectionOffsets();
this.ensureBannerVideosPlay(); this.playActiveBannerVideo();
}); });
}, },
onBannerVideoReady(e) { onBannerChange(index) {
const video = e && e.target; this.currentBannerIndex = typeof index === 'number' ? index : 0;
this.$nextTick(() => this.playActiveBannerVideo());
},
playActiveBannerVideo() {
const list = this.$refs.bannerVideoRefs || [];
list.forEach((video, i) => {
if (!video) return; if (!video) return;
if (i === this.currentBannerIndex) {
video.muted = true; video.muted = true;
const playPromise = video.play(); try { video.currentTime = 0; } catch (e) {}
if (playPromise && typeof playPromise.catch === 'function') { const p = video.play();
playPromise.catch(() => {}); if (p && typeof p.catch === 'function') {
p.catch((err) => console.warn('[banner video] play rejected:', err));
} }
}, } else {
ensureBannerVideosPlay() { video.pause();
if (!this.$el) return; try { video.currentTime = 0; } catch (e) {}
this.$el.querySelectorAll('.banner-video').forEach((video) => {
video.muted = true;
const playPromise = video.play();
if (playPromise && typeof playPromise.catch === 'function') {
playPromise.catch(() => {});
} }
}); });
}, },
onUserInteractUnlockBanner() {
this.playActiveBannerVideo();
},
refreshSectionOffsets() { refreshSectionOffsets() {
const scrollRoot = this.getScrollRoot(); const scrollRoot = this.getScrollRoot();
if (!scrollRoot) return; if (!scrollRoot) return;