uu
This commit is contained in:
parent
26e5e22e5d
commit
bba77fcfef
@ -16,7 +16,7 @@ OutputStreamWriter = plus.android.importClass("java.io.OutputStreamWriter")
|
||||
* @param mac_address 打印机ID
|
||||
* @param data 指令集字符串, 为了灵活起见, 指令集在业务代码中进行转换然后传递进来
|
||||
*/
|
||||
export const print = (mac_address, data) => {
|
||||
export const print = (mac_address, data, isBytes) => {
|
||||
console.log("=====mac_address====", mac_address)
|
||||
var that = this
|
||||
if (!mac_address) {
|
||||
@ -69,10 +69,14 @@ export const print = (mac_address, data) => {
|
||||
plus.android.importClass(outputStream)
|
||||
outputStream.write([0x1b, 0x40]) //打印复位
|
||||
outputStream.flush()
|
||||
|
||||
let bytes
|
||||
console.log("plus.android.invoke data getBytes======= before")
|
||||
var bytes = plus.android.invoke(data, "getBytes", "gbk") /*utf-8*/
|
||||
console.log("plus.android.invoke data getBytes======= end")
|
||||
if(!isBytes) {
|
||||
bytes = plus.android.invoke(data, "getBytes", "gbk") /*utf-8*/
|
||||
} else {
|
||||
bytes = data
|
||||
}
|
||||
console.log("plus.android.invoke data getBytes======= end", bytes)
|
||||
outputStream.write(bytes)
|
||||
outputStream.flush()
|
||||
|
||||
@ -131,6 +135,32 @@ export const printTest = function (printerid) {
|
||||
}
|
||||
}
|
||||
|
||||
// 打印测试
|
||||
export const printTestSimple = function (printerid) {
|
||||
printerid = printerid || uni.getStorageSync("ble_printerId")
|
||||
if (printerid) {
|
||||
if (printerid != null && printerid.length > 0) {
|
||||
var data = {
|
||||
name: "鹤山市捷仕克汽车配件有限公司",
|
||||
}
|
||||
// 标签开始
|
||||
var str = " ! 0 200 200 350 1 " + "\r\n"
|
||||
// str += "PAGE-WIDTH 600" + "\r\n"
|
||||
// 标签内容
|
||||
str += "TEXT 24 0 10 10 " + data.name + "\r\n"
|
||||
|
||||
str += "PRINT " + "\r\n"
|
||||
print(printerid, str)
|
||||
}
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "请先选择已配对的蓝牙打印机, 再进行测试.",
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const IsNullOrEmpty = function (obj) {
|
||||
if (obj == null || obj.length == 0) {
|
||||
return true
|
||||
|
||||
@ -26,7 +26,7 @@ var tanexPrinter = {
|
||||
[名称] 开始命令
[格式] ! {offset} 200 200 {height} {qty}
[说明] {offset}:整个标签的水平偏移量
200:水平分辨率,203 点/英寸(8 点/mm)
200:垂直分辨率,203 点/英寸(8 点/mm)
{height}:标签最大高度,点为单位
{qty}:打印标签的数量,最大1024 张
[实例] Input: Output:
! 0 200 200 210 1
TEXT 4 0 30 40 Hello World Hello World
FORM
PRINT
|
||||
*/
|
||||
tanexPrinter.init = function(maxHeight) {
|
||||
data = "! 0 200 200 " + maxHeight + " 1\r\n"
|
||||
data = " ! 0 200 200 " + maxHeight + " 1\r\n"
|
||||
tanexPrinter.addCommand(data)
|
||||
};
|
||||
|
||||
@ -83,12 +83,16 @@ var tanexPrinter = {
|
||||
}
|
||||
// console.log('===>setBitmapCmd:',JSON.stringify(r))
|
||||
}
|
||||
tanexPrinter.addText = function(text) {
|
||||
data = `TEXT 24 0 10 10 ${text}\r\n`
|
||||
tanexPrinter.addCommand(data)
|
||||
};
|
||||
|
||||
/*
|
||||
[名称] 设置打印命令
[格式] {command}
[说明] {command}:PRINT
在CPCL 指令模式下,打印命令终止和打印文件,这是最后的一条命令;执行打印命
令后,打印机退出控制段,在打印命令后,必须跟一个回车。
如果打印中出错,等待错误恢复后重新打印。
[实例] Input:
! 0 200 200 210 1
……………
PRINT
|
||||
*/
|
||||
tanexPrinter.setPagePrint = function() {
|
||||
data = "PRINT\r\n"
|
||||
data = "PRINT \r\n"
|
||||
tanexPrinter.addCommand(data)
|
||||
};
|
||||
|
||||
|
||||
@ -69,8 +69,8 @@ export default {
|
||||
prtInstance.setPagePrint()
|
||||
let commond = prtInstance.getPrintCmd()
|
||||
console.log("打印命令组装完成,开始打印=====")
|
||||
// printModule.print(deviceId, commond)
|
||||
printModule.printTest(deviceId)
|
||||
printModule.print(deviceId, commond, true)
|
||||
// printModule.printTestSimple(deviceId)
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user