<script>
	
	export default {
		onLaunch: function() {
			const that=this;
			// #ifdef MP
			let sysInfo=uni.getSystemInfoSync(),menuInfo=uni.getMenuButtonBoundingClientRect();
			let offsetBottom=menuInfo.top-sysInfo.statusBarHeight;
			
			if(sysInfo.system.indexOf('iOS')!==-1){
				this.$store.commit('setPlatform','ios');
			}
			else if(sysInfo.system.indexOf('Android')!==-1){
				this.$store.commit('setPlatform','android');
			}
			else{
				this.$store.commit('setPlatform','other');
			}
			this.$store.commit('setStatusBarHeight',sysInfo.statusBarHeight);
			this.$store.commit('setTopbarOffsetHeight',sysInfo.statusBarHeight + offsetBottom*2 + menuInfo.height);
			this.$store.commit('setTabBarHeight',(this.$util.hasSafeArea()?68:20)+106);
			
			return;//单元测试开关
			if(uni.getStorageSync('autoLogin')==='false'){
				return;
			}
			uni.login({//免密登录
				success:(res)=>{
					that.$api.login.wxLogin({
						scene: "WxMPLogin",
						miniProgramEncryUserInfoParam:{
							jsCode:res.code
						}
					}).then(result=>{
						if(result.status==='Succ'){
							if(!result.data.succ){
								if(result.data.wxLoginInfo){//新用户保存用户openid,unionId
									uni.setStorageSync('openId',result.data.wxLoginInfo.openId);
									uni.setStorageSync('unionId',result.data.wxLoginInfo.unionId);
								}
							}
							else{
								uni.setStorageSync('LL_Ukn',result.data.userToken.ukn);
								uni.setStorageSync('token',result.data.userToken.token);
								uni.setStorageSync('userInfo',JSON.stringify(result.data));
								uni.setStorageSync('user',JSON.stringify(result.data.userToken.user));
								this.$api.public.aliossCdn({}).then(cdnRes=>{
									this.$store.commit('setImageCdn',cdnRes.data.pictureCdn);
									this.$store.commit('setVideoCdn',cdnRes.data.videoCdn);
								})
								this.$api.public.mineDetail({
									getAlbum:true,
									completeUser:result.data.userToken.user
								}).then(res=>{
									this.$store.commit('setUserInfo',res.data);
									uni.setStorageSync('userInfo',JSON.stringify(res.data));
									
									if(result.data.isNew){
										uni.reLaunch({
											url:'/pages/info/sex'
										})
										return;
									}
									let step=result.data.regStepNew||result.data.regStep;
									switch(step){
										case 'Sex':
											uni.reLaunch({
												url:'/pages/info/sex'
											})
										break;
										case 'SocialImage':
											uni.reLaunch({
												url:'/pages/info/figure'
											})
										break;
										case 'SocialData':
											uni.reLaunch({
												url:'/pages/info/datum'
											})
										break;
										case 'CityStay':
											uni.reLaunch({
												url:'/pages/info/city'
											})
										break;
										case 'WxInfo':
											uni.reLaunch({
												url:'/pages/info/wechat'
											})
										break;
										case 'Basic':
										case 'Index':
											uni.reLaunch({
												url:'/pages/friends/friends'
											})
										break;
									}
									uni.reLaunch({
										url:'/pages/friends/friends'
									})
								})
								
							}
						}
						
						
					})
				},
				fail: (err) => {
					console.log(err)
				}
			});
			// #endif
		},
		onShow: function() {
			console.log('App Show')
			
		},
		onHide: function() {
			console.log('App Hide')
		},
		onUnload() {
			console.log('im logout')
			uni.$TUIKit.logout();
			uni.$TUIKit.destroy();
		},
		
	}
</script>
