uu
This commit is contained in:
parent
d2d632a087
commit
4fe62d1f08
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<tpx-bluetooth v-model:value="blueToothData">
|
<tpx-bluetooth ref="curBlueTooth">
|
||||||
<template v-slot:button>
|
<template v-slot:button>
|
||||||
<u-button @click="handlePrint" type="primary" :disabled="!(blueToothData.deviceId && blueToothData.serviceId && blueToothData.characteristicId)">打印</u-button>
|
<u-button @click="handlePrint" type="primary">确认打印</u-button>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:content>
|
<template v-slot:content>
|
||||||
<view class="pt-20 pb-10">打印内容</view>
|
<view class="pt-20 pb-10">打印内容</view>
|
||||||
@ -52,11 +52,6 @@ export default {
|
|||||||
imgData: '',
|
imgData: '',
|
||||||
percentage: 0, // 打印进度
|
percentage: 0, // 打印进度
|
||||||
threshold: 200, // 阈值(值越大,图片打印越深)
|
threshold: 200, // 阈值(值越大,图片打印越深)
|
||||||
blueToothData: {
|
|
||||||
deviceId: '',
|
|
||||||
serviceId: '',
|
|
||||||
characteristicId: ''
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
@ -71,8 +66,10 @@ export default {
|
|||||||
// 打印
|
// 打印
|
||||||
async handlePrint(){
|
async handlePrint(){
|
||||||
const that = this
|
const that = this
|
||||||
|
let { deviceId, serviceId, characteristicId } = this.$refs.curBlueTooth.getInstance()
|
||||||
|
|
||||||
const opt = {
|
const opt = {
|
||||||
...this.blueToothData,
|
...{ deviceId, serviceId, characteristicId },
|
||||||
onProgress: (percentage) => {
|
onProgress: (percentage) => {
|
||||||
console.log("打印进度====", percentage)
|
console.log("打印进度====", percentage)
|
||||||
that.percentage = percentage
|
that.percentage = percentage
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<tpx-layout>
|
<tpx-layout v-if="showConnectPage">
|
||||||
<template v-slot:header>
|
<template v-slot:header>
|
||||||
<view class="blcok-white" style="margin-top: 0;">
|
<view class="blcok-white" style="margin-top: 0;">
|
||||||
<view >
|
<view >
|
||||||
@ -27,8 +27,8 @@
|
|||||||
</u-steps>
|
</u-steps>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-slot:body>
|
<template v-slot:body>
|
||||||
<view class="blcok-white">
|
<view class="blcok-white">
|
||||||
<view v-if="curTab == 0">
|
<view v-if="curTab == 0">
|
||||||
@ -90,15 +90,16 @@
|
|||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<slot name="content"></slot>
|
<slot name="content"></slot>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
</tpx-layout>
|
</tpx-layout>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { showLoading, showToast, hideLoading } from "@/common/untool"
|
import { showLoading, showToast, hideLoading } from "@/common/untool"
|
||||||
|
import { getSessionBluetoothInfo, setSessionBluetoothInfo } from "@/session"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
computed: {
|
computed: {
|
||||||
@ -113,69 +114,92 @@ export default {
|
|||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
deviceId(val){
|
deviceId(val){
|
||||||
this.value.deviceId = val
|
updateBlueSessionInfo()
|
||||||
this.$emit('update:value', this.value)
|
|
||||||
},
|
},
|
||||||
serviceId(val){
|
serviceId(val){
|
||||||
this.value.serviceId = val
|
updateBlueSessionInfo()
|
||||||
this.$emit('update:value', this.value)
|
|
||||||
},
|
},
|
||||||
characteristicId(val){
|
characteristicId(val){
|
||||||
this.value.characteristicId = val
|
updateBlueSessionInfo()
|
||||||
this.$emit('update:value', this.value)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props:{
|
props:{
|
||||||
value: {
|
|
||||||
default () {
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
|
let { deviceId, serviceId, characteristicId } = getSessionBluetoothInfo()
|
||||||
return {
|
return {
|
||||||
|
showConnectPage: true,
|
||||||
canvasId: 'shareCanvas',
|
canvasId: 'shareCanvas',
|
||||||
canvas_width: 240,
|
canvas_width: 240,
|
||||||
canvas_height: 240,
|
canvas_height: 240,
|
||||||
curTab: 0,
|
curTab: 0,
|
||||||
searchLoading: false,
|
searchLoading: false,
|
||||||
devices: [],
|
devices: [],
|
||||||
deviceId: this.value?.deviceId,
|
deviceId,
|
||||||
serverList: [],
|
serverList: [],
|
||||||
serviceId: this.value?.deviceId,
|
serviceId,
|
||||||
characteristics: [],
|
characteristics: [],
|
||||||
characteristicId: this.value?.deviceId,
|
characteristicId,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
async mounted () {
|
||||||
// 初始化蓝牙模块
|
// 初始化蓝牙模块
|
||||||
this.openBluetoothAdapter()
|
await this.openBluetoothAdapter()
|
||||||
// 自动搜索设备
|
this.autoConnect()
|
||||||
this.discoveryPrinter()
|
|
||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
this.stopDiscoveryPrinter()
|
this.stopDiscoveryPrinter()
|
||||||
this.closeBluetoothAdapter()
|
// this.closeBluetoothAdapter()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
updateBlueSessionInfo() {
|
||||||
|
let { deviceId, serviceId, characteristicId } = this
|
||||||
|
setSessionBluetoothInfo({ deviceId, serviceId, characteristicId })
|
||||||
|
},
|
||||||
|
// 自动连接历史蓝牙配置
|
||||||
|
async autoConnect() {
|
||||||
|
let conSta = await this.checkConnectStat()
|
||||||
|
// 自动连接
|
||||||
|
if(!conSta) {
|
||||||
|
this.discoveryPrinter()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
|
||||||
|
// 检查蓝牙 缓存连接状态 【获取不到characteristics说明连接已经过期】
|
||||||
|
async checkConnectStat(){
|
||||||
|
let bl = false
|
||||||
|
try{
|
||||||
|
await this.getBLEDeviceCharacteristics()
|
||||||
|
bl = true
|
||||||
|
}catch(e){
|
||||||
|
}
|
||||||
|
return bl
|
||||||
|
},
|
||||||
changeTab(type) {
|
changeTab(type) {
|
||||||
this.curTab = type
|
this.curTab = type
|
||||||
},
|
},
|
||||||
openBluetoothAdapter () {
|
openBluetoothAdapter () {
|
||||||
var _this = this
|
var _this = this
|
||||||
|
return new Promise((resolve, reject)=> {
|
||||||
uni?.openBluetoothAdapter?.({
|
uni?.openBluetoothAdapter?.({
|
||||||
complete (e) {
|
complete (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
if (!e.errCode) {
|
if (!e.errCode) {
|
||||||
|
resolve()
|
||||||
console.log('初始化完成')
|
console.log('初始化完成')
|
||||||
} else if (e.errCode == 10001) {
|
} else if (e.errCode == 10001) {
|
||||||
|
reject(e)
|
||||||
showToast('请打开手机蓝牙')
|
showToast('请打开手机蓝牙')
|
||||||
} else {
|
} else {
|
||||||
|
reject(e)
|
||||||
console.log('openBluetoothAdapter:error=========', e.errMsg)
|
console.log('openBluetoothAdapter:error=========', e.errMsg)
|
||||||
showToast(e.errMsg)
|
showToast(e.errMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
// 开始搜寻附近的蓝牙外围设备
|
// 开始搜寻附近的蓝牙外围设备
|
||||||
discoveryPrinter () {
|
discoveryPrinter () {
|
||||||
@ -183,10 +207,12 @@ export default {
|
|||||||
_this.devices = []
|
_this.devices = []
|
||||||
_this.searchLoading = true
|
_this.searchLoading = true
|
||||||
_this.curTab = 0
|
_this.curTab = 0
|
||||||
|
return new Promise((resolve, reject)=> {
|
||||||
uni?.startBluetoothDevicesDiscovery?.({
|
uni?.startBluetoothDevicesDiscovery?.({
|
||||||
complete (e) {
|
complete (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
if (e.errMsg == "startBluetoothDevicesDiscovery:ok") {
|
if (e.errMsg == "startBluetoothDevicesDiscovery:ok") {
|
||||||
|
resolve()
|
||||||
// ArrayBuffer转16进度字符串示例
|
// ArrayBuffer转16进度字符串示例
|
||||||
uni.onBluetoothDeviceFound(devices => {
|
uni.onBluetoothDeviceFound(devices => {
|
||||||
console.log("========devices=====", devices)
|
console.log("========devices=====", devices)
|
||||||
@ -196,9 +222,12 @@ export default {
|
|||||||
_this.devices.push(curDvs)
|
_this.devices.push(curDvs)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
reject()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
// 停止搜寻附近的蓝牙外围设备
|
// 停止搜寻附近的蓝牙外围设备
|
||||||
async stopDiscoveryPrinter () {
|
async stopDiscoveryPrinter () {
|
||||||
@ -294,7 +323,7 @@ export default {
|
|||||||
},
|
},
|
||||||
getBLEDeviceCharacteristics () {
|
getBLEDeviceCharacteristics () {
|
||||||
var _this = this
|
var _this = this
|
||||||
return new Promise((resolve)=> {
|
return new Promise((resolve, reject)=> {
|
||||||
showLoading('正在搜索特征值')
|
showLoading('正在搜索特征值')
|
||||||
uni.getBLEDeviceCharacteristics({
|
uni.getBLEDeviceCharacteristics({
|
||||||
// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
|
// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
|
||||||
@ -310,12 +339,15 @@ export default {
|
|||||||
},
|
},
|
||||||
fail:(res)=>{
|
fail:(res)=>{
|
||||||
hideLoading()
|
hideLoading()
|
||||||
resolve()
|
reject()
|
||||||
console.log(res)
|
console.log(res)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
getInstance() {
|
||||||
|
return this
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -96,7 +96,7 @@
|
|||||||
|
|
||||||
<tpx-checkitems :list="resData.list" v-model:value="submitParam.billCode" v-slot="dlCurrent" type="multiple"
|
<tpx-checkitems :list="resData.list" v-model:value="submitParam.billCode" v-slot="dlCurrent" type="multiple"
|
||||||
>
|
>
|
||||||
<view slot class="yditem mt-20">
|
<view slot class="yditem">
|
||||||
<u-row>
|
<u-row>
|
||||||
<u-col span="8">
|
<u-col span="8">
|
||||||
<u-row>
|
<u-row>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { XTOKEN_KEY, USERINFO_KEY } from "./key"
|
import { XTOKEN_KEY, USERINFO_KEY, BLUETOOTH_KEY } from "./key"
|
||||||
|
|
||||||
export const setSessionXToken = (val = '')=> {
|
export const setSessionXToken = (val = '')=> {
|
||||||
uni.setStorageSync(XTOKEN_KEY, val)
|
uni.setStorageSync(XTOKEN_KEY, val)
|
||||||
@ -15,3 +15,12 @@ export const setSessionUserInfo = (val = {})=> {
|
|||||||
export const getSessionUserInfo = ()=> {
|
export const getSessionUserInfo = ()=> {
|
||||||
return uni.getStorageSync(USERINFO_KEY) || {}
|
return uni.getStorageSync(USERINFO_KEY) || {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const setSessionBluetoothInfo = (val = {})=> {
|
||||||
|
uni.setStorageSync(BLUETOOTH_KEY, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getSessionBluetoothInfo = ()=> {
|
||||||
|
return uni.getStorageSync(BLUETOOTH_KEY) || {}
|
||||||
|
}
|
||||||
@ -1,2 +1,3 @@
|
|||||||
export const XTOKEN_KEY = 'XTOKEN_KEY'
|
export const XTOKEN_KEY = 'XTOKEN_KEY'
|
||||||
export const USERINFO_KEY = 'USERINFO_KEY'
|
export const USERINFO_KEY = 'USERINFO_KEY'
|
||||||
|
export const BLUETOOTH_KEY = 'BLUETOOTH_KEY'
|
||||||
Loading…
Reference in New Issue
Block a user