From 3f9032e92fdd383bfefc87a0bec9b242e1223851 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期二, 09 六月 2026 17:08:44 +0800
Subject: [PATCH] 改bug
---
app/App.vue | 368 ++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 314 insertions(+), 54 deletions(-)
diff --git a/app/App.vue b/app/App.vue
index e4066ef..609b777 100644
--- a/app/App.vue
+++ b/app/App.vue
@@ -1,10 +1,16 @@
<script>
import { mapState } from 'vuex'
+ import md5 from 'js-md5';
+ import { getLocationWithNotice } from '@/utils/utils'
export default {
data() {
return {
locationTimer: null,
- jpushModule: null
+ jpushModule: null,
+ tts: null,
+ ttsPlatform: '',
+ ttsVoice: null,
+ hasGrantedLocationPermission: false
}
},
computed: {
@@ -13,7 +19,6 @@
watch: {
token(newVal) {
if (newVal) {
- this.startLocationPolling()
this.bindJPushAlias()
} else {
this.stopLocationPolling()
@@ -22,76 +27,255 @@
}
},
onLaunch: function() {
- this.initJPush()
- this.checkAndStartLocationPolling()
+ uni.$on('locationPermissionGranted', this.handleLocationPermissionGranted)
+ uni.$on('loginSuccessStartLocationPolling', this.handleLoginSuccessStartLocationPolling)
+ uni.$on('privacyAgreed', this.handlePrivacyAgreed)
+ // 妫�鏌ユ槸鍚﹀凡缁忓悓鎰忚繃闅愮鏀跨瓥锛屽鏋滄槸鍒欑洿鎺ュ垵濮嬪寲鏋佸厜鎺ㄩ��
+ console.log('login_privacy_policy_agreed', uni.getStorageSync('login_privacy_policy_agreed'))
+ if (uni.getStorageSync('login_privacy_policy_agreed')) {
+ // 鍒濆鍖栨瀬鍏夋帹閫�
+ this.initJPush()
+ // 鍒濆鍖栬闊虫挱鎶�
+ this.initTTS()
+ // 鑾峰彇鐗堟湰鍙�
+ this.checkAppUpdate()
+ }
},
onShow: function() {
console.log('App Show')
- this.checkAndStartLocationPolling()
},
onHide: function() {
console.log('App Hide')
+ },
+ onUnload() {
+ uni.$off('locationPermissionGranted', this.handleLocationPermissionGranted)
+ uni.$off('loginSuccessStartLocationPolling', this.handleLoginSuccessStartLocationPolling)
+ uni.$off('privacyAgreed', this.handlePrivacyAgreed)
+ if (this.tts) {
+ try {
+ if (this.ttsPlatform === 'android') {
+ this.tts.stop()
+ this.tts.shutdown()
+ } else if (this.ttsPlatform === 'ios') {
+ this.tts.stopSpeakingAtBoundary(0)
+ }
+ } catch (e) {
+ console.log('閲婃斁璇煶鎾姤澶辫触', e)
+ }
+ }
this.stopLocationPolling()
},
methods: {
+ handleLoginSuccessStartLocationPolling() {
+ if (this.locationTimer) return
+ if (this.hasGrantedLocationPermission) {
+ console.log('鐧诲綍鎴愬姛鍚庡紑濮嬩綅缃疆璇笂鎶�')
+ this.startLocationPolling()
+ return
+ }
+ this.checkAndStartLocationPolling()
+ },
+ handlePrivacyAgreed() {
+ console.log('闅愮鏀跨瓥宸插悓鎰忥紝鍒濆鍖栨瀬鍏夋帹閫�')
+ this.initJPush()
+ },
+ handleLocationPermissionGranted() {
+ this.hasGrantedLocationPermission = true
+ if (!this.token || this.locationTimer) return
+ console.log('瀹氫綅鎺堟潈鎴愬姛锛屽紑濮嬩綅缃疆璇笂鎶�')
+ this.startLocationPolling()
+ },
+ initTTS() {
+ const platform = uni.getSystemInfoSync().platform
+ this.ttsPlatform = platform
+
+ if (platform === 'android') {
+ try {
+ const TextToSpeech = plus.android.importClass('android.speech.tts.TextToSpeech')
+ const Locale = plus.android.importClass('java.util.Locale')
+
+ this.tts = new TextToSpeech(plus.android.runtimeMainActivity(), {
+ onInit: (status) => {
+ if (status == 0) {
+ this.tts.setLanguage(Locale.CHINA)
+ console.log('瀹夊崜璇煶鍒濆鍖栨垚鍔�')
+ }
+ }
+ })
+ } catch (e) {
+ console.log('瀹夊崜璇煶鍒濆鍖栧け璐�', e)
+ }
+ return
+ }
+
+ if (platform === 'ios') {
+ try {
+ const AVSpeechSynthesizer = plus.ios.importClass('AVSpeechSynthesizer')
+ const AVSpeechSynthesisVoice = plus.ios.importClass('AVSpeechSynthesisVoice')
+ this.tts = new AVSpeechSynthesizer()
+ this.ttsVoice = AVSpeechSynthesisVoice.voiceWithLanguage('zh-CN')
+ console.log('iOS璇煶鍒濆鍖栨垚鍔�')
+ } catch (e) {
+ console.log('iOS璇煶鍒濆鍖栧け璐�', e)
+ }
+ return
+ }
+
+ console.log('褰撳墠骞冲彴鏆備笉鏀寔璇煶鎾姤')
+ },
+ speak(text) {
+ if (!this.tts) {
+ uni.showToast({
+ title: '璇煶鏈噯澶囧ソ',
+ icon: 'none'
+ })
+ return
+ }
+
+ try {
+ if (this.ttsPlatform === 'android') {
+ this.tts.speak(text, 0, null)
+ return
+ }
+
+ if (this.ttsPlatform === 'ios') {
+ const content = String(text || '').trim()
+ if (!content) return
+ const AVSpeechUtterance = plus.ios.importClass('AVSpeechUtterance')
+ const utterance = AVSpeechUtterance.speechUtteranceWithString(content)
+ if (this.ttsVoice) {
+ utterance.setVoice(this.ttsVoice)
+ }
+ utterance.setRate(0.5)
+ utterance.setVolume(1)
+ utterance.setPitchMultiplier(1)
+ this.tts.stopSpeakingAtBoundary(0)
+ this.tts.speakUtterance(utterance)
+ }
+ } catch (err) {
+ console.log('鎾姤澶辫触', err)
+ }
+ },
initJPush() {
- const jpushModule = uni.requireNativePlugin('JPush')
+ console.log('寮�濮嬪垵濮嬪寲鏋佸厜鎺ㄩ��...')
+ // #ifdef APP-PLUS
+ let jpushModule = null
+ try {
+ jpushModule = uni.requireNativePlugin('JG-JPush')
+ } catch (e) {
+ console.error('鍔犺浇鏋佸厜鎺ㄩ�佹彃浠跺け璐�:', e)
+ return
+ }
if (!jpushModule) {
- console.log('鏋佸厜鎺ㄩ�佹彃浠舵湭鎵惧埌锛岃鍏堝畨瑁呮彃浠�')
+ console.error('鏋佸厜鎺ㄩ�佹彃浠舵湭鎵惧埌')
return
}
this.jpushModule = jpushModule
+ console.log('鏋佸厜鎺ㄩ�佹彃浠跺姞杞芥垚鍔燂紝妯″潡:', typeof jpushModule)
+ console.log('妯″潡鏂规硶:', Object.keys(jpushModule))
- jpushModule.init()
- console.log('鏋佸厜鎺ㄩ�佸垵濮嬪寲鎴愬姛')
+ if (typeof jpushModule.initJPushService === 'function') {
+ jpushModule.initJPushService()
+ console.log('鏋佸厜鎺ㄩ�乮nitJPushService璋冪敤鎴愬姛')
+ } else {
+ console.error('jpushModule.initJPushService 涓嶆槸鍑芥暟锛屽綋鍓嶆柟娉�:', typeof jpushModule.initJPushService)
+ return
+ }
- jpushModule.setLoggerEnable(true)
+ if (typeof jpushModule.setLoggerEnable === 'function') {
+ jpushModule.setLoggerEnable(true)
+ }
+ console.log('鏋佸厜鎺ㄩ�佸垵濮嬪寲瀹屾垚锛岃缃洃鍚櫒...')
+ this.setupJPushListeners()
+ this.getRegistrationID()
+ // #endif
+ },
- jpushModule.addReceiveNotificationListener((result) => {
+ setupJPushListeners() {
+ var that = this
+ if (!this.jpushModule) return
+
+ // 鐩戝惉杩炴帴鐘舵��
+ this.jpushModule.addConnectEventListener((result) => {
+ console.log('鏋佸厜杩炴帴鐘舵��:', result.connectEnable)
+ })
+
+ // 鐩戝惉閫氱煡
+ this.jpushModule.addNotificationListener((result) => {
console.log('鏀跺埌閫氱煡:', JSON.stringify(result))
- const extras = result.extras || {}
- if (extras.type === 'order') {
- uni.$emit('jpush_order_notification', extras)
+ that.speak(result.content || '')
+ const notificationEventType = result.notificationEventType
+ // notificationOpened = 鐐瑰嚮閫氱煡
+ if (notificationEventType === 'notificationOpened') {
+ console.log('閫氱煡琚偣鍑�', result.extras)
+ const extras = result.extras ? result.extras : {}
+ if (extras.type === 'new_order' && extras.orderId) {
+ uni.navigateTo({
+ url: '/pages/order-detail/order-detail?id=' + extras.orderId
+ })
+ } else {
+ uni.switchTab({
+ url: '/pages/index/index'
+ })
+ }
}
})
+ },
- 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)
+ getRegistrationID() {
+ if (!this.jpushModule) {
+ console.log('JPush妯″潡鏈垵濮嬪寲锛屾棤娉曡幏鍙朢egistrationID')
+ return
+ }
+ console.log('寮�濮嬭幏鍙朖Push RegistrationID...')
+ this.jpushModule.getRegistrationID((result) => {
+ console.log('JPush getRegistrationID result:', JSON.stringify(result))
+ if (result && result.registerID) {
+ console.log('JPush RegistrationID鑾峰彇鎴愬姛:', result.registerID)
+ uni.setStorageSync('jpush_registration_id', result.registerID)
+ } else {
+ console.log('JPush RegistrationID鑾峰彇澶辫触锛屽皾璇曢噸鏂拌幏鍙�')
+ setTimeout(() => {
+ this.getRegistrationID()
+ }, 2000)
}
})
},
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))
- })
+ if (!this.token) return
+ if (!this.jpushModule) {
+ console.log('JPush鏈垵濮嬪寲锛屽欢杩熻缃埆鍚�')
+ setTimeout(() => {
+ this.bindJPushAlias()
+ }, 1000)
+ return
}
+ // 浼樺厛浠巗tore鑾峰彇锛屽鏋滀负绌哄垯浠庢湰鍦板瓨鍌ㄨ幏鍙�
+ let telephone = this.$store.state.userInfo?.telephone || ''
+ if (!telephone) {
+ telephone = uni.getStorageSync('userInfo')?.telephone || ''
+ }
+ if (!telephone) {
+ console.log('鐢ㄦ埛鎵嬫満鍙蜂负绌猴紝寤惰繜鑾峰彇...')
+ setTimeout(() => {
+ this.bindJPushAlias()
+ }, 2000)
+ return
+ }
+ const alias = md5(telephone)
+ console.log('璁剧疆鏋佸厜鍒悕:', alias)
+ this.jpushModule.setAlias({
+ alias: alias,
+ sequence: Date.now()
+ }, (result) => {
+ console.log('璁剧疆鍒悕缁撴灉:', JSON.stringify(result))
+ if (result && (result.code === 0 || result.errCode === 0)) {
+ console.log('璁剧疆鏋佸厜鍒悕鎴愬姛')
+ } else {
+ console.log('璁剧疆鏋佸厜鍒悕澶辫触')
+ }
+ })
},
deleteJPushAlias() {
@@ -99,14 +283,26 @@
this.jpushModule.deleteAlias({
sequence: Date.now()
}, (result) => {
- console.log('鍒犻櫎鏋佸厜鍒悕鎴愬姛:', JSON.stringify(result))
+ console.log('鍒犻櫎鏋佸厜鍒悕:', JSON.stringify(result))
})
},
checkAndStartLocationPolling() {
- if (this.token) {
- this.startLocationPolling()
- }
+ if (!this.token) return
+ getLocationWithNotice({
+ type: 'gcj02',
+ success: (res) => {
+ console.log('鑾峰彇瀹氫綅鏉冮檺鎴愬姛锛屽紑濮嬪畾鏃舵洿鏂颁綅缃�')
+ this.startLocationPolling()
+ },
+ fail: (err) => {
+ // console.log('鑾峰彇瀹氫綅鏉冮檺澶辫触:', err.errMsg)
+ // uni.showToast({
+ // title: '闇�瑕佸畾浣嶆潈闄愭墠鑳芥洿鏂颁綅缃�',
+ // icon: 'none'
+ // })
+ }
+ }).catch(() => {})
},
startLocationPolling() {
@@ -125,13 +321,72 @@
},
updateLocation() {
- uni.getLocation({
+ if (!this.token) return
+ var that = this;
+ getLocationWithNotice({
type: 'gcj02',
success: (res) => {
- this.$u.api.updateLocation({
+ console.log('瀹氭椂鏇存柊浣嶇疆:', res.latitude, res.longitude)
+ that.$store.commit('setLocation', { latitude: res.latitude, longitude: res.longitude })
+ that.$u.api.updateLocation({
latitude: res.latitude,
longitude: res.longitude
+ }).then(res => {
+ if (res.code === 200) {
+ console.log('鏇存柊浣嶇疆鎴愬姛')
+ } else {
+ console.log('鏇存柊浣嶇疆澶辫触')
+ }
+ }).catch(err => {
+ console.log('鏇存柊浣嶇疆璇锋眰澶辫触:', err)
})
+ },
+ fail: (err) => {
+ console.log('鑾峰彇浣嶇疆澶辫触:', err.errMsg)
+ }
+ }).catch(() => {})
+ },
+
+ checkAppUpdate() {
+ plus.runtime.getProperty(plus.runtime.appid, (inf) => {
+ const currentVersion = inf.versionCode
+ this.$u.api.getApiVersion({ type: 0 }).then(res => {
+ if (res.code === 200 && res.data) {
+ const latestVersion = res.data.versionNum
+ if (latestVersion > currentVersion) {
+ if (res.data.isForce === 1) {
+ this.showForceUpdateDialog(res.data.fileUrl, res.data.versionNum)
+ } else {
+ this.showOptionalUpdateDialog(res.data.fileUrl, res.data.versionNum)
+ }
+ }
+ }
+ })
+ })
+ },
+
+ showForceUpdateDialog(fileUrl, version) {
+ uni.showModal({
+ title: '鐗堟湰鏇存柊',
+ content: `妫�娴嬪埌鏂扮増鏈�${version}锛岃鏇存柊鍚庣户缁娇鐢╜,
+ showCancel: false,
+ confirmText: '绔嬪嵆鏇存柊',
+ success: () => {
+ plus.runtime.openURL(fileUrl)
+ }
+ })
+ },
+
+ showOptionalUpdateDialog(fileUrl, version) {
+ uni.showModal({
+ title: '鐗堟湰鏇存柊',
+ content: `妫�娴嬪埌鏂扮増鏈�${version}锛屾槸鍚︽洿鏂帮紵`,
+ confirmText: '鏇存柊',
+ cancelText: '绋嶅悗',
+ success: (res) => {
+ if (res.confirm) {
+ plus.runtime.openURL(fileUrl)
+ }
}
})
}
@@ -139,6 +394,11 @@
}
</script>
-<style lang="scss">
- @import "uview-ui/index.scss";
-</style>
\ No newline at end of file
+<style>
+ page {
+ background-color: #f6f8fc;
+ }
+ uni-mp-share {
+ display: none !important;
+ }
+</style>
--
Gitblit v1.9.3