打印自动记录
This commit is contained in:
parent
5d3ac55f07
commit
336df1bf66
@ -159,18 +159,20 @@ export default {
|
|||||||
},
|
},
|
||||||
// 自动连接历史蓝牙配置
|
// 自动连接历史蓝牙配置
|
||||||
async autoConnect() {
|
async autoConnect() {
|
||||||
let { characteristicId } = getSessionBluetoothInfo()
|
console.log("autoConnect start===========")
|
||||||
|
let { characteristicId, serviceId, deviceId } = this
|
||||||
let conSta = false
|
let conSta = false
|
||||||
|
const _this = this
|
||||||
// 判断是否有历史连接
|
// 判断是否有历史连接
|
||||||
if(characteristicId) {
|
if(deviceId) {
|
||||||
let { res, err } = await this.connect()
|
await this.handleAutoSelectAllData({ deviceId })
|
||||||
conSta = !!res
|
conSta = !!_this.characteristicId // 判断是否有选中 characteristicId
|
||||||
}
|
}
|
||||||
console.log("=========当前蓝牙连接状态=======", conSta)
|
console.log("=========当前蓝牙连接状态=======", conSta)
|
||||||
// 连接不成功,打开蓝牙配置页面
|
// 连接不成功,打开蓝牙配置页面
|
||||||
if(!conSta) {
|
if(!conSta) {
|
||||||
this.showConnectPage = true
|
this.showConnectPage = true
|
||||||
this.discoveryPrinter()
|
// this.discoveryPrinter()
|
||||||
} else {
|
} else {
|
||||||
this.stopDiscoveryPrinter()
|
this.stopDiscoveryPrinter()
|
||||||
}
|
}
|
||||||
@ -258,9 +260,14 @@ export default {
|
|||||||
showLoading('正在连接蓝牙')
|
showLoading('正在连接蓝牙')
|
||||||
let { res, err } = await uniPromiseApi('createBLEConnection', { deviceId: _this.deviceId })
|
let { res, err } = await uniPromiseApi('createBLEConnection', { deviceId: _this.deviceId })
|
||||||
hideLoading()
|
hideLoading()
|
||||||
if( res) {
|
if(res || err?.code == -1) {
|
||||||
|
// code: -1 已连接
|
||||||
|
res = res || err
|
||||||
|
err = undefined
|
||||||
|
}
|
||||||
|
if(res) {
|
||||||
showToast(`蓝牙连接成功`)
|
showToast(`蓝牙连接成功`)
|
||||||
await promiseTimeout(1000)
|
await promiseTimeout(1500)
|
||||||
// 获取蓝牙设备所有服务(service)。
|
// 获取蓝牙设备所有服务(service)。
|
||||||
await _this.getBLEDeviceServices()
|
await _this.getBLEDeviceServices()
|
||||||
}
|
}
|
||||||
@ -277,7 +284,6 @@ export default {
|
|||||||
})
|
})
|
||||||
if(res) {
|
if(res) {
|
||||||
_this.serverList = res.services
|
_this.serverList = res.services
|
||||||
// _this.serviceId = res.services[0].uuid;
|
|
||||||
console.log('serverId:', _this.serviceId)
|
console.log('serverId:', _this.serviceId)
|
||||||
}
|
}
|
||||||
if(err) {
|
if(err) {
|
||||||
@ -301,25 +307,27 @@ export default {
|
|||||||
},
|
},
|
||||||
// 根据选择的deviceId自动匹配 serviceId, characteristicId
|
// 根据选择的deviceId自动匹配 serviceId, characteristicId
|
||||||
async handleAutoSelectAllData(item) {
|
async handleAutoSelectAllData(item) {
|
||||||
|
console.log("handleAutoSelectAllData :item======", item)
|
||||||
const _this = this
|
const _this = this
|
||||||
await this.handleSelectDeviceId(item)
|
await this.handleSelectDeviceId(item)
|
||||||
|
|
||||||
if(this.serverList?.length > 0) {
|
if(this.serverList?.length > 0) {
|
||||||
for(let i=0; i<_this.serverList?.length; i++) {
|
for(let i=0; i<_this.serverList?.length; i++) {
|
||||||
let _serviceId = _this.serverList[i].uuid
|
let _serviceId = _this.serverList[i].uuid
|
||||||
let charApi = await uniPromiseApi('getBLEDeviceCharacteristics', {
|
let charPms = await uniPromiseApi('getBLEDeviceCharacteristics', {
|
||||||
deviceId: _this.deviceId,
|
deviceId: _this.deviceId,
|
||||||
serviceId: _serviceId,
|
serviceId: _serviceId,
|
||||||
})
|
})
|
||||||
let { res, err } = charApi
|
let { res, err } = charPms
|
||||||
if(res) {
|
if(res) {
|
||||||
let charItem = res.characteristics.filter(t=> {
|
let charItem = res.characteristics.filter(t=> {
|
||||||
let { notify, indicate, write } = t.properties || {}
|
let { notify, indicate, write } = t.properties || {}
|
||||||
|
// return write
|
||||||
return (notify || indicate) && write
|
return (notify || indicate) && write
|
||||||
})[0]
|
})[0]
|
||||||
if(charItem) {
|
if(charItem) {
|
||||||
_this.serviceId = _serviceId
|
_this.serviceId = _serviceId
|
||||||
_this.characteristicId = charRes.uuid
|
_this.characteristicId = charItem.uuid
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user