App.vue 2.8 KB
Newer Older
Y
..  
yyt 已提交
1 2 3
<script>
	export default {
		onLaunch: function() {
Y
yyt 已提交
4 5 6 7 8 9 10 11 12 13 14 15
			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 已提交
16
			console.log('App Launch')
Y
yyt 已提交
17 18 19 20 21 22 23 24 25 26 27 28

			uni.onPushMessage((res) => {
				console.log(res)
				if (res.type == 'click') {
					setTimeout(function() {
						uni.navigateTo({
							url: '/pages/team/main'
						})
					}, 1000)
				}
			})

Y
yyt 已提交
29 30 31
			var now = new Date().getTime()
			var token = uni.getStorageSync('token')
			var time = uni.getStorageSync('time')
Y
yyt 已提交
32
			if (token && time && now - time < 60000) { //一分钟过期
Y
yyt 已提交
33 34 35 36 37 38 39 40 41 42 43 44
				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('mobile')
				getApp().globalData.gender = uni.getStorageSync('gender')
				getApp().globalData.teamNameStorageCount = uni.getStorageSync('teamNameStorageCount')
				getApp().globalData.runningRecordStorageCount = uni.getStorageSync('runningRecordStorageCount')
				getApp().globalData.walkingRecordStorageCount = uni.getStorageSync('walkingRecordStorageCount')
			} else {
Y
yyt 已提交
45
				if (token) {
Y
yyt 已提交
46 47
					uni.removeStorageSync('token')
				}
Y
yyt 已提交
48 49 50 51 52 53 54
				uni.reLaunch({
					url: '/pages/login/login',
					success: () => {
						plus.navigator.closeSplashscreen();
					}
				})
			}
Y
..  
yyt 已提交
55 56
		},
		onShow: function() {
M
MicroMilo 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
			// let push_clientid;
			// uni.getPushClientId({
			// 	success: (res) => {
			// 		push_clientid = res.cid
			// 		console.log('客户端推送标识:', push_clientid)
			// 		uniCloud.callFunction({
			// 				name: 'uni-cloud-push',
			// 				data: {
			// 					"appId": "__UNI__AAFC50C",
			// 					"push_clientid": push_clientid,
			// 					"title": "unitest",
			// 					"content": push_clientid,
			// 					"payload": {
			// 						"text": "ddddddoooo"
			// 					}
			// 				}
			// 			})
			// 			.then(res => {
			// 				console.log(res);
			// 			});
			// 	},
			// 	fail(err) {
			// 		console.log(err)
			// 	}
			// })
Y
..  
yyt 已提交
82 83 84 85
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
Y
yyt 已提交
86 87
			var time = new Date().getTime()
			uni.setStorageSync('time', time)
R
Renic1 已提交
88 89
		},
		globalData: {
M
MicroMilo 已提交
90 91 92 93 94 95 96
			userId: '',
			name: '',
			type: '',
			icon: '',
			teamNameStorageCount: 1,
			runningRecordStorageCount: 1,
			walkingRecordStorageCount: 1,
Y
yyt 已提交
97
			push_clientid: '',
Y
..  
yyt 已提交
98 99 100 101
		}
	}
</script>

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