150 lines
3.0 KiB
Vue
150 lines
3.0 KiB
Vue
<template>
|
|
<view class="start-page">
|
|
<video
|
|
v-if="bgSrc && isVideo"
|
|
class="bg"
|
|
:src="bgSrc"
|
|
autoplay
|
|
loop
|
|
muted
|
|
:controls="false"
|
|
:show-fullscreen-btn="false"
|
|
:show-play-btn="false"
|
|
:show-center-play-btn="false"
|
|
:enable-progress-gesture="false"
|
|
object-fit="cover"
|
|
@error="onMediaError"
|
|
@click="onMediaClick"
|
|
/>
|
|
<image
|
|
v-else-if="bgSrc"
|
|
class="bg"
|
|
:src="bgSrc"
|
|
mode="aspectFill"
|
|
@error="onMediaError"
|
|
@click="onMediaClick"
|
|
/>
|
|
<view class="count-down" :class="{ enabled: canEnter }" @click.stop="onEnterClick">
|
|
{{ canEnter ? '进入' : `跳过 ${countDown}s` }}
|
|
</view>
|
|
</view>
|
|
</template>
|
|
<script setup>
|
|
import { ref, onMounted, onUnmounted } from 'vue'
|
|
import * as IndexApi from '@/sheep/api/index/index'
|
|
|
|
const bgSrc = ref('')
|
|
const jumpUrl = ref('')
|
|
const isVideo = ref(false)
|
|
|
|
const isVideoUrl = (url) => {
|
|
const u = String(url || '')
|
|
if (!u) return false
|
|
const clean = u.split('?')[0].split('#')[0]
|
|
return /\.(mp4|mov|m4v|webm|ogg)$/i.test(clean)
|
|
}
|
|
|
|
const fetchStartPage = async () => {
|
|
try {
|
|
const res = await IndexApi.getstartpage({})
|
|
if (res?.code !== 0) return false
|
|
const data = res?.data || {}
|
|
const media = String(data?.picUrl || '').trim()
|
|
const url = String(data?.url || '').trim()
|
|
if (!media) return false
|
|
bgSrc.value = media
|
|
jumpUrl.value = url
|
|
isVideo.value = isVideoUrl(media)
|
|
return true
|
|
} catch (e) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
function onMediaError() {
|
|
bgSrc.value = ''
|
|
isVideo.value = false
|
|
}
|
|
|
|
const countDown = ref(3)
|
|
let timer = null
|
|
const canEnter = ref(false)
|
|
|
|
onMounted(() => {
|
|
fetchStartPage()
|
|
timer = setInterval(() => {
|
|
if (countDown.value <= 1) {
|
|
//点击进入
|
|
// countDown.value = 0
|
|
// canEnter.value = true
|
|
clearInterval(timer)
|
|
//直接进入
|
|
toHome()
|
|
return
|
|
}
|
|
countDown.value -= 1
|
|
}, 1000)
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
if (timer) clearInterval(timer)
|
|
})
|
|
|
|
function toHome() {
|
|
uni.reLaunch({
|
|
url: '/pages/index/index',
|
|
})
|
|
}
|
|
|
|
function onMediaClick() {
|
|
const url = String(jumpUrl.value || '').trim()
|
|
if (!url) return
|
|
if (/^https?:\/\//i.test(url)) {
|
|
uni.navigateTo({
|
|
url: `/pages/public/webview?url=${encodeURIComponent(url)}`,
|
|
})
|
|
return
|
|
}
|
|
if (url.startsWith('/pages/')) {
|
|
uni.navigateTo({ url })
|
|
return
|
|
}
|
|
}
|
|
|
|
function onEnterClick() {
|
|
if (!canEnter.value) return
|
|
toHome()
|
|
}
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
.start-page {
|
|
position: fixed;
|
|
inset: 0;
|
|
width: 100vw;
|
|
height: 100vh;
|
|
overflow: hidden;
|
|
background: #fff;
|
|
}
|
|
.bg {
|
|
position: absolute;
|
|
inset: 0;
|
|
width: 100vw;
|
|
height: 100vh;
|
|
}
|
|
.count-down {
|
|
position: absolute;
|
|
top: calc(env(safe-area-inset-top) + 100rpx);
|
|
right: 60rpx;
|
|
padding: 18rpx 20rpx;
|
|
border-radius: 50rpx;
|
|
font-size: 28rpx;
|
|
line-height: 1;
|
|
color: #fff;
|
|
background: rgba(0, 0, 0, 0.4);
|
|
z-index: 10;
|
|
}
|
|
.count-down.enabled {
|
|
// background: rgba(54, 110, 238, 0.85);
|
|
}
|
|
</style>
|