From b7d451c91ec40bee70f23b1e2cf6a8797643faef Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期六, 25 四月 2026 15:18:58 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
app/App.vue | 128 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 126 insertions(+), 2 deletions(-)
diff --git a/app/App.vue b/app/App.vue
index a3c7e0c..12bc3d4 100644
--- a/app/App.vue
+++ b/app/App.vue
@@ -1,17 +1,141 @@
<script>
import { mapState } from 'vuex'
export default {
+ data() {
+ return {
+ locationTimer: null,
+ jpushModule: null
+ }
+ },
computed: {
- ...mapState(['userInfo'])
+ ...mapState(['userInfo', 'token'])
+ },
+ watch: {
+ token(newVal) {
+ if (newVal) {
+ this.startLocationPolling()
+ this.bindJPushAlias()
+ } else {
+ this.stopLocationPolling()
+ this.deleteJPushAlias()
+ }
+ }
},
onLaunch: function() {
-
+ this.initJPush()
+ this.checkAndStartLocationPolling()
},
onShow: function() {
console.log('App Show')
+ this.checkAndStartLocationPolling()
},
onHide: function() {
console.log('App Hide')
+ this.stopLocationPolling()
+ },
+ methods: {
+ initJPush() {
+ const jpushModule = uni.requireNativePlugin('JPush')
+ if (!jpushModule) {
+ console.log('鏋佸厜鎺ㄩ�佹彃浠舵湭鎵惧埌锛岃鍏堝畨瑁呮彃浠�')
+ return
+ }
+ this.jpushModule = jpushModule
+
+ jpushModule.init()
+ console.log('鏋佸厜鎺ㄩ�佸垵濮嬪寲鎴愬姛')
+
+ jpushModule.setLoggerEnable(true)
+
+ jpushModule.addReceiveNotificationListener((result) => {
+ console.log('鏀跺埌閫氱煡:', JSON.stringify(result))
+ const extras = result.extras || {}
+ if (extras.type === 'order') {
+ uni.$emit('jpush_order_notification', extras)
+ }
+ })
+
+ jpushModule.addReceiveOpenNotificationListener((result) => {
+ console.log('鐐瑰嚮閫氱煡:', JSON.stringify(result))
+ const extras = result.extras || {}
+ if (extras.type === 'order') {
+ uni.navigateTo({
+ url: '/pages/order-detail/order-detail?id=' + extras.orderId
+ })
+ } else if (extras.type === 'message') {
+ uni.switchTab({
+ url: '/pages/message/message'
+ })
+ }
+ })
+
+ jpushModule.addReceiveMessageListener((result) => {
+ console.log('鏀跺埌閫忎紶娑堟伅:', JSON.stringify(result))
+ })
+
+ jpushModule.getRegistrationID((res) => {
+ console.log('JPush RegistrationID:', res)
+ if (res && res.registerID) {
+ uni.setStorageSync('jpush_registration_id', res.registerID)
+ }
+ })
+ },
+
+ bindJPushAlias() {
+ if (!this.jpushModule || !this.token) return
+ const userId = this.$store.state.userInfo?.id || ''
+ if (userId) {
+ this.jpushModule.setAlias({
+ alias: String(userId),
+ sequence: Date.now()
+ }, (result) => {
+ console.log('璁剧疆鏋佸厜鍒悕鎴愬姛:', JSON.stringify(result))
+ })
+ }
+ },
+
+ deleteJPushAlias() {
+ if (!this.jpushModule) return
+ this.jpushModule.deleteAlias({
+ sequence: Date.now()
+ }, (result) => {
+ console.log('鍒犻櫎鏋佸厜鍒悕鎴愬姛:', JSON.stringify(result))
+ })
+ },
+
+ checkAndStartLocationPolling() {
+ if (this.token) {
+ this.startLocationPolling()
+ }
+ },
+
+ startLocationPolling() {
+ this.stopLocationPolling()
+ this.updateLocation()
+ this.locationTimer = setInterval(() => {
+ this.updateLocation()
+ }, 60000)
+ },
+
+ stopLocationPolling() {
+ if (this.locationTimer) {
+ clearInterval(this.locationTimer)
+ this.locationTimer = null
+ }
+ },
+
+ updateLocation() {
+ uni.getLocation({
+ type: 'gcj02',
+ success: (res) => {
+ console.log(res)
+ this.$u.api.updateLocation({
+ latitude: res.latitude,
+ longitude: res.longitude
+ })
+ }
+ })
+ }
}
}
</script>
--
Gitblit v1.9.3