2024-08-06 09:40:20 +08:00
|
|
|
<script>
|
2025-02-06 11:37:41 +08:00
|
|
|
import { mapState, mapActions } from 'pinia'
|
2024-08-14 15:04:01 +08:00
|
|
|
import { useBluetoothStore } from '@/stores/bluetooth'
|
2024-08-21 16:20:11 +08:00
|
|
|
import { useUserStore } from '@/stores/user'
|
2024-09-19 11:50:23 +08:00
|
|
|
import { getStorage } from './utils/storage'
|
2025-02-06 11:37:41 +08:00
|
|
|
|
2024-08-22 16:37:15 +08:00
|
|
|
let firstCheckSetting = true
|
2024-08-14 15:04:01 +08:00
|
|
|
|
2025-02-06 11:37:41 +08:00
|
|
|
export default {
|
2024-08-21 16:20:11 +08:00
|
|
|
globalData: {
|
|
|
|
|
// 更新登录状态
|
|
|
|
|
updateIsLogin(isLogin) {
|
|
|
|
|
useUserStore().updateLoginStatus(isLogin)
|
2024-08-28 16:55:11 +08:00
|
|
|
},
|
|
|
|
|
// 账号信息
|
2024-08-30 10:28:06 +08:00
|
|
|
appid: '',
|
|
|
|
|
// 小程序版本
|
2024-09-02 13:41:35 +08:00
|
|
|
envVersion: '',
|
2025-04-10 16:34:00 +08:00
|
|
|
sn: '',
|
2024-09-02 13:41:35 +08:00
|
|
|
// 获取环境配置
|
2025-02-06 11:37:41 +08:00
|
|
|
getEnvConfig() {
|
2024-09-19 11:50:23 +08:00
|
|
|
const envVersionStorage = getStorage('envVersion')
|
|
|
|
|
if (envVersionStorage) {
|
2024-09-18 15:49:14 +08:00
|
|
|
return envVersionStorage
|
2024-09-02 13:41:35 +08:00
|
|
|
}
|
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'
|
2024-09-02 13:41:35 +08:00
|
|
|
}
|
2024-08-21 16:20:11 +08:00
|
|
|
},
|
2024-08-14 15:04:01 +08:00
|
|
|
computed: {
|
2025-02-06 11:37:41 +08:00
|
|
|
...mapState(useBluetoothStore, ['bluetoothStatus'])
|
2024-08-14 15:04:01 +08:00
|
|
|
},
|
2025-02-06 11:37:41 +08:00
|
|
|
async onLaunch() {
|
2025-05-09 11:52:58 +08:00
|
|
|
// #ifdef MP-WEIXIN
|
2024-08-14 18:33:23 +08:00
|
|
|
// 检查强制升级
|
2024-08-06 11:07:48 +08:00
|
|
|
this.updateMiniProgram()
|
2025-05-16 14:23:41 +08:00
|
|
|
// 设置voip配置
|
|
|
|
|
this.setVoipConfig()
|
2025-05-09 11:52:58 +08:00
|
|
|
// #endif
|
2025-05-16 14:23:41 +08:00
|
|
|
|
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) {
|
2024-08-29 19:42:52 +08:00
|
|
|
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'
|
|
|
|
|
]),
|
2024-08-21 16:20:11 +08:00
|
|
|
...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',
|
2025-07-01 15:33:58 +08:00
|
|
|
enableToggleCamera: true
|
2025-04-07 17:01:22 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
wmpfVoip.setVoipEndPagePath({
|
|
|
|
|
url: '/pages/main/home',
|
|
|
|
|
key: 'Call',
|
|
|
|
|
routeType: 'switchTab'
|
|
|
|
|
})
|
2025-04-10 16:34:00 +08:00
|
|
|
|
|
|
|
|
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">
|
2025-04-10 16:34:00 +08:00
|
|
|
@import 'uview-plus/index';
|
2024-08-06 10:57:56 +08:00
|
|
|
</style>
|