From 0367ba7be0a36bf386487c02c32e3fbfbd7be13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E5=A4=A7=E5=BE=B7?= Date: Mon, 9 Oct 2023 20:56:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9B=B8=E5=85=B3=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/jcPrinter.js | 67 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/www/jcPrinter.js b/www/jcPrinter.js index ad9edcf..0050271 100644 --- a/www/jcPrinter.js +++ b/www/jcPrinter.js @@ -1,7 +1,33 @@ var exec = require('cordova/exec'); -exports.print = function (arg0, success, error) { - exec(success, error, 'JcPrinter', 'print', [arg0]); +/** + * + * @param {*} data Instance.generateLabelJson()[] + * @param {*} info + * //Z401/B32/B32R/T8为300dpi机型,其他机型均为200dpi + { + "printerImageProcessingInfo": {//打印附加信息 + "orientation": 0,//旋转角度 + "margin": [//边距 + 0, + 0, + 0, + 0 + ], + "printQuantity": 1,//用于指定当前页的打印份数。例如,如果你需要打印3页,第一页打印3份,第二页打印2份,第三页打印5份,那么在3次提交数据时,printQuantity值分别应为3,2,5。 + "horizontalOffset": 0,//水平偏移(暂不生效) + "verticalOffset": 0,//垂直偏移(暂不生效) + "width": 60,//画布宽度,单位mm + "height": 40,//画布高度,单位mm + "printMultiple": 8,//打印倍率 200dpi的打印机为8,300dpi的打印机为11.81 + "epc": ""//RFID标签写入数据,B32R机器打印RFID标签时填充数据,其他场景默认”“ + } + } + * @param {*} success + * @param {*} error + */ +exports.print = function (data,info, success, error) { + exec(success, error, 'JcPrinter', 'print', [data,info]); }; exports.getList = function (arg0, success, error) { @@ -12,9 +38,6 @@ exports.connectPrinter = function (arg0, success, error) { exec(success, error, 'JcPrinter', 'connectPrinter', [arg0]); } -exports.generateData = function(instance, success, error){ - -} exports.Instance = function(){ /** @@ -26,8 +49,8 @@ exports.Instance = function(){ * @param rotate 旋转角度,可选值:0、90、180、270,表示绘图板的旋转角度 * @param fontDir 字体文件路径,用于绘制文本时指定字体,暂不支持自定义,默认“”即可 */ - function drawEmptyLabel(width, height, rotate,success,error) { - exec(success,error,"JcPrinter","action",["drawEmptyLabel",[width, height, rotate,fontDir||""]]); + async function drawEmptyLabel(width, height, rotate) { + return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","action",["drawEmptyLabel",[width, height, rotate,fontDir||""]])); } /** * 绘制文本 @@ -48,8 +71,8 @@ exports.Instance = function(){ * @param lineSpace 行间距(倍距),单位:毫米 * @param mFontStyles 字体样式,数组长度为4,依次表示:加粗,斜体,下划线,删除下划线(暂不生效) */ - function drawLabelText(x, y, width, height, value,fontFamily, fontSize, rotate, textAlignHorizontal, textAlignVertical, lineModel, letterSpace, lineSpace, mFontStyles,success,error){ - exec(success,error,"JcPrinter","action",["drawLabelText",[x, y, width, height, value, fontFamily||"", fontSize, rotate, textAlignHorizontal, textAlignVertical, lineModel, letterSpace, lineSpace, mFontStyles]]); + async function drawLabelText(x, y, width, height, value,fontFamily, fontSize, rotate, textAlignHorizontal, textAlignVertical, lineModel, letterSpace, lineSpace, mFontStyles){ + return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","action",["drawLabelText",[x, y, width, height, value, fontFamily||"", fontSize, rotate, textAlignHorizontal, textAlignVertical, lineModel, letterSpace, lineSpace, mFontStyles]])); } /** @@ -67,8 +90,8 @@ exports.Instance = function(){ * @param textHeight 文本高度,单位:毫米 * @param textPosition 文本位置,可选值:0-下方显示,1-上方显示,2-不显示 */ - function drawLabelBarCode(x, y, width, height, codeType, value, fontSize, rotate, textHeight, textPosition,success,error){ - exec(success,error,"JcPrinter","action",["drawLabelBarCode",[x, y, width, height, codeType, value, fontSize, rotate, textHeight, textPosition]]); + async function drawLabelBarCode(x, y, width, height, codeType, value, fontSize, rotate, textHeight, textPosition){ + return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","action",["drawLabelBarCode",[x, y, width, height, codeType, value, fontSize, rotate, textHeight, textPosition]])); } /** @@ -83,8 +106,8 @@ exports.Instance = function(){ * @param codeType 二维码类型,可选值:31-QR_CODE,32-PDF417,33-DATA_MATRIX,34-AZTEC * @param rotate 旋转角度,可选值:0、90、180、270 */ - function drawLabelQrCode(x, y, width, height, value, codeType, rotate,success,error){ - exec(success,error,"JcPrinter","action",["drawLabelQrCode",[x, y, width, height, value, codeType, rotate]]); + async function drawLabelQrCode(x, y, width, height, value, codeType, rotate){ + return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","action",["drawLabelQrCode",[x, y, width, height, value, codeType, rotate]])); } /** @@ -102,8 +125,8 @@ exports.Instance = function(){ * @param lineType 图形类型,可选值:1-圆,2-椭圆,3-矩形,4-圆角矩形 * @param dashWidth 虚线样式,数组中包含实线段长度和空线段长度 */ - function drawLabelGraph(x, y, width, height, graphType, rotate, cornerRadius, lineWidth, lineType, dashWidth,success,error){ - exec(success,error,"JcPrinter","action",["drawLabelGraph",[x, y, width, height, graphType, rotate, cornerRadius, lineWidth, lineType, dashWidth]]); + async function drawLabelGraph(x, y, width, height, graphType, rotate, cornerRadius, lineWidth, lineType, dashWidth){ + return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","action",["drawLabelGraph",[x, y, width, height, graphType, rotate, cornerRadius, lineWidth, lineType, dashWidth]])); } /** @@ -119,8 +142,8 @@ exports.Instance = function(){ * @param imageProcessingType 处理算法,默认1即可 * @param imageProcessingValue 阈值 阈值,默认127即可 */ - function drawLabelImage(imageData, x, y, width, height, rotate, imageProcessingType, imageProcessingValue,success,error){ - exec(success,error,"JcPrinter","action",["drawLabelImage",[imageData, x, y, width, height, rotate, imageProcessingType, imageProcessingValue]]); + async function drawLabelImage(imageData, x, y, width, height, rotate, imageProcessingType, imageProcessingValue){ + return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","action",["drawLabelImage",[imageData, x, y, width, height, rotate, imageProcessingType, imageProcessingValue]])); } /** @@ -135,12 +158,12 @@ exports.Instance = function(){ * @param lineType 线条类型,1:实线,2:虚线类型(虚实比例1:1) * @param dashWidth 线条为虚线时的宽度,包含实线段长度和空线段长度,单位:毫米 */ - function drawLabelLine(x, y, width, height, rotate, lineType, dashWidth,success,error){ - exec(success,error,"JcPrinter","action",["drawLabelLine",[x, y, width, height, rotate, lineType, dashWidth]]); + async function drawLabelLine(x, y, width, height, rotate, lineType, dashWidth){ + return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","action",["drawLabelLine",[x, y, width, height, rotate, lineType, dashWidth]])); } - function generateLabelJson(success,error){ - exec(success,error,"JcPrinter","generateLabelJson"); + async function generateLabelJson(){ + return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","generateLabelJson")); } -} \ No newline at end of file +}(); \ No newline at end of file