<template>
	<view class="title">
		正在微信授权登录
	</view>
</template>

<script lang="ts" setup>
	import api from "@/api/api";
	import { onLoad } from "@dcloudio/uni-app";
	onLoad(option =>{
		let param = {
			code: option.code,
			state: option.state
		}
		api.wxLogin(param).then((res) => {
			if (res['success']) {
				uni.setStorageSync('video_userId', String(res['data']['userId']));
				uni.setStorageSync('uni-token', res['data']['token']);
				uni.setStorageSync('isLogin', '1');
				uni.setStorageSync('loginType', 'codelogin');
				uni.redirectTo({
					url:'/myPackageA/videoProject/videoDetail?videoId='+option.fileId
				})
			} else {
				uni.showToast({
					title: res['message'],
					duration: 2000,
					icon: 'none'
				})
				uni.redirectTo({
					url:'/myPackageA/videoProject/login?videoId='+option.fileId
				})
			}
		})
	})
</script>

<style lang="scss">
	.title {}
</style>