123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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;
- }
- 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);
-
-
- 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 maxNums = maxFontNums
- const rowHeight = lightHeight
- const textArr = getTextRows(text.replace(/\s+/g, ' '),maxNums*2)
- const rows = textArr.length
- for(let i=0;i<rows;i++){
- if(align=="center"){
- const ltxt = textArr[i]
- const ltlen = getBytesCount(ltxt)/2*fontSize
- command.setText(left+((maxNums-ltlen)/2)*rowHeight, rowTop, "TSS24.BF2", fontSize, fontSize, ltxt)
- }
- else{
- command.setText(left, rowTop, "TSS24.BF2", fontSize, fontSize, textArr[i])
- }
- rowTop = rowTop+rowHeight*fontSize+10
- }
- return rowTop
- }
- export const printTempl = function(tsc,data){
- let top = 16
- const left = 8
- const lightHeight = 24
- const pageW = 60
- const pageH = 40
- const maxFontNums = Math.floor((pageW*8-left*2)/lightHeight)
- const leftMaxFnums = Math.floor(maxFontNums*0.6)
- let rightTop = 0
- let rightLeft = (leftMaxFnums+2)*lightHeight
-
- const command = tsc.jpPrinter.createNew()
- command.init()
- command.setSize(pageW, pageH)
- command.setGap(3)
- command.setCls()
-
- top = textFormat(command,data.dealerName,maxFontNums,left,top,lightHeight,"center",1)
-
- top = top+10
- rightTop = top
- top = textFormat(command,data.shelfName,leftMaxFnums,left,top,lightHeight,"left",1)
-
- top = top+10
- top = textFormat(command,data.productCode,leftMaxFnums,left,top,lightHeight,"left",1)
-
- top = top+6
- top = textFormat(command,data.productName,leftMaxFnums,left,top,lightHeight,"left",1)
-
- top = top+10
- top = textFormat(command,data.printDate+' '+data.printUser,leftMaxFnums,left,top,lightHeight,"left",1)
-
- const qrtop = textFormat(command,data.shelfPlaceCode,maxFontNums-leftMaxFnums-2,rightLeft,rightTop,lightHeight,"center",2)
-
- command.setQR(rightLeft, qrtop, "L", 3, "A", data.barCode)
- command.setPagePrint(1,data.currentInven)
- console.log("开始打印了",command.getData())
- return command
- }
|