taro-bluetooth-print 1.0.1 → 1.0.2
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/LICENSE +2 -2
- package/dist/bluetooth/index.d.ts +31 -4
- package/dist/bluetooth/index.js +206 -28
- package/dist/bluetooth/index.js.map +1 -1
- package/dist/index.d.ts +50 -4
- package/dist/index.js +132 -6
- package/dist/index.js.map +1 -1
- package/dist/printer/index.d.ts +25 -3
- package/dist/printer/index.js +108 -8
- package/dist/printer/index.js.map +1 -1
- package/dist/printer/templates/base.d.ts +96 -0
- package/dist/printer/templates/base.js +179 -0
- package/dist/printer/templates/base.js.map +1 -0
- package/dist/printer/templates/index.d.ts +53 -0
- package/dist/printer/templates/index.js +92 -0
- package/dist/printer/templates/index.js.map +1 -0
- package/dist/printer/templates/receipt.d.ts +43 -0
- package/dist/printer/templates/receipt.js +198 -0
- package/dist/printer/templates/receipt.js.map +1 -0
- package/dist/types/index.d.ts +124 -0
- package/dist/types/index.js +38 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/config.d.ts +76 -0
- package/dist/utils/config.js +109 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/events.d.ts +69 -0
- package/dist/utils/events.js +140 -0
- package/dist/utils/events.js.map +1 -0
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025 Agions
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { BluetoothDevice } from '
|
|
1
|
+
import { BluetoothDevice, ConnectOptions, DiscoveryOptions } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 蓝牙管理器类
|
|
4
|
+
* 负责蓝牙设备的扫描、连接和通信
|
|
5
|
+
*/
|
|
2
6
|
export declare class BluetoothManager {
|
|
3
7
|
private adapter;
|
|
4
8
|
private isInitialized;
|
|
@@ -7,6 +11,9 @@ export declare class BluetoothManager {
|
|
|
7
11
|
private discoveredDevices;
|
|
8
12
|
private serviceUUID;
|
|
9
13
|
private characteristicUUID;
|
|
14
|
+
/**
|
|
15
|
+
* 创建蓝牙管理器实例
|
|
16
|
+
*/
|
|
10
17
|
constructor();
|
|
11
18
|
/**
|
|
12
19
|
* 初始化蓝牙模块
|
|
@@ -14,8 +21,9 @@ export declare class BluetoothManager {
|
|
|
14
21
|
init(): Promise<boolean>;
|
|
15
22
|
/**
|
|
16
23
|
* 开始搜索蓝牙设备
|
|
24
|
+
* @param options 搜索选项
|
|
17
25
|
*/
|
|
18
|
-
startDiscovery(): Promise<boolean>;
|
|
26
|
+
startDiscovery(options?: DiscoveryOptions): Promise<boolean>;
|
|
19
27
|
/**
|
|
20
28
|
* 停止搜索蓝牙设备
|
|
21
29
|
*/
|
|
@@ -26,9 +34,10 @@ export declare class BluetoothManager {
|
|
|
26
34
|
getDiscoveredDevices(): Promise<BluetoothDevice[]>;
|
|
27
35
|
/**
|
|
28
36
|
* 连接蓝牙设备
|
|
29
|
-
* @param deviceId
|
|
37
|
+
* @param deviceId 设备ID
|
|
38
|
+
* @param options 连接选项
|
|
30
39
|
*/
|
|
31
|
-
connect(deviceId: string): Promise<boolean>;
|
|
40
|
+
connect(deviceId: string, options?: ConnectOptions): Promise<boolean>;
|
|
32
41
|
/**
|
|
33
42
|
* 断开蓝牙连接
|
|
34
43
|
*/
|
|
@@ -38,6 +47,24 @@ export declare class BluetoothManager {
|
|
|
38
47
|
* @param data 要写入的数据
|
|
39
48
|
*/
|
|
40
49
|
writeData(data: ArrayBuffer): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* 检查是否已连接
|
|
52
|
+
*/
|
|
53
|
+
isConnected(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* 获取已连接的设备ID
|
|
56
|
+
*/
|
|
57
|
+
getConnectedDeviceId(): string | null;
|
|
58
|
+
/**
|
|
59
|
+
* 获取适配器初始化状态
|
|
60
|
+
*/
|
|
61
|
+
getInitStatus(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* 设置服务和特征值UUID
|
|
64
|
+
* @param serviceUUID 服务UUID
|
|
65
|
+
* @param characteristicUUID 特征值UUID
|
|
66
|
+
*/
|
|
67
|
+
setServiceUUIDs(serviceUUID: string, characteristicUUID: string): void;
|
|
41
68
|
/**
|
|
42
69
|
* 销毁蓝牙模块
|
|
43
70
|
*/
|
package/dist/bluetooth/index.js
CHANGED
|
@@ -6,8 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.BluetoothManager = void 0;
|
|
7
7
|
const adapter_1 = require("./adapter");
|
|
8
8
|
const logger_1 = require("../utils/logger");
|
|
9
|
+
const events_1 = require("../utils/events");
|
|
10
|
+
const config_1 = require("../utils/config");
|
|
11
|
+
const types_1 = require("../types");
|
|
9
12
|
const taro_1 = __importDefault(require("@tarojs/taro"));
|
|
13
|
+
/**
|
|
14
|
+
* 蓝牙管理器类
|
|
15
|
+
* 负责蓝牙设备的扫描、连接和通信
|
|
16
|
+
*/
|
|
10
17
|
class BluetoothManager {
|
|
18
|
+
/**
|
|
19
|
+
* 创建蓝牙管理器实例
|
|
20
|
+
*/
|
|
11
21
|
constructor() {
|
|
12
22
|
this.isInitialized = false;
|
|
13
23
|
this.connectedDeviceId = null;
|
|
@@ -18,42 +28,98 @@ class BluetoothManager {
|
|
|
18
28
|
// 蓝牙特征值UUID,用于写入数据
|
|
19
29
|
this.characteristicUUID = '49535343-8841-43F4-A8D4-ECBE34729BB3';
|
|
20
30
|
this.adapter = (0, adapter_1.getAdapter)();
|
|
31
|
+
logger_1.logger.debug('蓝牙管理器已创建');
|
|
21
32
|
}
|
|
22
33
|
/**
|
|
23
34
|
* 初始化蓝牙模块
|
|
24
35
|
*/
|
|
25
36
|
async init() {
|
|
26
37
|
try {
|
|
38
|
+
if (this.isInitialized) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
logger_1.logger.debug('正在初始化蓝牙适配器...');
|
|
27
42
|
const result = await this.adapter.init();
|
|
28
43
|
this.isInitialized = result;
|
|
44
|
+
if (result) {
|
|
45
|
+
logger_1.logger.info('蓝牙适配器初始化成功');
|
|
46
|
+
// 触发初始化成功事件
|
|
47
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_INITIALIZED, { success: true });
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
logger_1.logger.error('蓝牙适配器初始化失败');
|
|
51
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_ERROR, new types_1.PrinterError(types_1.ErrorCode.BLUETOOTH_INIT_FAILED, '蓝牙适配器初始化失败'));
|
|
52
|
+
}
|
|
29
53
|
return result;
|
|
30
54
|
}
|
|
31
55
|
catch (error) {
|
|
32
|
-
|
|
56
|
+
this.isInitialized = false;
|
|
57
|
+
const printerError = new types_1.PrinterError(types_1.ErrorCode.BLUETOOTH_INIT_FAILED, '初始化蓝牙模块失败');
|
|
58
|
+
logger_1.logger.error(printerError.message, error);
|
|
59
|
+
// 触发错误事件
|
|
60
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_ERROR, printerError);
|
|
33
61
|
return false;
|
|
34
62
|
}
|
|
35
63
|
}
|
|
36
64
|
/**
|
|
37
65
|
* 开始搜索蓝牙设备
|
|
66
|
+
* @param options 搜索选项
|
|
38
67
|
*/
|
|
39
|
-
async startDiscovery() {
|
|
68
|
+
async startDiscovery(options = {}) {
|
|
40
69
|
if (!this.isInitialized) {
|
|
41
70
|
await this.init();
|
|
42
71
|
}
|
|
72
|
+
// 如果已经在搜索中,先停止
|
|
73
|
+
if (this.discoveryStarted) {
|
|
74
|
+
await this.stopDiscovery();
|
|
75
|
+
}
|
|
76
|
+
// 合并默认选项
|
|
77
|
+
const finalOptions = {
|
|
78
|
+
timeout: options.timeout || config_1.BLUETOOTH_DEFAULTS.SCAN_TIMEOUT,
|
|
79
|
+
services: options.services || ['1812'],
|
|
80
|
+
allowDuplicatesKey: options.allowDuplicatesKey || false
|
|
81
|
+
};
|
|
43
82
|
try {
|
|
44
|
-
|
|
83
|
+
logger_1.logger.debug('开始搜索蓝牙设备...', finalOptions);
|
|
84
|
+
const result = await this.adapter.startDiscovery(finalOptions);
|
|
45
85
|
this.discoveryStarted = result;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
86
|
+
if (result) {
|
|
87
|
+
// 清空设备列表
|
|
88
|
+
this.discoveredDevices.clear();
|
|
89
|
+
// 触发搜索开始事件
|
|
90
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_DISCOVERY_STARTED, finalOptions);
|
|
91
|
+
// 监听设备发现事件
|
|
92
|
+
taro_1.default.onBluetoothDeviceFound(res => {
|
|
93
|
+
const devices = res.devices || [];
|
|
94
|
+
devices.forEach(device => {
|
|
95
|
+
this.discoveredDevices.set(device.deviceId, device);
|
|
96
|
+
// 触发设备发现事件
|
|
97
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_DEVICE_FOUND, device);
|
|
98
|
+
});
|
|
51
99
|
});
|
|
52
|
-
|
|
100
|
+
// 设置搜索超时
|
|
101
|
+
if (finalOptions.timeout) {
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
if (this.discoveryStarted) {
|
|
104
|
+
logger_1.logger.debug(`搜索超时(${finalOptions.timeout}ms),自动停止搜索`);
|
|
105
|
+
this.stopDiscovery().catch(err => {
|
|
106
|
+
logger_1.logger.warn('停止搜索失败', err);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}, finalOptions.timeout);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
logger_1.logger.error('开始搜索蓝牙设备失败');
|
|
114
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_ERROR, new types_1.PrinterError(types_1.ErrorCode.BLUETOOTH_UNAVAILABLE, '开始搜索蓝牙设备失败'));
|
|
115
|
+
}
|
|
53
116
|
return result;
|
|
54
117
|
}
|
|
55
118
|
catch (error) {
|
|
56
|
-
|
|
119
|
+
const printerError = new types_1.PrinterError(types_1.ErrorCode.BLUETOOTH_UNAVAILABLE, '开始搜索蓝牙设备失败');
|
|
120
|
+
logger_1.logger.error(printerError.message, error);
|
|
121
|
+
// 触发错误事件
|
|
122
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_ERROR, printerError);
|
|
57
123
|
return false;
|
|
58
124
|
}
|
|
59
125
|
}
|
|
@@ -65,8 +131,15 @@ class BluetoothManager {
|
|
|
65
131
|
return true;
|
|
66
132
|
}
|
|
67
133
|
try {
|
|
134
|
+
logger_1.logger.debug('停止搜索蓝牙设备...');
|
|
68
135
|
const result = await this.adapter.stopDiscovery();
|
|
69
136
|
this.discoveryStarted = !result;
|
|
137
|
+
if (result) {
|
|
138
|
+
// 触发搜索停止事件
|
|
139
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_DISCOVERY_STOPPED, {
|
|
140
|
+
devicesFound: this.discoveredDevices.size
|
|
141
|
+
});
|
|
142
|
+
}
|
|
70
143
|
return result;
|
|
71
144
|
}
|
|
72
145
|
catch (error) {
|
|
@@ -93,9 +166,22 @@ class BluetoothManager {
|
|
|
93
166
|
}
|
|
94
167
|
/**
|
|
95
168
|
* 连接蓝牙设备
|
|
96
|
-
* @param deviceId
|
|
169
|
+
* @param deviceId 设备ID
|
|
170
|
+
* @param options 连接选项
|
|
97
171
|
*/
|
|
98
|
-
async connect(deviceId) {
|
|
172
|
+
async connect(deviceId, options = {}) {
|
|
173
|
+
var _a, _b;
|
|
174
|
+
// 参数检查
|
|
175
|
+
if (!deviceId) {
|
|
176
|
+
const error = new types_1.PrinterError(types_1.ErrorCode.INVALID_PARAM, '连接失败: 设备ID不能为空');
|
|
177
|
+
logger_1.logger.error(error.message);
|
|
178
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_ERROR, error);
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
// 默认选项
|
|
182
|
+
const retries = (_a = options.retries) !== null && _a !== void 0 ? _a : config_1.BLUETOOTH_DEFAULTS.CONNECT_RETRIES;
|
|
183
|
+
const timeout = (_b = options.timeout) !== null && _b !== void 0 ? _b : config_1.BLUETOOTH_DEFAULTS.CONNECT_TIMEOUT;
|
|
184
|
+
// 确保蓝牙已初始化
|
|
99
185
|
if (!this.isInitialized) {
|
|
100
186
|
await this.init();
|
|
101
187
|
}
|
|
@@ -103,17 +189,51 @@ class BluetoothManager {
|
|
|
103
189
|
if (this.connectedDeviceId && this.connectedDeviceId !== deviceId) {
|
|
104
190
|
await this.disconnect();
|
|
105
191
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
192
|
+
else if (this.connectedDeviceId === deviceId) {
|
|
193
|
+
// 已经连接到相同设备
|
|
194
|
+
logger_1.logger.info(`已连接到设备: ${deviceId}`);
|
|
195
|
+
return true;
|
|
112
196
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
197
|
+
// 添加重试逻辑
|
|
198
|
+
let lastError = null;
|
|
199
|
+
for (let i = 0; i <= retries; i++) {
|
|
200
|
+
try {
|
|
201
|
+
// 添加超时控制
|
|
202
|
+
const connectPromise = this.adapter.connect(deviceId);
|
|
203
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
204
|
+
setTimeout(() => reject(new types_1.PrinterError(types_1.ErrorCode.TIMEOUT_ERROR, `连接超时 (${timeout}ms)`)), timeout);
|
|
205
|
+
});
|
|
206
|
+
// 使用Promise.race实现超时控制
|
|
207
|
+
const result = await Promise.race([connectPromise, timeoutPromise]);
|
|
208
|
+
if (result) {
|
|
209
|
+
this.connectedDeviceId = deviceId;
|
|
210
|
+
const message = `成功连接到设备: ${deviceId}${i > 0 ? ` (重试 ${i} 次)` : ''}`;
|
|
211
|
+
logger_1.logger.info(message);
|
|
212
|
+
// 触发连接成功事件
|
|
213
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_CONNECTED, {
|
|
214
|
+
deviceId,
|
|
215
|
+
retryCount: i
|
|
216
|
+
});
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
222
|
+
// 记录错误,但在最后一次重试前不返回
|
|
223
|
+
const retryMsg = i < retries ? `,将在1秒后重试 (${i + 1}/${retries})` : '';
|
|
224
|
+
logger_1.logger.warn(`连接设备 ${deviceId} 失败${retryMsg}`, error);
|
|
225
|
+
if (i < retries) {
|
|
226
|
+
// 等待1秒再重试
|
|
227
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
116
230
|
}
|
|
231
|
+
// 所有重试都失败
|
|
232
|
+
const printerError = new types_1.PrinterError(types_1.ErrorCode.BLUETOOTH_CONNECT_FAILED, `连接蓝牙设备失败,已重试 ${retries} 次`);
|
|
233
|
+
logger_1.logger.error(printerError.message, lastError);
|
|
234
|
+
// 触发错误事件
|
|
235
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_ERROR, printerError);
|
|
236
|
+
return false;
|
|
117
237
|
}
|
|
118
238
|
/**
|
|
119
239
|
* 断开蓝牙连接
|
|
@@ -122,15 +242,28 @@ class BluetoothManager {
|
|
|
122
242
|
if (!this.connectedDeviceId) {
|
|
123
243
|
return true;
|
|
124
244
|
}
|
|
245
|
+
const deviceId = this.connectedDeviceId;
|
|
125
246
|
try {
|
|
126
|
-
|
|
247
|
+
logger_1.logger.info(`正在断开设备连接: ${deviceId}`);
|
|
248
|
+
const result = await this.adapter.disconnect(deviceId);
|
|
127
249
|
if (result) {
|
|
128
250
|
this.connectedDeviceId = null;
|
|
251
|
+
logger_1.logger.info(`已断开设备连接: ${deviceId}`);
|
|
252
|
+
// 触发断开连接事件
|
|
253
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_DISCONNECTED, { deviceId });
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
logger_1.logger.warn(`断开设备连接失败: ${deviceId}`);
|
|
129
257
|
}
|
|
130
258
|
return result;
|
|
131
259
|
}
|
|
132
260
|
catch (error) {
|
|
133
|
-
|
|
261
|
+
const printerError = new types_1.PrinterError(types_1.ErrorCode.BLUETOOTH_DISCONNECT_FAILED, `断开蓝牙连接出错: ${deviceId}`);
|
|
262
|
+
logger_1.logger.error(printerError.message, error);
|
|
263
|
+
// 触发错误事件
|
|
264
|
+
events_1.eventManager.emit(events_1.EVENTS.BLUETOOTH_ERROR, printerError);
|
|
265
|
+
// 即使出错,也将连接状态重置为未连接
|
|
266
|
+
this.connectedDeviceId = null;
|
|
134
267
|
return false;
|
|
135
268
|
}
|
|
136
269
|
}
|
|
@@ -140,16 +273,53 @@ class BluetoothManager {
|
|
|
140
273
|
*/
|
|
141
274
|
async writeData(data) {
|
|
142
275
|
if (!this.connectedDeviceId) {
|
|
143
|
-
|
|
276
|
+
const error = new types_1.PrinterError(types_1.ErrorCode.PRINTER_NOT_CONNECTED, '未连接到蓝牙设备');
|
|
277
|
+
throw error;
|
|
144
278
|
}
|
|
145
279
|
try {
|
|
146
|
-
|
|
280
|
+
logger_1.logger.debug(`正在写入数据,大小: ${data.byteLength} 字节`);
|
|
281
|
+
const result = await this.adapter.write(this.connectedDeviceId, this.serviceUUID, this.characteristicUUID, data);
|
|
282
|
+
if (!result) {
|
|
283
|
+
logger_1.logger.error('写入数据失败');
|
|
284
|
+
// 不抛出异常,防止中断命令批量发送流程
|
|
285
|
+
}
|
|
286
|
+
return result;
|
|
147
287
|
}
|
|
148
288
|
catch (error) {
|
|
149
|
-
|
|
150
|
-
|
|
289
|
+
const printerError = new types_1.PrinterError(types_1.ErrorCode.BLUETOOTH_WRITE_FAILED, '写入数据失败');
|
|
290
|
+
logger_1.logger.error(printerError.message, error);
|
|
291
|
+
throw printerError;
|
|
151
292
|
}
|
|
152
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* 检查是否已连接
|
|
296
|
+
*/
|
|
297
|
+
isConnected() {
|
|
298
|
+
return !!this.connectedDeviceId;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* 获取已连接的设备ID
|
|
302
|
+
*/
|
|
303
|
+
getConnectedDeviceId() {
|
|
304
|
+
return this.connectedDeviceId;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* 获取适配器初始化状态
|
|
308
|
+
*/
|
|
309
|
+
getInitStatus() {
|
|
310
|
+
return this.isInitialized;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* 设置服务和特征值UUID
|
|
314
|
+
* @param serviceUUID 服务UUID
|
|
315
|
+
* @param characteristicUUID 特征值UUID
|
|
316
|
+
*/
|
|
317
|
+
setServiceUUIDs(serviceUUID, characteristicUUID) {
|
|
318
|
+
this.serviceUUID = serviceUUID;
|
|
319
|
+
this.characteristicUUID = characteristicUUID;
|
|
320
|
+
logger_1.logger.debug('已设置服务UUID:', serviceUUID);
|
|
321
|
+
logger_1.logger.debug('已设置特征值UUID:', characteristicUUID);
|
|
322
|
+
}
|
|
153
323
|
/**
|
|
154
324
|
* 销毁蓝牙模块
|
|
155
325
|
*/
|
|
@@ -161,12 +331,20 @@ class BluetoothManager {
|
|
|
161
331
|
await this.stopDiscovery();
|
|
162
332
|
}
|
|
163
333
|
try {
|
|
334
|
+
logger_1.logger.debug('正在销毁蓝牙适配器...');
|
|
164
335
|
const result = await this.adapter.destroy();
|
|
165
336
|
this.isInitialized = !result;
|
|
337
|
+
if (result) {
|
|
338
|
+
logger_1.logger.info('蓝牙适配器已销毁');
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
logger_1.logger.warn('销毁蓝牙适配器失败');
|
|
342
|
+
}
|
|
166
343
|
return result;
|
|
167
344
|
}
|
|
168
345
|
catch (error) {
|
|
169
|
-
|
|
346
|
+
const printerError = new types_1.PrinterError(types_1.ErrorCode.BLUETOOTH_UNAVAILABLE, '销毁蓝牙模块失败');
|
|
347
|
+
logger_1.logger.error(printerError.message, error);
|
|
170
348
|
return false;
|
|
171
349
|
}
|
|
172
350
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bluetooth/index.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bluetooth/index.ts"],"names":[],"mappings":";;;;;;AAAA,uCAAuC;AACvC,4CAAyC;AACzC,4CAAuD;AACvD,4CAAqD;AACrD,oCAOkB;AAClB,wDAAgC;AAEhC;;;GAGG;AACH,MAAa,gBAAgB;IAY3B;;OAEG;IACH;QAbQ,kBAAa,GAAY,KAAK,CAAC;QAC/B,sBAAiB,GAAkB,IAAI,CAAC;QACxC,qBAAgB,GAAY,KAAK,CAAC;QAClC,sBAAiB,GAAiC,IAAI,GAAG,EAAE,CAAC;QAEpE,iBAAiB;QACT,gBAAW,GAAW,sCAAsC,CAAC;QACrE,mBAAmB;QACX,uBAAkB,GAAW,sCAAsC,CAAC;QAM1E,IAAI,CAAC,OAAO,GAAG,IAAA,oBAAU,GAAE,CAAC;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;SAC5B;QAED,IAAI;YACF,eAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;YAC7B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAC5C,IAAI,CAAC,aAAa,GAAG,CAAC,MAAM,CAAC;YAE7B,IAAI,MAAM,EAAE;gBACV,eAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aACzB;iBAAM;gBACL,eAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;aAC1B;YAED,OAAO,MAAM,CAAC;SACf;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,YAAY,GAAG,IAAI,oBAAY,CACnC,iBAAS,CAAC,qBAAqB,EAC/B,UAAU,CACX,CAAC;YACF,eAAM,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC1C,OAAO,KAAK,CAAC;SACd;IACH,CAAC;CACF;AAlaD,4CAkaC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,62 @@
|
|
|
1
1
|
import { BluetoothManager } from './bluetooth';
|
|
2
2
|
import { PrinterManager } from './printer';
|
|
3
3
|
import { Commands } from './printer/commands';
|
|
4
|
-
|
|
4
|
+
import { PrinterOptions } from './utils/config';
|
|
5
|
+
import { EVENTS } from './utils/events';
|
|
6
|
+
import { Result, ErrorCode, PrinterError } from './types';
|
|
7
|
+
export { BluetoothManager, PrinterManager, Commands, EVENTS, PrinterOptions, ErrorCode, PrinterError };
|
|
8
|
+
/**
|
|
9
|
+
* Taro蓝牙打印库主类
|
|
10
|
+
* 提供跨平台蓝牙打印功能
|
|
11
|
+
*/
|
|
5
12
|
export default class TaroBluePrint {
|
|
6
13
|
bluetooth: BluetoothManager;
|
|
7
14
|
printer: PrinterManager;
|
|
8
|
-
commands: typeof Commands;
|
|
9
|
-
|
|
15
|
+
readonly commands: typeof Commands;
|
|
16
|
+
private initialized;
|
|
17
|
+
/**
|
|
18
|
+
* 创建蓝牙打印库实例
|
|
19
|
+
* @param options 打印机配置选项
|
|
20
|
+
*/
|
|
21
|
+
constructor(options?: PrinterOptions);
|
|
22
|
+
/**
|
|
23
|
+
* 获取库版本号
|
|
24
|
+
*/
|
|
25
|
+
getVersion(): string;
|
|
26
|
+
/**
|
|
27
|
+
* 注册事件监听器
|
|
28
|
+
* @param eventName 事件名称
|
|
29
|
+
* @param callback 回调函数
|
|
30
|
+
* @returns 用于取消监听的函数
|
|
31
|
+
*/
|
|
32
|
+
on(eventName: string, callback: (...args: any[]) => void): () => void;
|
|
33
|
+
/**
|
|
34
|
+
* 一次性事件监听
|
|
35
|
+
* @param eventName 事件名称
|
|
36
|
+
* @param callback 回调函数
|
|
37
|
+
* @returns 用于取消监听的函数
|
|
38
|
+
*/
|
|
39
|
+
once(eventName: string, callback: (...args: any[]) => void): () => void;
|
|
40
|
+
/**
|
|
41
|
+
* 移除事件监听器
|
|
42
|
+
* @param eventName 事件名称
|
|
43
|
+
* @param callback 回调函数,不提供则移除该事件所有监听器
|
|
44
|
+
*/
|
|
45
|
+
off(eventName: string, callback?: (...args: any[]) => void): void;
|
|
10
46
|
/**
|
|
11
47
|
* 快速打印文本
|
|
12
48
|
* @param text 文本内容
|
|
13
49
|
* @param deviceId 蓝牙设备ID
|
|
50
|
+
* @returns 打印结果
|
|
51
|
+
*/
|
|
52
|
+
quickPrint(text: string, deviceId: string): Promise<Result<boolean>>;
|
|
53
|
+
/**
|
|
54
|
+
* 更新配置
|
|
55
|
+
* @param options 新的配置选项
|
|
56
|
+
*/
|
|
57
|
+
updateConfig(options: Partial<PrinterOptions>): void;
|
|
58
|
+
/**
|
|
59
|
+
* 销毁实例,释放资源
|
|
14
60
|
*/
|
|
15
|
-
|
|
61
|
+
destroy(): Promise<void>;
|
|
16
62
|
}
|