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 | 321 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 317 insertions(+), 4 deletions(-)
diff --git a/app/App.vue b/app/App.vue
index a3c7e0c..faa3c9e 100644
--- a/app/App.vue
+++ b/app/App.vue
@@ -1,21 +1,334 @@
<script>
import { mapState } from 'vuex'
+ import md5 from 'js-md5';
export default {
+ data() {
+ return {
+ locationTimer: null,
+ jpushModule: null,
+ tts: null
+ }
+ },
computed: {
- ...mapState(['userInfo'])
+ ...mapState(['userInfo', 'token'])
+ },
+ watch: {
+ token(newVal) {
+ if (newVal) {
+ this.checkAndStartLocationPolling()
+ this.bindJPushAlias()
+ } else {
+ this.stopLocationPolling()
+ this.deleteJPushAlias()
+ }
+ }
},
onLaunch: function() {
-
+ this.initTTS()
+ this.initJPush()
+ this.checkAndStartLocationPolling()
+ this.checkAppUpdate()
},
onShow: function() {
console.log('App Show')
+ // 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() {
+ console.log('寮�濮嬪垵濮嬪寲鏋佸厜鎺ㄩ��...')
+ // #ifdef APP-PLUS
+ let jpushModule = null
+ try {
+ jpushModule = uni.requireNativePlugin('JG-JPush')
+ } catch (e) {
+ console.error('鍔犺浇鏋佸厜鎺ㄩ�佹彃浠跺け璐�:', e)
+ return
+ }
+ if (!jpushModule) {
+ console.error('鏋佸厜鎺ㄩ�佹彃浠舵湭鎵惧埌')
+ return
+ }
+ this.jpushModule = jpushModule
+ console.log('鏋佸厜鎺ㄩ�佹彃浠跺姞杞芥垚鍔燂紝妯″潡:', typeof jpushModule)
+ console.log('妯″潡鏂规硶:', Object.keys(jpushModule))
+
+ if (typeof jpushModule.initJPushService === 'function') {
+ jpushModule.initJPushService()
+ console.log('鏋佸厜鎺ㄩ�乮nitJPushService璋冪敤鎴愬姛')
+ } else {
+ console.error('jpushModule.initJPushService 涓嶆槸鍑芥暟锛屽綋鍓嶆柟娉�:', typeof jpushModule.initJPushService)
+ return
+ }
+
+ if (typeof jpushModule.setLoggerEnable === 'function') {
+ jpushModule.setLoggerEnable(true)
+ }
+ console.log('鏋佸厜鎺ㄩ�佸垵濮嬪寲瀹屾垚锛岃缃洃鍚櫒...')
+ this.setupJPushListeners()
+ this.getRegistrationID()
+ // #endif
+ },
+
+ 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 {
+ uni.switchTab({
+ url: '/pages/index/index'
+ })
+ }
+ }
+ })
+ },
+
+ 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.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() {
+ if (!this.jpushModule) return
+ this.jpushModule.deleteAlias({
+ sequence: Date.now()
+ }, (result) => {
+ console.log('鍒犻櫎鏋佸厜鍒悕:', JSON.stringify(result))
+ })
+ },
+
+ checkAndStartLocationPolling() {
+ 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() {
+ this.stopLocationPolling()
+ this.updateLocation()
+ this.locationTimer = setInterval(() => {
+ this.updateLocation()
+ }, 60000)
+ },
+
+ stopLocationPolling() {
+ if (this.locationTimer) {
+ clearInterval(this.locationTimer)
+ this.locationTimer = null
+ }
+ },
+
+ updateLocation() {
+ if (!this.token) return
+ var that = this;
+ uni.getLocation({
+ type: 'gcj02',
+ success: (res) => {
+ 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)
+ }
+ }
+ })
+ }
}
}
</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