<script>
	/**
	 * vuex管理登陆状态，具体可以参考官方登陆模板示例
	 */
	import Vue from 'vue'
	import { mapState,mapMutations} from 'vuex';
	import authorize from '@/common/config/authorize.js'
	import { userInfoLogin } from "@/api/use.js"
	export default {
		onLaunch: function() {
			let self = this
			uni.getSystemInfo({
				success: function(e) {
					let modelmes = e.model;
					if (modelmes.search('iPhone X') != -1) { //XS,XR,XS MAX均可以适配
					  self.$store.dispatch('setVariableFun',true)
					}
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
						Vue.prototype.platformClass = true
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
						Vue.prototype.platformClass = false
					};
					// #endif
			
					// #ifdef MP-WEIXIN || MP-QQ
					console.log(e.platform)
					if (e.platform == 'android') {
						Vue.prototype.platformClass = 'left'
					} else {
						Vue.prototype.platformClass = 'center'
					}
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.fontSizeSetting = e.fontSizeSetting
					Vue.prototype.screenWidth = e.screenWidth
					let capsule = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.capsule = capsule
					if (capsule) {
						Vue.prototype.Custom = capsule;
						// Vue.prototype.capsuleSafe = uni.upx2px(750) - capsule.left + uni.upx2px(750) - capsule.right;
						Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					}
					// #endif		
				
			
					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			})
			this.refresh()
		},
		methods:{
			...mapMutations(['login','logout']),
			getCheekeyCode(){// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
				authorize.getCode('weixin').then(wechatcode =>{
					// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
					userInfoLogin({code:wechatcode}).then(response =>{
						uni.removeStorageSync('sessionid')
						uni.setStorageSync('token',response.data.token)
						uni.setStorageSync('sessionid','JSESSIONID='+response.data.sessionId)
						this.$store.commit('updateStatus',response.data)
					}).catch(response =>{
						this.logout()
						uni.removeStorageSync('sessionid')
						uni.setStorageSync('sessionid','JSESSIONID='+response.data)
						this.$store.commit('updateStatus',response.data)
					})
				})
			},
			refresh(){
				let TIME = (20*60)*1000;
				setInterval(()=>{
					this.getCheekeyCode()
				},TIME)
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/common/css/common.scss";
	@import "@/common/css/iconfont.scss";

view,
scroll-view,
swiper,
swiper-item,
cover-view,
cover-image,
icon,
text,
rich-text,
progress,
button,
checkbox,
form,
input,
label,
radio,
slider,
switch,
textarea,
navigator,
audio,
camera,
image,
video {
	// box-sizing: border-box;
}
page{
	height: 100%;
	background-color: #FFFFFF;
}
/* 骨架屏替代方案 */
.Skeleton {
	background: #f3f3f3;
	padding: 20upx 0;
	border-radius: 8upx;
}

.clamp {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	display: block;
}

.common-hover {
	background: #f5f5f5;
}
/* input 样式 */
.input-placeholder {
	color: #999999;
}

.placeholder {
	color: #999999;
}
</style>
