From 00a7a61df86db969f2ba61c508d02ba4709ce3d4 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期五, 05 六月 2026 10:09:06 +0800
Subject: [PATCH] 改bug
---
app/App.vue | 131 +++++++++++++++++++++++++++++++------------
1 files changed, 95 insertions(+), 36 deletions(-)
diff --git a/app/App.vue b/app/App.vue
index faa3c9e..2973d26 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,9 +27,10 @@
}
},
onLaunch: function() {
+ uni.$on('locationPermissionGranted', this.handleLocationPermissionGranted)
+ uni.$on('loginSuccessStartLocationPolling', this.handleLoginSuccessStartLocationPolling)
this.initTTS()
this.initJPush()
- this.checkAndStartLocationPolling()
this.checkAppUpdate()
},
onShow: function() {
@@ -38,37 +42,75 @@
// this.stopLocationPolling()
},
onUnload() {
+ uni.$off('locationPermissionGranted', this.handleLocationPermissionGranted)
+ uni.$off('loginSuccessStartLocationPolling', this.handleLoginSuccessStartLocationPolling)
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()
+ },
+ 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 +122,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 +278,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 +312,7 @@
updateLocation() {
if (!this.token) return
var that = this;
- uni.getLocation({
+ getLocationWithNotice({
type: 'gcj02',
success: (res) => {
console.log('瀹氭椂鏇存柊浣嶇疆:', res.latitude, res.longitude)
@@ -274,7 +333,7 @@
fail: (err) => {
console.log('鑾峰彇浣嶇疆澶辫触:', err.errMsg)
}
- })
+ }).catch(() => {})
},
checkAppUpdate() {
@@ -331,4 +390,4 @@
uni-mp-share {
display: none !important;
}
-</style>
\ No newline at end of file
+</style>
--
Gitblit v1.9.3