<script>
	import {
		getUserInfo
	} from '@/request/api/login'
	export default {
		onLaunch() {
			console.log('App Launch')
		},
		onShow() {
			// #ifdef H5
			if (sessionStorage.getItem('store')) {
				this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem(
					'store'))));
				sessionStorage.setItem('store', ''); //重新置完清空session
			}
			window.addEventListener('beforeunload', () => {
				sessionStorage.setItem('store', JSON.stringify(this.$store.state));
			});
			// #endif
			// #ifdef MP-WEIXIN
			console.log(uni.getStorageSync('token') && !this.$store.getters.user.userId);
			if (uni.getStorageSync('token') && !this.$store.getters.user.userId) {
				getUserInfo().then(user => {
					if (user.code === 200) {
						let userInfo = user.data;
						this.$store.dispatch('app/changeOrganization', userInfo.organization);
						this.$store.dispatch('app/changeUser', userInfo);
					}
				})
			}
			// #endif
		},
		onHide() {}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';

	// 设置整个项目的背景色
	page {
		color: $uni-main-color;
		font-size: 28rpx;
		background: $uni-background-color;

		img {
			width: 100%;
			height: 100%;
		}
	}
</style>