From a418b80c9d405e6f343cf6cce8d8ff6275df1291 Mon Sep 17 00:00:00 2001 From: tianyi <13521030702@163.com> Date: Mon, 22 Jun 2026 09:18:40 +0800 Subject: [PATCH] 1 --- App.vue | 144 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 101 insertions(+), 43 deletions(-) diff --git a/App.vue b/App.vue index 7c72da3..2778b6f 100644 --- a/App.vue +++ b/App.vue @@ -66,43 +66,43 @@ $t: '', userInfo: {}, registrationID: '', - printData: [], // 打印任务队列,按顺序存储待打印的通知数据 - isPrinting: false, // 标记当前是否正在打印,防止并发 + printData: [], // 打印任务队列,按顺序存储待打印的通知数据 + isPrinting: false, // 标记当前是否正在打印,防止并发 }, onLaunch: function() { let context = this; //这里是热更新的代码 // #ifdef APP-PLUS - plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) { - - // uni.request({ - // url: '', - // data: { - // version: widgetInfo.version, - // name: widgetInfo.name - // }, - // success: (result) => { - // var data = result.data; - // if (data.update && data.wgtUrl) { - // uni.downloadFile({ - // url: data.wgtUrl, - // success: (downloadResult) => { - // if (downloadResult.statusCode === 200) { - // plus.runtime.install(downloadResult.tempFilePath, { - // force: false - // }, function() { - // console.log('install success...'); - // plus.runtime.restart(); - // }, function(e) { - // console.error('install fail...'); - // }); - // } - // } - // }); - // } - // } - // }); - }); + plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) { + + // uni.request({ + // url: '', + // data: { + // version: widgetInfo.version, + // name: widgetInfo.name + // }, + // success: (result) => { + // var data = result.data; + // if (data.update && data.wgtUrl) { + // uni.downloadFile({ + // url: data.wgtUrl, + // success: (downloadResult) => { + // if (downloadResult.statusCode === 200) { + // plus.runtime.install(downloadResult.tempFilePath, { + // force: false + // }, function() { + // console.log('install success...'); + // plus.runtime.restart(); + // }, function(e) { + // console.error('install fail...'); + // }); + // } + // } + // }); + // } + // } + // }); + }); // #endif this.globalData._i18n = this.$i18n //这是原型链上的$i18n this.globalData.$t = function(str) { @@ -137,12 +137,23 @@ plus.runtime.setBadgeNumber(0); let notificationEventType = result.notificationEventType let woopId = result.extras && result.extras.dataType === 'woop' && result.extras.value; - - if(result.notificationEventType == 'notificationArrived'){ + //用户点击了通知消息 + if (result.notificationEventType === 'notificationOpened') { + console.log('用户点击了通知消息') + if (this.NB.isAndroidOrIOS() == 'iOS') { + this.handlePushClick(result.ios.inAppExtras); + } else { + this.handlePushClick(result.android.inAppExtras); + } + + } + if (result.notificationEventType == 'notificationArrived') { if (result.content.includes('订单出餐已超时')) { this.onPlayAudio(2) - } else if (result.content.includes('您有一笔配送订单无人接单')){ + } else if (result.content.includes('您有一笔配送订单无人接单')) { this.onPlayAudio(5) + } else if (result.content.includes('您有中转配送订单超时未送达中转点')) { + this.onPlayAudio(7) } else { if (result.content.includes('您有一笔新的订单')) { this.onPlayAudio(4) @@ -150,9 +161,9 @@ this.onPlayAudio(3) } else if (result.content.includes('您有一笔订单申请退款')) { this.onPlayAudio(1) - } else if(result.content.includes('您有一笔商家自配送订单,请立即处理')){ + } else if (result.content.includes('您有一笔商家自配送订单,请立即处理')) { this.onPlayAudio(6) - } + } // 将消息数据推入打印队列 this.globalData.printData.push(JSON.parse(result.android.inAppExtras)) // 若当前未在打印,则启动队列处理 @@ -161,9 +172,8 @@ } } } - - }); + }); jpushModule.isPushStopped(res => { // code 0已停止推送 1未停止推送 const { @@ -240,6 +250,52 @@ this.processPrintQueue() }) }, + // 统一处理推送点击逻辑 + handlePushClick(extras) { + console.log('消息内容',extras) + if (!extras) return; + + // 兼容处理:Android有时返回JSON字符串,iOS返回Object + let data = extras; + if (typeof data === 'string') { + try { + data = JSON.parse(data); + } catch (e) { + console.error('解析推送extras失败', e); + return; + } + } + + // 判断是否是订单详情推送 + + const targetUrl = `/pages/shop/orderDetail?id=${data.order_id}`; + + // 将跳转路径存入本地缓存(关键:用于冷启动时首页接管) + uni.setStorageSync('push_jump_url', targetUrl); + + // 尝试直接跳转(针对热启动) + const pages = getCurrentPages(); + if (pages.length > 0) { + // 延迟300ms,确保页面栈稳定 + setTimeout(() => { + this.executeJump(targetUrl); + }, 300); + } + }, + + // 执行跳转 + executeJump(url) { + uni.navigateTo({ + url: url, + fail: (err) => { + // 如果页面栈超过10层导致 navigateTo 失败,则降级使用 redirectTo + console.warn('navigateTo失败,尝试redirectTo', err); + uni.redirectTo({ + url: url + }); + } + }); + }, onPlayAudio(type) { var audio = null; audio = uni.getBackgroundAudioManager(); @@ -248,19 +304,21 @@ // #ifdef APP-PLUS if (type == 1) { //退款 audio.src = 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/cb24e35cfb1b48a58823633f23398d45.mp3'; - } else if (type == 2) { //超时 + } else if (type == 2) { //超时 audio.src = 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/4d20a1cbc92c42f4b70de1b9dacb7979.mp3'; } else if (type == 3) { //到店订单 audio.src = 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/3ced308cf72348a3adeb07d003ced5f3.mp3'; } else if (type == 4) { //新订单 audio.src = 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/c60ef3944e58461fbe7ce23ae38c70a2.mp3'; - } else if(type == 5){ //无人接单 + } else if (type == 5) { //无人接单 audio.src = 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/e41404ed7c964ec4a203f0a7404585af.mp3'; - } else if(type == 6){ //自配送 + } else if (type == 6) { //自配送 audio.src = 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/7050e7134dc24f56992fe405605d480e.mp3'; + } else if (type == 7) { //中转超时 + audio.src = 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/2fe04974ece245a79cd078dc7def773d.mp3'; } // #endif - + audio.play(); audio.onEnded(function(res) { audio = null;