lilei 3 rokov pred
rodič
commit
9bd0afc576

+ 60 - 0
libs/printTools.js

@@ -0,0 +1,60 @@
+// 获取文本字节总数
+export const getBytesCount = function(str){
+	var bytesCount = 0;
+	if (str != null) {
+		for (var i = 0; i < str.length; i++) {
+			var c = str.charAt(i);
+			if (c.match(/[^\x00-\xff]/ig) != null) //全角
+			{
+				bytesCount += 2;
+			} else {
+				bytesCount += 1;
+			}
+		}
+	}
+	return bytesCount;
+}
+
+// JS 包含中文的字符串按固定长度拆分换行算法
+export const getTextRows = function(str,iPageSize){
+	var strArray = [];
+	var tempStr = "";
+	var iTotalLength = getBytesCount(str);
+	for (var i = 0; i < str.length; i++) {
+		var iCount = getBytesCount(str[i]);
+		var iCountTemp = getBytesCount(tempStr);
+		//iCountTemp + iCount >= iPageSize 这里可能出现两种情况:
+		//长度等于 iPageSize 或 等于 iPageSize + 1(最后一个为中文字符就等于 9 + 2 情况)
+		if (iCountTemp + iCount >= iPageSize) {
+			tempStr += str[i];
+			strArray.push(tempStr);
+			tempStr = "";
+		} else {
+			tempStr += str[i];
+		}
+	}
+	
+	// //最后一次尾巴
+	if (tempStr.length > 0){
+		strArray.push(tempStr)
+	}
+	return strArray
+}
+// 格式化打印文本
+export const textFormat = function(command,text,maxFontNums,left,top,lightHeight,align,fontSize){
+	let rowTop = top
+	const textArr = getTextRows(text.replace(/\s+/g, ' '),maxFontNums*2)
+	const rows = textArr.length
+	for(let i=0;i<rows;i++){
+		if(align=="center"){
+			const ltxt = textArr[i]
+			const ltlen = ltxt.replace(/[^x00-xFF]/g,'**').length/2
+			command.setText(left+((maxFontNums-ltlen)/2)*lightHeight, rowTop, "TSS24.BF2", fontSize, fontSize, ltxt)
+		}
+		else{
+			command.setText(left, rowTop, "TSS24.BF2", fontSize, fontSize, textArr[i])
+		}
+		rowTop = rowTop+lightHeight
+	}
+	return rowTop
+}

+ 7 - 64
pages/common/printTag/printTag.vue

@@ -28,6 +28,7 @@
 <script>
 	import { shelfDetail } from '@/api/shelf'
 	import kkPrinter from '@/components/kk-printer/index.vue';
+	import {textFormat} from '@/libs/printTools.js'
 	export default {
 		components:{
 			kkPrinter
@@ -91,64 +92,6 @@
 				}
 				console.log('printInfo-----------',_this.printInfo)
 			},
-			getBytesCount(str){
-				var bytesCount = 0;
-				if (str != null) {
-					for (var i = 0; i < str.length; i++) {
-						var c = str.charAt(i);
-						if (c.match(/[^\x00-\xff]/ig) != null) //全角
-						{
-							bytesCount += 2;
-						} else {
-							bytesCount += 1;
-						}
-					}
-				}
-				return bytesCount;
-			},
-			// JS 包含中文的字符串按固定长度拆分换行算法
-			getTextRows(str,iPageSize){
-				var strArray = [];
-				var tempStr = "";
-				var iTotalLength = this.getBytesCount(str);
-				for (var i = 0; i < str.length; i++) {
-					var iCount = this.getBytesCount(str[i]);
-					var iCountTemp = this.getBytesCount(tempStr);
-					//iCountTemp + iCount >= iPageSize 这里可能出现两种情况:
-					//长度等于 iPageSize 或 等于 iPageSize + 1(最后一个为中文字符就等于 9 + 2 情况)
-					if (iCountTemp + iCount >= iPageSize) {
-						tempStr += str[i];
-						strArray.push(tempStr);
-						// console.log("iCountTemp + iCount >= iPageSize " + tempStr)
-						tempStr = "";
-					} else {
-						tempStr += str[i];
-					}
-				}
-				
-				// //最后一次尾巴
-				if (tempStr.length > 0){
-					strArray.push(tempStr)
-				}
-				return strArray
-			},
-			textFormat(command,text,maxFontNums,left,top,lightHeight,align,fontSize){
-				let rowTop = top
-				const textArr = this.getTextRows(text.replace(/\s+/g, ' '),maxFontNums*2)
-				const rows = textArr.length
-				for(let i=0;i<rows;i++){
-					if(align=="center"){
-						const ltxt = textArr[i]
-						const ltlen = ltxt.replace(/[^x00-xFF]/g,'**').length/2
-						command.setText(left+((maxFontNums-ltlen)/2)*lightHeight, rowTop, "TSS24.BF2", fontSize, fontSize, ltxt)
-					}
-					else{
-						command.setText(left, rowTop, "TSS24.BF2", fontSize, fontSize, textArr[i])
-					}
-					rowTop = rowTop+lightHeight
-				}
-				return rowTop
-			},
 			// 打印
 			startPrint(opt,tsc,blesdk){
 				console.log(opt,'opt')
@@ -162,7 +105,7 @@
 					return
 				}
 				let top = 10 // 距离顶部10点像素
-				const left = 24 // 距离左边
+				const left = 32 // 距离左边
 				const lightHeight = 24 // 行高3mm,1mm = 8点
 				const pageW = 40 // 页签宽度mm
 				const pageH = 30 // 页签高度mm
@@ -176,21 +119,21 @@
 				command.setGap(2) // 标签上下间距,单位mm
 				command.setCls() // 清除缓冲区数据
 				// 经销商文字高度,是否换行
-				top = this.textFormat(command,this.printInfo.dealerName,maxFontNums,left,top,lightHeight,"center",1)
+				top = textFormat(command,this.printInfo.dealerName,maxFontNums,left,top,lightHeight,"center",1)
 				// 数字货架名称文字
 				top = top+10
 				rightTop = top
 				const lwidth = Math.floor(maxFontNums*0.6)
 				rightLeft = (lwidth + 1.5) * lightHeight
-				top = this.textFormat(command,this.printInfo.shelfName,lwidth,left,top,lightHeight,"left",1)
+				top = textFormat(command,this.printInfo.shelfName,lwidth,left,top,lightHeight,"left",1)
 				// 产品编码
 				top = top+10
-				top = this.textFormat(command,this.printInfo.productCode,lwidth,left,top,lightHeight,"left",1)
+				top = textFormat(command,this.printInfo.productCode,lwidth,left,top,lightHeight,"left",1)
 				// 产品名称
 				top = top+5
-				top = this.textFormat(command,this.printInfo.productName,lwidth,left,top,lightHeight,"left",1)
+				top = textFormat(command,this.printInfo.productName,lwidth,left,top,lightHeight,"left",1)
 				// 货位号
-				this.textFormat(command,this.printInfo.shelfPlaceCode,maxFontNums-lwidth,rightLeft,rightTop,lightHeight,"center",1)
+				textFormat(command,this.printInfo.shelfPlaceCode,maxFontNums-lwidth,rightLeft,rightTop,lightHeight,"center",1)
 				// 二维码
 				const qrtop = rightTop +lightHeight+10
 				command.setQR(rightLeft, qrtop, "L", 3, "A", this.printInfo.barCode)

+ 16 - 36
pages/replenishmentManage/manualPrint.vue

@@ -21,6 +21,7 @@
 	import kkPrinter from '@/components/kk-printer/index.vue';
 	import { shelfReplenishDetail, shelfReplenishDetailList, shelfReplenishPrintSign } from '@/api/shelfReplenish'
 	import partList from '@/pages/common/partList.vue'
+	import {textFormat} from '@/libs/printTools.js'
 	export default {
 		components: { partList, kkPrinter },
 		data() {
@@ -79,35 +80,12 @@
 			allCheckedCallback(val){
 				this.allChecked = val
 			},
-			textFormat(command,text,maxFontNums,left,top,lightHeight){
-				const textLen = text.length
-				console.log(textLen,maxFontNums)
-				if(textLen > maxFontNums){
-					const rows = Math.ceil(textLen/maxFontNums)
-					console.log(rows)
-					for(let i=0;i<rows;i++){
-						top = top+i*lightHeight
-						console.log(top)
-						// 最后一行
-						if(i==rows-1){
-							const ltxt = text.substring(i*maxFontNums)
-							const ltlen = ltxt.length
-							command.setText(left+((maxFontNums-ltlen)/2)*lightHeight, top, "TSS24.BF2", 1, 1, ltxt)
-						}else{
-							command.setText(left, top, "TSS24.BF2", 1, 1, text.substring(i*maxFontNums,maxFontNums))
-						}
-					}
-				}else{
-					command.setText(left+((maxFontNums-textLen)/2)*lightHeight, top, "TSS24.BF2", 1, 1, text)
-				}
-				return top
-			},
 			printOnce(opt,tsc,blesdk,data){
 				const _this = this
 				const dealer = this.$store.state.vuex_userData
 				console.log(opt,data,'opt')
 				let top = 10 // 距离顶部10点像素
-				const left = 10 // 距离左边10点
+				const left = 32 // 距离左边
 				const lightHeight = 24 // 行高3mm,1mm = 8点
 				const pageW = 40 // 页签宽度mm
 				const pageH = 30 // 页签高度mm
@@ -121,28 +99,30 @@
 				command.setGap(2) // 标签上下间距,单位mm
 				command.setCls() // 清除缓冲区数据
 				// 经销商文字高度,是否换行
-				top = this.textFormat(command,dealer.orgName,maxFontNums,left,top,lightHeight)
+				top = textFormat(command,dealer.orgName,maxFontNums,left,top,lightHeight,"center",1)
 				// 数字货架名称文字
-				top = top+lightHeight+15
-				top = this.textFormat(command,this.basicInfoData.shelfInfo.shelfName,Math.floor(maxFontNums*0.6),left,top,lightHeight)
+				top = top+10
 				rightTop = top
+				const lwidth = Math.floor(maxFontNums*0.6)
+				rightLeft = (lwidth + 1.5) * lightHeight
+				top = textFormat(command,this.basicInfoData.shelfInfo.shelfName,lwidth,left,top,lightHeight,"left",1)
 				// 产品编码
-				top = top+lightHeight+15
-				command.setText(left, top, "TSS24.BF2", 1, 1, data.productCode)
+				top = top+10
+				top = textFormat(command,data.productCode,lwidth,left,top,lightHeight,"left",1)
 				// 产品名称
-				top = top+lightHeight+5
-				top = this.textFormat(command,data.product.name,Math.floor(maxFontNums*0.6),left,top,lightHeight)
+				top = top+5
+				top = textFormat(command,data.product.name,lwidth,left,top,lightHeight,"left",1)
 				// 时间
-				top = top+lightHeight+15
-				command.setText(left, top, "TSS24.BF2", 1, 1, this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'))
+				top = top+10
+				top = textFormat(command,this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),lwidth,left,top,lightHeight,"left",1)
 				// 货位号
-				command.setText(rightLeft, rightTop, "TSS24.BF2", 1, 1, data.shelfPlaceCode)
+				textFormat(command,data.shelfPlaceCode,maxFontNums-lwidth,rightLeft,rightTop,lightHeight,"center",1)
 				// 二维码
-				const qrtop = rightTop +lightHeight+15
+				const qrtop = rightTop +lightHeight+10
 				const qrcont = `dealerSn=${dealer.orgSn}&shelfSn=${data.shelfSn}&productCode=${data.productCode}&shelfPlaceCode=${data.shelfPlaceCode}&shelfPlaceSn=${data.shelfPlaceSn}`
 				command.setQR(rightLeft, qrtop, "L", 3, "A", qrcont)
 				command.setPagePrint(1,data.printQty) // 打印分数1,每个标签重发打印2次
-				// -----------
+				
 				console.log("开始打印了",command.getData())
 				blesdk.senBlData(
 				opt.deviceId, 

+ 1 - 1
pages/replenishmentManage/scanCodePrint.vue

@@ -69,7 +69,7 @@
 					replenishBillSn: this.replenishBillSn
 				}).then(res => {
 					console.log(res)
-					if(res.status == 200){
+					if(res.status == 200&&res.data.length){
 						let params = {
 							shelfName: res.data&&res.data[0]&&res.data[0].shelf&&res.data[0].shelf.shelfName,
 							productName: res.data&&res.data[0]&&res.data[0].product&&res.data[0].product.name,