wx-starlock/App.vue

121 lines
3.2 KiB
Vue
Raw Normal View History

2024-08-06 09:40:20 +08:00
<script>
2025-02-06 11:37:41 +08:00
import { mapState, mapActions } from 'pinia'
import { useBluetoothStore } from '@/stores/bluetooth'
import { useUserStore } from '@/stores/user'
import { getStorage } from './utils/storage'
2025-02-06 11:37:41 +08:00
2024-08-22 16:37:15 +08:00
let firstCheckSetting = true
2025-02-06 11:37:41 +08:00
export default {
globalData: {
// 更新登录状态
updateIsLogin(isLogin) {
useUserStore().updateLoginStatus(isLogin)
},
// 账号信息
appid: '',
// 小程序版本
envVersion: '',
sn: '',
// 获取环境配置
2025-02-06 11:37:41 +08:00
getEnvConfig() {
const envVersionStorage = getStorage('envVersion')
if (envVersionStorage) {
return envVersionStorage
}
2025-06-09 15:37:56 +08:00
// #ifdef MP-WEIXIN
2025-02-06 11:37:41 +08:00
if (this.envVersion === 'develop') {
2025-07-29 11:07:43 +08:00
return 'SKY'
2025-02-06 11:37:41 +08:00
}
if (this.envVersion === 'trial') {
2025-07-29 11:07:43 +08:00
return 'SKY'
2025-02-06 11:37:41 +08:00
}
2025-06-06 15:20:34 +08:00
// #endif
2025-07-29 11:07:43 +08:00
return 'SKY'
}
},
computed: {
2025-02-06 11:37:41 +08:00
...mapState(useBluetoothStore, ['bluetoothStatus'])
},
2025-02-06 11:37:41 +08:00
async onLaunch() {
// #ifdef MP-WEIXIN
// 检查强制升级
2024-08-06 11:07:48 +08:00
this.updateMiniProgram()
// 设置voip配置
this.setVoipConfig()
// #endif
2024-09-14 10:26:06 +08:00
// 监听蓝牙开关状态
this.onBluetoothState()
2024-08-22 16:37:15 +08:00
// 检查蓝牙权限
const checkResult = await this.checkSetting()
2025-02-06 11:37:41 +08:00
if (checkResult === true) {
this.initAndListenBluetooth(false)
2024-08-22 16:37:15 +08:00
}
2025-02-06 11:37:41 +08:00
},
onShow() {
if (firstCheckSetting) {
2024-08-22 16:37:15 +08:00
firstCheckSetting = false
} else {
this.checkSetting()
}
2025-02-06 11:37:41 +08:00
},
2024-08-06 11:07:48 +08:00
methods: {
2025-02-06 11:37:41 +08:00
...mapActions(useBluetoothStore, [
'initBluetooth',
'onBluetoothState',
'updateBluetoothStatus',
'checkSetting',
'onBluetoothConnectStatus',
'onBluetoothCharacteristicValueChange',
'updateInitBluetooth',
'initAndListenBluetooth'
]),
...mapActions(useUserStore, ['updateLoginStatus']),
2025-04-07 17:01:22 +08:00
// voip设置
setVoipConfig() {
const wmpfVoip = requirePlugin('wmpf-voip').default
wmpfVoip.setUIConfig({
btnText: '去开门',
customBoxHeight: '75vh',
listenerUI: {
cameraRotation: 270,
objectFit: 'fill',
enableToggleCamera: true
2025-04-07 17:01:22 +08:00
}
})
wmpfVoip.setVoipEndPagePath({
url: '/pages/main/home',
key: 'Call',
routeType: 'switchTab'
})
wmpfVoip.onVoipEvent(event => {
if (event.eventName === 'callPageOnShow') {
const query = wmpfVoip.getPluginOnloadOptions()
getApp().globalData.sn = query.callerId
}
})
2025-04-07 17:01:22 +08:00
},
2024-08-06 11:07:48 +08:00
// 强制升级
updateMiniProgram() {
const updateManager = uni.getUpdateManager()
updateManager.onUpdateReady(function () {
uni.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
showCancel: false,
2025-02-06 11:37:41 +08:00
success() {
2024-08-06 11:07:48 +08:00
updateManager.applyUpdate()
}
})
})
}
}
2025-02-06 11:37:41 +08:00
}
2024-08-06 09:40:20 +08:00
</script>
2024-08-06 10:57:56 +08:00
<style lang="scss">
@import 'uview-plus/index';
2024-08-06 10:57:56 +08:00
</style>