vite-uni-dev-tool 1.0.0 → 1.1.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 (168) hide show
  1. package/README.md +46 -0
  2. package/dist/const.cjs +1 -1
  3. package/dist/const.d.ts +12 -0
  4. package/dist/const.d.ts.map +1 -1
  5. package/dist/const.js +1 -1
  6. package/dist/core-shared.d.ts +1 -1
  7. package/dist/core-shared.d.ts.map +1 -1
  8. package/dist/core-shared.js +1 -1
  9. package/dist/core.d.ts +10 -3
  10. package/dist/core.d.ts.map +1 -1
  11. package/dist/core.js +2 -2
  12. package/dist/i18n/locales/en.cjs +1 -1
  13. package/dist/i18n/locales/en.d.ts +81 -0
  14. package/dist/i18n/locales/en.d.ts.map +1 -1
  15. package/dist/i18n/locales/en.js +1 -1
  16. package/dist/i18n/locales/zh-Hans.cjs +1 -1
  17. package/dist/i18n/locales/zh-Hans.d.ts +82 -1
  18. package/dist/i18n/locales/zh-Hans.d.ts.map +1 -1
  19. package/dist/i18n/locales/zh-Hans.js +1 -1
  20. package/dist/modules/devConsole/index.cjs +1 -1
  21. package/dist/modules/devConsole/index.js +3 -3
  22. package/dist/modules/devEvent/index.cjs +3 -3
  23. package/dist/modules/devEvent/index.d.ts +1 -0
  24. package/dist/modules/devEvent/index.d.ts.map +1 -1
  25. package/dist/modules/devEvent/index.js +3 -3
  26. package/dist/modules/devIntercept/index.cjs +14 -13
  27. package/dist/modules/devIntercept/index.d.ts +19 -0
  28. package/dist/modules/devIntercept/index.d.ts.map +1 -1
  29. package/dist/modules/devIntercept/index.js +14 -13
  30. package/dist/modules/devStore/index.cjs +1 -1
  31. package/dist/modules/devStore/index.d.ts +21 -0
  32. package/dist/modules/devStore/index.d.ts.map +1 -1
  33. package/dist/modules/devStore/index.js +1 -1
  34. package/dist/plugins/uniDevTool/transform/transformMain.cjs +1 -1
  35. package/dist/plugins/uniDevTool/transform/transformMain.js +1 -1
  36. package/dist/type.d.ts +47 -2
  37. package/dist/type.d.ts.map +1 -1
  38. package/dist/utils/language.cjs +1 -1
  39. package/dist/utils/language.d.ts.map +1 -1
  40. package/dist/utils/language.js +1 -1
  41. package/dist/utils/object.cjs +1 -1
  42. package/dist/utils/object.d.ts.map +1 -1
  43. package/dist/utils/object.js +1 -1
  44. package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -0
  45. package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -0
  46. package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -0
  47. package/dist/v3/{CaptureScreen → DevTool/components/CaptureScreen}/index.vue +109 -109
  48. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/ConsoleItem.vue +225 -224
  49. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/RunJSInput.vue +247 -249
  50. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/index.vue +171 -160
  51. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/staticTips.ts +1145 -1145
  52. package/dist/v3/{DevToolButton → DevTool/components/DevToolButton}/index.vue +7 -4
  53. package/dist/v3/{DevToolTitle → DevTool/components/DevToolTitle}/index.vue +24 -24
  54. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/DevToolOverlay.vue +197 -182
  55. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/const.ts +28 -5
  56. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/dataUtils.ts +48 -48
  57. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolData.ts +387 -338
  58. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolHandlers.ts +629 -549
  59. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolOverlay.ts +197 -184
  60. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.vue +67 -16
  61. package/dist/v3/{ElEvent → DevTool/components/ElEvent}/ElEventItem.vue +105 -105
  62. package/dist/v3/{ElEvent → DevTool/components/ElEvent}/index.vue +106 -109
  63. package/dist/v3/{Instance → DevTool/components/Instance}/components/InstanceTreeNode.vue +265 -265
  64. package/dist/v3/{Instance → DevTool/components/Instance}/flatten.ts +226 -226
  65. package/dist/v3/{Instance → DevTool/components/Instance}/index.vue +94 -94
  66. package/dist/v3/{Instance → DevTool/components/Instance}/registry.ts +49 -49
  67. package/dist/v3/{Instance → DevTool/components/Instance}/transformTree.ts +375 -375
  68. package/dist/v3/{Instance → DevTool/components/Instance}/transformTreeCtx.ts +268 -268
  69. package/dist/v3/{Instance → DevTool/components/Instance}/typing.d.ts +43 -43
  70. package/dist/v3/{InstanceDetail → DevTool/components/InstanceDetail}/index.vue +485 -485
  71. package/dist/v3/{JsonDetail → DevTool/components/JsonDetail}/index.vue +70 -70
  72. package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCItem.vue +112 -113
  73. package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCTool.vue +454 -478
  74. package/dist/v3/{NFCList → DevTool/components/NFCList}/const.ts +56 -56
  75. package/dist/v3/{NFCList → DevTool/components/NFCList}/index.vue +94 -98
  76. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptConfig.vue +624 -608
  77. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptItem.vue +140 -140
  78. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkDetail.vue +287 -296
  79. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkIntercept.vue +88 -93
  80. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkItem.vue +163 -167
  81. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkSend.vue +589 -556
  82. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/const.ts +4 -4
  83. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/hooks/useNetworkForm.ts +86 -86
  84. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/index.vue +160 -160
  85. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/utils.ts +101 -101
  86. package/dist/v3/{Performance → DevTool/components/Performance}/index.vue +498 -495
  87. package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceMetrics.vue +153 -153
  88. package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceWidget.vue +12 -9
  89. package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceChart.ts +460 -460
  90. package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceData.ts +258 -258
  91. package/dist/v3/{PiniaList → DevTool/components/PiniaList}/index.vue +93 -94
  92. package/dist/v3/{RouteList → DevTool/components/RouteList}/index.vue +21 -24
  93. package/dist/v3/{RunJS → DevTool/components/RunJS}/index.vue +148 -148
  94. package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/ScanCodeItem.vue +97 -98
  95. package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/index.vue +100 -104
  96. package/dist/v3/{SettingButton → DevTool/components/SettingButton}/index.vue +45 -45
  97. package/dist/v3/{SettingList → DevTool/components/SettingList}/index.vue +218 -150
  98. package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +304 -0
  99. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingDevTool.vue +212 -208
  100. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingInfo.vue +157 -119
  101. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLanguage.vue +74 -74
  102. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLog.vue +230 -230
  103. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingNetwork.vue +3 -3
  104. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingTheme.vue +37 -7
  105. package/dist/v3/{SettingList → DevTool/components/SettingList}/typing.d.ts +2 -2
  106. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/Line.vue +127 -116
  107. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/index.vue +8 -8
  108. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/parseCode.ts +609 -701
  109. package/dist/v3/{StorageList → DevTool/components/StorageList}/index.vue +174 -174
  110. package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferDetail.vue +268 -268
  111. package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferItem.vue +4 -4
  112. package/dist/v3/{TransferList → DevTool/components/TransferList}/index.vue +8 -8
  113. package/dist/v3/{UniEvent → DevTool/components/UniEvent}/UniEventItem.vue +6 -7
  114. package/dist/v3/{UniEvent → DevTool/components/UniEvent}/index.vue +6 -6
  115. package/dist/v3/{VuexList → DevTool/components/VuexList}/index.vue +84 -84
  116. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketDetail.vue +8 -8
  117. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketItem.vue +4 -4
  118. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/index.vue +8 -8
  119. package/dist/v3/DevTool/index.vue +179 -5
  120. package/dist/v3/{AppTransition → components/AppTransition}/index.vue +176 -170
  121. package/dist/v3/{AutoSizer → components/AutoSizer}/index.vue +192 -192
  122. package/dist/v3/{AutoSizer → components/AutoSizer}/index1.vue +184 -184
  123. package/dist/v3/{AutoSizer → components/AutoSizer}/utils.ts +49 -49
  124. package/dist/v3/components/Barrage/BarrageItem.vue +137 -0
  125. package/dist/v3/components/Barrage/index.vue +202 -0
  126. package/dist/v3/{CircularButton → components/CircularButton}/index.vue +84 -84
  127. package/dist/v3/{CustomSwiper → components/CustomSwiper}/CustomSwiperItem.vue +49 -49
  128. package/dist/v3/{CustomSwiper → components/CustomSwiper}/index.vue +104 -104
  129. package/dist/v3/{DraggableContainer → components/DraggableContainer}/index.vue +1 -1
  130. package/dist/v3/{Empty → components/Empty}/index.vue +29 -29
  131. package/dist/v3/{FilterInput → components/FilterInput}/index.vue +1 -1
  132. package/dist/v3/{FilterSelect → components/FilterSelect}/index.vue +179 -179
  133. package/dist/v3/{JsonPretty → components/JsonPretty}/components/Brackets/index.vue +27 -27
  134. package/dist/v3/{JsonPretty → components/JsonPretty}/components/Carets/index.vue +59 -59
  135. package/dist/v3/{JsonPretty → components/JsonPretty}/components/CheckController/index.vue +136 -136
  136. package/dist/v3/{JsonPretty → components/JsonPretty}/components/TreeNode/index.vue +387 -381
  137. package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useClipboard.ts +21 -21
  138. package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useError.ts +21 -21
  139. package/dist/v3/{JsonPretty → components/JsonPretty}/index.vue +16 -13
  140. package/dist/v3/{JsonPretty → components/JsonPretty}/type.ts +127 -126
  141. package/dist/v3/{JsonPretty → components/JsonPretty}/utils/index.ts +169 -169
  142. package/dist/v3/{MovableContainer → components/MovableContainer}/index.vue +1 -1
  143. package/dist/v3/{Pick → components/Pick}/index.vue +322 -322
  144. package/dist/v3/{Tabs → components/Tabs}/index.vue +30 -4
  145. package/dist/v3/{Tag → components/Tag}/index.vue +113 -113
  146. package/dist/v3/{VirtualList → components/VirtualList}/AutoSize.vue +40 -40
  147. package/dist/v3/{VirtualList → components/VirtualList}/index.vue +416 -412
  148. package/dist/v3/hooks/useBluetooth/index.ts +561 -0
  149. package/dist/v3/hooks/useContainerStyle.ts +153 -153
  150. package/dist/v3/hooks/useNFC/index.ts +107 -107
  151. package/dist/v3/hooks/useNFC/typing.d.ts +396 -396
  152. package/dist/v3/hooks/useNFC/useNFCAndroid.ts +966 -966
  153. package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +812 -812
  154. package/dist/v3/hooks/useNFC/utils.ts +754 -754
  155. package/dist/v3/hooks/useRequest/index.ts +586 -573
  156. package/dist/v3/hooks/useRequest/utils.ts +267 -267
  157. package/dist/v3/hooks/useScanCode/index.ts +206 -206
  158. package/dist/v3/hooks/useWebsocket/README.md +79 -0
  159. package/dist/v3/hooks/useWebsocket/index.ts +253 -0
  160. package/dist/v3/styles/theme.css +17 -10
  161. package/dist/v3/styles/theme.ts +12 -12
  162. package/package.json +59 -64
  163. package/dist/plugins/uniParseStock/index.d.ts +0 -10
  164. package/dist/plugins/uniParseStock/index.d.ts.map +0 -1
  165. /package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.css +0 -0
  166. /package/dist/v3/{SettingList → DevTool/components/SettingList}/index.css +0 -0
  167. /package/dist/v3/{Empty → components/Empty}/empty.png +0 -0
  168. /package/dist/v3/{VirtualList → components/VirtualList}/readme.md +0 -0
@@ -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
+ }