wx-starlock/App.vue

48 lines
1.4 KiB
Vue

<script>
import { useBluetoothStore } from '@/stores/bluetooth'
import { mapState, mapActions } from 'pinia'
export default {
computed: {
...mapState(useBluetoothStore, ['bluetoothStatus'])
},
onLaunch: function() {
// 检查强制升级
this.updateMiniProgram()
// 初始化蓝牙
this.initBluetooth()
// 监听蓝牙开关状态
this.onBluetoothState()
// 监听蓝牙连接状态
this.onBluetoothConnectStatus()
// 监听设备特征值变化
this.onBluetoothCharacteristicValueChange()
},
onShow: function() {
this.checkSetting()
},
methods: {
...mapActions(useBluetoothStore, ['initBluetooth', 'onBluetoothState', 'updateBluetoothStatus', 'checkSetting',
'onBluetoothConnectStatus', 'onBluetoothCharacteristicValueChange']),
// 强制升级
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>