<template>
	<view class="all">
		<view>
			<view>
				<!-- <img src="http://110.42.248.235:866/images/system/666/HmCyrnRc-login.png" class="img"> -->
			</view>
			<view class="text_all">
				<view class="text_tishi">
					请完成授权以继续使用
				</view>
				<button @click="login" class="text_btn">微信账号一键登录</button>
<!-- 				<view class="text_no">
					请选择手机号登录?
				</view> -->
			</view>
		</view>
	</view>

</template>

<script setup>
import { ref } from 'vue'
import { baseUrl, testUrl , suiUrl} from '@/api/request';
const login = () => {
	uni.login({
		provider: 'weixin', //使用微信登录
		success: function (loginRes) {
			if (loginRes.code !== null) {
				console.log("获取code:" + loginRes.code)
				loginUser(loginRes.code);
			} else {
				console.log("code为空");
			}
		}
	})
}
//非遗
const loginUser = async ( code ) =>{
	const res = await uni.request({
		url: baseUrl + '/user/login/wx_open',
		method: 'GET',
		data: {
			code: code
		}  
	})
	console.log('loginUser后台返回的==>',res.header['Set-Cookie']);
	uni.removeStorageSync('cookie'); 
	uni.setStorageSync("cookie",res.header['Set-Cookie']);  //保存setStorageSync到
	if(res.data.code == 1) {
		uni.showToast({
			title: '登录成功',
			duration: 2000  //提示两秒
		})
		uni.setStorageSync('userInfo',res.data.data);
		uni.switchTab({
			url: '/pages/home/home'
		})
	} else {
		uni.showToast({
			icon: 'error',
			title: "登录失败，请重试"
		})
		return;
	}
}

</script>

<style lang="scss" scoped>
	.all {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 750rpx;
		height: 1206rpx;
		.img {
			display: flex;
			width: 480rpx;
			height: 380rpx;
			margin:30rpx auto;
			
		}

		.text_all {
			width: 520rpx;
			height: 400rpx;
			margin: 40rpx auto 0;

			.text_tishi {
				font-size: 28rpx;
				text-align: center;
				margin-bottom: 40rpx;
			}

			.text_btn {
				width: 520rpx;
				height: 90rpx;
				background-color: yellow;
				border-radius: 120rpx;
				font-size: 32rpx;
				color: #fff;
				text-align: center;
				line-height: 90rpx;
				margin-bottom: 20rpx;
			}

			.text_no {
				font-size: 28rpx;
				text-align: center;
				color: #2493F1;

			}
		}
	}
</style>