<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')

			var now = new Date().getTime()
			var token = uni.getStorageSync('token')
			var time = uni.getStorageSync('time')
			if (token && time && now - time < 60000) { //一分钟过期
				plus.navigator.closeSplashscreen();
				getApp().globalData.userId = uni.getStorageSync('userId')
				getApp().globalData.name = uni.getStorageSync('name')
				getApp().globalData.type = uni.getStorageSync('type')
				getApp().globalData.icon = uni.getStorageSync('icon')
				getApp().globalData.school = uni.getStorageSync('school')
				getApp().globalData.moblie = uni.getStorageSync('moblie')
				getApp().globalData.gender = uni.getStorageSync('gender')
				getApp().globalData.teamNameStorageCount = uni.getStorageSync('teamNameStorageCount')
				getApp().globalData.runningRecordStorageCount = uni.getStorageSync('runningRecordStorageCount')
				getApp().globalData.walkingRecordStorageCount = uni.getStorageSync('walkingRecordStorageCount')
				console.log(111222)
			} else {
				if (token) {
					uni.removeStorageSync('token')
				}
				uni.reLaunch({
					url: '/pages/login/login',
					success: () => {
						plus.navigator.closeSplashscreen();
					}
				})
			}

			let push_clientid;
			uni.getPushClientId({
				success: (res) => {
					getApp().globalData.push_clientid = res.cid
					push_clientid = res.cid
					console.log('客户端推送标识:', push_clientid)
				},
				fail(err) {
					console.log(err)
				}
			})
		},
		onShow: function() {
			console.log('App Show')

			uni.onPushMessage((res) => {
				console.log(res)
				if (res.type == 'click') {
					uni.reLaunch({
						url: '/pages/team/main',
						success: () => {
							plus.navigator.closeSplashscreen();
						}
					})
				}
			})
		},
		onHide: function() {
			console.log('App Hide')
			var time = new Date().getTime()
			uni.setStorageSync('time', time)
		},
		globalData: {
			userId: '',
			name: '',
			type: '',
			icon: '',
			school: '',
			gender: '',
			moblie: '',
			teamNameStorageCount: 1,
			runningRecordStorageCount: 1,
			walkingRecordStorageCount: 1,
			push_clientid: '',
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
</style>