<script>
	import {authUrl} from '@/common/conf/config.js';
	export default {
		onLaunch: function(e) {
			console.log('App Launch', e)
			// if (this.$isWxBrowser()) {
			// 	this.WxBrowser(e);
			// } else {
			// 	this.externalBrowser(e);
			// }
			if (this.$isWxBrowser() && this.$u.test.isEmpty(e.query)) {
				// uni.reLaunch({
				// 	url: "/pages/index/guide"
				// })
				let path = 'pages/index/guide?login=1';
				window.location.href = authUrl(path);
			} else if (this.$isWxBrowser() && !this.$u.test.isEmpty(e.query.login)) {
				uni.reLaunch({
					url: 'pages/index/guide'
				})
			} else if (this.$isWxBrowser() && !this.$u.test.isEmpty(e.query.userId)) {
				if (e.query.userId != uni.getStorageSync("userId")) {
					let url = window.location.href;
					let len = url.indexOf("userId=") - 1
					let tmp = url.substring(0, len)
					console.log(tmp);
					window.location.href = tmp
				} else {
					uni.reLaunch({
						url: 'pages/index/guide?userId=' + e.query.userId
					})
				}
				
			} else {
				if (!this.$u.test.isEmpty(e.query.userId)) {
					uni.reLaunch({
						url: "/pages/activityList/home/home?activityId=1407016573251153922&userId=" + e.query.userId
					})
				} else {
					uni.reLaunch({
						url: "/pages/activityList/home/home?activityId=1407016573251153922"
					})
				}
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			WxBrowser(e) {
				let userId = uni.getStorageSync("userId");
				if (this.$u.test.isEmpty(e.query) && this.$u.test.isEmpty(userId)) {
					let path = 'pages/index/guide?login=1';
					window.location.href = authUrl(path);
				} else if (!this.$u.test.isEmpty(e.query.login)) {
					uni.reLaunch({
						url: 'pages/index/guide'
					})
				} else if (!this.$u.test.isEmpty(userId) && (userId != e.query.userId)) {
					window.location.href = "https://music.nanyue6688.com/vote-h5/index.html#/";
				} else {
					uni.reLaunch({
						url: 'pages/index/guide?userId=' + e.query.userId
					})
				}
			},
			externalBrowser(e) {
				if (!this.$u.test.isEmpty(e.query.userId)) {
					uni.reLaunch({
						url: "/pages/activityList/home/home?activityId=1407016573251153922&userId=" + e.query.userId
					})
				} else {
					uni.reLaunch({
						url: "/pages/activityList/home/home?activityId=1407016573251153922"
					})
				}
			}
		}
	}
</script>

<style lang="scss">
		@import "uview-ui/index.scss";
		@import "common/css/colorui/main.css";
		@import "common/css/colorui/icon.css";
		@import "common/css/app.scss";
</style>
