taro-bluetooth-print 2.7.0 → 2.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +104 -133
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/types/device/DeviceManager.d.ts +1 -1
- package/dist/types/device/DiscoveryService.d.ts +3 -2
- package/dist/types/drivers/SprtDriver.d.ts +87 -0
- package/dist/types/drivers/XprinterDriver.d.ts +84 -0
- package/dist/types/drivers/index.d.ts +2 -0
- package/dist/types/services/CloudPrintManager.d.ts +123 -0
- package/dist/types/services/PrintScheduler.d.ts +3 -3
- package/dist/types/services/QRCodeDiscoveryService.d.ts +120 -0
- package/dist/types/services/QRCodeParser.d.ts +60 -0
- package/dist/types/services/index.d.ts +3 -0
- package/dist/types/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/device/DeviceManager.ts +2 -2
- package/src/device/DiscoveryService.ts +39 -26
- package/src/drivers/SprtDriver.ts +163 -0
- package/src/drivers/XprinterDriver.ts +155 -0
- package/src/drivers/index.ts +4 -0
- package/src/services/CloudPrintManager.ts +372 -0
- package/src/services/PrintScheduler.ts +18 -8
- package/src/services/QRCodeDiscoveryService.ts +429 -0
- package/src/services/QRCodeParser.ts +185 -0
- package/src/services/index.ts +29 -0
- package/src/template/TemplateEngine.ts +2 -2
- package/src/types.ts +1 -1
- package/src/utils/image.ts +37 -38
|
@@ -22,7 +22,7 @@ export interface BluetoothDevice {
|
|
|
22
22
|
/** Signal strength (RSSI) */
|
|
23
23
|
rssi?: number;
|
|
24
24
|
/** Advertisement data */
|
|
25
|
-
|
|
25
|
+
advertisementData?: ArrayBuffer;
|
|
26
26
|
/** Service UUIDs */
|
|
27
27
|
serviceUUIDs?: string[];
|
|
28
28
|
/** Local name from advertisement */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from '../core/EventEmitter';
|
|
2
|
+
import { IPrinterAdapter } from '../types';
|
|
2
3
|
export interface DiscoveredDevice {
|
|
3
4
|
id: string;
|
|
4
5
|
name: string;
|
|
@@ -40,7 +41,7 @@ export interface DiscoveryEvents {
|
|
|
40
41
|
'discovery-stop': void;
|
|
41
42
|
'discovery-complete': DiscoveredDevice[];
|
|
42
43
|
'discovery-error': Error;
|
|
43
|
-
|
|
44
|
+
retry: {
|
|
44
45
|
attempt: number;
|
|
45
46
|
maxRetries: number;
|
|
46
47
|
};
|
|
@@ -58,7 +59,7 @@ export declare class DiscoveryService extends EventEmitter<DiscoveryEvents> {
|
|
|
58
59
|
/**
|
|
59
60
|
* 设置平台适配器
|
|
60
61
|
*/
|
|
61
|
-
setPlatformAdapter(adapter:
|
|
62
|
+
setPlatformAdapter(adapter: IPrinterAdapter): void;
|
|
62
63
|
/**
|
|
63
64
|
* 开始发现设备
|
|
64
65
|
*/
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { EscPos, EscPosOptions } from './EscPos';
|
|
2
|
+
/**
|
|
3
|
+
* SprtDriver options (same as EscPosOptions)
|
|
4
|
+
*/
|
|
5
|
+
export type SprtDriverOptions = EscPosOptions;
|
|
6
|
+
/**
|
|
7
|
+
* SprtDriver for Sprt (思普瑞特) thermal printers
|
|
8
|
+
*
|
|
9
|
+
* 思普瑞特打印机基于 ESC/POS 指令集,此驱动扩展了标准 EscPos
|
|
10
|
+
* 添加了思普瑞特特定的命令支持,特别是低功耗相关的功能
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { SprtDriver } from 'taro-bluetooth-print';
|
|
15
|
+
*
|
|
16
|
+
* const driver = new SprtDriver();
|
|
17
|
+
* let commands = driver.init();
|
|
18
|
+
* commands = driver.text('Hello 思普瑞特!', 'GBK');
|
|
19
|
+
* commands = driver.cut();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class SprtDriver extends EscPos {
|
|
23
|
+
/**
|
|
24
|
+
* 思普瑞特特定: 进入低功耗/休眠模式
|
|
25
|
+
* @returns Array of command buffers
|
|
26
|
+
*/
|
|
27
|
+
sleep(): Uint8Array[];
|
|
28
|
+
/**
|
|
29
|
+
* 思普瑞特特定: 唤醒打印机
|
|
30
|
+
* 发送空字符或特定序列唤醒休眠中的打印机
|
|
31
|
+
* @returns Array of command buffers
|
|
32
|
+
*/
|
|
33
|
+
wakeUp(): Uint8Array[];
|
|
34
|
+
/**
|
|
35
|
+
* 思普瑞特特定: 深度唤醒
|
|
36
|
+
* 使用完整的初始化序列唤醒打印机
|
|
37
|
+
* @returns Array of command buffers
|
|
38
|
+
*/
|
|
39
|
+
wakeUpDeep(): Uint8Array[];
|
|
40
|
+
/**
|
|
41
|
+
* 思普瑞特特定: 打开钱箱
|
|
42
|
+
* @param pin 钱箱引脚 (0 或 1, 默认 0)
|
|
43
|
+
* @returns Array of command buffers
|
|
44
|
+
*/
|
|
45
|
+
openCashDrawer(pin?: number): Uint8Array[];
|
|
46
|
+
/**
|
|
47
|
+
* 思普瑞特特定: 发送声响警报
|
|
48
|
+
* @param times 次数 (1-9)
|
|
49
|
+
* @param duration 持续时间 (ms)
|
|
50
|
+
* @returns Array of command buffers
|
|
51
|
+
*/
|
|
52
|
+
beep(times?: number, duration?: number): Uint8Array[];
|
|
53
|
+
/**
|
|
54
|
+
* 思普瑞特特定: 打印自检页
|
|
55
|
+
* @returns Array of command buffers
|
|
56
|
+
*/
|
|
57
|
+
selfTest(): Uint8Array[];
|
|
58
|
+
/**
|
|
59
|
+
* 思普瑞特特定: 获取打印机状态
|
|
60
|
+
* @returns Array of command buffers
|
|
61
|
+
*/
|
|
62
|
+
getStatus(): Uint8Array[];
|
|
63
|
+
/**
|
|
64
|
+
* 思普瑞特特定: 设置字符代码页
|
|
65
|
+
* @param codePage 代码页编号 (0-255)
|
|
66
|
+
* @returns Array of command buffers
|
|
67
|
+
*/
|
|
68
|
+
setCodePage(codePage: number): Uint8Array[];
|
|
69
|
+
/**
|
|
70
|
+
* 思普瑞特特定: 设置左边界
|
|
71
|
+
* @param n 左边界字符数
|
|
72
|
+
* @returns Array of command buffers
|
|
73
|
+
*/
|
|
74
|
+
setLeftMargin(n: number): Uint8Array[];
|
|
75
|
+
/**
|
|
76
|
+
* 思普瑞特特定: 设置打印区域宽度
|
|
77
|
+
* @param n 宽度 (字符数)
|
|
78
|
+
* @returns Array of command buffers
|
|
79
|
+
*/
|
|
80
|
+
setPrintWidth(n: number): Uint8Array[];
|
|
81
|
+
/**
|
|
82
|
+
* 思普瑞特特定: 使能/禁止自动休眠
|
|
83
|
+
* @param enable true=使能自动休眠, false=禁止自动休眠
|
|
84
|
+
* @returns Array of command buffers
|
|
85
|
+
*/
|
|
86
|
+
setAutoSleep(enable: boolean): Uint8Array[];
|
|
87
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { EscPos, EscPosOptions } from './EscPos';
|
|
2
|
+
/**
|
|
3
|
+
* Xprinter options (same as EscPosOptions)
|
|
4
|
+
*/
|
|
5
|
+
export type XprinterOptions = EscPosOptions;
|
|
6
|
+
/**
|
|
7
|
+
* XprinterDriver for Xprinter (芯烨) thermal printers
|
|
8
|
+
*
|
|
9
|
+
* 芯烨打印机基于 ESC/POS 指令集,此驱动扩展了标准 EscPos
|
|
10
|
+
* 添加了芯烨特定的命令支持
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { XprinterDriver } from 'taro-bluetooth-print';
|
|
15
|
+
*
|
|
16
|
+
* const driver = new XprinterDriver();
|
|
17
|
+
* let commands = driver.init();
|
|
18
|
+
* commands = driver.text('Hello 芯烨!', 'GBK');
|
|
19
|
+
* commands = driver.cut();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class XprinterDriver extends EscPos {
|
|
23
|
+
/**
|
|
24
|
+
* 芯烨打印机特定: 增强初始化
|
|
25
|
+
* 添加芯烨特定的初始化序列
|
|
26
|
+
*
|
|
27
|
+
* @returns Array of command buffers
|
|
28
|
+
*/
|
|
29
|
+
init(): Uint8Array[];
|
|
30
|
+
/**
|
|
31
|
+
* 芯烨打印机特定: 打开钱箱
|
|
32
|
+
* @param pin 钱箱引脚 (0 或 1, 默认 0)
|
|
33
|
+
* @returns Array of command buffers
|
|
34
|
+
*/
|
|
35
|
+
openCashDrawer(pin?: number): Uint8Array[];
|
|
36
|
+
/**
|
|
37
|
+
* 芯烨打印机特定: 发送声响警报
|
|
38
|
+
* @param times 次数 (1-9)
|
|
39
|
+
* @param duration 持续时间 (ms)
|
|
40
|
+
* @returns Array of command buffers
|
|
41
|
+
*/
|
|
42
|
+
beep(times?: number, duration?: number): Uint8Array[];
|
|
43
|
+
/**
|
|
44
|
+
* 芯烨打印机特定: 打印自检页
|
|
45
|
+
* @returns Array of command buffers
|
|
46
|
+
*/
|
|
47
|
+
selfTest(): Uint8Array[];
|
|
48
|
+
/**
|
|
49
|
+
* 芯烨打印机特定: 获取打印机状态
|
|
50
|
+
* 返回打印机状态字节
|
|
51
|
+
* @returns Array of command buffers
|
|
52
|
+
*/
|
|
53
|
+
getStatus(): Uint8Array[];
|
|
54
|
+
/**
|
|
55
|
+
* 芯烨打印机特定: 获取详细状态
|
|
56
|
+
* 使用 DLE EOT 命令获取不同类型的状态
|
|
57
|
+
* @returns Array of command buffers (4 status queries)
|
|
58
|
+
*/
|
|
59
|
+
getDetailedStatus(): Uint8Array[];
|
|
60
|
+
/**
|
|
61
|
+
* 芯烨打印机特定: 设置字符代码页
|
|
62
|
+
* @param codePage 代码页编号 (0-255)
|
|
63
|
+
* @returns Array of command buffers
|
|
64
|
+
*/
|
|
65
|
+
setCodePage(codePage: number): Uint8Array[];
|
|
66
|
+
/**
|
|
67
|
+
* 芯烨打印机特定: 设置左边界
|
|
68
|
+
* @param n 左边界字符数
|
|
69
|
+
* @returns Array of command buffers
|
|
70
|
+
*/
|
|
71
|
+
setLeftMargin(n: number): Uint8Array[];
|
|
72
|
+
/**
|
|
73
|
+
* 芯烨打印机特定: 设置打印区域宽度
|
|
74
|
+
* @param n 宽度 (字符数)
|
|
75
|
+
* @returns Array of command buffers
|
|
76
|
+
*/
|
|
77
|
+
setPrintWidth(n: number): Uint8Array[];
|
|
78
|
+
/**
|
|
79
|
+
* 芯烨打印机特定: 进纸并切割
|
|
80
|
+
* @param lines 进纸行数
|
|
81
|
+
* @returns Array of command buffers
|
|
82
|
+
*/
|
|
83
|
+
feedAndCut(lines: number): Uint8Array[];
|
|
84
|
+
}
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { EscPos, type EscPosOptions } from './EscPos';
|
|
6
6
|
export { GPrinterDriver, type GPrinterOptions } from './GPrinterDriver';
|
|
7
|
+
export { XprinterDriver, type XprinterOptions } from './XprinterDriver';
|
|
8
|
+
export { SprtDriver, type SprtDriverOptions } from './SprtDriver';
|
|
7
9
|
export { TsplDriver, type LabelSize, type TextOptions, type BarcodeOptions, type QRCodeOptions, type BoxOptions, type LineOptions, } from './TsplDriver';
|
|
8
10
|
export { ZplDriver, type ZplLabelSize, type ZplTextOptions, type ZplBarcodeOptions, type ZplQRCodeOptions, type ZplBoxOptions, } from './ZplDriver';
|
|
9
11
|
export { CpclDriver, type CPCLPageSize, type CpclTextOptions, type CpclBarcodeOptions, type CpclQRCodeOptions, type CpclLineOptions, type CpclBoxOptions, } from './CpclDriver';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { EventEmitter } from '../core/EventEmitter';
|
|
2
|
+
export interface CloudPrintOptions {
|
|
3
|
+
/** WebSocket 服务器地址 */
|
|
4
|
+
serverUrl: string;
|
|
5
|
+
/** 设备 ID */
|
|
6
|
+
deviceId: string;
|
|
7
|
+
/** API 密钥(可选) */
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
/** 自动重连 */
|
|
10
|
+
reconnect?: boolean;
|
|
11
|
+
/** 重连间隔 (ms) */
|
|
12
|
+
reconnectInterval?: number;
|
|
13
|
+
/** 心跳间隔 (ms) */
|
|
14
|
+
heartbeatInterval?: number;
|
|
15
|
+
/** 连接超时 (ms) */
|
|
16
|
+
connectTimeout?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface PrintJob {
|
|
19
|
+
/** 任务 ID */
|
|
20
|
+
id: string;
|
|
21
|
+
/** 打印数据 */
|
|
22
|
+
data: Uint8Array | string;
|
|
23
|
+
/** 份数 */
|
|
24
|
+
copies?: number;
|
|
25
|
+
/** 优先级 */
|
|
26
|
+
priority?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface CloudPrinterStatus {
|
|
29
|
+
/** 打印机状态 */
|
|
30
|
+
status: 'idle' | 'printing' | 'error' | 'offline';
|
|
31
|
+
/** 纸张状态 */
|
|
32
|
+
paper?: 'ok' | 'low' | 'out';
|
|
33
|
+
/** 错误信息 */
|
|
34
|
+
error?: string;
|
|
35
|
+
/** 最后更新时间 */
|
|
36
|
+
timestamp: number;
|
|
37
|
+
}
|
|
38
|
+
export interface CloudPrintEvents {
|
|
39
|
+
/** 连接成功 */
|
|
40
|
+
connect: void;
|
|
41
|
+
/** 断开连接 */
|
|
42
|
+
disconnect: void;
|
|
43
|
+
/** 连接错误 */
|
|
44
|
+
error: Error;
|
|
45
|
+
/** 状态更新 */
|
|
46
|
+
status: CloudPrinterStatus;
|
|
47
|
+
/** 打印完成 */
|
|
48
|
+
'print-complete': string;
|
|
49
|
+
/** 打印失败 */
|
|
50
|
+
'print-error': {
|
|
51
|
+
jobId: string;
|
|
52
|
+
error: string;
|
|
53
|
+
};
|
|
54
|
+
/** 收到原始消息 */
|
|
55
|
+
message: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
export type CloudPrintEvent = keyof CloudPrintEvents;
|
|
58
|
+
/**
|
|
59
|
+
* 云打印管理器
|
|
60
|
+
*
|
|
61
|
+
* 通过 WebSocket 连接到云端服务器,实现远程打印任务下发
|
|
62
|
+
*/
|
|
63
|
+
export declare class CloudPrintManager extends EventEmitter<CloudPrintEvents> {
|
|
64
|
+
private readonly log;
|
|
65
|
+
private options;
|
|
66
|
+
private ws;
|
|
67
|
+
private isConnected;
|
|
68
|
+
private reconnectTimer;
|
|
69
|
+
private heartbeatTimer;
|
|
70
|
+
private status;
|
|
71
|
+
private connectResolve;
|
|
72
|
+
private connectReject;
|
|
73
|
+
constructor(options: CloudPrintOptions);
|
|
74
|
+
/**
|
|
75
|
+
* 检查是否已连接
|
|
76
|
+
*/
|
|
77
|
+
get connected(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* 获取当前打印机状态
|
|
80
|
+
*/
|
|
81
|
+
get currentStatus(): CloudPrinterStatus;
|
|
82
|
+
/**
|
|
83
|
+
* 连接到云端服务器
|
|
84
|
+
*/
|
|
85
|
+
connect(): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* 断开连接
|
|
88
|
+
*/
|
|
89
|
+
disconnect(): void;
|
|
90
|
+
/**
|
|
91
|
+
* 发送打印任务
|
|
92
|
+
* @throws Error 如果未连接
|
|
93
|
+
*/
|
|
94
|
+
print(job: PrintJob): void;
|
|
95
|
+
/**
|
|
96
|
+
* 获取打印机状态
|
|
97
|
+
*/
|
|
98
|
+
getStatus(): CloudPrinterStatus;
|
|
99
|
+
/**
|
|
100
|
+
* 处理接收到的消息
|
|
101
|
+
*/
|
|
102
|
+
private handleMessage;
|
|
103
|
+
/**
|
|
104
|
+
* 启动心跳
|
|
105
|
+
*/
|
|
106
|
+
private startHeartbeat;
|
|
107
|
+
/**
|
|
108
|
+
* 停止心跳
|
|
109
|
+
*/
|
|
110
|
+
private stopHeartbeat;
|
|
111
|
+
/**
|
|
112
|
+
* 安排重连
|
|
113
|
+
*/
|
|
114
|
+
private scheduleReconnect;
|
|
115
|
+
/**
|
|
116
|
+
* 取消重连
|
|
117
|
+
*/
|
|
118
|
+
private cancelReconnect;
|
|
119
|
+
/**
|
|
120
|
+
* ArrayBuffer 转 Base64
|
|
121
|
+
*/
|
|
122
|
+
private arrayBufferToBase64;
|
|
123
|
+
}
|
|
@@ -28,7 +28,7 @@ export interface ScheduleOptions {
|
|
|
28
28
|
}
|
|
29
29
|
export interface ScheduleEvents {
|
|
30
30
|
'will-execute': ScheduledPrint;
|
|
31
|
-
|
|
31
|
+
executed: {
|
|
32
32
|
job: ScheduledPrint;
|
|
33
33
|
success: boolean;
|
|
34
34
|
error?: Error;
|
|
@@ -37,8 +37,8 @@ export interface ScheduleEvents {
|
|
|
37
37
|
job: ScheduledPrint;
|
|
38
38
|
runTime: number;
|
|
39
39
|
};
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
completed: ScheduledPrint;
|
|
41
|
+
failed: {
|
|
42
42
|
job: ScheduledPrint;
|
|
43
43
|
error: Error;
|
|
44
44
|
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QRCodeDiscoveryService - 二维码打印机配对服务
|
|
3
|
+
*
|
|
4
|
+
* 用于扫描打印机屏幕二维码获取设备信息并直连
|
|
5
|
+
*
|
|
6
|
+
* 支持的二维码格式:
|
|
7
|
+
* 1. 商米格式 (Sunmi): 包含蓝牙地址和服务信息
|
|
8
|
+
* 2. 标准格式: 包含 MAC 地址
|
|
9
|
+
* 3. 自定义格式: 可扩展
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* 二维码发现服务配置选项
|
|
13
|
+
*/
|
|
14
|
+
export interface QRCodeDiscoveryOptions {
|
|
15
|
+
/** 二维码格式类型 */
|
|
16
|
+
format: 'sunmi' | 'standard' | 'custom';
|
|
17
|
+
/** 是否自动连接 */
|
|
18
|
+
autoConnect?: boolean;
|
|
19
|
+
/** 自定义解析函数 */
|
|
20
|
+
parser?: (content: string) => ParsedDeviceInfo;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 解析后的设备信息
|
|
24
|
+
*/
|
|
25
|
+
export interface ParsedDeviceInfo {
|
|
26
|
+
/** 设备名称 */
|
|
27
|
+
name?: string;
|
|
28
|
+
/** 蓝牙 MAC 地址 */
|
|
29
|
+
address?: string;
|
|
30
|
+
/** 服务 UUID */
|
|
31
|
+
serviceUuid?: string;
|
|
32
|
+
/** 设备类型 */
|
|
33
|
+
type?: 'printer' | 'scanner' | 'other';
|
|
34
|
+
/** 其他元数据 */
|
|
35
|
+
metadata?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 发现结果
|
|
39
|
+
*/
|
|
40
|
+
export interface DiscoveryResult {
|
|
41
|
+
/** 解析后的设备信息 */
|
|
42
|
+
device: ParsedDeviceInfo;
|
|
43
|
+
/** 原始二维码内容 */
|
|
44
|
+
raw: string;
|
|
45
|
+
/** 解析格式 */
|
|
46
|
+
format: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 二维码发现服务
|
|
50
|
+
*/
|
|
51
|
+
export declare class QRCodeDiscoveryService {
|
|
52
|
+
private options;
|
|
53
|
+
constructor(options: QRCodeDiscoveryOptions);
|
|
54
|
+
/**
|
|
55
|
+
* 解析二维码内容
|
|
56
|
+
* @param content 二维码字符串内容
|
|
57
|
+
* @returns 解析结果
|
|
58
|
+
*/
|
|
59
|
+
parse(content: string): DiscoveryResult;
|
|
60
|
+
/**
|
|
61
|
+
* 解析商米格式二维码
|
|
62
|
+
* 商米打印机二维码通常包含:
|
|
63
|
+
* - 设备名称
|
|
64
|
+
* - 蓝牙地址
|
|
65
|
+
* - 连接参数
|
|
66
|
+
*
|
|
67
|
+
* 支持的格式:
|
|
68
|
+
* 1. JSON: {"name":"SUNMI P2","mac":"AA:BB:CC:DD:EE:FF","type":"printer"}
|
|
69
|
+
* 2. 分隔符: SUNMI P2|AA:BB:CC:DD:EE:FF|printer
|
|
70
|
+
*/
|
|
71
|
+
parseSunmi(content: string): DiscoveryResult;
|
|
72
|
+
/**
|
|
73
|
+
* 解析商米 JSON 格式
|
|
74
|
+
*/
|
|
75
|
+
private parseSunmiJson;
|
|
76
|
+
/**
|
|
77
|
+
* 解析商米分隔符格式 (name|MAC|type)
|
|
78
|
+
*/
|
|
79
|
+
private parseSunmiPipe;
|
|
80
|
+
/**
|
|
81
|
+
* 解析标准格式二维码
|
|
82
|
+
* 标准格式通常是 MAC 地址或蓝牙设备信息
|
|
83
|
+
*
|
|
84
|
+
* 支持的格式:
|
|
85
|
+
* 1. AA:BB:CC:DD:EE:FF (冒号分隔)
|
|
86
|
+
* 2. AA-BB-CC-DD-EE-FF (连字符分隔)
|
|
87
|
+
* 3. AABBCCDDEEFF (无分隔符)
|
|
88
|
+
*/
|
|
89
|
+
parseStandard(content: string): DiscoveryResult;
|
|
90
|
+
/**
|
|
91
|
+
* 解析 MAC 地址
|
|
92
|
+
*/
|
|
93
|
+
private parseMacAddress;
|
|
94
|
+
/**
|
|
95
|
+
* 标准化 MAC 地址格式(转换为大写冒号分隔)
|
|
96
|
+
*/
|
|
97
|
+
private normalizeMacAddress;
|
|
98
|
+
/**
|
|
99
|
+
* 格式化 MAC 地址为冒号分隔格式
|
|
100
|
+
*/
|
|
101
|
+
private formatMacWithColons;
|
|
102
|
+
/**
|
|
103
|
+
* 标准化设备类型
|
|
104
|
+
*/
|
|
105
|
+
private normalizeDeviceType;
|
|
106
|
+
/**
|
|
107
|
+
* 从 JSON 字符串中提取元数据
|
|
108
|
+
*/
|
|
109
|
+
private extractJsonMetadata;
|
|
110
|
+
/**
|
|
111
|
+
* 获取配置选项
|
|
112
|
+
*/
|
|
113
|
+
getOptions(): QRCodeDiscoveryOptions;
|
|
114
|
+
/**
|
|
115
|
+
* 验证解析结果是否有效
|
|
116
|
+
*/
|
|
117
|
+
static isValidResult(result: DiscoveryResult): boolean;
|
|
118
|
+
}
|
|
119
|
+
export { parseQRCode, parseMultipleQRCodes, detectQRCodeFormat, addQRCodeFormat, removeQRCodeFormat, getSupportedFormats, QR_CODE_FORMATS, } from './QRCodeParser';
|
|
120
|
+
export type { QRCodeFormat } from './QRCodeParser';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ParsedDeviceInfo } from './QRCodeDiscoveryService';
|
|
2
|
+
/**
|
|
3
|
+
* 二维码格式定义
|
|
4
|
+
*/
|
|
5
|
+
export interface QRCodeFormat {
|
|
6
|
+
/** 格式名称 */
|
|
7
|
+
name: string;
|
|
8
|
+
/** 正则表达式 */
|
|
9
|
+
pattern: RegExp;
|
|
10
|
+
/** 解析函数 */
|
|
11
|
+
parse: (match: RegExpMatchArray, raw: string) => ParsedDeviceInfo;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 内置支持的二维码格式
|
|
15
|
+
*/
|
|
16
|
+
export declare const QR_CODE_FORMATS: QRCodeFormat[];
|
|
17
|
+
/**
|
|
18
|
+
* 解析二维码字符串
|
|
19
|
+
*
|
|
20
|
+
* @param content 二维码原始内容
|
|
21
|
+
* @returns 解析后的设备信息,如果无法解析则返回 null
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseQRCode(content: string): ParsedDeviceInfo | null;
|
|
24
|
+
/**
|
|
25
|
+
* 批量解析多个二维码
|
|
26
|
+
*
|
|
27
|
+
* @param contents 二维码内容数组
|
|
28
|
+
* @returns 解析结果数组,包含成功解析和失败的结果
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseMultipleQRCodes(contents: string[]): {
|
|
31
|
+
success: Array<{
|
|
32
|
+
content: string;
|
|
33
|
+
device: ParsedDeviceInfo;
|
|
34
|
+
}>;
|
|
35
|
+
failed: string[];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* 检测二维码内容类型
|
|
39
|
+
*
|
|
40
|
+
* @param content 二维码内容
|
|
41
|
+
* @returns 格式名称,如果无法识别则返回 null
|
|
42
|
+
*/
|
|
43
|
+
export declare function detectQRCodeFormat(content: string): string | null;
|
|
44
|
+
/**
|
|
45
|
+
* 添加自定义二维码格式
|
|
46
|
+
*
|
|
47
|
+
* @param format 格式定义
|
|
48
|
+
*/
|
|
49
|
+
export declare function addQRCodeFormat(format: QRCodeFormat): void;
|
|
50
|
+
/**
|
|
51
|
+
* 移除自定义二维码格式
|
|
52
|
+
*
|
|
53
|
+
* @param formatName 格式名称
|
|
54
|
+
* @returns 是否成功移除
|
|
55
|
+
*/
|
|
56
|
+
export declare function removeQRCodeFormat(formatName: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* 获取所有支持的格式名称列表
|
|
59
|
+
*/
|
|
60
|
+
export declare function getSupportedFormats(): string[];
|
|
@@ -12,3 +12,6 @@ export { PrintStatistics, printStatistics, type PrintStatisticsData, type JobTra
|
|
|
12
12
|
export { ScheduledRetryManager, scheduledRetryManager, type ScheduledRetry, type RetryOptions, type ScheduledRetryEvents, type ScheduledRetryManagerConfig, } from './ScheduledRetryManager';
|
|
13
13
|
export { PrintScheduler, printScheduler, type ScheduledPrint, type ScheduleOptions, type ScheduleEvents, parseCronExpression, getNextCronRun, getNextIntervalRun, } from './PrintScheduler';
|
|
14
14
|
export * from './interfaces';
|
|
15
|
+
export { CloudPrintManager, type CloudPrintOptions, type PrintJob, type CloudPrinterStatus, type CloudPrintEvents, type CloudPrintEvent, } from './CloudPrintManager';
|
|
16
|
+
export { QRCodeDiscoveryService, type QRCodeDiscoveryOptions, type ParsedDeviceInfo, type DiscoveryResult, } from './QRCodeDiscoveryService';
|
|
17
|
+
export { parseQRCode, parseMultipleQRCodes, detectQRCodeFormat, addQRCodeFormat, removeQRCodeFormat, getSupportedFormats, QR_CODE_FORMATS, type QRCodeFormat, } from './QRCodeParser';
|
package/dist/types/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@ export interface BluetoothDevice {
|
|
|
26
26
|
/** Signal strength (RSSI) */
|
|
27
27
|
rssi?: number;
|
|
28
28
|
/** Advertisement data */
|
|
29
|
-
|
|
29
|
+
advertisementData?: ArrayBuffer;
|
|
30
30
|
/** Service UUIDs */
|
|
31
31
|
serviceUUIDs?: string[];
|
|
32
32
|
/** Local name from advertisement */
|
|
@@ -404,7 +404,7 @@ export class DeviceManager implements IDeviceManager {
|
|
|
404
404
|
deviceId: device.deviceId,
|
|
405
405
|
name: device.name || device.localName || 'Unknown',
|
|
406
406
|
rssi: device.RSSI,
|
|
407
|
-
|
|
407
|
+
advertisementData: device.advertisData,
|
|
408
408
|
serviceUUIDs: device.advertisServiceUUIDs,
|
|
409
409
|
localName: device.localName,
|
|
410
410
|
};
|