<script>
	import store from '@/store/index.js'	
	//#ifdef APP-PLUS
	var jpushModule = uni.requireNativePlugin("JG-JPush");
	//#endif
	export default {
		onLaunch: function() {
			//#ifdef APP-PLUS	
			store.commit('initJpush',jpushModule);			
			jpushModule.initJPushService();
			jpushModule.setLoggerEnable(true);			
			jpushModule.addConnectEventListener(result=>{
				let connectEnable = result.connectEnable
				console.log('connectEnable');
				uni.$emit('connectStatusChange',connectEnable)
			});			
			jpushModule.addNotificationListener(result=>{
				let notificationEventType = result.notificationEventType
				let messageID = result.messageID
				let title = result.title
				let content = result.content
				let extras = result.extras;
				let id=extras.id;
				let redirectUrl=extras.url;
				console.log("id:",id)
				console.log("通知",result)
				console.log("redirectUrl",result)
				uni.reLaunch({
					url:`/${redirectUrl}?id=${id}`,
					success() {
						console.log('老铁没毛病！收到通知消息，跳转到'+redirectUrl)
					},
					fail(res) {
						uni.showToast({
							icon: 'none',
							title: JSON.stringify(res),
							duration:2000
						})									
					},
					complete() {
						uni.hideToast();
					}
				})
			});			
			jpushModule.addCustomMessageListener(result=>{
				let type = result.type
				let messageType = result.messageType
				let content = result.content
				uni.showToast({
					icon: 'none',
					title: JSON.stringify(result),
					duration: 3000
				})
			})			
			jpushModule.addLocalNotificationListener(result=>{
				let messageID = result.messageID
				let title = result.title
				let content = result.content
				let extras = result.extras
				uni.showToast({
					icon: 'none',
					title: JSON.stringify(result),
					duration: 3000
				})
			})					
			jpushModule.setIsAllowedInMessagePop(true)		
			jpushModule.addInMessageListener(result=>{
				let eventType = result.eventType
				let messageType = result.messageType
				let content = result.content
				console.log('inMessageListener',eventType,messageType,content)				
				uni.showToast({
					icon: 'none',
					title: JSON.stringify(result),
					duration: 3000
				})
			})
			//#endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import './styles/index.css';
	@import './static/icon/iconfont.css';	
</style>
