<script>
	export default {
		globalData:{
			userInfo: {}
		},
		onLaunch: function() {
			console.warn('当前组件仅支持 uni_modules 目录结构 ，请升级 HBuilderX 到 3.1.0 版本以上！')
			console.log('App Launch')
			var that = this;
			// #ifdef MP-WEIXIN
			// that.wxmpLogin();
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			wxmpLogin: function(needLoad=true) {
				//微信小程序登录流程
				var that = this;
				uni.login({
					provider: 'weixin',
					success: (loginRes) => {
						that.$api.wxmpLogin({code: loginRes.code}).then(res=>{
							uni.hideLoading()
							uni.setStorageSync('access', res.access)
							that.$api.getUserInfo().then(res=>{
								uni.setStorageSync('userInfo', res)
								if(needLoad){
									var pages = getCurrentPages();    //获取加载的页面
								　　var currentPage = pages[pages.length - 1];  //获取当前页面的对象
								　　var url = currentPage.route;  //当前页面url
									uni.redirectTo({
										url: '/' + url,
										fail() {
											uni.reLaunch({
												url: '/' + url
											})
										}
									})
								}
							})
						}).catch(e=>{
							uni.reLaunch({
								url: '/pages/auth/login?autoLoading=no'
							})
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';
	@import '@/uni_modules/uni-scss/theme.scss';
	@import '@/uni_modules/uni-scss/variables.scss';
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';
	/* #endif */
	// 设置整个项目的背景色
	page {
		background-color: #f7f7f7;
	}
	.container {
		color: #333;
		padding: 12rpx;
	}
	.uni-forms-item {
		margin-bottom: 8rpx !important;
	}
	.uni-forms-item--border {
		padding: 4rpx
	}
	.dialogWrap {
		position: fixed;
		width: 100vw;
		height: 100vh;
		background-color: rgba(0, 0, 0, .3);
		top: 0;
		left: 0;
		z-index: 110;
	}
	
	.dialogCont {
		width: 92vw;
		position: absolute;
		top: 50%;
		margin: auto;
		background-color: #ffffff;
		left: 2vw;
		transform: translateY(-50%);
		padding: 10rpx;
		border-radius: 20rpx;
	}
	
	.dialogTitle {
		font-size: 28rpx;
		padding-bottom: 12rpx;
		border-bottom: 1upx solid #eeeeee;
		display: flex;
		justify-content: space-between;
	}
</style>
