From 7a0b33a5f2e0ba589bf35a1b8d896700a21f94a4 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期四, 30 四月 2026 16:00:55 +0800
Subject: [PATCH] 支付宝支付dddadd

---
 app/App.vue |  422 +++++++++++++++++++++++++++-------------------------
 1 files changed, 220 insertions(+), 202 deletions(-)

diff --git a/app/App.vue b/app/App.vue
index 20b66e5..9a731a9 100644
--- a/app/App.vue
+++ b/app/App.vue
@@ -1,15 +1,12 @@
 <script>
 	import { mapState } from 'vuex'
+	import md5 from 'js-md5';
 	export default {
 		data() {
 			return {
 				locationTimer: null,
 				jpushModule: null,
-				jpushListenersBound: false,
-				jpushRegistrationTimer: null,
-				jpushAliasRetryTimer: null,
-				jpushRegistrationRetryCount: 0,
-				jpushAliasRetryCount: 0
+				tts: null
 			}
 		},
 		computed: {
@@ -18,223 +15,224 @@
 		watch: {
 			token(newVal) {
 				if (newVal) {
-					this.startLocationPolling()
-					this.bindJPushAlias(true)
+					this.checkAndStartLocationPolling()
+					this.bindJPushAlias()
 				} else {
 					this.stopLocationPolling()
-					this.clearJPushRetryTimers()
 					this.deleteJPushAlias()
 				}
 			}
 		},
 		onLaunch: function() {
+			this.initTTS()
 			this.initJPush()
-			this.ensureJPushAliasOnLaunch()
 			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: {
-			initJPush() {
-				// #ifdef APP-PLUS
-				if (this.jpushModule) {
-					this.retryGetRegistrationID()
+			initTTS() {
+				if (uni.getSystemInfoSync().platform !== 'android') {
+					console.log('浠呮敮鎸佸畨鍗�')
 					return
 				}
 
-				const jpushModule = uni.requireNativePlugin('JG-JPush')
+				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() {
+				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))
 
-				try {
-					jpushModule.setLoggerEnable(false)
-					jpushModule.init()
-				} catch (error) {
-					console.log('鏋佸厜鎺ㄩ�佸垵濮嬪寲澶辫触:', error)
+				if (typeof jpushModule.initJPushService === 'function') {
+					jpushModule.initJPushService()
+					console.log('鏋佸厜鎺ㄩ�乮nitJPushService璋冪敤鎴愬姛')
+				} else {
+					console.error('jpushModule.initJPushService 涓嶆槸鍑芥暟锛屽綋鍓嶆柟娉�:', typeof jpushModule.initJPushService)
 					return
 				}
-				console.log('鏋佸厜鎺ㄩ�佸垵濮嬪寲鎴愬姛')
 
-				if (!this.jpushListenersBound) {
-					jpushModule.addReceiveNotificationListener((result) => {
-						console.log('鏀跺埌閫氱煡:', JSON.stringify(result))
-						const extras = this.normalizeJPushExtras(result && result.extras)
-						if (extras.type === 'order') {
-							uni.$emit('jpush_order_notification', extras)
-						}
-					})
+				if (typeof jpushModule.setLoggerEnable === 'function') {
+					jpushModule.setLoggerEnable(true)
+				}
+				console.log('鏋佸厜鎺ㄩ�佸垵濮嬪寲瀹屾垚锛岃缃洃鍚櫒...')
+				this.setupJPushListeners()
+				this.getRegistrationID()
+				// #endif
+			},
 
-					jpushModule.addReceiveOpenNotificationListener((result) => {
-						console.log('鐐瑰嚮閫氱煡:', JSON.stringify(result))
-						const extras = this.normalizeJPushExtras(result && result.extras)
-						if (extras.type === 'order' && extras.orderId) {
+			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))
+					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 if (extras.type === 'message') {
+						} else {
 							uni.switchTab({
-								url: '/pages/message/message'
+								url: '/pages/index/index'
 							})
 						}
-					})
-
-					jpushModule.addReceiveMessageListener((result) => {
-						console.log('鏀跺埌閫忎紶娑堟伅:', JSON.stringify(result))
-					})
-
-					this.jpushListenersBound = true
-				}
-
-				this.retryGetRegistrationID()
-				if (this.token) {
-					this.bindJPushAlias(true)
-				}
-				// #endif
-			},
-
-			ensureJPushAliasOnLaunch() {
-				// #ifdef APP-PLUS
-				if (this.token) {
-					this.bindJPushAlias(true)
-				}
-				// #endif
-			},
-
-			clearJPushRetryTimers() {
-				if (this.jpushRegistrationTimer) {
-					clearTimeout(this.jpushRegistrationTimer)
-					this.jpushRegistrationTimer = null
-				}
-				if (this.jpushAliasRetryTimer) {
-					clearTimeout(this.jpushAliasRetryTimer)
-					this.jpushAliasRetryTimer = null
-				}
-			},
-
-			normalizeJPushExtras(extras) {
-				if (!extras) return {}
-				if (typeof extras === 'string') {
-					try {
-						return JSON.parse(extras)
-					} catch (error) {
-						return {}
 					}
-				}
-				return extras
-			},
-
-			isJPushActionSuccess(result) {
-				if (!result) return false
-				const successCodes = [0, '0']
-				return successCodes.includes(result.code) || successCodes.includes(result.errCode)
-			},
-
-			retryGetRegistrationID(forceRetry = false) {
-				// #ifdef APP-PLUS
-				if (!this.jpushModule) return
-
-				if (forceRetry) {
-					this.jpushRegistrationRetryCount = 0
-				}
-
-				if (this.jpushRegistrationTimer) {
-					clearTimeout(this.jpushRegistrationTimer)
-					this.jpushRegistrationTimer = null
-				}
-
-				this.jpushModule.getRegistrationID((res) => {
-					console.log('JPush RegistrationID:', res)
-					if (res && res.registerID) {
-						uni.setStorageSync('jpush_registration_id', res.registerID)
-						this.jpushRegistrationRetryCount = 0
-						return
-					}
-
-					if (this.jpushRegistrationRetryCount >= 5) {
-						console.log('澶氭鑾峰彇 RegistrationID 澶辫触锛屽仠姝㈤噸璇�')
-						return
-					}
-
-					this.jpushRegistrationRetryCount += 1
-					this.jpushRegistrationTimer = setTimeout(() => {
-						this.retryGetRegistrationID()
-					}, 1500)
 				})
-				// #endif
 			},
 
-			bindJPushAlias(forceRetry = false) {
-				// #ifdef APP-PLUS
-				if (!this.token) return
+			getRegistrationID() {
 				if (!this.jpushModule) {
-					this.initJPush()
+					console.log('JPush妯″潡鏈垵濮嬪寲锛屾棤娉曡幏鍙朢egistrationID')
 					return
 				}
-				const userId = this.$store.state.userInfo?.id || ''
-				if (!userId) return
-
-				if (forceRetry) {
-					this.jpushAliasRetryCount = 0
-				}
-
-				if (this.jpushAliasRetryTimer) {
-					clearTimeout(this.jpushAliasRetryTimer)
-					this.jpushAliasRetryTimer = null
-				}
-
-				this.jpushModule.setAlias({
-					alias: String(userId),
-					sequence: Date.now()
-				}, (result) => {
-					if (this.isJPushActionSuccess(result)) {
-						console.log('璁剧疆鏋佸厜鍒悕鎴愬姛:', JSON.stringify(result))
-						this.jpushAliasRetryCount = 0
-						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)
 					}
+				})
+			},
 
-					console.log('璁剧疆鏋佸厜鍒悕澶辫触:', JSON.stringify(result))
-					if (this.jpushAliasRetryCount >= 3) {
-						return
-					}
-
-					this.jpushAliasRetryCount += 1
-					this.jpushAliasRetryTimer = setTimeout(() => {
+			bindJPushAlias() {
+				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('璁剧疆鏋佸厜鍒悕澶辫触')
+					}
 				})
-				// #endif
 			},
 
 			deleteJPushAlias() {
-				// #ifdef APP-PLUS
 				if (!this.jpushModule) return
-				this.clearJPushRetryTimers()
 				this.jpushModule.deleteAlias({
 					sequence: Date.now()
 				}, (result) => {
-					if (this.isJPushActionSuccess(result)) {
-						console.log('鍒犻櫎鏋佸厜鍒悕鎴愬姛:', JSON.stringify(result))
-					} else {
-						console.log('鍒犻櫎鏋佸厜鍒悕澶辫触:', JSON.stringify(result))
-					}
+					console.log('鍒犻櫎鏋佸厜鍒悕:', JSON.stringify(result))
 				})
-				// #endif
 			},
 
 			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() {
@@ -253,63 +251,83 @@
 			},
 
 			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.$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)
 					}
 				})
-			},
-
-			compareVersion(localVersion, serverVersion) {
-				const v1 = localVersion.split('.')
-				const v2 = serverVersion.split('.')
-				for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
-					const n1 = parseInt(v1[i] || 0)
-					const n2 = parseInt(v2[i] || 0)
-					if (n1 < n2) return -1
-					if (n1 > n2) return 1
-				}
-				return 0
 			},
 
 			checkAppUpdate() {
-				// #ifdef APP-PLUS
-				this.$u.api.getApiVersion({ type: 0 }).then(res => {
-					if (res.code === 200 && res.data) {
-						const localVersionCode = plus.runtime.versionCode
-						const serverVersionCode = res.data.versionCode
-						if (serverVersionCode && localVersionCode < serverVersionCode) {
-							const isForce = res.data.isForce === 1
-							uni.showModal({
-								title: '鍙戠幇鏂扮増鏈�',
-								content: res.data.versionInfo || '鏈夋柊鐗堟湰鍙敤锛屾槸鍚︾珛鍗虫洿鏂帮紵',
-								showCancel: !isForce,
-								cancelText: isForce ? '' : '鏆備笉鏇存柊',
-								confirmText: '绔嬪嵆鏇存柊',
-								success: (modalRes) => {
-									if (modalRes.confirm) {
-										if (res.data.fileUrl) {
-											plus.runtime.openURL(res.data.fileUrl)
-										}
-									}
-									if (isForce && modalRes.cancel) {
-										this.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)
 						}
 					}
 				})
-				// #endif
 			}
 		}
 	}
 </script>
 
-<style lang="scss">
-	@import "uview-ui/index.scss"; 
-</style>
+<style>
+	page {
+		background-color: #f6f8fc;
+	}
+	uni-mp-share {
+		display: none !important;
+	}
+</style>
\ No newline at end of file

--
Gitblit v1.9.3