更新记录
1.0.2(2023-07-28)
修改插件前缀
1.0.1(2023-07-14)
- 优化API
1.0.0(2023-07-14)
- TSC打印文本标签pdf,支持蓝牙、Wi-Fi、USB等连接
平台兼容性
Vue2 | Vue3 |
---|---|
√ | √ |
App | 快应用 | 微信小程序 | 支付宝小程序 | 百度小程序 | 字节小程序 | QQ小程序 |
---|---|---|---|---|---|---|
HBuilderX 3.6.8,Android:4.4,iOS:9,HarmonyNext:不确定 | × | × | × | × | × | × |
钉钉小程序 | 快手小程序 | 飞书小程序 | 京东小程序 |
---|---|---|---|
× | × | × | × |
H5-Safari | Android Browser | 微信浏览器(Android) | QQ浏览器(Android) | Chrome | IE | Edge | Firefox | PC-Safari |
---|---|---|---|---|---|---|---|---|
× | × | × | × | × | × | × | × | × |
TSC打印,支持蓝牙、Wi-Fi、USB等连接
import {
UTSTsc
} from "@/uni_modules/wrs-uts-tsc";
蓝牙连接
ios需要在manifest.json-》App权限配置里增加蓝牙权限说明
- 蓝牙扫描 Android通过蓝牙扫描插件https://ext.dcloud.net.cn/plugin?id=13533进行扫描,获取蓝牙地址address
ios通过调用接口searchBLEDevice来扫描
// ios蓝牙扫描2秒
tsc.searchBLEDevice(2, (resp)=>{
console.log("扫描到蓝牙:" + JSON.stringify(resp))
this.bluetoothArray.push(...resp)
})
- 蓝牙连接
Android:
let macAddress = "xxx"
tsc.openportBT(macAddress)
iOS:
let uuid = "xxxx"
tsc.openportBT(uuid)
wifi连接
let ipaddress = "192.168.1.50";
let portnumber = 9100;
tsc.openportWifi(ipaddress, portnumber)
-
获取所有USB设备 通过USB插件获取USB设备列表https://ext.dcloud.net.cn/plugin?id=13300
-
USB连接
let deviceId = xxx;
tsc.openportUSB(deviceId)
打印接口
- 发送命令
let connectType = 1; // 连接方式: 0: 蓝牙 1: wifi 2: USB
let command = "SIZE 75 mm, 50 mm\r\n"
tsc.sendcommand(command, connectType)
- 清楚缓存
let connectType = 1; // 连接方式: 0: 蓝牙 1: wifi 2: USB
tsc.clearbuffer(connectType)
- 打印标签
let sets = 2; // sets up the number of label sets
let copies = 1; // sets up the number of print copies
let connectType = 1; // 连接方式: 0: 蓝牙 1: wifi 2: USB
tsc.printlabel(sets, copies, connectType)
- 打印条码
let x = 100;
let y = 100;
let type = "128";
let height = 100;
let human_readable = 1;
let rotation = 0;
let narrow = 3;
let wide = 3;
if(this.isAndroid) { // android
x = 100;
y = 100;
height = 100;
human_readable = 1;
rotation = 0;
narrow = 3;
wide = 3;
} else { // ios,ios参数都需要字符串类型
x = "100";
y = "100";
height = "100";
human_readable = "1";
rotation = "0";
narrow = "3";
wide = "3";
}
let str = "123456789";
let connectType = 1; // 连接方式: 0: 蓝牙 1: wifi 2: USB
tsc.barcode(x, y, type, height, human_readable, rotation, narrow, wide, str, connectType)
- 打印文本字体
let x = 100;
let y = 250;
let size = "3";
let rotation = 0;
let x_multiplication = 1;
let y_multiplication = 1;
let str = "987654321";
if(this.isAndroid) { // android
x = 100;
y = 250;
rotation = 0;
x_multiplication = 1;
y_multiplication = 1;
} else { // ios,ios参数都需要字符串类型
x = "100";
y = "250";
rotation = "0";
x_multiplication = "1";
y_multiplication = "1";
}
let connectType = 1; // 连接方式: 0: 蓝牙 1: wifi 2: USB
tsc.printerfont(x, y, size, rotation, x_multiplication, y_multiplication, str, connectType)
- 关闭连接
let timeout = 5000;
let connectType = 1; // 连接方式: 0: 蓝牙 1: wifi 2: USB
tsc.closeportTimeout(timeout, connectType)
- 打印PDF(仅支持Android)
let filePath = "/xxx/xxx/aa.pdf"; // 绝对路径
let x_coordinates = 100;
let y_coordinates = 100;
let printer_dpi = 10;
let connectType = 1; // 连接方式: 0: 蓝牙 1: wifi 2: USB
tsc.printPDFbyFile( filePath, x_coordinates, y_coordinates, printer_dpi, connectType)