wx-starlock/App.vue
范鹏 e97763af57 1. 优化首页列表请求顺序,减短loading时间
2. 获取小程序版本并保存
2024-08-30 10:28:06 +08:00

64 lines
1.9 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: '',
// 小程序版本
envVersion: ''
},
computed: {
...mapState(useBluetoothStore, ['bluetoothStatus']),
},
onLaunch: async function() {
// 检查强制升级
this.updateMiniProgram()
// 检查蓝牙权限
const checkResult = await this.checkSetting()
console.log(checkResult)
if(checkResult === true) {
this.initAndListenBluetooth(false)
}
},
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>