Files
2023-10-12 22:05:41 +08:00

174 lines
9.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var exec = require('cordova/exec');
/**
*
* @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值分别应为325。
"horizontalOffset": 0,//水平偏移(暂不生效)
"verticalOffset": 0,//垂直偏移(暂不生效)
"width": 60,//画布宽度,单位mm
"height": 40,//画布高度,单位mm
"printMultiple": 8,//打印倍率 200dpi的打印机为8300dpi的打印机为11.81
"epc": ""//RFID标签写入数据,B32R机器打印RFID标签时填充数据,其他场景默认”“
}
}
* @param {*} success
* @param {*} error
*/
exports.print = async function (data,info,cfg) {
return new Promise((resolve, reject) => exec(resolve,reject, 'JcPrinter', 'print', [data,info,cfg||{}]));
};
exports.getList = function () {
return new Promise((resolve, reject) => exec(resolve,reject, 'JcPrinter', 'getList', []));
};
exports.connectPrinter = function (arg0) {
return new Promise((resolve, reject) => exec(resolve,reject,'JcPrinter', 'connectPrinter', [arg0]));
}
exports.isConnection = function () {
return new Promise((resolve, reject) => exec(resolve,reject,'JcPrinter', 'isConnection', []));
}
exports.Instance = {
/**
* 初始化画板
* 该方法用于初始化绘图板,以便进行绘制操作。
*
* @param width 绘图板的宽度,单位:毫米
* @param height 绘图板的高度,单位:毫米
* @param rotate 旋转角度,可选值:0、90、180、270,表示绘图板的旋转角度
* @param fontDir 字体文件路径,用于绘制文本时指定字体,暂不支持自定义,默认“”即可
*/
drawEmptyLabel: async function (width, height, rotate, fontDir) {
return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","action",["drawEmptyLabel",[width, height, rotate,fontDir||""]]));
},
/**
* 绘制文本
* 该方法用于在绘图板上绘制文本,包括位置、内容、字体样式等信息。
*
* @param x 位置x,单位:毫米
* @param y 位置y,单位:毫米
* @param width 文本框宽度,单位:毫米
* @param height文本框高度,单位:毫米
* @param value 文本内容
* @param fontFamily 字体名称,传入空字符串时使用默认字体(暂时用默认字体)
* @param fontSize 字体大小,单位:毫米
* @param rotate 旋转角度,可选值:0、90、180、270
* @param textAlignHorizontal 水平对齐方式:0-左对齐,1-居中对齐,2-右对齐
* @param textAlignVertical 垂直对齐方式:0-顶对齐,1-垂直居中,2-底对齐
* @param lineModel 行模式:1-宽高固定,内容大小自适应,2-宽度固定,高度自适应,3-宽高固定,超出内容用省略号表示,4-宽高固定,超出内容直接裁切,6-宽高固定,内容超过预设的宽高时自动缩小
* @param letterSpace 字母之间的标准间隔,单位:毫米
* @param lineSpace 行间距(倍距),单位:毫米
* @param mFontStyles 字体样式,数组长度为4,依次表示:加粗,斜体,下划线,删除下划线(暂不生效)
*/
drawLabelText: async function (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]]));
},
/**
* 绘制一维码
* 该方法用于在绘图板上绘制一维码,包括位置、类型、内容等信息。
*
* @param x 水平坐标x,单位:毫米
* @param y 垂直坐标y,单位:毫米
* @param width 宽度,单位:毫米
* @param height 高度,单位:毫米
* @param codeType 一维码类型,可选值:20-CODE12821-UPC-A22-UPC-E23-EAN824-EAN1325-CODE9326-CODE3927-CODEBAR28-ITF25
* @param value 一维码内容
* @param fontSize 字号大小,单位:毫米
* @param rotate 旋转角度,可选值:0、90、180、270
* @param textHeight 文本高度,单位:毫米
* @param textPosition 文本位置,可选值:0-下方显示,1-上方显示,2-不显示
*/
drawLabelBarCode: async function (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]]));
},
/**
* 绘制二维码
* 该方法用于在绘图板上绘制二维码,包括位置、类型、内容等信息。
*
* @param x 水平坐标x,单位:毫米
* @param y 垂直坐标y,单位:毫米
* @param width 宽度,单位:毫米
* @param height 高度,单位:毫米
* @param value 二维码内容
* @param codeType 二维码类型,可选值:31-QR_CODE32-PDF41733-DATA_MATRIX34-AZTEC
* @param rotate 旋转角度,可选值:0、90、180、270
*/
drawLabelQrCode: async function (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]]));
},
/**
* 绘制图形
* 该方法用于在绘图板上绘制图形,包括位置、类型、线条样式等信息。
*
* @param x 水平坐标x,单位:毫米
* @param y 垂直坐标y,单位:毫米
* @param width 宽度,单位:毫米
* @param height 高度,单位:毫米
* @param graphType 线条类型,可选值:1-实线,2-虚线类型(虚实比例1:1)
* @param rotate 旋转角度,可选值:0、90、180、270
* @param cornerRadius 圆角半径,单位:毫米
* @param lineWidth 线宽,单位:毫米
* @param lineType 图形类型,可选值:1-圆,2-椭圆,3-矩形,4-圆角矩形
* @param dashWidth 虚线样式,数组中包含实线段长度和空线段长度
*/
drawLabelGraph: async function (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]]));
},
/**
* 绘制图像
* 该方法用于在绘图板上绘制图像,包括图像的Base64数据、位置、大小、旋转角度等信息。
*
* @param imageData 图像的Base64数据(去除数据头)
* @param x 水平坐标x,单位:毫米
* @param y 垂直坐标y,单位:毫米
* @param width 宽度,单位:毫米
* @param height 高度,单位:毫米
* @param rotate 旋转角度,可选值:0、90、180、270
* @param imageProcessingType 处理算法,默认1即可
* @param imageProcessingValue 阈值 阈值,默认127即可
*/
drawLabelImage: async function (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]]));
},
/**
* 绘制线条
* 该方法用于在绘图板上绘制线条,包括位置、大小、旋转角度、线条类型等信息。
*
* @param x 水平坐标x,单位:毫米
* @param y 垂直坐标y,单位:毫米
* @param width 宽度,单位:毫米
* @param height 高度,单位:毫米
* @param rotate 旋转角度,可选值:0、90、180、270
* @param lineType 线条类型,1:实线,2:虚线类型(虚实比例1:1)
* @param dashWidth 线条为虚线时的宽度,包含实线段长度和空线段长度,单位:毫米
*/
drawLabelLine: async function (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]]));
},
generateLabelJson: async function (){
return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","generateLabelJson"));
}
};