<template>
</template>
<script>
	import Api from '@/common/js/api.js'
	export default {
		onLaunch: function() {
			// #ifdef MP-WEIXIN
			uni.cache.set('menuInfo', uni.getMenuButtonBoundingClientRect());
			// #endif
			uni.cache.set('NAME', '零点八零');
			this.userlogin()
		},
		onLoad() {
		},
		onShow: function() {
			this.$store.dispatch("HeightActions"); //获取随时获取页面的高度
			// #ifdef MP-WEIXIN
			// 当向小程序后台请求完新版本信息，会进行回调。res: {hasUpdate: true, version: 1.0.0}
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate(function(res) {
				if (res.hasUpdate) { // 有更新
					uni.showLoading({
						title: '更新中...'
					}); // 开始下载前，显示Loading
				}
			});
			// 当新版本下载完成，会进行回调
			updateManager.onUpdateReady(function() {
				uni.hideLoading(); // 关闭 Loading 
				uni.showModal({ // 弹确认框（强制更新）
					title: '更新提示',
					content: '更新完毕，是否重启？',
					success: function(res) {
						if (res.confirm) {
							updateManager.applyUpdate(); // 强制小程序重启并使用新版本。
						}
					}
				})
			});
			// 当新版本下载失败，会进行回调
			updateManager.onUpdateFailed(function() {
				uni.hideLoading(); // 关闭 Loading 
				uni.showToast({
					title: '更新失败，稍后再试...',
					icon: "error"
				});
			});
			// #endif

		},
		onHide: function() {
			// console.log('App Hide');
		},
		methods: {
			userlogin() {
				if (!uni.cache.get('token')) {
					uni.login({
						provider: 'weixin',
						success: (data) => {
							uni.getUserInfo({
								provider: 'weixin',
								success: async (infoRes) => {
									uni.cache.set('weixincode', data.code);
									let res = await Api.userwxlogin({
										code: uni.cache.get('weixincode'), //临时登录凭证
										rawData: infoRes.rawData,
									})
									if (res.code == 0) {
										uni.cache.set('token', res.data.token);
										uni.cache.set('miniAppOpenId', res.data.userInfo
											.miniAppOpenId)
										uni.cache.set('userInfo', res.data.userInfo);
										this.$isResolve()
									}
								},
								fail: (err) => {}
							});
						},
						})
				}
			}
		}
	};
</script>

<style lang="scss">
	@import '@/uni_modules/uview-ui/index.scss';
	/* #ifndef APP-PLUS-NVUE */
	@import './common/css/uni.scss';
	/* #endif */
	/* uni.scss */
	@import './common/css/flex.css';

	page,
	view,
	scroll-view,
	swiper,
	swiper-item,
	match-media,
	movable-area,
	movable-view,
	cover-view,
	cover-image,
	icon,
	text,
	rich-text,
	progress,
	button,
	checkbox-group,
	editor,
	form,
	input,
	label,
	picker,
	picker-view,
	radio-group,
	slider,
	switch,
	textarea,
	navigator,
	audio,
	camera,
	image,
	video,
	live-player,
	live-pusher,
	map,
	canvas,
	web-view {
		box-sizing: border-box;
	}

	input {
		height: auto;
	}

	image {
		display: block;
	}

	page {
		background-color: #F9F9F9;
	}

	text {
		font-size: 28upx;
		color: #333;
	}

	@font-face {
		font-family: 'BebasNeue-Regular';
		src: url('./static/font/BebasNeue-Regular.woff');
	}

	.num {
		font-family: 'BebasNeue-Regular';
	}
</style>