This commit is contained in:
aihe 2024-05-10 11:30:15 +08:00
parent d54d9268a3
commit 540ee738f1

View File

@ -5,7 +5,7 @@
<view class="blcok-white">
<view >
<u-row custom-style="gap: 10rpx;">
<u-button @click="discoveryPrinter">搜索周边设备</u-button>
<u-button @click="discoveryPrinter" type="info" :loading="searchLoading" loadingSize="24" loadingText="搜索中">搜索周边设备</u-button>
<u-button @click="stopDiscoveryPrinter">停止搜索</u-button>
<u-button @click="writeBLECharacteristicValue" type="primary" :disabled="!(deviceId && serviceId && characteristicId)">打印</u-button>
</u-row>
@ -118,6 +118,7 @@ export default {
canvas_width: 240,
canvas_height: 240,
curTab: 0,
searchLoading: false,
devices: [],
deviceId: '',
serverList: [],
@ -130,6 +131,9 @@ export default {
// 初始化蓝牙模块
this.openBluetoothAdapter()
},
unmounted() {
this.stopDiscoveryPrinter()
},
methods: {
changeTab(type) {
this.curTab = type
@ -154,6 +158,7 @@ export default {
discoveryPrinter () {
var _this = this
_this.devices = []
_this.searchLoading = true
_this.curTab = 0
uni.startBluetoothDevicesDiscovery({
complete (e) {
@ -174,6 +179,7 @@ export default {
},
// 停止搜寻附近的蓝牙外围设备
async stopDiscoveryPrinter () {
this.searchLoading = false
let res = await this.renderPic()
uni.stopBluetoothDevicesDiscovery()
},