shish 5 лет назад
Родитель
Сommit
c5c3d820c2
2 измененных файлов с 51 добавлено и 43 удалено
  1. 2 1
      ghsApp/src/admin/home/order.vue
  2. 49 42
      ghsApp/src/mixins/BLE.js

+ 2 - 1
ghsApp/src/admin/home/order.vue

@@ -312,9 +312,10 @@ export default {
           },
         });
       }else if (s.type === "print") {
+        uni.showLoading({title:"打印中..."})
         if(this.hasCloudPrint == 1){
             //云打印
-            uni.showLoading({title:"打印中..."})
+            console.log('走云打印方式')
             cloudPrintOrder({id:item.id}).then((res) => {
               item.printNum++
               uni.hideLoading()

+ 49 - 42
ghsApp/src/mixins/BLE.js

@@ -30,6 +30,7 @@ export default {
 	methods: {
 		//断开蓝牙链接
 		destroyed(BleVal) {
+			this.BleVal = BleVal;
 			let self = this;
 			if(!uni.getStorageSync('BLE')){
 				uni.showModal({
@@ -102,9 +103,6 @@ export default {
 					if(re.devices && re.devices.length > 0){
 
 						re.devices.forEach(function(item){
- 
-							    //code something
-							 
 							  
 						let name = item.name?item.name:'未知设备';
 						if (name != "未知设备" && name != "") {
@@ -258,51 +256,60 @@ export default {
 			uni.getBLEDeviceServices({
 				// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
 				deviceId: deviceId,
-				complete(res) {
-					console.log(res)
-					for (var s = 0; s < res.services.length; s++) {
-						console.log(res.services[s].uuid);
-						let serviceId = res.services[s].uuid;
-						uni.getBLEDeviceCharacteristics({
-							// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
-							deviceId: deviceId,
-							// 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
-							serviceId: serviceId,
-							success(res) {
-								var re = JSON.parse(JSON.stringify(res));
-
-								console.log("deviceId = [" + deviceId + "]  serviceId = [" + serviceId + "]")
-
-								for (var c = 0; c < re.characteristics.length; c++) {
-									if (re.characteristics[c].properties.write == true) {
-										let uuid = re.characteristics[c].uuid;
-										console.log(" deviceId = [" +deviceId +"]  serviceId = [" +serviceId +"] characteristics = [" +uuid +"]");
-										//是否是直接打印
-										if(that.isAutoBle){
-											console.log('打印订单 11111111111111111111111111111111111111111111111111111111111111')
-											that.senBleLabel()
-											uni.hideLoading()
-											that.isAutoBle = false
-										}
-										for (var index in that.devices) {
-											if (that.devices[index].deviceId == deviceId) {
-												that.devices[index].services.push({serviceId: serviceId,characteristicId: uuid});
-												that.$nextTick(()=>{
-													uni.setStorageSync('BLE',that.devices[index]);
-													that.$msg("连接蓝牙-[" + that.devices[index].name + "]--成功");
-												})
-												break;
+				success(res) {
+						console.log('getBLEDeviceServices成功:',res)
+						for (var s = 0; s < res.services.length; s++) {
+							console.log(res.services[s].uuid);
+							let serviceId = res.services[s].uuid;
+							uni.getBLEDeviceCharacteristics({
+								// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
+								deviceId: deviceId,
+								// 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
+								serviceId: serviceId,
+								success(res) {
+									var re = JSON.parse(JSON.stringify(res));
+
+									console.log("deviceId = [" + deviceId + "]  serviceId = [" + serviceId + "]")
+
+									for (var c = 0; c < re.characteristics.length; c++) {
+										if (re.characteristics[c].properties.write == true) {
+											let uuid = re.characteristics[c].uuid;
+											console.log(" deviceId = [" +deviceId +"]  serviceId = [" +serviceId +"] characteristics = [" +uuid +"]");
+											//是否是直接打印
+											if(that.isAutoBle){
+												console.log('打印订单 11111111111111111111111111111111111111111111111111111111111111')
+												that.senBleLabel()
+												uni.hideLoading()
+												that.isAutoBle = false
+											}
+											for (var index in that.devices) {
+												if (that.devices[index].deviceId == deviceId) {
+													that.devices[index].services.push({serviceId: serviceId,characteristicId: uuid});
+													that.$nextTick(()=>{
+														uni.setStorageSync('BLE',that.devices[index]);
+														that.$msg("连接蓝牙-[" + that.devices[index].name + "]--成功");
+													})
+													break;
+												}
 											}
+											console.log(JSON.stringify(that.devices));
 										}
-										console.log(JSON.stringify(that.devices));
 									}
 								}
-							}
-						});
-					}
+							});
+						}
 				},
 				fail(res) {
-					console.log(res);
+					console.log('getBLEDeviceServices失败:',res)
+					uni.hideLoading()
+					uni.showLoading({title:"打印失败..."})
+					setTimeout(function(){
+						uni.hideLoading()
+					},2000)
+					// if(res.errCode && res.errCode == 10004){
+					// 	uni.showLoading({title:"重打中..."})
+					// 	that.destroyed(that.BleVal)
+					// }
 				}
 			});
 		},