diff --git a/pages/index/startPage.vue b/pages/index/startPage.vue index 4ccff6c..f6e89e2 100644 --- a/pages/index/startPage.vue +++ b/pages/index/startPage.vue @@ -33,11 +33,18 @@ @load="onImageLoaded" @click="onMediaClick" /> - - {{ getSkipText() }} - - - {{ getSkipText() }} + + {{ getSkipText() }} + + + + + 加载中... + @@ -54,6 +61,7 @@ const bgSrc = ref('') const jumpUrl = ref('') const isVideo = ref(false) const mediaReady = ref(false) +const isLoading = ref(false) let downloadToken = 0 let readyFallbackTimer = null let countDownTimer = null @@ -123,10 +131,7 @@ const fetchStartPage = async () => { } function onMediaError() { - bgSrc.value = '' - isVideo.value = false - mediaReady.value = false - startCountDown(DEFAULT_IMAGE_SECONDS) + toHome() } const countDown = ref(0) @@ -181,6 +186,7 @@ function scheduleJumpAfter(seconds) { function onImageLoaded() { if (mediaReady.value) return mediaReady.value = true + isLoading.value = false closeNativeSplashIfNeeded() startCountDown(DEFAULT_IMAGE_SECONDS) scheduleJumpAfter(DEFAULT_IMAGE_SECONDS + 0.2) @@ -189,6 +195,7 @@ function onImageLoaded() { function onVideoReady() { if (!mediaReady.value) { mediaReady.value = true + isLoading.value = false closeNativeSplashIfNeeded() } if (countDownTimer) return @@ -208,6 +215,7 @@ function onVideoMetadata(e) { } if (!mediaReady.value) { mediaReady.value = true + isLoading.value = false closeNativeSplashIfNeeded() } const duration = Number(e?.detail?.duration || e?.detail?.totalTime || 0) @@ -241,22 +249,16 @@ onMounted(() => { scheduleJumpAfter(DEFAULT_IMAGE_SECONDS + 0.2) return } + isLoading.value = true fetchStartPage().then((ok) => { if (!ok) { - closeNativeSplashIfNeeded() - startCountDown(DEFAULT_IMAGE_SECONDS) - scheduleJumpAfter(DEFAULT_IMAGE_SECONDS + 0.2) + toHome() return } readyFallbackTimer = setTimeout(() => { - if (countDownTimer) return - if (isVideo.value) { - onVideoReady() - return - } - startCountDown(DEFAULT_IMAGE_SECONDS) - scheduleJumpAfter(DEFAULT_IMAGE_SECONDS + 0.2) - }, isVideo.value ? 2500 : 1200) + if (mediaReady.value) return + toHome() + }, isVideo.value ? 3500 : 2000) }) }) @@ -266,6 +268,7 @@ onUnmounted(() => { function toHome() { clearTimers() + isLoading.value = false uni.reLaunch({ url: '/pages/index/index', }) @@ -323,4 +326,47 @@ function onMediaClick() { font-size: 28rpx; line-height: 32rpx; } + +.loading-mask { + position: absolute; + inset: 0; + z-index: 9998; + display: flex; + align-items: center; + justify-content: center; + background: rgba(255, 255, 255, 0.1); +} + +.loading-box { + padding: 22rpx 26rpx; + border-radius: 16rpx; + background: rgba(0, 0, 0, 0.45); + display: flex; + align-items: center; + gap: 16rpx; +} + +.loading-spinner { + width: 32rpx; + height: 32rpx; + border-radius: 50%; + border: 4rpx solid rgba(255, 255, 255, 0.35); + border-top-color: rgba(255, 255, 255, 0.95); + animation: spin 0.85s linear infinite; +} + +.loading-text { + font-size: 26rpx; + color: #fff; + line-height: 32rpx; +} + +@keyframes spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +}