wx-starlock/App.vue
范鹏 f9669c8d2c 1. 完成锁密码相关功能
2. 完成锁电子钥匙相关功能
2024-08-28 16:55:11 +08:00

62 lines
1.8 KiB
Vue

<script>
import { useBluetoothStore } from '@/stores/bluetooth'
import { useUserStore } from '@/stores/user'
import { useBasicStore } from '@/stores/basic'
import { mapState, mapActions } from 'pinia'
let firstCheckSetting = true
export default {
globalData: {
// 更新登录状态
updateIsLogin(isLogin) {
useUserStore().updateLoginStatus(isLogin)
},
// 账号信息
appid: ''
},
computed: {
...mapState(useBluetoothStore, ['bluetoothStatus']),
},
onLaunch: async function() {
// 检查强制升级
this.updateMiniProgram()
// 检查蓝牙权限
const checkResult = await this.checkSetting()
console.log(checkResult)
if(checkResult === true) {
this.initAndListenBluetooth()
}
},
onShow() {
if(firstCheckSetting) {
firstCheckSetting = false
} else {
this.checkSetting()
}
},
methods: {
...mapActions(useBluetoothStore, ['initBluetooth', 'onBluetoothState', 'updateBluetoothStatus', 'checkSetting',
'onBluetoothConnectStatus', 'onBluetoothCharacteristicValueChange', 'updateInitBluetooth', 'initAndListenBluetooth']),
...mapActions(useUserStore, ['updateLoginStatus']),
// 强制升级
updateMiniProgram() {
const updateManager = uni.getUpdateManager()
updateManager.onUpdateReady(function () {
uni.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
showCancel: false,
success: function () {
updateManager.applyUpdate()
}
})
})
}
}
}
</script>
<style lang="scss">
@import "uview-plus/index.scss";
</style>