فهرست منبع

Merge branch 'develop_szhj05' of http://git.chelingzhu.com/jianguan-web/qpls-md-app into develop_szhj05

chenrui 2 سال پیش
والد
کامیت
c34f2c1c94

+ 34 - 30
components/kk-printer/index.vue

@@ -16,10 +16,7 @@
 						<input type="text"  placeholder-class="kk-placeholder-class" placeholder="请输入蓝牙名字或设备ID搜索" v-model="filterName" />
 					</view> -->
 					<view style="text-align: left;">
-						<view>注意事项:</view>
-						<view>1、连接打印机之前,先打开手机蓝牙开关</view>
-						<view>2、请检查打印机是否已被其它手机连接,如果是请关闭其它手机蓝牙,然后再用您的手机连接</view>
-						<view>3、如果一直处于打印中状态,但打印机没有任何反应,请关闭app应用重新打开再试试</view>
+						<u-parse :html="content"></u-parse>
 					</view>
 					<view class="kk-btn-wrap">
 						<view class="kk-btn-item confirm-btn" @tap="searchBtnTap" v-if="!isSearching">
@@ -38,24 +35,22 @@
 							<view class="empty-text">~ 无可搜索到的设备 ~</view>
 						</view>
 						<view class="" v-else>
-							<view class="kk-devices-item flex align_center justify_between" v-for="(item,index) in filterDeviceList" :key="index" @tap="handleConnectDevice(item)">
-								<view style="text-align: left;flex-grow: 1;">
+							<view class="kk-devices-item" 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 class="flex align_center justify_between">
+										<view class="rssi">
+											<text>信号强度:</text>
+											<text>({{Math.max(0, item.RSSI + 100)}}%)</text>
+										</view>
+										<view style="width: 120rpx;text-align: right;">
+											<!-- <u-icon :size="60" color="#55aaff" name="plus-circle"></u-icon> -->
+											<u-button :loading="isConnecting" @tap="handleConnectDevice(item)" shape="circle" size="mini" :custom-style="{background:$config('primaryColor')}" type="primary">{{isConnecting?'连接中':'连接'}}</u-button>
+										</view>
 									</view>
-									<view class="deviceid">
-										<text>设备ID:</text>
-										<text>{{item.deviceId}}</text>
-									</view>
-								</view>
-								<view style="width: 120rpx;text-align: right;">
-									<!-- <u-icon :size="60" color="#55aaff" name="plus-circle"></u-icon> -->
-									<u-button :loading="isConnecting" @tap="handleConnectDevice(item)" shape="circle" size="mini" :custom-style="{background:$config('primaryColor')}" type="primary">{{isConnecting?'连接中':'连接'}}</u-button>
 								</view>
 							</view>
 						</view>
@@ -72,11 +67,21 @@
 <script>
 	import tsc from '@/components/kk-printer/printer/tsc.js'
 	// import esc from '@/components/kk-printer/printer/esc.js'
+	import * as cpcl from '@/components/kk-printer/printer/cpcl.js'
 	import * as blesdk from './utils/bluetoolth';
 	import util from './utils/util.js';
 	export default {
 		data(){
 			return{
+				content: `
+					<div style="font-size:12px;">
+					<p>注意事项:</p>
+					<p>1、连接打印机之前,先打开手机蓝牙开关</p>
+					<p>2、如果已有其它手机连接,请手动断开或重启打印机</p>
+					<p>3、如果连接打印机没有任何反应或需要切换连接其它打印机,请在“我的”页面点击“重置打印机”后再试</p>
+					<p>4、目前仅支持“得力(DL-886BW(NEW))”、“新北洋(BTP-P39)”蓝牙打印机</p>
+					</div>
+				`,
 				//是否正在打印
 				isPrinting:false,
 				//是否正在搜索设备
@@ -86,13 +91,14 @@
 				//是否显示蓝牙列表
 				isShowSearch:false,
 				//按蓝牙名过滤
-				filterName:'DL-',
+				filterName: ['DL-','BTP-'],
 				//按信号过滤
 				filterRSSI:-95,
 				//设备列表
 				devicesList:[],
 				//连接的设备ID
 				deviceId:'',
+				deviceName: '',
 				//根据设备ID获取的服务
 				services:'',
 				//获取特征值时返回的三要素
@@ -150,7 +156,7 @@
 				let filterDevices2
 				if(name!=''){
 					filterDevices2 = filterDevices1.filter((item)=>{
-						return (item.name.indexOf(name) >= 0 || item.deviceId.indexOf(name) >= 0)
+						return name.find(a => item.name.indexOf(a) >= 0 || item.deviceId.indexOf(a) >= 0)
 					})
 				}else{
 					filterDevices2 = filterDevices1
@@ -192,9 +198,11 @@
 							// 有正在连接的设备,且和上次连接设备一样
 							if(res.devices.length && res.devices[0].deviceId == lastDevice.deviceId){
 								this.deviceId = lastDevice.deviceId
+								this.deviceName = lastDevice.name
 								this.serviceId = lastDevice.serviceId
 								this.writeId = lastDevice.writeId
 								this.readId = lastDevice.readId
+								console.log(this.deviceName.indexOf('DL-')>=0?tsc:cpcl)
 								if(flag){
 									this.isPrinting = true;
 									this.$nextTick(()=>{
@@ -202,7 +210,9 @@
 											deviceId: this.deviceId,
 											serviceId: this.serviceId,
 											writeId: this.writeId
-										},tsc,blesdk)
+										},
+										this.deviceName.indexOf('DL-')>=0?tsc:cpcl,
+										blesdk)
 									})
 								}
 							}else{
@@ -254,7 +264,7 @@
 				let deviceId = device.deviceId;
 				let name = device.name;
 				this.deviceId = deviceId;
-				console.log('deviceId',this.deviceId)
+				this.deviceName = name;
 				this.isConnecting = true
 				this.stopSearchBtnTap()
 				uni.onBLEConnectionStateChange(function(res){
@@ -307,7 +317,7 @@
 				this.readId = res.readId;
 				this.isShowSearch = false;
 				try {
-					uni.setStorageSync('vuex_lastBuleDevice', {deviceId:this.deviceId,serviceId:this.serviceId,writeId:this.writeId,readId:this.readId});
+					uni.setStorageSync('vuex_lastBuleDevice', {deviceId:this.deviceId,serviceId:this.serviceId,writeId:this.writeId,readId:this.readId,name:this.deviceName});
 				} catch (e) {
 					// error
 				}
@@ -357,7 +367,7 @@
 				z-index: 10000;
 				.kk-modal{
 					width:680upx;
-					height: 60%;
+					height: 80%;
 					padding:24upx;
 					box-sizing: border-box;
 					overflow-y: auto;
@@ -449,17 +459,11 @@
 							.kk-devices-item{
 								width:100%;
 								border-bottom: 1upx solid #ebebeb;
-								padding:10upx 0;
+								padding:20upx 0;
 								box-sizing: border-box;
 								&:nth-last-child(1){
 									border-bottom: none;
 								}
-								> view{
-									&:first-child{
-										flex-grow: 1;
-										width: 80%;
-									}
-								}
 								button{
 									width: auto;
 								}

+ 284 - 118
components/kk-printer/printer/cpcl.js

@@ -1,122 +1,288 @@
+/* 16hex insert 0 */
+function Hex2Str(num) {
+	if (num.toString(16).length < 2) return "0" + num.toString(16);
+	else
+		return num.toString(16);
+}
+/*****CPCL指令接口****/
+
 /**
- * cpcl 命令打印工具类
- * 2021.04.26 uni-app版本
- * @auth boolTrue
- */
-var gbk = require("./printUtil-GBK.js");
-var jpPrinter = {
-	createNew: function() {
-		var jpPrinter = {};
-		var data = "";
-		var command = []
-		var rawCommand = ''
-
-		jpPrinter.name = "标签模式";
-		
-		jpPrinter.addCommand = function(content) { //将指令转成数组装起
-			rawCommand += content
-		}
-		
-		jpPrinter.init = function(width, height, printNum, rotation = 0, offset = 0) {
-			var strCmd = '! ' + offset + ' 200 200 ' + height + ' ' + printNum + '\n';
-			strCmd += "PAGE-WIDTH " + width + '\n';
-			if (rotation == 1)
-				strCmd += "ZPROTATE90\n";
-			else if (rotation == 2)
-				strCmd += "ZPROTATE180\n";
-			else if (rotation == 3)
-				strCmd += "ZPROTATE270\n";
-			else
-				strCmd += "ZPROTATE0\n";
-			jpPrinter.addCommand(strCmd)
-		};
-		
-		jpPrinter.setText = function(x, y, font, xsize, ysize, str) { //横向打印文字
-			data = "T " + "4" + " " + xsize + " " + x + " " + y + " " + str + "\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setGap = function(pageWidth) { //设置标签模式
-			data = "GAP-SENSE" + "\n";
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setSpeed = function(printSpeed) { //设置打印机速度0 - 5
-			data = "SPEED " + printSpeed + "\n";
-			jpPrinter.addCommand(data)
-		};
-
-		jpPrinter.setDensity = function(printDensity) { //设置打印机浓度最亮的打印输出为对比度级别 0。最暗的对比度级别为 3。
-			data = "CONTRAST " + printDensity + "\n";
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setMag = function(w,h) { //字体放大指定的放大倍数。
-			data = "SETMAG " + w + " " + h + "\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setLine = function(x0, y0, x1, y1, width) { //绘制线条
-			data = "LINE " + x0 + " " + y0 + " " + x1 + " " + y1 + " " + width + "\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setBox = function(x_start, y_start, x_end, y_end, thickness) { //绘制方框
-			data = "BOX " + x_start + " " + y_start + " " + x_end + " " + y_end + " " + thickness + "\n";
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setFeed = function(feed) { //将纸向前推出n
-			data = "PREFEED " + feed + "\n";
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setQR = function(x, y, level, ver, scale, content) { //打印二维码
-			var strCmd = 'B QR ' + x + ' ' + y + ' M ' + ver + ' U ' + scale + '\n' + level + 'A,' + content + '\n';
-			strCmd += 'ENDQR\n';
-			jpPrinter.addCommand(strCmd)
-		};
-		
-		jpPrinter.setBar = function(type, width, ratio, height, x, y, content) { //打印条形码
-			data = "BARCODE " + type + " " + width + " " + ratio + " " + height + " " + x + " " + y + " " + content + "\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setSound = function(interval) { //控制蜂鸣器,蜂鸣持续时间
-			data = "BEEP " + interval + "\n";
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setPageForm = function() { //换页
-			data = "FORM "+"\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setPagePrint = function() { //打印页面
-			data = "PRINT "+"\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		// 添加命令
-		jpPrinter.RawCommand = function(data) {
-			jpPrinter.addCommand(data)
-		}
-		
-		//获取打印数据
-		jpPrinter.getData = function() {
-			let buffer = gbk.strToGBKByte(rawCommand)
-			return buffer;
-		};
-
-		jpPrinter.getRawData = function() {
-			return rawCommand;
-		};
-		jpPrinter.clearCommand = function() {
-			rawCommand = ''
-		};
-
-		return jpPrinter;
+ * 配置项如下
+ *
+ * width: 标签纸的宽度,单位像素點
+ * height: 标签纸的高度,单位像素點
+ * 8像素=1mm
+ * printNum: 打印张数,默认为1
+ * rotation:页面整体旋转 1-90度 2-180度 3-270度 其他-不旋转
+ */
+export function CreatCPCLPage(width, height, printNum, rotation = 0, offset = 0) {
+	var strCmd = '! ' + offset + ' 203 203 ' + height + ' ' + printNum + '\n';
+	strCmd += "PAGE-WIDTH " + width + '\n';
+	if (rotation == 1)
+		strCmd += "ZPROTATE90\n";
+	else if (rotation == 2)
+		strCmd += "ZPROTATE180\n";
+	else if (rotation == 3)
+		strCmd += "ZPROTATE270\n";
+	else
+		strCmd += "ZPROTATE0\n";
+	return strCmd;
+}
+
+/**
+ * 打印文字
+ * x: 文字方块左上角X座标,单位dot
+ * y: 文字方块左上角Y座标,单位dot
+ * fontName,fontSize: 字体,取值: 參考文檔
+ * rotation: 旋转 1-90度 2-180度 3-270度 其他-不旋转 
+ * content: 文字内容
+ */
+export function addCPCLText(x, y, fontName, fontSize, rotation, content) {
+	//console.log(fontName,fontSize,rotation, content);   
+	var strCmd = '';
+	if (rotation == 1) {
+		strCmd += 'T90 ';
+	}
+	if (rotation == 2) {
+		strCmd += 'T180 ';
+	}
+	if (rotation == 3) {
+		strCmd += 'T270 ';
+	} else {
+		strCmd += 'T ';
+	}
+	strCmd += fontName + ' ' + fontSize + ' ' + x + ' ' + y + ' ' + content + '\n';
+	return strCmd;
+};
+
+/**
+ * 打印一维码
+ *
+ * x: 文字方块左上角X座标,单位dot
+ * y: 文字方块左上角Y座标,单位dot
+ * codeType: 条码类型,取值为128、UPCA、UPCA2、UPCA5、UPCE、UPCE2、UPC5、EAN13、EAN13+2、EAN13+5、
+ *      EAN8、EAN8+2、EAN8+5、39、39C、F39、F39C、93、CODABAR、CODABAR16、ITF、I2OF5
+ * h: 条码高度,单位dot 
+ * rotation: 顺时针旋转角度,取值如下:
+ *     - 0 不旋转
+ *     - 1 顺时针旋转90度
+ *     
+ * narrow: 窄条码比例因子(dot) 取值: 參考文檔
+ * wide: 宽条码比例因子(dot) 取值: 參考文檔
+ * content: 文字内容
+ *
+ */
+export function addCPCLBarCode(x, y, codeType, h, rotation, narrow, wide, content) {
+	var strCmd = '';
+	if (rotation == 0)
+		strCmd += 'B ';
+	else
+		strCmd += 'VB ';
+	strCmd += codeType + ' ' + narrow + ' ' + wide + ' ' + h + ' ' + x + ' ' + y + ' ' + content + '\n'
+	return strCmd;
+};
+
+/**
+ * 打印二维码
+ *
+ * x: 文字方块左上角X座标,单位dot
+ * y: 文字方块左上角Y座标,单位dot
+ * level: 错误纠正能力等级,取值为L(7%)、M(15%)、Q(25%)、H(30%)
+ * ver: 1-10 版本,根据内容调整以获取合适容量
+ * scale: 1-10 放大倍数
+ * content: 文字内容
+ *
+ */
+export function addCPCLQRCode(x, y, level, ver, scale, content) {
+	var strCmd = 'B QR ' + x + ' ' + y + ' M ' + ver + ' U ' + scale + '\n' + level + 'A,' + content + '\n';
+	strCmd += 'ENDQR\n';
+	return strCmd;
+};
+
+/**
+ * 放大指令
+ * scaleX: 横向放大倍数 1,2,3等整数
+ * scaleY: 纵向放大倍数 1,2,3等整数
+ */
+export function addCPCLSETMAG(scaleX, scaleY) {
+	var strCmd = 'SETMAG ' + scaleX + ' ' + scaleY + '\n';
+	return strCmd;
+};
+
+/**
+ * 对齐指令 0-左对齐 1-右对齐 2-居中
+ */
+export function addCPCLLocation(set) {
+	var strCmd = '';
+	if (set == 1) {
+		strCmd += 'RIGHT\n';
+	} else if (set == 2) {
+		strCmd += 'CENTER\n';
+	} else {
+		strCmd += 'LEFT\n';
+	}
+	return strCmd;
+};
+
+/**
+ * 反白线 x0,y0,x1,y1,width
+ */
+export function addCPCLInverseLine(x0, y0, x1, y1, width) {
+	var strCmd = 'IL ' + x0 + ' ' + y0 + ' ' + x1 + ' ' + y1 + ' ' + width + '\n';
+	return strCmd;
+};
+
+/**
+ * 画线 x0,y0,x1,y1,width
+ */
+export function addCPCLLine(x0, y0, x1, y1, width) {
+	var strCmd = 'L ' + x0 + ' ' + y0 + ' ' + x1 + ' ' + y1 + ' ' + width + '\n';
+	return strCmd;
+};
+
+/**
+ * 画框 x0,y0,x1,y1,width
+ */
+export function addCPCLBox(x0, y0, x1, y1, width) {
+	var strCmd = 'BOX ' + x0 + ' ' + y0 + ' ' + x1 + ' ' + y1 + ' ' + width + '\n';
+	return strCmd;
+};
+
+/**
+ * 字体加粗
+ */
+export function addCPCLSETBOLD(bold) {
+	var strCmd = 'SETBOLD ' + bold + '\n';
+	return strCmd;
+};
+
+/**
+ * 字体下划线
+ */
+export function addCPCLUNDERLINE(c) {
+	var strCmd = 'UNDERLINE ';
+	if (c) strCmd += 'ON\n';
+	else if (c) strCmd += 'OFF\n';
+	return strCmd;
+};
+
+/**
+ * 水印打印灰度等级 0-255
+ */
+export function addCPCLBACKGROUND(level) {
+	var strCmd = 'BACKGROUND ';
+	if (level > 255 || level < 0) level = 255;
+	strCmd += level + '\n';
+	return strCmd;
+};
+
+/**
+ * 打印水印文字
+ * x: 文字方块左上角X座标,单位dot
+ * y: 文字方块左上角Y座标,单位dot
+ * fontName,fontSize: 字体,取值: 參考文檔
+ * rotation: 旋转 1-90度 2-180度 3-270度 其他-不旋转 
+ * content: 文字内容
+ */
+export function addCPCLBKVText(x, y, fontName, fontSize, rotation, content) {
+	//console.log(fontName,fontSize,rotation, content);   
+	var strCmd = '';
+	if (rotation == 1) {
+		strCmd += 'BKT90 ';
+	}
+	if (rotation == 2) {
+		strCmd += 'BKT180 ';
+	}
+	if (rotation == 3) {
+		strCmd += 'BKT270 ';
+	} else {
+		strCmd += 'BKT ';
 	}
+	strCmd += fontName + ' ' + fontSize + ' ' + x + ' ' + y + ' ' + content + '\n';
+	return strCmd;
+};
+
+
+/**
+ * 标签缝隙定位指令
+ */
+export function addCPCLGAP() {
+	var strCmd = 'GAP-SENSE\nFORM\n';
+	return strCmd;
 };
 
-module.exports.jpPrinter = jpPrinter;
+/**
+ * 标签右黑标检测指令
+ */
+export function addCPCLSENSE() {
+	var strCmd = 'BAR-SENSE\nFORM\n';
+	return strCmd;
+};
+
+/**
+ * 标签左黑标检测指令
+ */
+export function addCPCLSENSELEFT() {
+	var strCmd = 'BAR-SENSE LEFT\nFORM\n';
+	return strCmd;
+};
+
+/**
+ * 打印指令
+ */
+export function addCPCLPrint() {
+	var strCmd = 'PRINT\n';
+	return strCmd;
+};
+
+/**
+ * 图片打印指令
+ * x: 文字方块左上角X座标,单位dot
+ * y: 文字方块左上角Y座标,单位dot
+ * data{
+            threshold,//0/1提取的灰度级
+            width,//图像宽度
+            height,//图像高度
+            imageData , //图像数据
+    }
+ */
+export function addCPCLImageCmd(x, y, data) {
+	var strImgCmd = '';
+	const threshold = data.threshold || 180;
+	let myBitmapWidth = data.width,
+		myBitmapHeight = data.height;
+	let len = parseInt((myBitmapWidth + 7) / 8); //一行的数据长度
+	//console.log('len=',len);
+	//console.log('myBitmapWidth=',myBitmapWidth);
+	//console.log('myBitmapHeight=',myBitmapHeight);
+	let ndata = 0;
+	let i = 0;
+	let j = 0;
+	let sendImageData = new ArrayBuffer(len * myBitmapHeight);
+	sendImageData = new Uint8Array(sendImageData);
+	let pix = data.imageData;
+	console.log('pix=', pix);
+
+	for (i = 0; i < myBitmapHeight; i++) {
+		for (j = 0; j < len; j++) {
+			sendImageData[ndata + j] = 0;
+		}
+		for (j = 0; j < myBitmapWidth; j++) {
+			const grayPixle1 = grayPixle(pix.slice((i * myBitmapWidth + j) * 4, (i * myBitmapWidth + j) * 4 + 3));
+			if (grayPixle1 < threshold)
+				sendImageData[ndata + parseInt(j / 8)] |= (0x80 >> (j % 8));
+
+		}
+		ndata += len;
+	}
+	//console.log('sendImageData=',sendImageData);
+	//CPCL指令图片数据 
+	strImgCmd += 'EG ' + len + ' ' + myBitmapHeight + ' ' + x + ' ' + y + ' ';
+	for (i = 0; i < sendImageData.length; i++) {
+		strImgCmd += Hex2Str(sendImageData[i]);
+	}
+	strImgCmd += '\n';
+	//console.log(strImgCmd);
+	return strImgCmd;
+}
+module.exports.type = 'cpcl';

+ 1 - 0
components/kk-printer/printer/esc.js

@@ -311,3 +311,4 @@ var jpPrinter = {
 };
 
 module.exports.jpPrinter = jpPrinter;
+module.exports.type = 'esc';

+ 1 - 0
components/kk-printer/printer/tsc.js

@@ -384,3 +384,4 @@ var jpPrinter = {
 };
 
 module.exports.jpPrinter = jpPrinter;
+module.exports.type = 'tsc';

+ 32 - 2
components/kk-printer/utils/bluetoolth.js

@@ -250,7 +250,7 @@ export function onGetBLECharacteristicValueChange(options, onChange = function()
 			lasterSuccess,
     }
  */
-export function senBlData(deviceId, serviceId, characteristicId,uint8Array,lasterSuccess) {
+export function senBlData(deviceId, serviceId, characteristicId,uint8Array,lasterSuccess,lasterError) {
 	console.log('************deviceId = [' + deviceId + ']  serviceId = [' + serviceId + '] characteristics=[' +characteristicId+ "]")
 	var uint8Buf = Array.from(uint8Array);
 	function split_array(datas,size){
@@ -292,13 +292,43 @@ export function senBlData(deviceId, serviceId, characteristicId,uint8Array,laste
 			},
 			fail(e) {
 				console.log('发送数据失败',e)
+				lasterError()
 			}
 		})
 	}
    var i = 0;
 	realWriteData(sendloop, i);
 }
- 
+// cpcl 发送数据
+export function sendDataToDevice(options) {
+	let byteLength = options.value.byteLength;
+	//这里默认一次20个字节发送
+	const speed = plus.os.name != 'Android' ? 180 : 15; //20; 
+	console.log("send data 20");
+	console.log(options,byteLength,options.value);
+	if (byteLength > 0) {
+		uniAsyncPromise('writeBLECharacteristicValue', {
+				...options,
+				value: options.value.slice(0, byteLength > speed ? speed : byteLength),
+			})
+			.then((res) => {
+				if (byteLength > speed) {
+					setTimeout(()=>{
+						sendDataToDevice({
+							...options,
+							value: options.value.slice(speed, byteLength),
+						});
+					},50)
+				} else {
+					options.lasterSuccess && options.lasterSuccess();
+				}
+			})
+			.catch((res) => {
+				console.log(res);
+				options.lasterError && options.lasterError();
+			});
+	}
+} 
 /**
  * toast显示捕获的蓝牙异常
  */

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 13 - 0
components/kk-printer/utils/printUtil-GBK.js


+ 71 - 0
libs/printTools.js

@@ -1,3 +1,4 @@
+import gbk from '@/components/kk-printer/utils/printUtil-GBK.js';
 // 获取文本字节总数
 export const getBytesCount = function(str){
 	var bytesCount = 0;
@@ -110,6 +111,76 @@ export const printTempl = function(tsc,data){
 	return command
 }
 
+// 格式化cpcl打印文本
+export const textCpclFormat = function(cpcl,text,maxFontNums,left,top,lightHeight,align,fontName,fontSize){
+	let rowTop = top
+	const maxNums = maxFontNums
+	const rowHeight = lightHeight
+	const textArr = getTextRows(text.replace(/\s+/g, ' '),maxNums*2)
+	const rows = textArr.length
+	let result = ''
+	for(let i=0;i<rows;i++){
+		if(align=="center"){
+			result += cpcl.addCPCLLocation(2)
+		}
+		else{
+			result += cpcl.addCPCLLocation(0)
+		}
+		result += cpcl.addCPCLText(left,rowTop,fontName,fontSize,0,textArr[i]);
+		rowTop = rowTop+rowHeight+5
+	}
+	return {result:result,top:rowTop}
+}
+// 60 * 40 尺寸模板 cpcl 指令
+export const printCpclTempl = function(cpcl,data){
+	console.log(cpcl)
+	let top = 0 // 距离顶部
+	const left = 8 // 距离左边
+	const lightHeight = 24 // 行高3mm,1mm = 8点
+	const pageW = 60 // 页签宽度mm
+	const pageH = 40 // 页签高度mm
+	const maxFontNums = Math.floor((pageW*8-left*4)/lightHeight) // 每行最多字体数
+	const leftMaxFnums = Math.floor(maxFontNums*0.4)
+	const rightMaxFnums = leftMaxFnums + 2
+	let rightLeft = (leftMaxFnums+2)*lightHeight
+	// 初始化打印机
+	let strCmd =cpcl.CreatCPCLPage(pageW*8,pageH*8,data.currentInven,0);
+	// 经销商文字高度,是否换行
+	const a = textCpclFormat(cpcl,data.dealerName,maxFontNums,0,top,lightHeight,"center",'24',0);
+	top = a.top;
+	strCmd += a.result;
+	// 数字货架名称文字
+	top = top+10;
+	const b = textCpclFormat(cpcl,data.shelfName,maxFontNums,0,top,lightHeight,"center",'24',0);
+	top = b.top;
+	strCmd += b.result;
+	// 二维码
+	top = top+15;
+	strCmd += cpcl.addCPCLLocation(0);
+	strCmd += cpcl.addCPCLQRCode(left*5,top,'M', 3, 5, data.barCode);
+	// 货位号
+	strCmd += cpcl.addCPCLSETMAG(4,4);
+	const c = textCpclFormat(cpcl,data.shelfPlaceCode,rightMaxFnums,rightLeft,top,lightHeight,"left",'7',0);
+	const rightTop = c.top;
+	strCmd += c.result;
+	// 产品编码
+	top = rightTop + 65;
+	strCmd += cpcl.addCPCLSETMAG(1,1);
+	const d = textCpclFormat(cpcl,data.productCode,rightMaxFnums,rightLeft,top,lightHeight,"left",'7',0);
+	top = d.top;
+	strCmd += d.result;
+	// 打印人打印时间
+	top = top+4;
+	strCmd += cpcl.addCPCLSETMAG(1,1);
+	const e = textCpclFormat(cpcl,data.printDate,rightMaxFnums,rightLeft,top,lightHeight,"left",'7',0);
+	top = e.top;
+	strCmd += e.result;
+	strCmd += 'FORM \n'
+	strCmd += cpcl.addCPCLPrint();
+	console.log(strCmd)
+	return gbk.strToGBKByte(strCmd);
+}
+
 // 40 * 30 尺寸模板
 export const printMiniTempl = function(tsc,data){
 	let top = 24 // 距离顶部

+ 2 - 2
manifest.json

@@ -100,8 +100,8 @@
                     "NSPhotoLibraryAddUsageDescription" : "扫描识别产品需要访问设备相册,是否同意?", //可选,字符串类型,系统相册写入权限描述
                     "NSCameraUsageDescription" : "扫描识别产品二维码需要访问相机,是否同意?", //可选,字符串类型,摄像头使用权限描述
                     "NSLocationWhenInUseUsageDescription" : "连接打印机需要开启位置权限,是否同意?", //可选,字符串类型,运行期访问位置权限描述
-					"NSLocationAlwaysUsageDescription": "连接打印机需要开启位置权限,是否同意?",  //可选,字符串类型,后台运行访问位置权限描述
-					"NSLocationAlwaysAndWhenInUseUsageDescription": "连接打印机需要开启位置权限,是否同意?", //可选,字符串类型,运行期后后台访问位置权限描述
+                    "NSLocationAlwaysUsageDescription" : "连接打印机需要开启位置权限,是否同意?", //可选,字符串类型,后台运行访问位置权限描述
+                    "NSLocationAlwaysAndWhenInUseUsageDescription" : "连接打印机需要开启位置权限,是否同意?", //可选,字符串类型,运行期后后台访问位置权限描述
                     "NSBluetoothPeripheralUsageDescription" : "连接打印机需要开启蓝牙权限,是否同意?", //可选,字符串类型,使用蓝牙权限描述
                     "NSBluetoothAlwaysUsageDescription" : "连接打印机需要开启蓝牙权限,是否同意?" //可选,字符串类型,后台使用蓝牙权限描述
                 }

+ 35 - 16
pages/batchShelves/batchPrint/batchPrint.vue

@@ -38,7 +38,7 @@
 	import { clzConfirm, numberToFixed } from '@/libs/tools';
 	import kkPrinter from '@/components/kk-printer/index.vue';
 	import productList from './productList.vue'
-	import {printTempl} from '@/libs/printTools.js'
+	import {printTempl,printCpclTempl} from '@/libs/printTools.js'
 	export default {
 		components: { productList, kkPrinter },
 		data() {
@@ -144,11 +144,10 @@
 			allCheckedCallback(val){
 				this.allChecked = val
 			},
-			printOnce(opt,tsc,blesdk,data){
+			printOnce(opt,cmd,blesdk,data){
 				const _this = this
 				const dealer = this.$store.state.vuex_userData
-				// 60*40 打印模板
-				const command = printTempl(tsc,{
+				const paramsData = {
 					dealerName: dealer.orgName,
 					shelfName: this.basicInfoData.shelfName || '',
 					productCode: data.productCode || '',
@@ -158,18 +157,13 @@
 					printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
 					printUser: dealer.userNameCN,
 					barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
-				})
-				// 开始批量打印 
-				blesdk.senBlData(
-				opt.deviceId, 
-				opt.serviceId, 
-				opt.writeId, 
-				command.getData(), 
-				function(){
+				}
+				// 打印成功后函数
+				const onPrintSuccess = function(){
 					const result =_this.$refs.productList.getAllChecked()
 					_this.printIndex = _this.printIndex + 1
 					if(_this.printIndex < result.length){
-						_this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
+						_this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
 					}else{
 						_this.printIndex = 0
 						_this.$refs.kkprinter.onPrintSuccess()
@@ -185,14 +179,39 @@
 						  }
 						})
 					}
-				});
+				}
+				// 开始批量打印
+				// tsc 指令 // 60*40 打印模板
+				console.log(cmd,cmd.type)
+				if(cmd.type&&cmd.type=='tsc'){
+					const command = printTempl(cmd,paramsData)
+					blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), onPrintSuccess, this.onPrintError);
+				}else{
+					const resultData = printCpclTempl(cmd,paramsData)
+					blesdk.sendDataToDevice({
+						deviceId: opt.deviceId, 
+						serviceId: opt.serviceId, 
+						characteristicId: opt.writeId,
+						value: resultData,
+						lasterSuccess: onPrintSuccess,
+						lasterError: this.onPrintError
+					});
+				}
 			},
 			closeConnect(){
 				this.isParinting = false
 				uni.hideLoading()
 			},
+			onPrintError(){
+				this.$refs.kkprinter.onPrintFail()
+				this.isParinting = false
+				this.show = false
+				uni.showToast({
+					title: '打印失败,请重试!'
+				})
+			},
 			// 批量打印 
-			startPrint(opt,tsc,blesdk){
+			startPrint(opt,cmd,blesdk){
 				const result =this.$refs.productList.getAllChecked()
 				console.log(result,result.length)
 				if(result.length){
@@ -204,7 +223,7 @@
 					 	mask: true,
 					 	title: '正在打印中,请勿息屏或退出应用!'
 					 })
-					 this.printOnce(opt,tsc,blesdk,result[this.printIndex])
+					 this.printOnce(opt,cmd,blesdk,result[this.printIndex])
 				}else{
 					this.toashMsg("请选择产品!")
 					this.$refs.kkprinter.onPrintFail()

+ 26 - 5
pages/common/printTag/printTag.vue

@@ -39,7 +39,7 @@
 	import { clzConfirm, numberToFixed } from '@/libs/tools';
 	import { shelfDetail } from '@/api/shelf'
 	import kkPrinter from '@/components/kk-printer/index.vue';
-	import {printTempl} from '@/libs/printTools.js'
+	import {printTempl,printCpclTempl} from '@/libs/printTools.js'
 	import moment from 'moment'
 	export default {
 		components:{
@@ -143,8 +143,8 @@
 				uni.hideLoading()
 			},
 			// 打印
-			startPrint(opt,tsc,blesdk){
-				console.log(opt,'opt')
+			startPrint(opt,cmd,blesdk){
+				console.log(opt,cmd,'opt')
 				this.getPrintContent()
 				if(this.printInfo.currentInven<=0){
 					uni.showToast({
@@ -159,8 +159,21 @@
 				}
 				this.isParinting = true
 				this.show = true
-				const command = printTempl(tsc,this.printInfo)
-				blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), this.onPrintSuccess);
+				// tsc 指令
+				if(cmd.type&&cmd.type=='tsc'){
+					const command = printTempl(cmd,this.printInfo)
+					blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), this.onPrintSuccess);
+				}else{
+					const resultData = printCpclTempl(cmd,this.printInfo)
+					blesdk.sendDataToDevice({
+										deviceId: opt.deviceId, 
+										serviceId: opt.serviceId, 
+										characteristicId: opt.writeId,
+										value: resultData,
+										lasterSuccess: this.onPrintSuccess,
+										lasterError: this.onPrintError
+									});
+				}
 			},
 			// 打印成功
 			onPrintSuccess(){
@@ -176,6 +189,14 @@
 					} 
 				  }
 				})
+			},
+			onPrintError(){
+				this.$refs.kkprinter.onPrintFail()
+				this.isParinting = false
+				this.show = false
+				uni.showToast({
+					title: '打印失败,请重试!'
+				})
 			}
 		}
 	}

+ 6 - 0
pages/latePlay/chooseProduct.vue

@@ -117,6 +117,12 @@
 			this.getpartList()
 			this.getShelfPlace()
 		},
+		onBackPress() {
+			if(this.showTab){
+				this.showTab = false
+				return true
+			}
+		},
 		// 批量打印
 		onNavigationBarButtonTap(e) {
 			if(this.queryWord=='' && this.placeTab.length>1){

+ 48 - 26
pages/replenishmentManage/manualPrint.vue

@@ -22,7 +22,7 @@
 	import kkPrinter from '@/components/kk-printer/index.vue';
 	import { shelfReplenishDetail, shelfReplenishDetailList, shelfReplenishPrintSign } from '@/api/shelfReplenish'
 	import partList from '@/pages/common/partList.vue'
-	import {printTempl} from '@/libs/printTools.js'
+	import {printTempl,printCpclTempl} from '@/libs/printTools.js'
 	export default {
 		components: { partList, kkPrinter },
 		data() {
@@ -113,33 +113,29 @@
 			allCheckedCallback(val){
 				this.allChecked = val
 			},
-			printOnce(opt,tsc,blesdk,data){
+			printOnce(opt,cmd,blesdk,data){
 				const _this = this
-				const dealer = this.$store.state.vuex_userData
 				// 60*40 打印模板
-				const command = printTempl(tsc,{
-					dealerName: dealer.orgName,
-					shelfName: this.basicInfoData.shelfInfo.shelfName || '',
-					productCode: data.productCode || '',
-					productName: data.product.name || '',
-					shelfPlaceCode: data.shelfPlaceCode || '',
-					currentInven: data.printQty,
-					printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
-					printUser: dealer.userNameCN,
-					barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
-					// barCode: `dealerSn=${dealer.orgSn}&shelfSn=${data.shelfSn}&productSn=${data.productSn}&productCode=${data.productCode}&shelfPlaceCode=${data.shelfPlaceCode}&shelfPlaceSn=${data.shelfPlaceSn}`
-				})
-				// 开始批量打印 
-				blesdk.senBlData(
-				opt.deviceId, 
-				opt.serviceId, 
-				opt.writeId, 
-				command.getData(), 
-				function(){
+				const dealer = this.$store.state.vuex_userData
+				const paramsData = {
+						dealerName: dealer.orgName,
+						shelfName: this.basicInfoData.shelfInfo.shelfName || '',
+						productCode: data.productCode || '',
+						productName: data.product.name || '',
+						shelfPlaceCode: data.shelfPlaceCode || '',
+						currentInven: data.printQty,
+						printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
+						printUser: dealer.userNameCN,
+						barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
+						// barCode: `dealerSn=${dealer.orgSn}&shelfSn=${data.shelfSn}&productSn=${data.productSn}&productCode=${data.productCode}&shelfPlaceCode=${data.shelfPlaceCode}&shelfPlaceSn=${data.shelfPlaceSn}`
+					}
+				
+				// 打印成功后函数
+				const onPrintSuccess = function(){
 					const result =_this.$refs.partList.getAllChecked()
 					_this.printIndex = _this.printIndex + 1
 					if(_this.printIndex < result.length){
-						_this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
+						_this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
 					}else{
 						_this.printIndex = 0
 						_this.$refs.kkprinter.onPrintSuccess()
@@ -155,14 +151,40 @@
 						  }
 						})
 					}
-				});
+				}
+				// tsc 指令
+				console.log(cmd,cmd.type)
+				if(cmd.type&&cmd.type=='tsc'){
+					const command = printTempl(cmd,paramsData)
+					// 开始批量打印
+					blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), onPrintSuccess, this.onPrintError);
+				}else{
+					const resultData = printCpclTempl(cmd,paramsData)
+					blesdk.sendDataToDevice({
+						deviceId: opt.deviceId, 
+						serviceId: opt.serviceId, 
+						characteristicId: opt.writeId,
+						value: resultData,
+						lasterSuccess: onPrintSuccess,
+						lasterError: this.onPrintError
+					});
+				}
+				
 			},
 			closeConnect(){
 				this.isParinting = false
 				uni.hideLoading()
 			},
+			onPrintError(){
+				this.$refs.kkprinter.onPrintFail()
+				this.isParinting = false
+				this.show = false
+				uni.showToast({
+					title: '打印失败,请重试!'
+				})
+			},
 			// 批量打印 
-			startPrint(opt,tsc,blesdk){
+			startPrint(opt,cmd,blesdk){
 				const result =this.$refs.partList.getAllChecked()
 				if(result.length){
 					 if(this.isParinting){
@@ -173,7 +195,7 @@
 					 	mask: true,
 					 	title: '正在打印中,请勿息屏或退出应用!'
 					 })
-					 this.printOnce(opt,tsc,blesdk,result[this.printIndex])
+					 this.printOnce(opt,cmd,blesdk,result[this.printIndex])
 				}else{
 					this.toashMsg("请选择产品!")
 					this.$refs.kkprinter.onPrintFail()

+ 6 - 0
pages/sales/list.vue

@@ -41,6 +41,12 @@
 		onNavigationBarButtonTap(e){  // 标题栏 按钮操作
 			this.openModal = true
 		},
+		onBackPress() {
+			if(this.openModal){
+				this.openModal = false
+				return true
+			}
+		},
 		onReady() {
 			const query = uni.createSelectorQuery().in(this);
 			query.select('#tjCons').boundingClientRect(data => {

+ 6 - 0
pages/sales/productPricing.vue

@@ -96,6 +96,12 @@
 		onNavigationBarButtonTap(e){
 			this.showModal=true
 		},
+		onBackPress() {
+			if(this.showModal){
+				this.showModal = false
+				return true
+			}
+		},
 		computed: {
 			selPriceShow() {
 				const a = this.priceList.filter(item => item.checked)

+ 7 - 0
pages/shelfOrder/shelfOrder.vue

@@ -55,6 +55,13 @@
 			this.openModal = true
 			this.openShlefModal = false
 		},
+		onBackPress() {
+			if(this.openModal||this.openShlefModal){
+				this.openModal = false
+				this.openShlefModal = false
+				return true
+			}
+		},
 		onReady() {
 			const query = uni.createSelectorQuery().in(this);
 			query.select('#tjCons').boundingClientRect(data => {

+ 46 - 20
pages/shelfSetting/batchPrint.vue

@@ -24,7 +24,7 @@
 	import { clzConfirm, numberToFixed } from '@/libs/tools';
 	import kkPrinter from '@/components/kk-printer/index.vue';
 	import productList from './productList.vue'
-	import {printTempl} from '@/libs/printTools.js'
+	import {printTempl,printCpclTempl} from '@/libs/printTools.js'
 	export default {
 		components: { productList, kkPrinter },
 		data() {
@@ -37,9 +37,6 @@
 			}
 		},
 		onReady() {
-			uni.showLoading({
-				title: '正在加载...'
-			})
 			this.$refs.productList.setData(this.partList)
 			setTimeout(()=>{
 				uni.hideLoading()
@@ -48,11 +45,14 @@
 					this.allCheckeChange({value: true})
 					this.allChecked = true
 				}
-			},3000)
+			},Math.floor(this.partList.length * 15))
 		},
 		onLoad(option) {
 			this.basicInfoData = JSON.parse(decodeURIComponent(option.data));
 			this.partList = this.$store.state.vuex_tempPrintList
+			uni.showLoading({
+				title: '正在加载...'
+			})
 			// 保持屏幕常亮
 			uni.setKeepScreenOn({
 				keepScreenOn: true
@@ -92,11 +92,10 @@
 			allCheckedCallback(val){
 				this.allChecked = val
 			},
-			printOnce(opt,tsc,blesdk,data){
+			printOnce(opt,cmd,blesdk,data){
 				const _this = this
 				const dealer = this.$store.state.vuex_userData
-				// 60*40 打印模板
-				const command = printTempl(tsc,{
+				const paramsData = {
 					dealerName: dealer.orgName,
 					shelfName: data.shelfName || '',
 					productCode: data.productCode || '',
@@ -106,18 +105,12 @@
 					printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
 					printUser: dealer.userNameCN,
 					barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
-				})
-				// 开始批量打印 
-				blesdk.senBlData(
-				opt.deviceId, 
-				opt.serviceId, 
-				opt.writeId, 
-				command.getData(), 
-				function(){
+				}
+				const onPrintSuccess = function(){
 					const result =_this.$refs.productList.getAllChecked()
 					_this.printIndex = _this.printIndex + 1
 					if(_this.printIndex < result.length){
-						_this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
+						_this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
 					}else{
 						_this.printIndex = 0
 						_this.$refs.kkprinter.onPrintSuccess()
@@ -133,14 +126,47 @@
 						  }
 						})
 					}
-				});
+				}
+				// 开始批量打印
+				// tsc 指令 // 60*40 打印模板
+				console.log(cmd,cmd.type)
+				if(cmd.type&&cmd.type=='tsc'){
+					const command = printTempl(cmd,paramsData)
+					// 开始批量打印 
+					blesdk.senBlData(
+					opt.deviceId, 
+					opt.serviceId, 
+					opt.writeId, 
+					command.getData(), 
+					onPrintSuccess
+					);
+				}else{
+					const resultData = printCpclTempl(cmd,paramsData)
+					blesdk.sendDataToDevice({
+						deviceId: opt.deviceId, 
+						serviceId: opt.serviceId, 
+						characteristicId: opt.writeId,
+						value: resultData,
+						lasterSuccess: onPrintSuccess,
+						lasterError: this.onPrintError
+					});
+				}
+				
 			},
 			closeConnect(){
 				this.isParinting = false
 				uni.hideLoading()
 			},
+			onPrintError(){
+				this.$refs.kkprinter.onPrintFail()
+				this.isParinting = false
+				this.show = false
+				uni.showToast({
+					title: '打印失败,请重试!'
+				})
+			},
 			// 批量打印 
-			startPrint(opt,tsc,blesdk){
+			startPrint(opt,cmd,blesdk){
 				const result =this.$refs.productList.getAllChecked()
 				console.log(result,result.length)
 				if(result.length){
@@ -152,7 +178,7 @@
 					 	mask: true,
 						title: '正在打印中,请勿息屏或退出应用!'
 					 })
-					 this.printOnce(opt,tsc,blesdk,result[this.printIndex])
+					 this.printOnce(opt,cmd,blesdk,result[this.printIndex])
 				}else{
 					this.toashMsg("请选择产品!")
 					this.$refs.kkprinter.onPrintFail()

+ 1 - 1
pages/shelfSetting/productList.vue

@@ -41,7 +41,7 @@
 					<view class="pcurnums flex align_center">
 						<text>打印数量</text>
 						<view class="u-ninput">
-							<u-number-box color="#000" :input-height="60" bg-color="#fff" v-model="item.printQty" :min="1"></u-number-box>
+							<u-number-box color="#000" :long-press="false" :input-height="60" bg-color="#fff" v-model="item.printQty" :min="1"></u-number-box>
 						</view>
 					</view>
 				</view>

+ 2 - 2
pages/shelfSetting/quickProductList.vue

@@ -33,7 +33,7 @@
 					<view class="pcurnums flex align_center">
 						<text>补货数量</text>
 						<view class="u-ninput">
-							<u-number-box color="#000" :input-height="60" bg-color="#fff" v-model="item.printQty" :min="0" :max="999999"></u-number-box>
+							<u-number-box color="#000" :long-press="false" :input-height="60" bg-color="#fff" v-model="item.printQty" :min="0" :max="999999"></u-number-box>
 						</view>
 					</view>
 				</view>
@@ -80,7 +80,7 @@
 					item.printQty = item.replenishBillQty
 					item.checked = false
 				})
-				this.partList = JSON.parse(JSON.stringify(list))
+				this.partList = list
 			},
 			// 全选
 			allSelect(val){

+ 53 - 17
pages/shelfSetting/quickReplenish.vue

@@ -41,7 +41,7 @@
 	import kkPrinter from '@/components/kk-printer/index.vue';
 	import chooseTypeModal from './chooseTypeModal.vue'
 	import stockModal from '@/pages/replenishmentManage/stockModal.vue'
-	import {printTempl} from '@/libs/printTools.js'
+	import {printTempl,printCpclTempl} from '@/libs/printTools.js'
 	import {saveReplenishBill} from '@/api/shelfReplenish.js'
 	import {clzConfirm} from '@/libs/tools.js'
 	export default {
@@ -73,8 +73,15 @@
 			this.$refs.productList.setData(this.partList)
 			this.allCheckeChange({value:true})
 			this.allChecked = true
+			setTimeout(()=>{
+				uni.hideLoading()
+			},Math.floor(this.partList.length * 15))
 		},
 		onLoad(option) {
+			uni.showLoading({
+				title: "正在加载数据...",
+				mask:true
+			})
 			this.basicInfoData = this.$store.state.vuex_tempData;
 			this.partList = this.basicInfoData.list
 			// 保持屏幕常亮
@@ -131,7 +138,8 @@
 				    qty: item.printQty,
 					shelfSn: this.basicInfoData.shelfSn,
 				    shelfPlaceCode: item.shelfPlaceCode,
-					shelfPlaceSn: item.shelfPlaceSn
+					shelfPlaceSn: item.shelfPlaceSn,
+					id: item.id
 				  })
 				})
 				const params = {
@@ -158,6 +166,9 @@
 							uni.navigateBack()
 							this.toashMsg(res.message)
 						}
+					}else{
+						uni.navigateBack()
+						this.toashMsg(res.message)
 					}
 					this.loading = false
 					this.chooseModal = false
@@ -173,11 +184,18 @@
 				this.isParinting = false
 				uni.hideLoading()
 			},
-			printOnce(opt,tsc,blesdk,data){
+			onPrintError(){
+				this.$refs.kkprinter.onPrintFail()
+				this.isParinting = false
+				this.show = false
+				uni.showToast({
+					title: '打印失败,请重试!'
+				})
+			},
+			printOnce(opt,cmd,blesdk,data){
 				const _this = this
 				const dealer = this.$store.state.vuex_userData
-				// 60*40 打印模板
-				const command = printTempl(tsc,{
+				const paramsData = {
 					dealerName: dealer.orgName,
 					shelfName: this.basicInfoData.shelfName || '',
 					productCode: data.productCode || '',
@@ -187,18 +205,12 @@
 					printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
 					printUser: dealer.userNameCN,
 					barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
-				})
-				// 开始批量打印 
-				blesdk.senBlData(
-				opt.deviceId, 
-				opt.serviceId, 
-				opt.writeId, 
-				command.getData(), 
-				function(){
+				}
+				const onPrintSuccess = function(){
 					const result =_this.$refs.productList.getAllChecked()
 					_this.printIndex = _this.printIndex + 1
 					if(_this.printIndex < result.length){
-						_this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
+						_this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
 					}else{
 						// 打印结束
 						_this.printIndex = 0
@@ -214,10 +226,34 @@
 						  }
 						})
 					}
-				});
+				}
+				// 开始批量打印
+				// tsc 指令 // 60*40 打印模板
+				console.log(cmd,cmd.type)
+				if(cmd.type&&cmd.type=='tsc'){
+					// 60*40 打印模板
+					const command = printTempl(cmd,paramsData)
+					// 开始批量打印 
+					blesdk.senBlData(
+					opt.deviceId, 
+					opt.serviceId, 
+					opt.writeId, 
+					command.getData(), 
+					onPrintSuccess);
+				}else{
+					const resultData = printCpclTempl(cmd,paramsData)
+					blesdk.sendDataToDevice({
+						deviceId: opt.deviceId, 
+						serviceId: opt.serviceId, 
+						characteristicId: opt.writeId,
+						value: resultData,
+						lasterSuccess: onPrintSuccess,
+						lasterError: this.onPrintError
+					});
+				}
 			},
 			// 批量打印 
-			startPrint(opt,tsc,blesdk){
+			startPrint(opt,cmd,blesdk){
 				const _this = this
 				const result =_this.$refs.productList.getAllChecked()
 				console.log(result,result.length)
@@ -231,7 +267,7 @@
 					   success (ret) {
 					 	if (ret.confirm || ret.index == 0) {
 					 		_this.isParinting = true
-					 		_this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
+					 		_this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
 					 	}else{
 							_this.$refs.kkprinter.onPrintFail()
 							_this.isParinting = false

+ 6 - 0
pages/shelfSetting/searchShelfHw.vue

@@ -104,6 +104,12 @@
 		onShow() {
 			this.changeSearch()
 		},
+		onBackPress() {
+			if(this.showTab){
+				this.showTab = false
+				return true
+			}
+		},
 		methods: {
 			//编辑货位
 			toEdit(item){

+ 2 - 2
pages/shelfSetting/shelfSet.vue

@@ -26,13 +26,13 @@
 				<view class="label" style="width: 50%;" @click="showTip(1)">是否设置完成 <u-icon color="#ffaa00" name="question-circle"></u-icon></view>
 				<view class="text" style="width: 50%;text-align: right;"><u-switch v-model="switchVal" @change="switchChange"></u-switch></view>
 			</view>
-			<view class="card-row align_center flex justify_between" v-if="showMore">
+			<!-- <view class="card-row align_center flex justify_between" v-if="showMore">
 				<view class="label" style="width: 40%;" @click="showTip(0)">价格显示 <u-icon color="#ffaa00" name="question-circle"></u-icon></view>
 				<view class="text flex align_center" style="width: 60%;text-align: right;" @click="updateShowPrice = true">
 					<text style="width: 80%;flex: 1;">非铺货产品——{{ showPrice == '1' ? '显示': '不显示' }}价格</text>
 					<u-icon name="arrow-right" color="#969da3" size="28"></u-icon>
 				</view>
-			</view>
+			</view> -->
 			<view class="moreSeting" @click="showMore=!showMore">
 				<text>{{!showMore?'更多设置':'收起'}}</text> <u-icon :name="showMore?'arrow-up':'arrow-down'"></u-icon>
 			</view>

+ 17 - 0
pages/userCenter/index.vue

@@ -24,6 +24,7 @@
 				</u-cell-item>
 				<u-cell-item icon="edit-pen" icon-size="38" :icon-style="{color:'#00aaff'}" index="1" @click="toPage(1)" title="修改密码"></u-cell-item>
 				<u-cell-item icon="man-delete" icon-size="38" :icon-style="{color:'#00aaff'}" index="1" @click="closeAccount" title="注销账户"></u-cell-item>
+				<u-cell-item icon="reload" icon-size="35" :icon-style="{color:'#00aaff'}" index="1" @click="resetPrint" title="重置打印机"></u-cell-item>
 			</u-cell-group>
 			<u-cell-group>
 				<!-- <u-cell-item icon="info-circle" icon-size="38" :icon-style="{color:'#00aaff'}" index="1" @click="toPage" title="关于我们"></u-cell-item> -->
@@ -103,6 +104,22 @@
 				data.permCodes = data.permCodes.filter(item => item.indexOf('_mobile') > 0);
 				return data;
 			},
+			// 重置打印机
+			resetPrint(){
+				const _this = this;
+				clzConfirm({
+					title: '提示',
+					content: '重置打印机后就可以重新选择其它打印机,您确定重置吗?',
+					success: function(res) {
+						if (res.confirm || res.index == 0) {
+							uni.setStorageSync('vuex_lastBuleDevice','')
+							uni.showToast({
+								title: '重置成功'
+							})
+						}
+					}
+				});
+			},
 			// 切换账户
 			changeAcount(index){
 				const _this = this

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است