fix(每日充值活动): 修复动效有时获取不到报错的问题

This commit is contained in:
hzj 2026-05-07 19:32:11 +08:00
parent b533451a40
commit bf1aec6559

View File

@ -339,16 +339,16 @@ justify-content: flex-start;
@click="handleMainRewardPreviewClick"
>
<VapMp4Player
v-if="isAndroidDevice && mainReward.sourceUrl"
v-if="shouldPlayMainRewardVap"
:model-value="true"
:src="mainReward.sourceUrl"
:src="mainRewardVapSourceUrl"
mode="inline"
fit="contain"
:loop="true"
:mute="true"
:auto-close="false"
:show-status="false"
@error="handleRewardVapError"
@error="(error) => handleRewardVapError(error, mainRewardVapSourceUrl)"
/>
<img
v-else
@ -358,7 +358,7 @@ justify-content: flex-start;
@error="(e) => handleRewardImageError(e, mainReward.type)"
/>
<button
v-if="isIosDevice && mainReward.sourceUrl"
v-if="isIosDevice && mainRewardVapSourceUrl"
type="button"
class="reward-showcase-play-button"
@click.stop="handleMainRewardPreviewClick"
@ -781,6 +781,16 @@ const selectedRewardList = computed(() => {
const mainReward = computed(() => {
return selectedRewardList.value[0] || null
})
const mainRewardVapSourceUrl = computed(() => {
return normalizeVapSourceUrl(mainReward.value?.sourceUrl)
})
const shouldPlayMainRewardVap = computed(() => {
return (
isAndroidDevice.value &&
Boolean(mainRewardVapSourceUrl.value) &&
!failedRewardVapUrls.value.has(mainRewardVapSourceUrl.value)
)
})
const rewardGridList = computed(() => {
return selectedRewardList.value.slice(1, 7)
})
@ -789,6 +799,7 @@ const mainRewardRenderKey = computed(() => {
})
const rewardVapPreloadElements = new Map()
const criticalVapPreloadElements = new Map()
const failedRewardVapUrls = ref(new Set())
let rewardVapPreloadTimer = null
let rewardVapPreloadIdleCallbackId = null
let rewardVapPreloadStarted = false
@ -802,6 +813,39 @@ const getRewardDisplayText = (reward) => {
return formatRewardDisplay(reward.type, reward)
}
const normalizeVapSourceUrl = (sourceUrl = '') => {
const resolvedUrl = resolveProtectedAssetUrl(sourceUrl || '').trim()
if (!resolvedUrl) {
return ''
}
if (resolvedUrl.startsWith('//')) {
const protocol =
typeof window !== 'undefined' && window.location?.protocol ? window.location.protocol : 'https:'
return `${protocol}${resolvedUrl}`
}
if (/^http:\/\//i.test(resolvedUrl)) {
return resolvedUrl.replace(/^http:\/\//i, 'https://')
}
if (/^https?:\/\//i.test(resolvedUrl)) {
return resolvedUrl
}
if (resolvedUrl.startsWith('/oss/')) {
return resolvedUrl
}
if (resolvedUrl.startsWith('/')) {
return process.env.NODE_ENV === 'development'
? `/oss${resolvedUrl}`
: `https://tkm-likei.oss-ap-southeast-1.aliyuncs.com${resolvedUrl}`
}
return `https://${resolvedUrl}`
}
const getRewardRenderKey = (reward, index) => {
return [
selectedRewardLevel.value,
@ -816,7 +860,7 @@ const getRewardRenderKey = (reward, index) => {
const getRewardVapUrls = (rewardTopList) => {
return (rewardTopList || [])
.flatMap((rewardTop) => rewardTop?.propsGroup?.activityRewardProps || [])
.map((reward) => resolveProtectedAssetUrl(reward?.sourceUrl || ''))
.map((reward) => normalizeVapSourceUrl(reward?.sourceUrl))
.filter(Boolean)
}
@ -1013,18 +1057,22 @@ const openPopup = (type) => {
}
}
const handleRewardVapError = (error) => {
const handleRewardVapError = (error, sourceUrl = '') => {
console.error('Reward VAP playback failed:', error)
const normalizedSourceUrl = normalizeVapSourceUrl(sourceUrl)
if (normalizedSourceUrl) {
failedRewardVapUrls.value = new Set([...failedRewardVapUrls.value, normalizedSourceUrl])
}
showError(error?.message || t('active_game_vap_playback_failed'))
}
const handleMainRewardPreviewClick = () => {
if (!mainReward.value?.sourceUrl) {
if (!mainRewardVapSourceUrl.value) {
return
}
if (isIosDevice.value) {
notifyAppPlayVap(mainReward.value.sourceUrl)
notifyAppPlayVap(mainRewardVapSourceUrl.value)
}
}