<template>
	<view class="loadTxt">Loading...</view>
</template>

<script setup >
	import { ref } from "vue";
	import api from '@/api/api';
	import { onLaunch, onLoad } from '@dcloudio/uni-app'
	import * as environment from '@/environments/environment'
	let dataToken = ref()
	onLoad((options) => {
		// 参数带token了重新登录
		if (options.dataToken) {
			// uni.clearStorageSync();
			
			dataToken.value = options.dataToken
			reLogin(options.landingPage)
		}

	})

	const reLogin = (landingPage) => {
		uni.showLoading({
			title: '加载中...'
		});
		// 添加iOS平台检测
		const isIOS = navigator.platform.match(/(iPhone|iPod|iPad)/i);
		const params = {
			loginType: '5',
			authToken: dataToken.value
		}
		api.loginVerification(params).then((res) => {
			if (res['success']) {
				uni.setStorageSync('isLogin', '1');
				uni.setStorageSync('loginType', 'codelogin');
				uni.setStorageSync('cffp_userId', res.data.userId);
				uni.setStorageSync('uni-token', res.data['token']);
				dataToken.value = ''
				uni.removeStorageSync('dataToken')
				if (landingPage == 'sfpHousePurchase') {
					uni.reLaunch({ url: `/sfp/housePurchase/housePurchase` })

				}else if(landingPage == 'sfpIndex'){
					uni.reLaunch({ url: `/sfp/index/index` })
				}
			} else {
				uni.showToast({
					title: res['message'],
					duration: 2000,
					icon: 'none'
				})
			}
		})
		uni.hideLoading()

	}
</script>
<style lang="scss" scoped>
	.loadTxt {
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
	}
</style>