<template>
	<view class="main">
		<view class="" style="width: 80%;margin: 0 auto;">
			<up-button type="primary" @click="login" text="登录"></up-button>
		</view>
	</view>
</template>

<script setup>
	import {
		loginByCode
	} from "@/comm/api.js"
	import {setToken} from "@/utils/Auth.js"
	async function login() {
		const __this = this
		uni.login({
			provider: "weixin",
			async success(e) {
				
				try {
					const resp = await loginByCode({
						code: e.code
					})
					console.log(resp)
					uni.showToast({
						icon:"none",
						title:"登录成功"
					})
					setToken(resp.token)
					setTimeout(()=>{
						uni.switchTab({
							url:"/pages/user/user"
						})
					},800)
				}catch(err){
					uni.showToast({
						icon:"none",
						title:"登录失败"
					})
				}
			}
		})
	}
</script>

<style>
	.main {
		height: 100vh;
		display: flex;
		align-items: center;
	}
</style>