<template>
	<view class="container"></view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app'
import { myRequest } from '@/utils/api.js'

onLoad(() => {
	uni.login({
		success: (res) => {
			vertify(res.code)
		}
	})
})

const vertify = async (code) => {
	const res = await myRequest({
		url: '/wanzai/api/wechat/vertify',
		data: {
			code
		}
	})
	// console.log(res)
	if (res.code == 200) {
		uni.setStorageSync('token', JSON.parse(res.message).token)
		uni.setStorageSync('userhead', JSON.parse(res.message).userhead)
		uni.setStorageSync('userInfo', JSON.parse(res.message).user[0])

		uni.redirectTo({
			url: '/pages/home/home'
		})
	} else {
		uni.redirectTo({
			url: '/pages/login/login'
		})
	}
}
</script>

<style lang="scss" scoped>
.container {
	min-height: 100vh;
	background-color: #f8f8fa;
}
</style>
