<script>
	import config from 'common/config.js'
	import store from '@/store'
	import {
		getToken
	} from '@/utils/auth'
	export default {
		onLaunch: function() {
			this.initApp();
		},
		onShow: function() {
			// #ifndef MP-WEIXIN
			uni.hideTabBar();
			// #endif
			if (getToken()) {
				this.$store.dispatch('GetInfo').then(res => {
					let isLognPge = this.isLoginPage()
					console.log("token未过期,直接进入主页", isLognPge);
					if (isLognPge) {
						uni.switchTab({
							url: '/pages/home/home'
						})
					}
				})
			}
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			initApp() {
				// 初始化应用配置
				this.initConfig()
				// this.checkLogin()
				// 检查用户登录状态
				//#ifdef H5
				// this.checkLogin()
				//#endif
			},
			initConfig() {
				this.globalData.config = config
			},
			isLoginPage() {
				const pages = getCurrentPages()
				// 当前页面
				const page = pages?.[pages.length - 1]?.$page?.fullPath
				return !page || page === '/pages/login' || page === '/pages/code' || page === '/pages/jump/weChatOffAcc'
			},
			checkWhite(url) {
				const path = url.split('?')[0]
				return whiteList.indexOf(path) !== -1
			},
			checkLogin() {
				if (!getToken()) {
					setTimeout(() => {
						console.log("首次跳转");
						this.$tab.reLaunch('/pages/login')
					}, 500)
				}
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	/* 引入 uView 基础样式 */
	@import '@/uni_modules/uview-ui/index.scss';
	/*每个页面公共scss */
	@import 'app.scss';
	@import '@/static/scss/index.scss'
</style>
