-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
40 lines (39 loc) · 1.35 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<script>
export default {
onLaunch: function() {
// #ifdef APP-PLUS
//监听push推送通知
plus.push.addEventListener('receive', data => {
let { title, content, payload } = data;
if (uni.getSystemInfoSync().platform != 'ios') {
//如果type!='receive'是自己本地插件的push消息栏,“拦截”避免死循环',安卓系统没有这个问题
if (typeof payload != 'object') {
payload = JSON.parse(payload);
} //判断是否为object,不是的话手动转一下。hbuilderx 3.0以上版本已经修复此问题可省略
plus.push.createMessage(content, JSON.stringify(payload), {
title: payload.title,
subtitle: payload.content
});
}
});
//监听点击通知栏
plus.push.addEventListener('click', function({ payload }) {
if (typeof payload != 'object') {
payload = JSON.parse(payload);
}
let pages = getCurrentPages();
let currentWebview = pages[pages.length - 1].$getAppWebview();
if (currentWebview.__uniapp_route != 'pages/index/index') {
uni.navigateTo({ url: '/pages/index/index' });
}
uni.$emit('readMsg', payload);
});
// #endif
},
onShow: function() {},
onHide: function() {}
};
</script>
<style>
/*每个页面公共css */
</style>