From fa4c7baec36d58b4bdca66159ece743b5a45a9c8 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期四, 11 六月 2026 10:15:45 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
app/App.vue | 152 +++++++++++++++++++++++++++++++++++++-------------
1 files changed, 111 insertions(+), 41 deletions(-)
diff --git a/app/App.vue b/app/App.vue
index faa3c9e..609b777 100644
--- a/app/App.vue
+++ b/app/App.vue
@@ -1,12 +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,
- tts: null
+ tts: null,
+ ttsPlatform: '',
+ ttsVoice: null,
+ hasGrantedLocationPermission: false
}
},
computed: {
@@ -15,7 +19,6 @@
watch: {
token(newVal) {
if (newVal) {
- this.checkAndStartLocationPolling()
this.bindJPushAlias()
} else {
this.stopLocationPolling()
@@ -24,51 +27,101 @@
}
},
onLaunch: function() {
- this.initTTS()
- this.initJPush()
- this.checkAndStartLocationPolling()
- this.checkAppUpdate()
+ 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')
- // this.stopLocationPolling()
},
onUnload() {
+ uni.$off('locationPermissionGranted', this.handleLocationPermissionGranted)
+ uni.$off('loginSuccessStartLocationPolling', this.handleLoginSuccessStartLocationPolling)
+ uni.$off('privacyAgreed', this.handlePrivacyAgreed)
if (this.tts) {
- this.tts.stop()
- this.tts.shutdown()
+ 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() {
- if (uni.getSystemInfoSync().platform !== 'android') {
- console.log('浠呮敮鎸佸畨鍗�')
+ 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
}
- 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)
+ 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) {
@@ -80,8 +133,25 @@
}
try {
- // 瀹夊崜鍘熺敓鎾姤锛圦UEUE_FLUSH = 绔嬪嵆鎾姤锛屾墦鏂笂涓�鏉★級
- this.tts.speak(text, 0, null)
+ 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)
}
@@ -219,20 +289,20 @@
checkAndStartLocationPolling() {
if (!this.token) return
- uni.getLocation({
+ getLocationWithNotice({
type: 'gcj02',
success: (res) => {
console.log('鑾峰彇瀹氫綅鏉冮檺鎴愬姛锛屽紑濮嬪畾鏃舵洿鏂颁綅缃�')
this.startLocationPolling()
},
fail: (err) => {
- console.log('鑾峰彇瀹氫綅鏉冮檺澶辫触:', err.errMsg)
- uni.showToast({
- title: '闇�瑕佸畾浣嶆潈闄愭墠鑳芥洿鏂颁綅缃�',
- icon: 'none'
- })
+ // console.log('鑾峰彇瀹氫綅鏉冮檺澶辫触:', err.errMsg)
+ // uni.showToast({
+ // title: '闇�瑕佸畾浣嶆潈闄愭墠鑳芥洿鏂颁綅缃�',
+ // icon: 'none'
+ // })
}
- })
+ }).catch(() => {})
},
startLocationPolling() {
@@ -253,7 +323,7 @@
updateLocation() {
if (!this.token) return
var that = this;
- uni.getLocation({
+ getLocationWithNotice({
type: 'gcj02',
success: (res) => {
console.log('瀹氭椂鏇存柊浣嶇疆:', res.latitude, res.longitude)
@@ -274,7 +344,7 @@
fail: (err) => {
console.log('鑾峰彇浣嶇疆澶辫触:', err.errMsg)
}
- })
+ }).catch(() => {})
},
checkAppUpdate() {
@@ -331,4 +401,4 @@
uni-mp-share {
display: none !important;
}
-</style>
\ No newline at end of file
+</style>
--
Gitblit v1.9.3