From 8a899e63502939dbf034b90ba46741e0faa9023c Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期五, 08 五月 2026 18:49:32 +0800
Subject: [PATCH] 管理端bug修改

---
 app/App.vue |  290 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 240 insertions(+), 50 deletions(-)

diff --git a/app/App.vue b/app/App.vue
index e4066ef..faa3c9e 100644
--- a/app/App.vue
+++ b/app/App.vue
@@ -1,10 +1,12 @@
 <script>
 	import { mapState } from 'vuex'
+	import md5 from 'js-md5';
 	export default {
 		data() {
 			return {
 				locationTimer: null,
-				jpushModule: null
+				jpushModule: null,
+				tts: null
 			}
 		},
 		computed: {
@@ -13,7 +15,7 @@
 		watch: {
 			token(newVal) {
 				if (newVal) {
-					this.startLocationPolling()
+					this.checkAndStartLocationPolling()
 					this.bindJPushAlias()
 				} else {
 					this.stopLocationPolling()
@@ -22,76 +24,188 @@
 			}
 		},
 		onLaunch: function() {
+			this.initTTS()
 			this.initJPush()
 			this.checkAndStartLocationPolling()
+			this.checkAppUpdate()
 		},
 		onShow: function() {
 			console.log('App Show')
-			this.checkAndStartLocationPolling()
+			// this.checkAndStartLocationPolling()
 		},
 		onHide: function() {
 			console.log('App Hide')
+			// this.stopLocationPolling()
+		},
+		onUnload() {
+			if (this.tts) {
+				this.tts.stop()
+				this.tts.shutdown()
+			}
 			this.stopLocationPolling()
 		},
 		methods: {
+			initTTS() {
+				if (uni.getSystemInfoSync().platform !== 'android') {
+					console.log('浠呮敮鎸佸畨鍗�')
+					return
+				}
+
+				try {
+					// 瀵煎叆瀹夊崜鍘熺敓绫�
+					const TextToSpeech = plus.android.importClass('android.speech.tts.TextToSpeech')
+					const Locale = plus.android.importClass('java.util.Locale')
+
+					// 鍒涘缓TTS
+					this.tts = new TextToSpeech(plus.android.runtimeMainActivity(), {
+						onInit: (status) => {
+							if (status == 0) {
+								// 璁剧疆涓枃
+								this.tts.setLanguage(Locale.CHINA)
+								console.log('璇煶鍒濆鍖栨垚鍔�')
+							}
+						}
+					})
+				} catch (e) {
+					console.log('鍒濆鍖栧け璐�', e)
+				}
+			},
+			speak(text) {
+				if (!this.tts) {
+					uni.showToast({
+						title: '璇煶鏈噯澶囧ソ',
+						icon: 'none'
+					})
+					return
+				}
+
+				try {
+					// 瀹夊崜鍘熺敓鎾姤锛圦UEUE_FLUSH = 绔嬪嵆鎾姤锛屾墦鏂笂涓�鏉★級
+					this.tts.speak(text, 0, null)
+				} 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 +213,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
+				uni.getLocation({
+					type: 'gcj02',
+					success: (res) => {
+						console.log('鑾峰彇瀹氫綅鏉冮檺鎴愬姛锛屽紑濮嬪畾鏃舵洿鏂颁綅缃�')
+						this.startLocationPolling()
+					},
+					fail: (err) => {
+						console.log('鑾峰彇瀹氫綅鏉冮檺澶辫触:', err.errMsg)
+						uni.showToast({
+							title: '闇�瑕佸畾浣嶆潈闄愭墠鑳芥洿鏂颁綅缃�',
+							icon: 'none'
+						})
+					}
+				})
 			},
 
 			startLocationPolling() {
@@ -125,13 +251,72 @@
 			},
 
 			updateLocation() {
+				if (!this.token) return
+				var that = this;
 				uni.getLocation({
 					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)
+					}
+				})
+			},
+
+			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 +324,11 @@
 	}
 </script>
 
-<style lang="scss">
-	@import "uview-ui/index.scss"; 
+<style>
+	page {
+		background-color: #f6f8fc;
+	}
+	uni-mp-share {
+		display: none !important;
+	}
 </style>
\ No newline at end of file

--
Gitblit v1.9.3