|
@@ -6,10 +6,10 @@
|
|
|
<view class="kk-shadow" :class="isShowSearch?'show':''" @tap="handleSearchClose">
|
|
|
<view class="kk-modal" @tap.stop="doNothing">
|
|
|
<view class="kk-search-device">
|
|
|
- <view class="kk-filter-wrap">
|
|
|
+ <!-- <view class="kk-filter-wrap">
|
|
|
<view class="filter-title">根据SRRI过滤设备</view>
|
|
|
<slider @change="handleSRRIChange" max='-20' min='-100' value="-95" show-value/>
|
|
|
- </view>
|
|
|
+ </view> -->
|
|
|
<view class="kk-filter-wrap">
|
|
|
<view class="filter-title">根据蓝牙名过滤</view>
|
|
|
<input type="text" placeholder-class="kk-placeholder-class" placeholder="请输入蓝牙名字或设备ID搜索" v-model="filterName" />
|
|
@@ -31,26 +31,30 @@
|
|
|
<view class="empty-text">~ 无可搜索到的设备 ~</view>
|
|
|
</view>
|
|
|
<view class="" v-else>
|
|
|
- <view class="kk-devices-item" v-for="(item,index) in filterDeviceList" :key="index" @tap="handleConnectDevice(item)">
|
|
|
- <view class="name">
|
|
|
- <text>设备名称:</text>
|
|
|
- <text>{{item.name?item.name:'未命名'}}</text>
|
|
|
- </view>
|
|
|
- <view class="rssi">
|
|
|
- <text>信号强度:</text>
|
|
|
- <text>({{Math.max(0, item.RSSI + 100)}}%)</text>
|
|
|
- </view>
|
|
|
- <view class="deviceid">
|
|
|
- <text>设备ID:</text>
|
|
|
- <text>{{item.deviceId}}</text>
|
|
|
+ <view class="kk-devices-item flex align_center" v-for="(item,index) in filterDeviceList" :key="index" @tap="handleConnectDevice(item)">
|
|
|
+ <view>
|
|
|
+ <view class="name">
|
|
|
+ <text>设备名称:</text>
|
|
|
+ <text>{{item.name?item.name:'未命名'}}</text>
|
|
|
+ </view>
|
|
|
+ <view class="rssi">
|
|
|
+ <text>信号强度:</text>
|
|
|
+ <text>({{Math.max(0, item.RSSI + 100)}}%)</text>
|
|
|
+ </view>
|
|
|
+ <view class="deviceid">
|
|
|
+ <text>设备ID:</text>
|
|
|
+ <text>{{item.deviceId}}</text>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
- <view class="advmac" v-if="item.advMac">
|
|
|
- <text>advMac:</text>
|
|
|
- <text>{{item.advMac}}</text>
|
|
|
+ <view>
|
|
|
+ <u-icon :size="60" color="#55aaff" name="plus-circle"></u-icon>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
+ <view style="margin-top: 20upx;">
|
|
|
+ <view style="text-align: center;padding: 20upx;border:2upx solid #eee;border-radius: 15upx;" @tap="handleSearchClose">取消打印</view>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
@@ -59,7 +63,7 @@
|
|
|
|
|
|
<script>
|
|
|
import tsc from '@/components/kk-printer/printer/tsc.js'
|
|
|
- import esc from '@/components/kk-printer/printer/esc.js'
|
|
|
+ // import esc from '@/components/kk-printer/printer/esc.js'
|
|
|
import * as blesdk from './utils/bluetoolth';
|
|
|
import util from './utils/util.js';
|
|
|
export default {
|
|
@@ -98,10 +102,6 @@
|
|
|
type:String,
|
|
|
default:'打印中...'
|
|
|
},
|
|
|
- bufferData:{
|
|
|
- type:String,
|
|
|
- require:true
|
|
|
- },
|
|
|
roomcode:{
|
|
|
type:String,
|
|
|
require:true
|
|
@@ -123,12 +123,10 @@
|
|
|
let devices = this.devicesList;
|
|
|
let name = this.filterName;
|
|
|
let rssi = this.filterRSSI;
|
|
|
- console.log(devices,name,rssi)
|
|
|
//按RSSI过滤
|
|
|
let filterDevices1 = devices.filter((item)=>{
|
|
|
return item.RSSI > rssi
|
|
|
})
|
|
|
- console.log(filterDevices1)
|
|
|
// 按名字过滤
|
|
|
let filterDevices2
|
|
|
if(name!=''){
|
|
@@ -153,7 +151,6 @@
|
|
|
|
|
|
},
|
|
|
beforeDestroy(){
|
|
|
-
|
|
|
this.stopSearchBtnTap();
|
|
|
},
|
|
|
methods:{
|
|
@@ -167,9 +164,13 @@
|
|
|
//获取已连接设备
|
|
|
blesdk.getConnectedBluetoothDevices().then((res)=>{
|
|
|
//若没有已连接设备,弹框搜索设备
|
|
|
- console.log(res,this.deviceId,this.serviceId,this.writeId,this.bufferData,this.onPrintSuccess)
|
|
|
+ console.log(res,this.deviceId,this.serviceId,this.writeId,this.onPrintSuccess)
|
|
|
if(res.devices.length == 0){
|
|
|
this.isShowSearch = true
|
|
|
+ this.devicesList = []
|
|
|
+ if(this.deviceId){
|
|
|
+ this.closeConnect(this.deviceId)
|
|
|
+ }
|
|
|
}else{
|
|
|
const lastDevice = this.$store.state.vuex_lastBuleDevice
|
|
|
if(lastDevice && res.devices[0].deviceId == lastDevice.deviceId){
|
|
@@ -178,25 +179,13 @@
|
|
|
this.writeId = lastDevice.writeId
|
|
|
this.readId = lastDevice.readId
|
|
|
}
|
|
|
- let datalen=20;
|
|
|
- if (plus.os.name != 'Android')
|
|
|
- {
|
|
|
- datalen=180;
|
|
|
- }
|
|
|
this.isPrinting = true;
|
|
|
this.$nextTick(()=>{
|
|
|
- var command = tsc.jpPrinter.createNew()
|
|
|
- command.init()
|
|
|
- command.setSize(40, 30) // 标签纸张宽高,单位mm
|
|
|
- command.setGap(2) // 标签上下间距,单位mm
|
|
|
- command.setCls() // 清除缓冲区数据
|
|
|
- command.setText(50, 10, "TSS24.BF2", 1, 1, "打印测试")
|
|
|
- command.setQR(50, 50, "L", 5, "A", "https://www.baidu.com")
|
|
|
- command.setBox(5, 5, 795, 595, 1)
|
|
|
- command.setPagePrint(1,2) // 打印分数1,每个标签重发打印2次
|
|
|
- console.log("开始打印了")
|
|
|
- blesdk.senBlData(this.deviceId, this.serviceId, this.writeId, command.getData(), this.onPrintSuccess);
|
|
|
- this.isPrinting = false;
|
|
|
+ this.$emit("startPrint",{
|
|
|
+ deviceId: this.deviceId,
|
|
|
+ serviceId: this.serviceId,
|
|
|
+ writeId: this.writeId
|
|
|
+ },tsc,blesdk)
|
|
|
})
|
|
|
}
|
|
|
}).catch((err)=>{
|
|
@@ -228,12 +217,11 @@
|
|
|
},
|
|
|
//点击连接设备
|
|
|
handleConnectDevice(device){
|
|
|
+ const _this = this
|
|
|
let deviceId = device.deviceId;
|
|
|
let name = device.name;
|
|
|
this.deviceId = deviceId;
|
|
|
console.log('deviceId',this.deviceId)
|
|
|
- // uni.setStorageSync('k_curDeviceID',deviceId);
|
|
|
- // uni.setStorageSync('k_curDeviceName',name);plus.bluetooth.onBluetoothDeviceFound
|
|
|
uni.onBLEConnectionStateChange(function(res){
|
|
|
console.log('连接',res)
|
|
|
if(res.connected){
|
|
@@ -241,6 +229,7 @@
|
|
|
verticalAlign:'center'
|
|
|
})
|
|
|
}else{
|
|
|
+ _this.closeConnect(deviceId)
|
|
|
plus.nativeUI.toast('设备'+ res.deviceId + '已断开连接',{
|
|
|
verticalAlign:'center'
|
|
|
})
|
|
@@ -276,7 +265,6 @@
|
|
|
},
|
|
|
onPrintSuccess(){
|
|
|
this.isPrinting = false;
|
|
|
- console.log({roomcode:this.roomcode,CustName:this.CustName,id:this.roomid})
|
|
|
console.log('打印成功')
|
|
|
// this.$emit('onPrintSuccess')
|
|
|
},
|
|
@@ -285,8 +273,8 @@
|
|
|
this.isPrinting = false;
|
|
|
},
|
|
|
closeConnect(){
|
|
|
- blesdk.closeBLEConnection()
|
|
|
- }
|
|
|
+ blesdk.closeBLEConnection(this.deviceId)
|
|
|
+ },
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
@@ -313,7 +301,7 @@
|
|
|
z-index: 10000;
|
|
|
.kk-modal{
|
|
|
width:680upx;
|
|
|
- height: 80%;
|
|
|
+ height: 60%;
|
|
|
padding:24upx;
|
|
|
box-sizing: border-box;
|
|
|
overflow-y: auto;
|
|
@@ -327,7 +315,7 @@
|
|
|
height: 100%;
|
|
|
.kk-filter-wrap{
|
|
|
width:100%;
|
|
|
- height: 160upx;
|
|
|
+ height: 200upx;
|
|
|
display: flex;
|
|
|
flex-direction: column;
|
|
|
justify-content: flex-start;
|
|
@@ -358,9 +346,9 @@
|
|
|
align-items: center;
|
|
|
&>view{
|
|
|
flex:1 1 auto;
|
|
|
- height: 100upx;
|
|
|
- line-height: 100upx;
|
|
|
- border-radius: 16upx;
|
|
|
+ height: 80upx;
|
|
|
+ line-height: 80upx;
|
|
|
+ border-radius: 100upx;
|
|
|
text-align: center;
|
|
|
color:#ffffff;
|
|
|
&.confirm-btn{
|
|
@@ -410,9 +398,11 @@
|
|
|
&:nth-last-child(1){
|
|
|
border-bottom: none;
|
|
|
}
|
|
|
- &>view{
|
|
|
- width:100%;
|
|
|
- font-size: 30upx;
|
|
|
+ > view{
|
|
|
+ &:first-child{
|
|
|
+ flex-grow: 1;
|
|
|
+ width: 80%;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|