修改Instance方法
This commit is contained in:
parent
48a6252707
commit
50c40589c9
@ -94,6 +94,9 @@ public class JcPrinter extends CordovaPlugin {
|
||||
case "connectPrinter":
|
||||
this.connectPrinter(args, callbackContext);
|
||||
return true;
|
||||
case "isConnection":
|
||||
this.isConnection(callbackContext);
|
||||
return true;
|
||||
case "action":
|
||||
String methodName = args.optString(0);
|
||||
JSONArray methodJsonArgs = args.getJSONArray(1);
|
||||
@ -148,14 +151,13 @@ public class JcPrinter extends CordovaPlugin {
|
||||
int pageCount = data.length();
|
||||
quantity = 1;
|
||||
int totalQuantity = pageCount * quantity;
|
||||
|
||||
//总打印份数
|
||||
//总打印份数,表示所有页面的打印份数之和。例如,如果你有3页需要打印,第一页打印3份,第二页打印2份,第三页打印5份,那么count的值应为10(3+2+5)。
|
||||
Util.getInstance().setTotalQuantityOfPrints(totalQuantity);
|
||||
printDensity = 8;
|
||||
printMode = 2;
|
||||
Log.d(TAG, "测试:参数设置-打印浓度: " + printDensity + ",打印模式:" + printMode);
|
||||
/*
|
||||
* 参数1 打印浓度 参数2 纸张类型 参数3 打印模式
|
||||
* 参数1:打印浓度 ,参数2:纸张类型 参数3:打印模式
|
||||
* 打印浓度 B50/B50W/T6/T7/T8 建议设置6或8,Z401/B32建议设置8,B3S/B21/B203/B1建议设置3
|
||||
*/
|
||||
Util.getInstance().startPrintJob(printDensity, 2, printMode, new PrintCallback() {
|
||||
@ -316,6 +318,29 @@ public class JcPrinter extends CordovaPlugin {
|
||||
|
||||
}
|
||||
|
||||
private void isConnection(CallbackContext callbackContext) throws JSONException {
|
||||
int connectFlag = Util.isConnection();
|
||||
cordova.getActivity().runOnUiThread(() -> {
|
||||
String hint = "";
|
||||
switch (connectFlag) {
|
||||
case 0:
|
||||
hint = "已连接";
|
||||
callbackContext.success(hint);
|
||||
break;
|
||||
case -1:
|
||||
hint = "未连接";
|
||||
callbackContext.error(hint);
|
||||
break;
|
||||
case -3:
|
||||
hint = "不支持的机型";
|
||||
callbackContext.error(hint);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void connectPrinter(JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
JSONObject obj = args.getJSONObject(0);
|
||||
String address = obj.getString("address");
|
||||
|
@ -38,8 +38,12 @@ exports.connectPrinter = function (arg0, success, error) {
|
||||
exec(success, error, 'JcPrinter', 'connectPrinter', [arg0]);
|
||||
}
|
||||
|
||||
exports.connectPrinter = function (success, error) {
|
||||
exec(success, error, 'JcPrinter', 'connectPrinter');
|
||||
}
|
||||
|
||||
exports.Instance = function(){
|
||||
|
||||
exports.Instance = {
|
||||
/**
|
||||
* 初始化画板
|
||||
* 该方法用于初始化绘图板,以便进行绘制操作。
|
||||
@ -49,9 +53,9 @@ exports.Instance = function(){
|
||||
* @param rotate 旋转角度,可选值:0、90、180、270,表示绘图板的旋转角度
|
||||
* @param fontDir 字体文件路径,用于绘制文本时指定字体,暂不支持自定义,默认“”即可
|
||||
*/
|
||||
async function drawEmptyLabel(width, height, rotate) {
|
||||
drawEmptyLabel: async function (width, height, rotate, fontDir) {
|
||||
return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","action",["drawEmptyLabel",[width, height, rotate,fontDir||""]]));
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 绘制文本
|
||||
* 该方法用于在绘图板上绘制文本,包括位置、内容、字体样式等信息。
|
||||
@ -71,9 +75,9 @@ exports.Instance = function(){
|
||||
* @param lineSpace 行间距(倍距),单位:毫米
|
||||
* @param mFontStyles 字体样式,数组长度为4,依次表示:加粗,斜体,下划线,删除下划线(暂不生效)
|
||||
*/
|
||||
async function drawLabelText(x, y, width, height, value,fontFamily, fontSize, rotate, textAlignHorizontal, textAlignVertical, lineModel, letterSpace, lineSpace, mFontStyles){
|
||||
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]]));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 绘制一维码
|
||||
@ -90,9 +94,9 @@ exports.Instance = function(){
|
||||
* @param textHeight 文本高度,单位:毫米
|
||||
* @param textPosition 文本位置,可选值:0-下方显示,1-上方显示,2-不显示
|
||||
*/
|
||||
async function drawLabelBarCode(x, y, width, height, codeType, value, fontSize, rotate, textHeight, textPosition){
|
||||
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]]));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 绘制二维码
|
||||
@ -106,9 +110,9 @@ exports.Instance = function(){
|
||||
* @param codeType 二维码类型,可选值:31-QR_CODE,32-PDF417,33-DATA_MATRIX,34-AZTEC
|
||||
* @param rotate 旋转角度,可选值:0、90、180、270
|
||||
*/
|
||||
async function drawLabelQrCode(x, y, width, height, value, codeType, rotate){
|
||||
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]]));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 绘制图形
|
||||
@ -125,9 +129,9 @@ exports.Instance = function(){
|
||||
* @param lineType 图形类型,可选值:1-圆,2-椭圆,3-矩形,4-圆角矩形
|
||||
* @param dashWidth 虚线样式,数组中包含实线段长度和空线段长度
|
||||
*/
|
||||
async function drawLabelGraph(x, y, width, height, graphType, rotate, cornerRadius, lineWidth, lineType, 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]]));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 绘制图像
|
||||
@ -142,9 +146,9 @@ exports.Instance = function(){
|
||||
* @param imageProcessingType 处理算法,默认1即可
|
||||
* @param imageProcessingValue 阈值 阈值,默认127即可
|
||||
*/
|
||||
async function drawLabelImage(imageData, x, y, width, height, rotate, imageProcessingType, imageProcessingValue){
|
||||
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]]));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 绘制线条
|
||||
@ -158,12 +162,13 @@ exports.Instance = function(){
|
||||
* @param lineType 线条类型,1:实线,2:虚线类型(虚实比例1:1)
|
||||
* @param dashWidth 线条为虚线时的宽度,包含实线段长度和空线段长度,单位:毫米
|
||||
*/
|
||||
async function drawLabelLine(x, y, width, height, rotate, lineType, 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]]));
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
async function generateLabelJson(){
|
||||
generateLabelJson: async function (){
|
||||
return new Promise((resolve, reject) => exec(resolve,reject,"JcPrinter","generateLabelJson"));
|
||||
}
|
||||
}();
|
||||
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user