App.vue
// #ifdef APP-PLUS
import {initPushInfo} from '@/plugins/pushANDNoticfication.js'
// #endif
onLaunch: function() {
const _this = this;
onPageChange()
// #ifdef APP-PLUS
plus.screen.lockOrientation('portrait-primary'); //锁定
try {
initPushInfo()
} catch(e) {
console.log(e);
}
// #endif
}
pushANDNoticfication.js
import * as Api from "../api/index.js"
export const initPushInfo = () => {
// console.log('initPushInfo');
// 获取本机的客户端ID
uni.getPushClientId({
success(res) {
// console.log('获取cid', res);
uni.$store.dispatch('userModule/SAVE_PUSH_CID', {
cid: res.cid
})
}
})
// uni.onPushMessage(res => {
// console.log('收到推送信息:', res);
// const {
// push_type,
// msg_type,
// msg_id,
// push_id
// } = res.data.payload;
// let url = '/pages'
// if (push_type === 'content') {
// switch (msg_type) {
// case 'graphic':
// url += '/index/newsDetail?id=' + msg_id;
// break;
// case 'topic':
// url += '/index/topic?id=' + msg_id;
// break;
// case 'subject':
// url += '/index/special?id=' + msg_id;
// break;
// case 'video':
// url += '/video/video?state=video&id=' + msg_id;
// break;
// case 'minivideo':
// url += '/video/immersive?content_type=2&id=' + msg_id;
// break;
// case 'live':
// url += '/video/live?id=' + msg_id;
// break;
// case 'album':
// url += '/video/album?id=' + msg_id;
// break;
// case 'vote':
// url += '/content/vote?id=' + msg_id;
// break;
// case 'gallery':
// url += '/content/gallery?id=' + msg_id;
// break;
// default:
// break;
// }
// }
// if (url === '/pages') return
// // 为了解决返回会到splash页面的问题
// const pages = getCurrentPages()
// console.log('pages-length:', pages.length);
// console.log('pages-last-route:', pages[pages.length - 1].route);
// if (pages.length === 0 || pages[pages.length - 1].route === 'pages/common/splash') {
// console.log('先跳转到首页,gogogo');
// uni.$utils.navTo('/pages/index/index')
// }
// console.log('当前页面路径:', pages[pages.length - 1]['$page']['fullPath']);
// console.log('要跳转到的url:', url);
// if(pages[pages.length - 1]['$page']['fullPath'] === url) {
// console.log('当前页面就是推送页面,不做处理');
// return
// }
// console.log('通过验证,开始跳转');
// setTimeout(() => {
// console.log('跳转到指定页面');
// uni.$utils.navTo(url)
// Api.report_push_act({
// push_cid: uni.$store.state.userModule.pushCID || '',
// push_id
// })
// }, 500)
// })
plus.push.addEventListener('receive', function(msg) {
console.log('receive',msg);
}, false)
plus.push.addEventListener('click', function(res) {
console.log('click',res);
const {
push_type,
msg_type,
msg_id,
push_id
} = res.payload;
let url = '/pages'
if (push_type === 'content') {
switch (msg_type) {
case 'graphic':
url += '/index/newsDetail?id=' + msg_id;
break;
case 'topic':
url += '/index/topic?id=' + msg_id;
break;
case 'subject':
url += '/index/special?id=' + msg_id;
break;
case 'video':
url += '/video/video?state=video&id=' + msg_id;
break;
case 'minivideo':
url += '/video/immersive?content_type=2&id=' + msg_id;
break;
case 'live':
url += '/video/live?id=' + msg_id;
break;
case 'album':
url += '/video/album?id=' + msg_id;
break;
case 'vote':
url += '/content/vote?id=' + msg_id;
break;
case 'gallery':
url += '/content/gallery?id=' + msg_id;
break;
default:
break;
}
}
if (url === '/pages') return
// 为了解决返回会到splash页面的问题
const pages = getCurrentPages()
console.log('pages-length:', pages.length);
console.log('pages-last-route:', pages[pages.length - 1].route);
if (pages.length === 0 || pages[pages.length - 1].route === 'pages/common/splash') {
console.log('先跳转到首页,gogogo');
uni.$utils.navTo('/pages/index/index')
}
console.log('当前页面路径:', pages[pages.length - 1]['$page']['fullPath']);
console.log('要跳转到的url:', url);
if(pages[pages.length - 1]['$page']['fullPath'] === url) {
console.log('当前页面就是推送页面,不做处理');
return
}
console.log('通过验证,开始跳转');
setTimeout(() => {
console.log('跳转到指定页面');
uni.$utils.navTo(url)
Api.report_push_act({
push_cid: uni.$store.state.userModule.pushCID || '',
push_id
})
}, 500)
}, false)
}
苍山暮色烟雨迟 (作者)
没有
2024-07-11 16:52