更新记录
1.0.2(2026-09-01)
更新示例代码;
1.0.1(2026-09-01)
发布格式调整;
1.0.0(2026-09-01)
首个同时支持 HarmonyOS, Android, IOS, 微信小程序,web等平台的标签编辑及打印接口。
查看更多平台兼容性
uni-app(5.15)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| - | √ | √ | - | - | - | √ | √ | √ |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | × | × | × | × | × | × | × | × | × | × | × |
uni-app x(5.15)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| - | - | - | - | - | - |
dz-lpapi-uts
插件使用方法
import { getApi } from '@/uni_modules/dz-lpapi-uts';
const api = getApi({});
//
onReady(() => {
console.log(`---- Preview.onReady:`);
api.startDiscovery({
timeout: 5000,
deviceFound: (res) => {
console.log(`----- startDiscovery.deviceFound: `, res);
// updatePrinterList(res.devices);
},
complete: (res) => {
console.log(`------- startDiscovery.complete[code = ${res.statusCode}]: `, res);
}
});
});
function printQrcode() {
const margin = 0;
const padding = 1.5;
const textHeight = 4;
const startRes = api.startJob({
width: 40,
height: 30,
});
// 绘制字符串
api.drawQrcode({
text: "https://www.thanmore.net",
x: padding,
y: padding,
width: labelWidth - padding * 2,
height: labelHeight - textHeight - padding * 3,
horizontalAlignment: 1,
});
// 图片描述信息
api.drawText({
text: "二维码打印测试",
x: padding,
y: labelHeight - padding - textHeight,
width: labelWidth - padding * 2,
height: textHeight,
fontHeight: 3,
horizontalAlignment: 1,
});
// 提交打印任务,开始打印
api.commitJob();
}
接口定义
/**
* 函数返回结果
* 可以是void, 基本数据类型,自定义type, 或者其他类型。
* [可选实现]
*/
export type LPA_Response = {
statusCode : number;
resultInfo ?: any;
}
/**
* myApi 异步函数的参数,在type里定义函数需要的参数以及api成功、失败的相关回调函数。
*/
export type LPA_RequestOptions = {
success ?: (res : any) => void;
fail ?: (res : LPA_Response) => void;
complete ?: (res : LPA_Response) => void;
}
export type LPA_BleAdapterStateChangeResult = {
/** 是否正在进行蓝牙搜索操作 */
discovering : boolean;
/** 蓝牙适配器是否可用 */
available ?: boolean;
}
export type LPA_DeviceFoundActionResult = {
devices : LPA_Device[]
}
export type LPA_PrintResponse = {
statusCode : number;
resultInfo ?: any;
previewData ?: string[];
// printData?: string[];
}
export type LPA_DeviceDiscoveryOptions = {
timeout ?: number;
interval ?: number;
success ?: (res : any) => void,
fail ?: (res : LPA_Response) => void,
complete ?: (res : LPA_Response) => void,
deviceFound ?: (res : LPA_DeviceFoundActionResult) => void,
adapterStateChange ?: (result : LPA_BleAdapterStateChangeResult) => void;
}
export type LPA_GetPrintersOptions = {
name ?: string,
// success ?: (res : LPA_Device[]) => void,
// fail ?: (res : LPA_Response<any>) => void,
// complete ?: (res : LPA_Response<LPA_Device[]>) => void,
}
export type LPA_OpenPrinterOptions = {
name ?: string;
deviceId ?: string;
timeout ?: number;
success ?: (res : boolean) => void,
fail ?: (res : LPA_Response) => void,
complete ?: (res : LPA_Response) => void,
}
export type LPA_PrintImageOptions = {
image : string;
// 打印参数
gapType ?: number;
printSpeed ?: number;
printDarkness ?: number;
printCopies ?: number;
threshold ?: number;
// 回调
success ?: (res : boolean) => void,
fail ?: (res : LPA_Response) => void,
complete ?: (res : LPA_Response) => void,
}
export type LPA_JobStartOptions = {
width : number;
height ?: number;
orientation ?: number;
jobName ?: string;
backgroundColor ?: string;
background ?: string;
gapType ?: number;
printSpeed ?: number;
printDarkness ?: number;
printCopies ?: number;
threshold ?: number;
}
export type LPA_JobCommitOptions = {
gapType ?: number;
printSpeed ?: number;
printDarkness ?: number;
printCopies ?: number;
threshold ?: number;
success ?: (res : LPA_PrintResponse) => void;
fail ?: (res : LPA_PrintResponse) => void;
complete ?: (res : LPA_PrintResponse) => void;
}
export type LPA_DrawTextOptions = {
text ?: string | string[];
x ?: number;
y ?: number;
width ?: number;
height ?: number;
fontHeight ?: number;
fontStyle ?: number;
fontName ?: string;
lineSpace ?: number;
autoReturn ?: number;
horizontalAlignment ?: number;
verticalAlignment ?: number;
orientation ?: number;
}
export type LPA_DrawImageOptions = {
image : any;
x ?: number;
y ?: number;
width ?: number;
height ?: number;
threshold ?: number;
horizontalAlignment ?: number;
verticalAlignment ?: number;
alignment ?: number;
orientation ?: number;
}
export type LPA_DrawBarcodeOptions = {
text : string;
x ?: number;
y ?: number;
width ?: number;
height ?: number;
barcodeType ?: number;
textHeight ?: number;
fontHeight ?: number;
fontName ?: string;
fontStyle ?: number;
textAlignment ?: number;
horizontalAlignment ?: number;
verticalAlignment ?: number;
orientation ?: number;
}
export type LPA_DrawQRCodeOptions = {
text : string;
x ?: number;
y ?: number;
width ?: number;
height ?: number;
eccLevel ?: number;
horizontalAlignment ?: number;
verticalAlignment ?: number;
orientation ?: number;
}
export type LPA_DrawRectOptions = {
x ?: number;
y ?: number;
width ?: number;
height ?: number;
lineWidth ?: number;
fill ?: boolean;
cornerWidth ?: number;
cornerHeight ?: number;
radius ?: number;
horizontalAlignment ?: number;
verticalAlignment ?: number;
orientation ?: number;
}
export type LPA_DrawCircleOptions = {
x ?: number;
y ?: number;
width ?: number;
height ?: number;
radius ?: number;
lineWidth ?: number;
fill ?: boolean;
}
export type LPA_DrawLineOptions = {
x1 ?: number;
y1 ?: number;
x2 ?: number;
y2 ?: number;
x ?: number;
y ?: number;
width ?: number;
height ?: number;
lineWidth ?: number;
dashLen ?: string;
dashLens ?: number[];
}
/**
* 错误码
* 根据uni错误码规范要求,建议错误码以90开头,以下是错误码示例:
* - 9010001 错误信息1
* - 9010002 错误信息2
*/
export type LPA_ResultCode = 0 | 1 | 2 | 3 | 4;
export type LPA_InitOptions = {
logLevel ?: number,
clientType ?: number,
// bleMode ?: boolean,
}
export type LPA_Device = {
name : string;
deviceId : string;
}
/**
* LPAPI 接口定义。
*/
interface LabelPrintApi {
setOptions(options : LPA_InitOptions) : void;
checkPermission(options ?: LPA_RequestOptions) : void;
startDiscovery(options ?: LPA_DeviceDiscoveryOptions) : void;
stopDiscovery(options ?: LPA_RequestOptions) : void;
openPrinter(options ?: LPA_OpenPrinterOptions) : void;
closePrinter(options ?: LPA_RequestOptions) : void;
// print : (options : LPA_RequestOptions) : void;
printImage(options : LPA_PrintImageOptions) : void;
startJob(options : LPA_JobStartOptions) : boolean;
commitJob(options ?: LPA_JobCommitOptions) : boolean;
drawText(options : LPA_DrawTextOptions) : void;
drawImage(options : LPA_DrawImageOptions) : void;
drawImageAsync(options : LPA_DrawImageOptions) : Promise<boolean>;
draw1DBarcode(options : LPA_DrawBarcodeOptions) : void;
drawBarcode(options : LPA_DrawBarcodeOptions) : void;
draw2DQRCode(options : LPA_DrawQRCodeOptions) : void;
drawQrcode(options : LPA_DrawQRCodeOptions) : void;
drawRectangle(options : LPA_DrawRectOptions) : void;
drawEllipse(options : LPA_DrawRectOptions) : void;
drawCircle(options : LPA_DrawCircleOptions) : void;
drawLine(options : LPA_DrawLineOptions) : void;
//
loadImage(path : string, callback ?: ((src : any) => void)) : Promise<any>;
}
/**
* 获取一个单实例的接口实例对象。
*/
export type GetApiFunc = (options ?: LPA_InitOptions) => LabelPrintApi;

收藏人数:
购买源码授权版(
试用
使用 HBuilderX 导入示例项目
赞赏(0)
下载 2701
赞赏 0
下载 12555186
赞赏 1948
赞赏
京公网安备:11010802035340号