123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- 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-2, rowTop, "TSS24.BF2", fontSize, fontSize, ltxt)
- }
- else{
- command.setText(left, rowTop, "TSS24.BF2", fontSize, fontSize, textArr[i])
- }
- rowTop = rowTop+rowHeight*fontSize+5
- }
- return rowTop
- }
- export const printText = function(tsc,text){
- const command = tsc.jpPrinter.createNew()
- command.init()
- command.setSize(40, 30)
- command.setGap(3)
- command.setCls()
- command.setText(100, 48, "5", 4, 3, text)
- command.setPagePrint(1,1)
- return command
- }
- export const printTempl = function(tsc,data){
- let top = 32
- const left = 8
- const lightHeight = 24
- const pageW = 60
- const pageH = 40
- const maxFontNums = Math.floor((pageW*8-left*4)/lightHeight)
- const leftMaxFnums = Math.floor(maxFontNums*0.4)
- const rightMaxFnums = leftMaxFnums + 1
- let rightLeft = (leftMaxFnums+2.5)*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
- top = textFormat(command,data.shelfName,maxFontNums,left,top,lightHeight,"center",1)
-
- top = top+15
- command.setQR(left*6, top, "M", 5, "A", data.barCode)
-
- const rightTop = textFormat(command,data.shelfPlaceCode,rightMaxFnums,rightLeft,top,lightHeight,"left",4)
-
- top = rightTop + 1
- top = textFormat(command,data.productCode,rightMaxFnums,rightLeft,top,lightHeight,"left",1)
-
- command.setPagePrint(1,data.currentInven)
- return command
- }
- export const printMiniTempl = function(tsc,data){
- let top = 24
- const left = 4
- const lightHeight = 24
- const pageW = 40
- const pageH = 30
- const maxFontNums = Math.floor((pageW*8-left*2)/lightHeight)
- const leftMaxFnums = Math.floor(maxFontNums*0.5)
- const rightMaxFnums = Math.floor(maxFontNums*0.4)
- let rightLeft = (leftMaxFnums+1)*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
- top = textFormat(command,data.shelfName,maxFontNums,left,top,lightHeight,"center",1)
-
- top = top+10
- command.setQR(left, top, "M", 5, "A", data.barCode)
-
- const rightTop = textFormat(command,data.shelfPlaceCode,rightMaxFnums,rightLeft,top,lightHeight,"left",3)
-
- top = rightTop
- top = textFormat(command,data.productCode,rightMaxFnums,rightLeft,top,lightHeight,"left",1)
-
- command.setPagePrint(1,data.currentInven)
- return command
- }
|