<template>
	<view class="third-jump-page" @click="retryJump">
		<image class="bg-img" :src="`${$baseUrl}${bgImg}`" mode="widthFix"></image>
	</view>
</template>

<script setup>
import { ref, onMounted, getCurrentInstance } from 'vue'
import { jump } from '../../utils/index.js'; // Import jump function

// 获取全局属性
const { proxy } = getCurrentInstance()
const $baseUrl = proxy.$baseUrl

// 响应式数据
const jumpFailed = ref(false)
const errorMessage = ref('')
const jumpParams = ref({})
const bgImg = ref('middlePage/middleBg.png')

// const bgImgObj = {
// 	'sy': 'thirdJumpMiddlePage/v1/syJumpPageBg.jpg'
// }


// 页面加载时获取参数
onMounted(() => {
	// 获取页面参数
	const pages = getCurrentPages()
	const currentPage = pages[pages.length - 1]
	const options = currentPage.options || {}

	// 解析跳转参数
	jumpParams.value = {
		appId: options.appId || '',
		path: decodeURIComponent(options.path) || '',
		extraData: options.extraData ? JSON.parse(decodeURIComponent(options.extraData)) : {},
		envVersion: options.envVersion || 'release',
		type: options.type,
		embedded: options.embedded,
	}
	setTimeout(() => {
		// 执行跳转
		executeJump()
	}, 30)

})

// 执行跳转
const executeJump = () => {
	const jumpData = {
		type: jumpParams.value.type * 1,
		url: jumpParams.value.path,
		extra: {
			appId: jumpParams.value.appId,
			path: jumpParams.value.path,
			extraData: jumpParams.value.extraData,
			envVersion: jumpParams.value.envVersion,
			embedded: jumpParams.value.embedded
		}
	}
	console.warn('executeJump jumpData:', jumpData)
	jump(jumpData)
}

// 重试跳转
const retryJump = () => {
	executeJump()
}

</script>

<style lang="less" scoped>
.third-jump-page {
	width: 100vw;
	height: 100vh;
	overflow: hidden;
	position: absolute;
}

.bg-img {
	width: 750rpx;
	height: 1624rpx;
	position: absolute;
	top: 0;
	bottom: 0;
	left: 0;
	margin: auto;
	z-index: 1;
}
</style>
