feat: 开屏页面优化

This commit is contained in:
2026-06-01 11:14:28 +08:00
parent 34fbca57a3
commit aa0a289f27
+44 -9
View File
@@ -20,6 +20,7 @@
@loadedmetadata="onVideoMetadata" @loadedmetadata="onVideoMetadata"
@canplay="onVideoReady" @canplay="onVideoReady"
@play="onVideoReady" @play="onVideoReady"
@timeupdate="onVideoTimeUpdate"
@ended="onVideoEnded" @ended="onVideoEnded"
@click="onMediaClick" @click="onMediaClick"
/> />
@@ -33,10 +34,10 @@
@click="onMediaClick" @click="onMediaClick"
/> />
<cover-view v-if="!USE_STATIC_START_PAGE && bgSrc && isVideo" class="count-down" @click.stop="toHome"> <cover-view v-if="!USE_STATIC_START_PAGE && bgSrc && isVideo" class="count-down" @click.stop="toHome">
<cover-view class="count-down-text">{{ `跳过 ${countDown}s` }}</cover-view> <cover-view class="count-down-text">{{ getSkipText() }}</cover-view>
</cover-view> </cover-view>
<view v-else class="count-down" @click.stop="toHome"> <view v-else class="count-down" @click.stop="toHome">
{{ `跳过 ${countDown}s` }} {{ getSkipText() }}
</view> </view>
</view> </view>
</template> </template>
@@ -47,7 +48,7 @@ import * as IndexApi from '@/sheep/api/index/index'
const USE_STATIC_START_PAGE = false const USE_STATIC_START_PAGE = false
const DEFAULT_IMAGE_SECONDS = 3 const DEFAULT_IMAGE_SECONDS = 3
const MAX_VIDEO_SECONDS = 15 const MAX_VIDEO_SECONDS = 9
const bgSrc = ref('') const bgSrc = ref('')
const jumpUrl = ref('') const jumpUrl = ref('')
@@ -57,6 +58,7 @@ let downloadToken = 0
let readyFallbackTimer = null let readyFallbackTimer = null
let countDownTimer = null let countDownTimer = null
let jumpTimer = null let jumpTimer = null
let videoCountdownBootTimer = null
const normalizeAppFileUrl = (path) => { const normalizeAppFileUrl = (path) => {
const p = String(path || '') const p = String(path || '')
@@ -127,7 +129,12 @@ function onMediaError() {
startCountDown(DEFAULT_IMAGE_SECONDS) startCountDown(DEFAULT_IMAGE_SECONDS)
} }
const countDown = ref(DEFAULT_IMAGE_SECONDS) const countDown = ref(0)
const getSkipText = () => {
const s = Number(countDown.value) || 0
return s > 0 ? `跳过 ${s}s` : '跳过'
}
function closeNativeSplashIfNeeded() { function closeNativeSplashIfNeeded() {
try { try {
@@ -144,6 +151,8 @@ function clearTimers() {
countDownTimer = null countDownTimer = null
if (jumpTimer) clearTimeout(jumpTimer) if (jumpTimer) clearTimeout(jumpTimer)
jumpTimer = null jumpTimer = null
if (videoCountdownBootTimer) clearTimeout(videoCountdownBootTimer)
videoCountdownBootTimer = null
} }
function startCountDown(seconds) { function startCountDown(seconds) {
@@ -182,13 +191,21 @@ function onVideoReady() {
mediaReady.value = true mediaReady.value = true
closeNativeSplashIfNeeded() closeNativeSplashIfNeeded()
} }
if (!countDownTimer) { if (countDownTimer) return
if (videoCountdownBootTimer) return
videoCountdownBootTimer = setTimeout(() => {
videoCountdownBootTimer = null
if (countDownTimer) return
startCountDown(MAX_VIDEO_SECONDS) startCountDown(MAX_VIDEO_SECONDS)
scheduleJumpAfter(MAX_VIDEO_SECONDS + 0.2) scheduleJumpAfter(MAX_VIDEO_SECONDS + 0.2)
} }, 300)
} }
function onVideoMetadata(e) { function onVideoMetadata(e) {
if (videoCountdownBootTimer) {
clearTimeout(videoCountdownBootTimer)
videoCountdownBootTimer = null
}
if (!mediaReady.value) { if (!mediaReady.value) {
mediaReady.value = true mediaReady.value = true
closeNativeSplashIfNeeded() closeNativeSplashIfNeeded()
@@ -199,6 +216,20 @@ function onVideoMetadata(e) {
scheduleJumpAfter(limit + 0.2) scheduleJumpAfter(limit + 0.2)
} }
function onVideoTimeUpdate(e) {
const duration = Number(e?.detail?.duration || e?.detail?.totalTime || 0)
if (!Number.isFinite(duration) || duration <= 0) return
const limit = Math.min(MAX_VIDEO_SECONDS, Math.ceil(duration))
if (countDown.value === limit) return
if (countDownTimer && countDown.value < MAX_VIDEO_SECONDS) return
if (videoCountdownBootTimer) {
clearTimeout(videoCountdownBootTimer)
videoCountdownBootTimer = null
}
startCountDown(limit)
scheduleJumpAfter(limit + 0.2)
}
function onVideoEnded() { function onVideoEnded() {
toHome() toHome()
} }
@@ -274,18 +305,22 @@ function onMediaClick() {
position: absolute; position: absolute;
top: calc(env(safe-area-inset-top) + 100rpx); top: calc(env(safe-area-inset-top) + 100rpx);
right: 60rpx; right: 60rpx;
padding: 18rpx 20rpx; height: 64rpx;
padding: 0 20rpx;
border-radius: 50rpx; border-radius: 50rpx;
font-size: 28rpx; font-size: 28rpx;
line-height: 1; line-height: 32rpx;
color: #fff; color: #fff;
background: rgba(0, 0, 0, 0.4); background: rgba(0, 0, 0, 0.4);
z-index: 9999; z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
} }
.count-down-text { .count-down-text {
color: #fff; color: #fff;
font-size: 28rpx; font-size: 28rpx;
line-height: 1; line-height: 32rpx;
} }
</style> </style>