|
|
@@ -4,6 +4,7 @@ var esc = require("@/pagesOrder/js/gprint/esc.js");
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
+ BleVal:'',
|
|
|
nameBLE:'未连接',
|
|
|
devices: [],
|
|
|
currDev: null,
|
|
|
@@ -13,19 +14,29 @@ export default {
|
|
|
};
|
|
|
},
|
|
|
onShow() {
|
|
|
+ this.devices = [];
|
|
|
+ this.isAutoBle = false;
|
|
|
if(uni.getStorageSync('BLE')){
|
|
|
this.nameBLE = uni.getStorageSync('BLE').name;
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
//断开蓝牙链接
|
|
|
- destroyed() {
|
|
|
- if (this.connId != "") {
|
|
|
- uni.closeBLEConnection({deviceId: this.connId,success(res) {
|
|
|
- console.log(res);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ destroyed(BleVal) {
|
|
|
+ this.BleVal = BleVal;
|
|
|
+ let self = this;
|
|
|
+ uni.closeBLEConnection({deviceId: uni.getStorageSync('BLE').deviceId,success(res) {
|
|
|
+ console.log(res);
|
|
|
+ self.autoLinkBle();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // if (this.connId != "") {
|
|
|
+ // uni.closeBLEConnection({deviceId: uni.getStorageSync('BLE').deviceId,success(res) {
|
|
|
+ // console.log(res);
|
|
|
+ // this.autoLinkBle();
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
},
|
|
|
//初始化蓝牙
|
|
|
searchBle() {
|
|
|
@@ -68,7 +79,20 @@ export default {
|
|
|
let name = re.devices[0].name?re.devices[0].name:'未知设备';
|
|
|
if (name != "未知设备" && name != "") {
|
|
|
let deviceId = re.devices[0].deviceId;
|
|
|
- that.devices.push({name: name,deviceId: deviceId,services: []});
|
|
|
+ switch(uni.getSystemInfoSync().platform){
|
|
|
+ case 'android':
|
|
|
+ that.devices.push({name: name,deviceId: deviceId,services: []});
|
|
|
+ break;
|
|
|
+ case 'ios':
|
|
|
+ for (let i=0;i<that.devices.length;i++){
|
|
|
+ console.log(that.devices[i].name,'----',name)
|
|
|
+ if (that.devices[i].name==name) {return}
|
|
|
+ }
|
|
|
+ that.devices.push({name: name,deviceId: deviceId,services: []});
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// that.$nextTick(()=>{
|
|
|
// that.$util.unique(that.devices);
|
|
|
// })
|
|
|
@@ -77,7 +101,8 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
//自动链接蓝牙-初始化蓝牙模块
|
|
|
- autoLinkBle(){
|
|
|
+ autoLinkBle(BleVal){
|
|
|
+ this.BleVal = BleVal;
|
|
|
let self = this;
|
|
|
if(!uni.getStorageSync('BLE')){
|
|
|
uni.showModal({
|
|
|
@@ -97,7 +122,10 @@ export default {
|
|
|
//初始化蓝牙模块
|
|
|
uni.openBluetoothAdapter({
|
|
|
success(res) {
|
|
|
+ console.log('初始化成功',res)
|
|
|
self.autoLinkBleFun(deviceId);
|
|
|
+ },fail(e){
|
|
|
+ console.log('初始化失败',e)
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
@@ -108,6 +136,7 @@ export default {
|
|
|
uni.createBLEConnection({
|
|
|
deviceId: deviceId,
|
|
|
complete(res) {
|
|
|
+ console.log(res,'自动连接成功')
|
|
|
if (res.errMsg == "createBLEConnection:ok") {
|
|
|
uni.setStorageSync('BLE',item);
|
|
|
setTimeout(function() {
|
|
|
@@ -126,16 +155,17 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
onConn(item) {
|
|
|
+ uni.showLoading({title: '正在连接...'});
|
|
|
var that = this;
|
|
|
- console.log("连接蓝牙---------------" + item.deviceId);
|
|
|
+ // console.log("连接蓝牙---------------" + item.deviceId);
|
|
|
let deviceId = item.deviceId;
|
|
|
uni.createBLEConnection({
|
|
|
deviceId: deviceId,
|
|
|
complete(res) {
|
|
|
if (res.errMsg == "createBLEConnection:ok") {
|
|
|
that.nameBLE = item.name;
|
|
|
- console.log("连接蓝牙-[" + item.name + "]--成功");
|
|
|
- that.$msg("连接蓝牙-[" + item.name + "]--成功");
|
|
|
+ // console.log("连接蓝牙-[" + item.name + "]--成功");
|
|
|
+ // that.$msg("连接蓝牙-[" + item.name + "]--成功");
|
|
|
that.connId = deviceId;
|
|
|
that.currDev = item;
|
|
|
setTimeout(function() {
|
|
|
@@ -185,6 +215,7 @@ export default {
|
|
|
that.devices[index].services.push({serviceId: serviceId,characteristicId: uuid});
|
|
|
that.$nextTick(()=>{
|
|
|
uni.setStorageSync('BLE',that.devices[index]);
|
|
|
+ that.$msg("连接蓝牙-[" + that.devices[index].name + "]--成功");
|
|
|
})
|
|
|
break;
|
|
|
}
|
|
|
@@ -252,15 +283,8 @@ export default {
|
|
|
command.setSize(40, 60);
|
|
|
command.setGap(2);
|
|
|
command.setCls();
|
|
|
- // command.setText(50, 10, "TSS24.BF2", 1, 1, "打印测试")
|
|
|
- // command.setQR(50, 50, "L", 5, "A", "977767937@qq.com")
|
|
|
- // command.setQR(a, b, c, d, e, f ")
|
|
|
- command.setText(30, 0, 2, 0, "arial", "测试");
|
|
|
- command.setText("福建省厦门市集美管控黄庄三里9号绿意花街");
|
|
|
- // command.setText("阿斯顿",'','13333333333');
|
|
|
- // command.setText(10, 90, "TSS24.BF2", 1, 1, "收花人电话:5521667788");
|
|
|
- // command.setText(10, 130, "TSS24.BF2", 1, 1, "收花时间:2020-6-10 上午");
|
|
|
- // command.setText(10,170,"TSS24.BF2",1,1,"收花地址:11111厦门市集美区凤林前山路147号110室");
|
|
|
+ command.setText(this.BleVal[0].name);
|
|
|
+ command.setText(this.BleVal[0].phone);
|
|
|
command.setPagePrint();
|
|
|
this.senBlData(deviceId, serviceId, characteristicId, command.getData());
|
|
|
},
|