<script>
import {  getAccessToken } from "@/api/index";
export default {
	globalData: {
		couponSelected: {}
	},
	data() {
		return {
		}
	},
	onLaunch() {
		console.log('App Launch')
		let isWechat = navigator.userAgent.toLowerCase().includes('micromessenger');
		// 非微信环境直接跳过
		if (!isWechat) return;

		const code = this.$utils.getQueryStr('code');
		const token = uni.getStorageSync('token');

		// 已有登录态，不用登录
		if (token) return;
		// 1. 没有code → 跳转微信静默授权
		if (!code && isWechat) {
			let appid = 'wx9dc677bd41e82569'
			//https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9dc677bd41e82569&redirect_uri=https://city.baoxianzhanggui.com/fragrance/wxcode/&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
			let ruri = encodeURIComponent('https://city.baoxianzhanggui.com/fragrance/');
			const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${ruri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`
			window.location.href = authUrl
		}


		let params = {
			code: code
		}
		getAccessToken(params).then(res => {
			if (res.data.code == 200) {
				uni.setStorageSync('wx_copenid', res.data.data.copenid);
				uni.setStorageSync('access-token', res.data.data.token);
			}
		});

	},
	onShow() {
		console.log('App Show')
	},
	onHide() {
		console.log('App Hide')
	}
}
</script>

<style lang="scss">
@import 'uview-ui/index.scss';
@import "common/common.scss";

html,
body {
	height: 100vh;
	overflow-x: hidden;

	&::-webkit-scrollbar {
		display: none;
	}
}

page {
	--theme-color: #03C8BE;
	--theme-color-gradient: linear-gradient(131deg, #00DAAB 0%, #07CDC4 100%);
	;
}
</style>
