vite-uni-dev-tool 1.1.0 → 1.2.0

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.
Files changed (135) hide show
  1. package/README.md +8 -0
  2. package/dist/const.cjs +1 -1
  3. package/dist/const.d.ts +1 -0
  4. package/dist/const.d.ts.map +1 -1
  5. package/dist/const.js +1 -1
  6. package/dist/core.d.ts.map +1 -1
  7. package/dist/core.js +2 -2
  8. package/dist/i18n/locales/en.cjs +1 -1
  9. package/dist/i18n/locales/en.d.ts +5 -0
  10. package/dist/i18n/locales/en.d.ts.map +1 -1
  11. package/dist/i18n/locales/en.js +1 -1
  12. package/dist/i18n/locales/zh-Hans.cjs +1 -1
  13. package/dist/i18n/locales/zh-Hans.d.ts +5 -0
  14. package/dist/i18n/locales/zh-Hans.d.ts.map +1 -1
  15. package/dist/i18n/locales/zh-Hans.js +1 -1
  16. package/dist/modules/devIntercept/index.cjs +9 -9
  17. package/dist/modules/devIntercept/index.d.ts +1 -1
  18. package/dist/modules/devIntercept/index.d.ts.map +1 -1
  19. package/dist/modules/devIntercept/index.js +9 -9
  20. package/dist/modules/devStore/index.cjs +1 -1
  21. package/dist/modules/devStore/index.d.ts.map +1 -1
  22. package/dist/modules/devStore/index.js +1 -1
  23. package/dist/plugins/uniDevTool/transform/transformMain.cjs +3 -3
  24. package/dist/plugins/uniDevTool/transform/transformMain.d.ts +2 -1
  25. package/dist/plugins/uniDevTool/transform/transformMain.d.ts.map +1 -1
  26. package/dist/plugins/uniDevTool/transform/transformMain.js +3 -3
  27. package/dist/plugins/uniDevTool/transform/transformVue.cjs +31 -25
  28. package/dist/plugins/uniDevTool/transform/transformVue.d.ts +2 -1
  29. package/dist/plugins/uniDevTool/transform/transformVue.d.ts.map +1 -1
  30. package/dist/plugins/uniDevTool/transform/transformVue.js +30 -24
  31. package/dist/plugins/uniDevTool/uniDevTool.cjs +3 -3
  32. package/dist/plugins/uniDevTool/uniDevTool.d.ts +3 -1
  33. package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
  34. package/dist/plugins/uniDevTool/uniDevTool.js +3 -3
  35. package/dist/type.d.ts +3 -0
  36. package/dist/type.d.ts.map +1 -1
  37. package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -199
  38. package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -730
  39. package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -167
  40. package/dist/v3/DevTool/components/CaptureScreen/index.vue +109 -109
  41. package/dist/v3/DevTool/components/ConsoleList/ConsoleItem.vue +230 -225
  42. package/dist/v3/DevTool/components/ConsoleList/RunJSInput.vue +247 -247
  43. package/dist/v3/DevTool/components/ConsoleList/index.vue +171 -171
  44. package/dist/v3/DevTool/components/ConsoleList/staticTips.ts +1145 -1145
  45. package/dist/v3/DevTool/components/DevToolTitle/index.vue +24 -24
  46. package/dist/v3/DevTool/components/DevToolWindow/DevToolOverlay.vue +197 -197
  47. package/dist/v3/DevTool/components/DevToolWindow/hooks/dataUtils.ts +48 -48
  48. package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolData.ts +387 -387
  49. package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolHandlers.ts +629 -629
  50. package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolOverlay.ts +201 -197
  51. package/dist/v3/DevTool/components/ElEvent/ElEventItem.vue +105 -105
  52. package/dist/v3/DevTool/components/ElEvent/index.vue +106 -106
  53. package/dist/v3/DevTool/components/Instance/components/InstanceTreeNode.vue +265 -265
  54. package/dist/v3/DevTool/components/Instance/flatten.ts +226 -226
  55. package/dist/v3/DevTool/components/Instance/index.vue +94 -94
  56. package/dist/v3/DevTool/components/Instance/registry.ts +49 -49
  57. package/dist/v3/DevTool/components/Instance/transformTree.ts +375 -375
  58. package/dist/v3/DevTool/components/Instance/transformTreeCtx.ts +268 -268
  59. package/dist/v3/DevTool/components/Instance/typing.d.ts +43 -43
  60. package/dist/v3/DevTool/components/InstanceDetail/index.vue +485 -485
  61. package/dist/v3/DevTool/components/JsonDetail/index.vue +70 -70
  62. package/dist/v3/DevTool/components/NFCList/NFCItem.vue +112 -112
  63. package/dist/v3/DevTool/components/NFCList/NFCTool.vue +454 -454
  64. package/dist/v3/DevTool/components/NFCList/const.ts +56 -56
  65. package/dist/v3/DevTool/components/NFCList/index.vue +94 -94
  66. package/dist/v3/DevTool/components/NetworkList/InterceptConfig.vue +624 -624
  67. package/dist/v3/DevTool/components/NetworkList/InterceptItem.vue +140 -140
  68. package/dist/v3/DevTool/components/NetworkList/NetworkDetail.vue +287 -287
  69. package/dist/v3/DevTool/components/NetworkList/NetworkIntercept.vue +88 -88
  70. package/dist/v3/DevTool/components/NetworkList/NetworkItem.vue +163 -163
  71. package/dist/v3/DevTool/components/NetworkList/NetworkSend.vue +589 -589
  72. package/dist/v3/DevTool/components/NetworkList/const.ts +4 -4
  73. package/dist/v3/DevTool/components/NetworkList/hooks/useNetworkForm.ts +86 -86
  74. package/dist/v3/DevTool/components/NetworkList/index.vue +160 -160
  75. package/dist/v3/DevTool/components/NetworkList/utils.ts +101 -101
  76. package/dist/v3/DevTool/components/Performance/index.vue +498 -498
  77. package/dist/v3/DevTool/components/Performance/modules/PerformanceMetrics.vue +153 -153
  78. package/dist/v3/DevTool/components/Performance/modules/usePerformanceChart.ts +460 -460
  79. package/dist/v3/DevTool/components/Performance/modules/usePerformanceData.ts +258 -258
  80. package/dist/v3/DevTool/components/PiniaList/index.vue +93 -93
  81. package/dist/v3/DevTool/components/RunJS/index.vue +148 -148
  82. package/dist/v3/DevTool/components/ScanCodeList/ScanCodeItem.vue +97 -97
  83. package/dist/v3/DevTool/components/ScanCodeList/index.vue +100 -100
  84. package/dist/v3/DevTool/components/SettingButton/index.vue +45 -45
  85. package/dist/v3/DevTool/components/SettingList/index.vue +218 -218
  86. package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +304 -304
  87. package/dist/v3/DevTool/components/SettingList/modules/SettingDevTool.vue +212 -212
  88. package/dist/v3/DevTool/components/SettingList/modules/SettingInfo.vue +157 -157
  89. package/dist/v3/DevTool/components/SettingList/modules/SettingLanguage.vue +74 -74
  90. package/dist/v3/DevTool/components/SettingList/modules/SettingLog.vue +230 -230
  91. package/dist/v3/DevTool/components/SettingList/typing.d.ts +2 -2
  92. package/dist/v3/DevTool/components/SourceCode/Line.vue +127 -127
  93. package/dist/v3/DevTool/components/SourceCode/parseCode.ts +609 -609
  94. package/dist/v3/DevTool/components/StorageList/index.vue +174 -174
  95. package/dist/v3/DevTool/components/TransferList/TransferDetail.vue +268 -268
  96. package/dist/v3/DevTool/components/VuexList/index.vue +84 -84
  97. package/dist/v3/DevTool/index.vue +1 -0
  98. package/dist/v3/components/AppTransition/index.vue +176 -176
  99. package/dist/v3/components/AutoSizer/index.vue +192 -192
  100. package/dist/v3/components/AutoSizer/index1.vue +184 -184
  101. package/dist/v3/components/AutoSizer/utils.ts +49 -49
  102. package/dist/v3/components/Barrage/BarrageItem.vue +137 -137
  103. package/dist/v3/components/Barrage/index.vue +202 -202
  104. package/dist/v3/components/CircularButton/index.vue +84 -84
  105. package/dist/v3/components/CustomSwiper/CustomSwiperItem.vue +49 -49
  106. package/dist/v3/components/CustomSwiper/index.vue +104 -104
  107. package/dist/v3/components/DevErrorBoundary/index.vue +380 -0
  108. package/dist/v3/components/Empty/index.vue +29 -29
  109. package/dist/v3/components/FilterSelect/index.vue +179 -179
  110. package/dist/v3/components/JsonPretty/components/Brackets/index.vue +27 -27
  111. package/dist/v3/components/JsonPretty/components/Carets/index.vue +59 -59
  112. package/dist/v3/components/JsonPretty/components/CheckController/index.vue +136 -136
  113. package/dist/v3/components/JsonPretty/components/TreeNode/index.vue +387 -387
  114. package/dist/v3/components/JsonPretty/hooks/useClipboard.ts +21 -21
  115. package/dist/v3/components/JsonPretty/hooks/useError.ts +21 -21
  116. package/dist/v3/components/JsonPretty/type.ts +127 -127
  117. package/dist/v3/components/JsonPretty/utils/index.ts +169 -169
  118. package/dist/v3/components/MovableContainer/index.vue +8 -4
  119. package/dist/v3/components/Pick/index.vue +322 -322
  120. package/dist/v3/components/Tag/index.vue +113 -113
  121. package/dist/v3/components/VirtualList/AutoSize.vue +40 -40
  122. package/dist/v3/components/VirtualList/index.vue +416 -416
  123. package/dist/v3/hooks/useBluetooth/index.ts +561 -561
  124. package/dist/v3/hooks/useContainerStyle.ts +153 -153
  125. package/dist/v3/hooks/useNFC/index.ts +107 -107
  126. package/dist/v3/hooks/useNFC/typing.d.ts +396 -396
  127. package/dist/v3/hooks/useNFC/useNFCAndroid.ts +966 -966
  128. package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +812 -812
  129. package/dist/v3/hooks/useNFC/utils.ts +754 -754
  130. package/dist/v3/hooks/useRequest/index.ts +586 -586
  131. package/dist/v3/hooks/useRequest/utils.ts +267 -267
  132. package/dist/v3/hooks/useScanCode/index.ts +206 -206
  133. package/dist/v3/hooks/useWebsocket/index.ts +253 -253
  134. package/dist/v3/styles/theme.ts +12 -12
  135. package/package.json +9 -1
@@ -1,396 +1,396 @@
1
- declare namespace NFC {
2
- type Listener = (data: NFC.Result) => void;
3
- type NfcOption = {
4
- /**
5
- * 轮询检验连接状态间隔
6
- * 目前只有 android 有效
7
- */
8
- checkConnectedDelay?: number;
9
- };
10
-
11
- type NfcResult = {
12
- /**
13
- * 读取到的数据
14
- */
15
- data: Ref<Result>;
16
- /**
17
- * 读取卡是否未 ndef
18
- */
19
- isNdef: Ref<boolean>;
20
- /**
21
- * 是否支持 nfc
22
- */
23
- isSupportNFC: Ref<boolean>;
24
- /**
25
- * 监听状态
26
- */
27
- isListening: Ref<boolean>;
28
- /**
29
- * 连接状态
30
- */
31
- isConnected: Ref<boolean>;
32
- /**
33
- * 实例,方便外界调用
34
- */
35
- nfcInstance: any;
36
- /**
37
- * 启用
38
- *
39
- */
40
- startHCE: () => Promise<{ errMsg: string }>;
41
-
42
- /**
43
- * 停止
44
- *
45
- */
46
- stopHCE: () => Promise<{ errMsg: string }>;
47
- /**
48
- * 连接
49
- *
50
- */
51
- connect: () => Promise<{ errMsg: string }>;
52
- /**
53
- * 断开连接
54
- * @returns
55
- */
56
- close: () => Promise<{ errMsg: string }>;
57
- /**
58
- * 非 ndef 数据写入
59
- * TODO: 暂时无法提供通用的写入方法
60
- * @deprecated
61
- */
62
- write: (data: ArrayBuffer) => Promise<{ errMsg: string; data?: any }>;
63
- /**
64
- * 通用的 ndef 写入方法
65
- *
66
- */
67
- writeNdef: (data: NdefRecord[]) => Promise<{ errMsg: string; data?: any }>;
68
- /**
69
- * 写入 NDEF 文本数据
70
- *
71
- * https://developer.android.google.cn/reference/kotlin/android/nfc/NdefRecord?hl=en#createtextrecord
72
- *
73
- *
74
- */
75
- writeNdefText: (
76
- text: string,
77
- /** 微信小程序不支持该属性 */
78
- language?: string,
79
- ) => Promise<{ errMsg: string; data?: any }>;
80
- /**
81
- * 写入 NDEF URI 数据
82
- *
83
- * 会自动根据
84
- * https://
85
- * tel:
86
- * ...
87
- * 进行区分
88
- *
89
- */
90
- writeNdefUri: (uri: string) => Promise<{ errMsg: string; data?: any }>;
91
- /**
92
- * Android 应用包名 写入
93
- *
94
- */
95
- writeNdefAndroidApp: (
96
- packageName: string,
97
- ) => Promise<{ errMsg: string; data?: any }>;
98
- /**
99
- * 写入 WiFi 配置到 NFC 标签
100
- *
101
- */
102
- writeNdefWifi: (data: WSCConfig) => Promise<{ errMsg: string; data?: any }>;
103
- /**
104
- * 写入 vCard 数据到 NFC 标签
105
- *
106
- */
107
- writeNdefVcard: (
108
- data: VCardContactInfo,
109
- ) => Promise<{ errMsg: string; data?: any }>;
110
- };
111
-
112
- interface WSCConfig {
113
- ssid: string;
114
- password: string;
115
- authType: string;
116
- encryptionType?: 'AES' | 'TKIP' | 'WEP' | 'NONE';
117
- networkKeyIndex?: number; // 1-4 for WEP
118
- }
119
- /**
120
- * 0: TNF_EMPTY
121
- * 1: TNF_WELL_KNOWN
122
- * 2: TNF_MIME_MEDIA
123
- * 3: TNF_ABSOLUTE_URI
124
- * 4: TNF_EXTERNAL_TYPE
125
- * 5: TNF_UNKNOWN
126
- * 6: TNF_UNCHANGED
127
- * 7: TNF_RESERVED
128
- */
129
- type Tnf = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7';
130
-
131
- /**
132
- * 这是只是列举了常用的格式
133
- * T: 文本记录
134
- * U: URI
135
- * Sp: Smart Poster记录
136
- * Sig: 签名记录
137
- * application/vnd.wfa.wsc : Wi-Fi Setup Configuration
138
- * android.com:pkg: Android 包名记录
139
- * text/vcard: 名片
140
- */
141
- type NdefMessageType =
142
- | 'T'
143
- | 'U'
144
- | 'Sp'
145
- | 'Sig'
146
- | 'application/vnd.wfa.wsc'
147
- | 'android.com:pkg'
148
- | 'text/vcard';
149
-
150
- type NfcType =
151
- | 'ISO-DEP'
152
- | 'MIFARE Classic'
153
- | 'MIFARE Ultralight'
154
- | 'NFC-A'
155
- | 'NFC-B'
156
- | 'NFC-F'
157
- | 'NFC-V'
158
- | 'Ndef'
159
- | 'NDEF'
160
- | 'Ndef Formatable'
161
- | '';
162
- type Message = {
163
- records: {
164
- id?: any;
165
- tnf: Tnf;
166
- tnfDescription: string;
167
- type: string;
168
- typeDescription: string;
169
- /** ndef 解析内容 */
170
- payload: any;
171
- }[];
172
- };
173
-
174
- interface VCardContactInfo {
175
- // 核心字段(对应 vCard 3.0 标准)
176
- fullName: string; // FN:全名
177
- version: string; // VERSION:vCard 版本
178
- organization: string; // ORG:组织/公司
179
- telephone: string; // TEL:电话号码
180
- address: string; // ADR:地址
181
- url: string; // URL:网址/个人链接
182
- // 可扩展字段(如 EMAIL、BDAY 等)
183
- [key: string]: string;
184
- }
185
- type Data = {
186
- id: ArrayBuffer;
187
- /**
188
- * (
189
- | 'ISO-DEP'
190
- | 'MIFARE Classic'
191
- | 'MIFARE Ultralight'
192
- | 'NFC-A'
193
- | 'NFC-B'
194
- | 'NFC-F'
195
- | 'NFC-V'
196
- )
197
- */
198
- techs: NfcType[];
199
-
200
- /**
201
- * ndef 数据
202
- */
203
- messages?: Message[];
204
- /** SAK */
205
- sak?: number;
206
- /** SAK 类型 */
207
- sakType?: string;
208
- sakHex?: string;
209
-
210
- /** 最大数据传输长度 */
211
- maxTransceiveLength?: number;
212
- /** 卡类型 */
213
- nfcType?: NfcType;
214
- /** 读写标准 */
215
- readWriteStandard?: string[];
216
- /** 扇区数 仅安卓 */
217
- sectorCount?: number;
218
- /** 块数 仅安卓 */
219
- blockCount?: number;
220
- /** 其他数据 */
221
- [key: string]: any;
222
- };
223
-
224
- type TransformId = {
225
- /** 卡片id 10进制字符串 */
226
- byteArray: number[];
227
- /** 卡片id 16进制字符串 */
228
- hexArray: string[];
229
- /** 卡片id 16进制字符串 */
230
- hexString: string;
231
- };
232
-
233
- type Result = Data & TransformId;
234
-
235
- type Atqa = {
236
- atqa: ArrayBuffer;
237
- errMsg: string;
238
- };
239
-
240
- type Sak = {
241
- /**
242
- * SAK 是 NFC 终端设备(如手机)与 NFC 标签通信时返回的一个字节数据
243
- *
244
- * 0x00 未指定类型
245
- * 0x08 Mifare Classic 1K
246
- * 0x09 Mifare Classic Mini
247
- * 0x10 Mifare Plus
248
- * 0x11 Mifare Classic 4K
249
- * 0x18 Mifare Ultralight / Ultralight C
250
- * 0x20 DESFire
251
- */
252
- sak: number;
253
- errno: number;
254
- errMsg: string;
255
- };
256
-
257
- type MaxTransceiveLength = {
258
- /** 最大传输长度 */
259
- length: number;
260
- errno: number;
261
- errMsg: string;
262
- };
263
-
264
- type Connected = {
265
- /** 标签是否连接 */
266
- connected: boolean;
267
- errno: number;
268
- errMsg: string;
269
- };
270
-
271
- type FnOption<R = any, E = any> = {
272
- success?: (result: R) => void;
273
- fail?: (error: E) => void;
274
- complete?: (res: R | E) => void;
275
- };
276
-
277
- type NdefData = {
278
- /** uri 数组 */
279
- uris?: any[];
280
- /** text 数组 */
281
- texts?: any[];
282
- /** 二进制对象数组, 需要指明 id, type 以及 payload (均为 ArrayBuffer 类型) */
283
- records?: {
284
- /**
285
- * 写入的 tnf 类型
286
- * 参考 NFC.Tnf 类型
287
- * '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' 转成的buffer
288
- *
289
- */
290
- tnf: string | number;
291
- /**
292
- * 将会转为 buffer
293
- */
294
- id?: ArrayBuffer | null;
295
- /**
296
- * 写入的数据格式
297
- *
298
- */
299
- type: ArrayBuffer;
300
- /**
301
- * 需要写入的数据
302
- *
303
- * 不同的数据有不同的转换方式,这里需要自定义转换成buffer
304
- *
305
- * 例如:application/vnd.wfa.wsc 格式 采用了 utils 中的 generateWSCBytesForAndroid 方法进行转换
306
- *
307
- */
308
- payload: ArrayBuffer;
309
- }[];
310
- };
311
-
312
- type NdefRecord = {
313
- tnf: string | number;
314
- id?: string;
315
- type: string;
316
- payload: ArrayBuffer;
317
- };
318
-
319
- type Instance = {
320
- /** 连接 NFC 标签 */
321
- connect: (options?: FnOption) => void;
322
- /** 断开连接 */
323
- close: (options?: FnOption) => void;
324
- /** 设置超时时间 */
325
- setTimeout: (options: ?(FnOption & { timeout: number })) => void;
326
- /** 获取最大传输长度 */
327
- getMaxTransceiveLength: (options?: FnOption<MaxTransceiveLength>) => void;
328
- getMaxSize?: (options?: FnOption) => void;
329
- /**
330
- * 写入数据
331
- * 支持以以下类型
332
- * ISO-DEP
333
- * MIFARE Classic
334
- * MIFARE Ultralight
335
- * NFC-A
336
- * NFC-B
337
- * NFC-F
338
- * NFC-V
339
- */
340
- transceive?: (options: ?(FnOption & { data: ArrayBuffer })) => void;
341
- /**
342
- * 写入数据
343
- * 支持以以下类型
344
- * Ndef
345
- *
346
- */
347
- writeNdefMessage?: (options: ?(FnOption & NdefData)) => void;
348
- /** 获取ATQA信息 */
349
- getAtqa?: (options?: FnOption<Atqa>) => void;
350
- /** 获取SAK信息 */
351
- getSak?: (options?: FnOption<Sak>) => void;
352
- /** 检测标签是否连接 */
353
- isConnected?: (options?: FnOption<Connected>) => void;
354
- };
355
-
356
- type Adapter = {
357
- /** 获取IsoDep实例,实例支持ISO-DEP (ISO 14443-4)标准的读写 */
358
- getIsoDep: () => any;
359
- /** 获取MifareClassic实例,实例支持MIFARE Classic标签的读写 */
360
- getMifareClassic: () => any;
361
- /** 获取MifareUltralight实例,实例支持MIFARE Ultralight标签的读写 */
362
- getMifareUltralight: () => any;
363
- /** 获取Ndef实例,实例支持对NDEF格式的NFC标签上的NDEF数据的读写 */
364
- getNdef: (options?: FnOption) => NfcA;
365
- /** 获取NfcA实例,实例支持NFC-A (ISO 14443-3A)标准的读写 */
366
- getNfcA: (options?: FnOption) => any;
367
- /** 获取NfcB实例,实例支持NFC-B (ISO 14443-3B)标准的读写 */
368
- getNfcB: (options?: FnOption) => any;
369
- /** 获取NfcF实例,实例支持NFC-F (JIS 6319-4)标准的读写 */
370
- getNfcF: (options?: FnOption) => any;
371
- /** 获取NfcV实例,实例支持NFC-V (ISO 15693)标准的读写 */
372
- getNfcV: (options?: FnOption) => any;
373
- /** 启用 nfc 模块 */
374
- startDiscovery: (options?: FnOption) => void;
375
- /** 停用 nfc 模块 */
376
- stopDiscovery: () => void;
377
- /** nfc 读取监听 */
378
- onDiscovered: (callback: (res: NFC.Data) => void) => void;
379
- /** nfc 移除监听 */
380
- offDiscovered: (callback: (res: NFC.Data) => void) => void;
381
-
382
- /** 安卓环境 判断适配器是否可用 */
383
- isEnabled: () => boolean;
384
-
385
- /** 安卓环境 停用前台调度 */
386
- disableForegroundDispatch: (main: any) => void;
387
-
388
- /** 安卓环境 启用前台调度 */
389
- enableForegroundDispatch: (
390
- main: any,
391
- pendingIntent: any,
392
- intentFiltersArray: any[],
393
- techListsArray: any[] | null,
394
- ) => void;
395
- };
396
- }
1
+ declare namespace NFC {
2
+ type Listener = (data: NFC.Result) => void;
3
+ type NfcOption = {
4
+ /**
5
+ * 轮询检验连接状态间隔
6
+ * 目前只有 android 有效
7
+ */
8
+ checkConnectedDelay?: number;
9
+ };
10
+
11
+ type NfcResult = {
12
+ /**
13
+ * 读取到的数据
14
+ */
15
+ data: Ref<Result>;
16
+ /**
17
+ * 读取卡是否未 ndef
18
+ */
19
+ isNdef: Ref<boolean>;
20
+ /**
21
+ * 是否支持 nfc
22
+ */
23
+ isSupportNFC: Ref<boolean>;
24
+ /**
25
+ * 监听状态
26
+ */
27
+ isListening: Ref<boolean>;
28
+ /**
29
+ * 连接状态
30
+ */
31
+ isConnected: Ref<boolean>;
32
+ /**
33
+ * 实例,方便外界调用
34
+ */
35
+ nfcInstance: any;
36
+ /**
37
+ * 启用
38
+ *
39
+ */
40
+ startHCE: () => Promise<{ errMsg: string }>;
41
+
42
+ /**
43
+ * 停止
44
+ *
45
+ */
46
+ stopHCE: () => Promise<{ errMsg: string }>;
47
+ /**
48
+ * 连接
49
+ *
50
+ */
51
+ connect: () => Promise<{ errMsg: string }>;
52
+ /**
53
+ * 断开连接
54
+ * @returns
55
+ */
56
+ close: () => Promise<{ errMsg: string }>;
57
+ /**
58
+ * 非 ndef 数据写入
59
+ * TODO: 暂时无法提供通用的写入方法
60
+ * @deprecated
61
+ */
62
+ write: (data: ArrayBuffer) => Promise<{ errMsg: string; data?: any }>;
63
+ /**
64
+ * 通用的 ndef 写入方法
65
+ *
66
+ */
67
+ writeNdef: (data: NdefRecord[]) => Promise<{ errMsg: string; data?: any }>;
68
+ /**
69
+ * 写入 NDEF 文本数据
70
+ *
71
+ * https://developer.android.google.cn/reference/kotlin/android/nfc/NdefRecord?hl=en#createtextrecord
72
+ *
73
+ *
74
+ */
75
+ writeNdefText: (
76
+ text: string,
77
+ /** 微信小程序不支持该属性 */
78
+ language?: string,
79
+ ) => Promise<{ errMsg: string; data?: any }>;
80
+ /**
81
+ * 写入 NDEF URI 数据
82
+ *
83
+ * 会自动根据
84
+ * https://
85
+ * tel:
86
+ * ...
87
+ * 进行区分
88
+ *
89
+ */
90
+ writeNdefUri: (uri: string) => Promise<{ errMsg: string; data?: any }>;
91
+ /**
92
+ * Android 应用包名 写入
93
+ *
94
+ */
95
+ writeNdefAndroidApp: (
96
+ packageName: string,
97
+ ) => Promise<{ errMsg: string; data?: any }>;
98
+ /**
99
+ * 写入 WiFi 配置到 NFC 标签
100
+ *
101
+ */
102
+ writeNdefWifi: (data: WSCConfig) => Promise<{ errMsg: string; data?: any }>;
103
+ /**
104
+ * 写入 vCard 数据到 NFC 标签
105
+ *
106
+ */
107
+ writeNdefVcard: (
108
+ data: VCardContactInfo,
109
+ ) => Promise<{ errMsg: string; data?: any }>;
110
+ };
111
+
112
+ interface WSCConfig {
113
+ ssid: string;
114
+ password: string;
115
+ authType: string;
116
+ encryptionType?: 'AES' | 'TKIP' | 'WEP' | 'NONE';
117
+ networkKeyIndex?: number; // 1-4 for WEP
118
+ }
119
+ /**
120
+ * 0: TNF_EMPTY
121
+ * 1: TNF_WELL_KNOWN
122
+ * 2: TNF_MIME_MEDIA
123
+ * 3: TNF_ABSOLUTE_URI
124
+ * 4: TNF_EXTERNAL_TYPE
125
+ * 5: TNF_UNKNOWN
126
+ * 6: TNF_UNCHANGED
127
+ * 7: TNF_RESERVED
128
+ */
129
+ type Tnf = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7';
130
+
131
+ /**
132
+ * 这是只是列举了常用的格式
133
+ * T: 文本记录
134
+ * U: URI
135
+ * Sp: Smart Poster记录
136
+ * Sig: 签名记录
137
+ * application/vnd.wfa.wsc : Wi-Fi Setup Configuration
138
+ * android.com:pkg: Android 包名记录
139
+ * text/vcard: 名片
140
+ */
141
+ type NdefMessageType =
142
+ | 'T'
143
+ | 'U'
144
+ | 'Sp'
145
+ | 'Sig'
146
+ | 'application/vnd.wfa.wsc'
147
+ | 'android.com:pkg'
148
+ | 'text/vcard';
149
+
150
+ type NfcType =
151
+ | 'ISO-DEP'
152
+ | 'MIFARE Classic'
153
+ | 'MIFARE Ultralight'
154
+ | 'NFC-A'
155
+ | 'NFC-B'
156
+ | 'NFC-F'
157
+ | 'NFC-V'
158
+ | 'Ndef'
159
+ | 'NDEF'
160
+ | 'Ndef Formatable'
161
+ | '';
162
+ type Message = {
163
+ records: {
164
+ id?: any;
165
+ tnf: Tnf;
166
+ tnfDescription: string;
167
+ type: string;
168
+ typeDescription: string;
169
+ /** ndef 解析内容 */
170
+ payload: any;
171
+ }[];
172
+ };
173
+
174
+ interface VCardContactInfo {
175
+ // 核心字段(对应 vCard 3.0 标准)
176
+ fullName: string; // FN:全名
177
+ version: string; // VERSION:vCard 版本
178
+ organization: string; // ORG:组织/公司
179
+ telephone: string; // TEL:电话号码
180
+ address: string; // ADR:地址
181
+ url: string; // URL:网址/个人链接
182
+ // 可扩展字段(如 EMAIL、BDAY 等)
183
+ [key: string]: string;
184
+ }
185
+ type Data = {
186
+ id: ArrayBuffer;
187
+ /**
188
+ * (
189
+ | 'ISO-DEP'
190
+ | 'MIFARE Classic'
191
+ | 'MIFARE Ultralight'
192
+ | 'NFC-A'
193
+ | 'NFC-B'
194
+ | 'NFC-F'
195
+ | 'NFC-V'
196
+ )
197
+ */
198
+ techs: NfcType[];
199
+
200
+ /**
201
+ * ndef 数据
202
+ */
203
+ messages?: Message[];
204
+ /** SAK */
205
+ sak?: number;
206
+ /** SAK 类型 */
207
+ sakType?: string;
208
+ sakHex?: string;
209
+
210
+ /** 最大数据传输长度 */
211
+ maxTransceiveLength?: number;
212
+ /** 卡类型 */
213
+ nfcType?: NfcType;
214
+ /** 读写标准 */
215
+ readWriteStandard?: string[];
216
+ /** 扇区数 仅安卓 */
217
+ sectorCount?: number;
218
+ /** 块数 仅安卓 */
219
+ blockCount?: number;
220
+ /** 其他数据 */
221
+ [key: string]: any;
222
+ };
223
+
224
+ type TransformId = {
225
+ /** 卡片id 10进制字符串 */
226
+ byteArray: number[];
227
+ /** 卡片id 16进制字符串 */
228
+ hexArray: string[];
229
+ /** 卡片id 16进制字符串 */
230
+ hexString: string;
231
+ };
232
+
233
+ type Result = Data & TransformId;
234
+
235
+ type Atqa = {
236
+ atqa: ArrayBuffer;
237
+ errMsg: string;
238
+ };
239
+
240
+ type Sak = {
241
+ /**
242
+ * SAK 是 NFC 终端设备(如手机)与 NFC 标签通信时返回的一个字节数据
243
+ *
244
+ * 0x00 未指定类型
245
+ * 0x08 Mifare Classic 1K
246
+ * 0x09 Mifare Classic Mini
247
+ * 0x10 Mifare Plus
248
+ * 0x11 Mifare Classic 4K
249
+ * 0x18 Mifare Ultralight / Ultralight C
250
+ * 0x20 DESFire
251
+ */
252
+ sak: number;
253
+ errno: number;
254
+ errMsg: string;
255
+ };
256
+
257
+ type MaxTransceiveLength = {
258
+ /** 最大传输长度 */
259
+ length: number;
260
+ errno: number;
261
+ errMsg: string;
262
+ };
263
+
264
+ type Connected = {
265
+ /** 标签是否连接 */
266
+ connected: boolean;
267
+ errno: number;
268
+ errMsg: string;
269
+ };
270
+
271
+ type FnOption<R = any, E = any> = {
272
+ success?: (result: R) => void;
273
+ fail?: (error: E) => void;
274
+ complete?: (res: R | E) => void;
275
+ };
276
+
277
+ type NdefData = {
278
+ /** uri 数组 */
279
+ uris?: any[];
280
+ /** text 数组 */
281
+ texts?: any[];
282
+ /** 二进制对象数组, 需要指明 id, type 以及 payload (均为 ArrayBuffer 类型) */
283
+ records?: {
284
+ /**
285
+ * 写入的 tnf 类型
286
+ * 参考 NFC.Tnf 类型
287
+ * '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' 转成的buffer
288
+ *
289
+ */
290
+ tnf: string | number;
291
+ /**
292
+ * 将会转为 buffer
293
+ */
294
+ id?: ArrayBuffer | null;
295
+ /**
296
+ * 写入的数据格式
297
+ *
298
+ */
299
+ type: ArrayBuffer;
300
+ /**
301
+ * 需要写入的数据
302
+ *
303
+ * 不同的数据有不同的转换方式,这里需要自定义转换成buffer
304
+ *
305
+ * 例如:application/vnd.wfa.wsc 格式 采用了 utils 中的 generateWSCBytesForAndroid 方法进行转换
306
+ *
307
+ */
308
+ payload: ArrayBuffer;
309
+ }[];
310
+ };
311
+
312
+ type NdefRecord = {
313
+ tnf: string | number;
314
+ id?: string;
315
+ type: string;
316
+ payload: ArrayBuffer;
317
+ };
318
+
319
+ type Instance = {
320
+ /** 连接 NFC 标签 */
321
+ connect: (options?: FnOption) => void;
322
+ /** 断开连接 */
323
+ close: (options?: FnOption) => void;
324
+ /** 设置超时时间 */
325
+ setTimeout: (options: ?(FnOption & { timeout: number })) => void;
326
+ /** 获取最大传输长度 */
327
+ getMaxTransceiveLength: (options?: FnOption<MaxTransceiveLength>) => void;
328
+ getMaxSize?: (options?: FnOption) => void;
329
+ /**
330
+ * 写入数据
331
+ * 支持以以下类型
332
+ * ISO-DEP
333
+ * MIFARE Classic
334
+ * MIFARE Ultralight
335
+ * NFC-A
336
+ * NFC-B
337
+ * NFC-F
338
+ * NFC-V
339
+ */
340
+ transceive?: (options: ?(FnOption & { data: ArrayBuffer })) => void;
341
+ /**
342
+ * 写入数据
343
+ * 支持以以下类型
344
+ * Ndef
345
+ *
346
+ */
347
+ writeNdefMessage?: (options: ?(FnOption & NdefData)) => void;
348
+ /** 获取ATQA信息 */
349
+ getAtqa?: (options?: FnOption<Atqa>) => void;
350
+ /** 获取SAK信息 */
351
+ getSak?: (options?: FnOption<Sak>) => void;
352
+ /** 检测标签是否连接 */
353
+ isConnected?: (options?: FnOption<Connected>) => void;
354
+ };
355
+
356
+ type Adapter = {
357
+ /** 获取IsoDep实例,实例支持ISO-DEP (ISO 14443-4)标准的读写 */
358
+ getIsoDep: () => any;
359
+ /** 获取MifareClassic实例,实例支持MIFARE Classic标签的读写 */
360
+ getMifareClassic: () => any;
361
+ /** 获取MifareUltralight实例,实例支持MIFARE Ultralight标签的读写 */
362
+ getMifareUltralight: () => any;
363
+ /** 获取Ndef实例,实例支持对NDEF格式的NFC标签上的NDEF数据的读写 */
364
+ getNdef: (options?: FnOption) => NfcA;
365
+ /** 获取NfcA实例,实例支持NFC-A (ISO 14443-3A)标准的读写 */
366
+ getNfcA: (options?: FnOption) => any;
367
+ /** 获取NfcB实例,实例支持NFC-B (ISO 14443-3B)标准的读写 */
368
+ getNfcB: (options?: FnOption) => any;
369
+ /** 获取NfcF实例,实例支持NFC-F (JIS 6319-4)标准的读写 */
370
+ getNfcF: (options?: FnOption) => any;
371
+ /** 获取NfcV实例,实例支持NFC-V (ISO 15693)标准的读写 */
372
+ getNfcV: (options?: FnOption) => any;
373
+ /** 启用 nfc 模块 */
374
+ startDiscovery: (options?: FnOption) => void;
375
+ /** 停用 nfc 模块 */
376
+ stopDiscovery: () => void;
377
+ /** nfc 读取监听 */
378
+ onDiscovered: (callback: (res: NFC.Data) => void) => void;
379
+ /** nfc 移除监听 */
380
+ offDiscovered: (callback: (res: NFC.Data) => void) => void;
381
+
382
+ /** 安卓环境 判断适配器是否可用 */
383
+ isEnabled: () => boolean;
384
+
385
+ /** 安卓环境 停用前台调度 */
386
+ disableForegroundDispatch: (main: any) => void;
387
+
388
+ /** 安卓环境 启用前台调度 */
389
+ enableForegroundDispatch: (
390
+ main: any,
391
+ pendingIntent: any,
392
+ intentFiltersArray: any[],
393
+ techListsArray: any[] | null,
394
+ ) => void;
395
+ };
396
+ }