App.vue 2.3 KB
Newer Older
Y
..  
yyt 已提交
1 2 3 4
<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
Y
yyt 已提交
5

Y
yyt 已提交
6 7 8
			var now = new Date().getTime()
			var token = uni.getStorageSync('token')
			var time = uni.getStorageSync('time')
Y
yyt 已提交
9
			if (token && time && now - time < 180000) { //三分钟过期
Y
yyt 已提交
10 11 12 13 14 15
				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')
Y
yyt 已提交
16
				getApp().globalData.moblie = uni.getStorageSync('moblie')
Y
yyt 已提交
17 18 19 20
				getApp().globalData.gender = uni.getStorageSync('gender')
				getApp().globalData.teamNameStorageCount = uni.getStorageSync('teamNameStorageCount')
				getApp().globalData.runningRecordStorageCount = uni.getStorageSync('runningRecordStorageCount')
				getApp().globalData.walkingRecordStorageCount = uni.getStorageSync('walkingRecordStorageCount')
Y
yyt 已提交
21
				console.log(111222)
Y
yyt 已提交
22
			} else {
Y
yyt 已提交
23
				if (token) {
Y
yyt 已提交
24 25
					uni.removeStorageSync('token')
				}
Y
yyt 已提交
26 27 28 29 30 31 32
				uni.reLaunch({
					url: '/pages/login/login',
					success: () => {
						plus.navigator.closeSplashscreen();
					}
				})
			}
Y
.  
yyt 已提交
33 34 35 36 37 38 39 40 41 42 43 44

			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)
				}
			})
Y
..  
yyt 已提交
45 46 47
		},
		onShow: function() {
			console.log('App Show')
Y
.  
yyt 已提交
48 49 50 51 52 53 54 55 56 57 58
			uni.onPushMessage((res) => {
				console.log(res)
				if (res.type == 'click') {
					uni.reLaunch({
						url: '/pages/team/main',
						success: () => {
							plus.navigator.closeSplashscreen();
						}
					})
				}
			})
Y
..  
yyt 已提交
59 60 61
		},
		onHide: function() {
			console.log('App Hide')
Y
yyt 已提交
62 63
			var time = new Date().getTime()
			uni.setStorageSync('time', time)
R
Renic1 已提交
64 65
		},
		globalData: {
M
MicroMilo 已提交
66 67 68 69
			userId: '',
			name: '',
			type: '',
			icon: '',
Y
yyt 已提交
70 71 72
			school: '',
			gender: '',
			moblie: '',
M
MicroMilo 已提交
73 74 75
			teamNameStorageCount: 1,
			runningRecordStorageCount: 1,
			walkingRecordStorageCount: 1,
Y
yyt 已提交
76
			push_clientid: '',
Y
..  
yyt 已提交
77 78 79 80
		}
	}
</script>

赵十四's avatar
赵十四 已提交
81 82 83 84
<style lang="scss">
	/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
</style>