ms-vite-plugin 1.1.2 → 1.1.4

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 (94) hide show
  1. package/dist/build.js +6 -0
  2. package/dist/cli.js +91 -1
  3. package/dist/mcp/device-config.d.ts +55 -0
  4. package/dist/mcp/device-config.js +183 -0
  5. package/dist/mcp/docs-service.d.ts +65 -0
  6. package/dist/mcp/docs-service.js +168 -0
  7. package/dist/mcp/project.d.ts +16 -0
  8. package/dist/mcp/project.js +74 -0
  9. package/dist/mcp/tools.d.ts +18 -0
  10. package/dist/mcp/tools.js +825 -0
  11. package/dist/mcp/types.d.ts +32 -0
  12. package/dist/mcp/types.js +11 -0
  13. package/dist/mcp-server.d.ts +2 -0
  14. package/dist/mcp-server.js +86 -0
  15. package/dist/project.d.ts +89 -0
  16. package/dist/project.js +306 -0
  17. package/dist/version.d.ts +12 -0
  18. package/dist/version.js +63 -0
  19. package/docs/api/action.md +922 -0
  20. package/docs/api/appleocr.md +229 -0
  21. package/docs/api/config.md +122 -0
  22. package/docs/api/cryptoUtils.md +232 -0
  23. package/docs/api/device.md +374 -0
  24. package/docs/api/file.md +516 -0
  25. package/docs/api/global.md +617 -0
  26. package/docs/api/hid.md +1032 -0
  27. package/docs/api/hotUpdate.md +166 -0
  28. package/docs/api/http.md +548 -0
  29. package/docs/api/image.md +907 -0
  30. package/docs/api/ime.md +290 -0
  31. package/docs/api/logger.md +324 -0
  32. package/docs/api/media.md +248 -0
  33. package/docs/api/mysql.md +441 -0
  34. package/docs/api/netCard.md +200 -0
  35. package/docs/api/node.md +353 -0
  36. package/docs/api/paddleocr.md +246 -0
  37. package/docs/api/pip.md +242 -0
  38. package/docs/api/system.md +572 -0
  39. package/docs/api/thread.md +269 -0
  40. package/docs/api/tomatoocr.md +425 -0
  41. package/docs/api/tts.md +334 -0
  42. package/docs/api/ui.md +947 -0
  43. package/docs/api/utils.md +265 -0
  44. package/docs/api/yolo.md +310 -0
  45. package/docs/apicn/action.md +919 -0
  46. package/docs/apicn/appleocr.md +233 -0
  47. package/docs/apicn/config.md +120 -0
  48. package/docs/apicn/device.md +385 -0
  49. package/docs/apicn/file.md +511 -0
  50. package/docs/apicn/global.md +613 -0
  51. package/docs/apicn/hid.md +1033 -0
  52. package/docs/apicn/hotUpdate.md +170 -0
  53. package/docs/apicn/http.md +672 -0
  54. package/docs/apicn/image.md +924 -0
  55. package/docs/apicn/ime.md +290 -0
  56. package/docs/apicn/logger.md +332 -0
  57. package/docs/apicn/media.md +252 -0
  58. package/docs/apicn/mysql.md +445 -0
  59. package/docs/apicn/netCard.md +200 -0
  60. package/docs/apicn/node.md +362 -0
  61. package/docs/apicn/paddleocr.md +255 -0
  62. package/docs/apicn/pip.md +242 -0
  63. package/docs/apicn/system.md +575 -0
  64. package/docs/apicn/thread.md +269 -0
  65. package/docs/apicn/tts.md +338 -0
  66. package/docs/apicn/ui.md +933 -0
  67. package/docs/apicn/utils.md +265 -0
  68. package/docs/apicn/yolo.md +314 -0
  69. package/docs/apipython/action.md +901 -0
  70. package/docs/apipython/appleocr.md +226 -0
  71. package/docs/apipython/config.md +126 -0
  72. package/docs/apipython/cryptoUtils.md +246 -0
  73. package/docs/apipython/device.md +365 -0
  74. package/docs/apipython/file.md +476 -0
  75. package/docs/apipython/g.md +154 -0
  76. package/docs/apipython/hid.md +1059 -0
  77. package/docs/apipython/hotUpdate.md +154 -0
  78. package/docs/apipython/image.md +938 -0
  79. package/docs/apipython/ime.md +306 -0
  80. package/docs/apipython/logger.md +330 -0
  81. package/docs/apipython/media.md +221 -0
  82. package/docs/apipython/mysql.md +432 -0
  83. package/docs/apipython/netCard.md +219 -0
  84. package/docs/apipython/node.md +331 -0
  85. package/docs/apipython/overview.md +66 -0
  86. package/docs/apipython/paddleocr.md +211 -0
  87. package/docs/apipython/pip.md +231 -0
  88. package/docs/apipython/system.md +458 -0
  89. package/docs/apipython/tomatoocr.md +444 -0
  90. package/docs/apipython/tts.md +331 -0
  91. package/docs/apipython/ui.md +949 -0
  92. package/docs/apipython/utils.md +284 -0
  93. package/docs/apipython/yolo.md +281 -0
  94. package/package.json +8 -4
@@ -0,0 +1,949 @@
1
+ # UI 模块 (UI)
2
+
3
+ UI 模块提供 WebView 相关功能,支持事件通信与 JavaScript 交互。该模块使用共享的 WebView 实例,通过静态方法进行操作。
4
+
5
+ ## UI 设计器
6
+
7
+ - <a href="/designer/index.html" target="_blank">在线设计器</a>
8
+
9
+ ## 注意事项
10
+
11
+ - UI 相关方法仅 app 在前台可用
12
+
13
+ ## 配置
14
+
15
+ ### UI 配置 网页会自动加载 package.json 中的配置
16
+
17
+ 在 `package.json` 中添加以下配置:
18
+
19
+ ```json
20
+ {
21
+ "ui": {
22
+ "tabs": [
23
+ {
24
+ "name": "快点JS",
25
+ "file": "index.html"
26
+ }
27
+ ]
28
+ }
29
+ }
30
+ ```
31
+
32
+ ### 配置项
33
+
34
+ - `tabs` - 网页标签配置数组
35
+ - `name` - 标签名称
36
+ - `file` - 网页文件路径(基于 res 目录)
37
+
38
+ ### 多个标签页
39
+
40
+ 如果配置了多个标签页,每个标签页会对应一个网页文件。在 `package.json` 中添加多个标签页配置即可。
41
+
42
+ ```json
43
+ {
44
+ "ui": {
45
+ "tabs": [
46
+ {
47
+ "name": "快点JS",
48
+ "file": "index.html"
49
+ },
50
+ {
51
+ "name": "设置",
52
+ "file": "settings.html"
53
+ }
54
+ ]
55
+ }
56
+ }
57
+ ```
58
+
59
+ ### 不显示标题栏
60
+
61
+ 如果只有一个页面且不需要标题栏,配置为空数组,会自动加载 `index.html`:
62
+
63
+ ```json
64
+ {
65
+ "ui": {
66
+ "tabs": []
67
+ }
68
+ }
69
+ ```
70
+
71
+ ## 核心方法
72
+
73
+ ### onEvent - 设置事件回调函数
74
+
75
+ ```python
76
+ from typing import Callable, Any
77
+
78
+ def onEvent(callback: Callable[[str, Any], None]) -> None
79
+ ```
80
+
81
+ **参数:**
82
+
83
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
84
+ | ---------- | ---------------------------- | -------- | ------ | ------------------------------------ |
85
+ | `callback` | `Callable[[str, Any], None]` | 是 | | 事件回调函数,用于处理来自网页的事件 |
86
+
87
+ **示例:**
88
+
89
+ ```python
90
+ from kuaijs import ui, logger
91
+ import json
92
+
93
+ def handle_event(event: str, data: Any):
94
+ logger.info(f"收到事件: {event}, 数据: {json.dumps(data)}")
95
+
96
+ ui.onEvent(handle_event)
97
+ ```
98
+
99
+ ### call - 调用 WebView 中的 JavaScript 函数
100
+
101
+ ```python
102
+ def call(key: str, data: dict) -> None
103
+ ```
104
+
105
+ **参数:**
106
+
107
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
108
+ | ------ | ---- | -------- | ------ | ----------------- |
109
+ | `key` | str | 是 | | JavaScript 方法名 |
110
+ | `data` | dict | 是 | | 传递给方法的参数 |
111
+
112
+ **示例:**
113
+
114
+ ```python
115
+ from kuaijs import ui
116
+ import time
117
+
118
+ # 调用网页中的方法
119
+ ui.call("updateStatus", {"status": "running", "progress": 50})
120
+ ui.call("loadData", {
121
+ "items": ["item1", "item2", "item3"],
122
+ "timestamp": int(time.time() * 1000)
123
+ })
124
+ ```
125
+
126
+ ### showToast - 显示 Toast 提示消息
127
+
128
+ ```python
129
+ def showToast(message: str) -> None
130
+ ```
131
+
132
+ **参数:**
133
+
134
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
135
+ | --------- | ---- | -------- | ------ | ------------ |
136
+ | `message` | str | 是 | | 提示消息内容 |
137
+
138
+ **示例:**
139
+
140
+ ```python
141
+ from kuaijs import ui
142
+
143
+ # 显示成功提示
144
+ ui.showToast("操作成功")
145
+
146
+ # 显示错误提示
147
+ ui.showToast("网络连接失败,请重试")
148
+
149
+ # 显示信息提示
150
+ ui.showToast("数据已保存")
151
+ ```
152
+
153
+ ### confirm - 显示确认对话框
154
+
155
+ ```python
156
+ def confirm(title: str, message: str) -> bool
157
+ ```
158
+
159
+ **参数:**
160
+
161
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
162
+ | --------- | ---- | -------- | ------ | ---------- |
163
+ | `title` | str | 是 | | 对话框标题 |
164
+ | `message` | str | 是 | | 对话框内容 |
165
+
166
+ **返回值:**
167
+
168
+ | 类型 | 描述 |
169
+ | ------ | ------------------------------------------- |
170
+ | `bool` | 用户选择结果,确定返回 True,取消返回 False |
171
+
172
+ **示例:**
173
+
174
+ ```python
175
+ from kuaijs import ui, logger, file
176
+
177
+ # 显示确认对话框
178
+ result = ui.confirm("确认删除", "是否确定要删除这个文件?")
179
+ if result:
180
+ logger.info("用户确认删除")
181
+ # 执行删除操作
182
+ # file.delete_all_file("temp.txt")
183
+ else:
184
+ logger.info("用户取消删除")
185
+
186
+ # 确认退出应用
187
+ should_exit = ui.confirm("退出应用", "确定要退出快点JS吗?")
188
+ if should_exit:
189
+ # 执行退出逻辑
190
+ pass
191
+ ```
192
+
193
+ ### confirmInput - 显示输入对话框
194
+
195
+ ```python
196
+ def confirmInput(title: str, message: str) -> str
197
+ ```
198
+
199
+ **参数:**
200
+
201
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
202
+ | --------- | ---- | -------- | ------ | ---------- |
203
+ | `title` | str | 是 | | 对话框标题 |
204
+ | `message` | str | 是 | | 对话框内容 |
205
+
206
+ **返回值:**
207
+
208
+ | 类型 | 描述 |
209
+ | ----- | ------------------------------ |
210
+ | `str` | 用户输入内容;取消返回空字符串 |
211
+
212
+ **示例:**
213
+
214
+ ```python
215
+ from kuaijs import ui, logger, config
216
+
217
+ # 获取用户输入
218
+ username = ui.confirmInput("用户登录", "请输入您的用户名:")
219
+ if username:
220
+ logger.info(f"用户输入的用户名:{username}")
221
+ # 继续登录流程
222
+ else:
223
+ logger.info("用户取消了输入")
224
+
225
+ # 获取配置值
226
+ api_url = ui.confirmInput("API配置", "请输入API服务器地址:")
227
+ if api_url:
228
+ config.set_config("apiUrl", api_url)
229
+ ui.showToast("API地址配置成功")
230
+ ```
231
+
232
+ ### alert - 显示警告对话框
233
+
234
+ ```python
235
+ def alert(title: str, message: str) -> None
236
+ ```
237
+
238
+ **参数:**
239
+
240
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
241
+ | --------- | ---- | -------- | ------ | ---------- |
242
+ | `title` | str | 是 | | 对话框标题 |
243
+ | `message` | str | 是 | | 对话框内容 |
244
+
245
+ **示例:**
246
+
247
+ ```python
248
+ from kuaijs import ui
249
+
250
+ # 显示错误警告
251
+ ui.alert("错误", "网络连接失败,请检查网络设置")
252
+
253
+ # 显示重要提示
254
+ ui.alert("重要提示", "请确保设备已连接到电脑并信任此设备")
255
+
256
+ # 显示操作结果
257
+ ui.alert("操作完成", "脚本执行完成,共处理了100个项目")
258
+ ```
259
+
260
+ ## 网页端 API
261
+
262
+ 以下 API 是在网页端 JavaScript 中使用的,用于与 Python 脚本交互。
263
+
264
+ ### registerUIFunc - 在网页中注册函数,供主进程调用
265
+
266
+ ```typescript
267
+ declare function registerUIFunc(
268
+ name: string,
269
+ func: (data: Record<string, any>) => void
270
+ ): void;
271
+ ```
272
+
273
+ **参数:**
274
+
275
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
276
+ | ------ | -------- | -------- | ------ | -------- |
277
+ | `name` | string | 是 | | 函数名称 |
278
+ | `func` | function | 是 | | 函数实现 |
279
+
280
+ **网页端示例:**
281
+
282
+ ```html
283
+ <!DOCTYPE html>
284
+ <html>
285
+ <head>
286
+ <title>快点JS UI</title>
287
+ </head>
288
+ <body>
289
+ <div id="status">等待中...</div>
290
+ <button onclick="sendMessage()">发送消息</button>
291
+
292
+ <script>
293
+ // 注册供主进程调用的函数
294
+ ms.registerUIFunc("updateStatus", function (data) {
295
+ document.getElementById(
296
+ "status"
297
+ ).textContent = `状态: ${data.status}, 进度: ${data.progress}%`;
298
+ });
299
+
300
+ ms.registerUIFunc("loadData", function (data) {
301
+ console.log(`收到数据: ${JSON.stringify(data)}`);
302
+ // 更新界面显示数据
303
+ updateUI(data.items);
304
+ });
305
+
306
+ function sendMessage() {
307
+ ms.emitEvent("button.click", {
308
+ buttonId: "send",
309
+ timestamp: Date.now(),
310
+ });
311
+ }
312
+
313
+ function updateUI(items) {
314
+ // 更新界面逻辑
315
+ }
316
+ </script>
317
+ </body>
318
+ </html>
319
+ ```
320
+
321
+ ### emitEvent - 从网页向主进程发送事件
322
+
323
+ ```typescript
324
+ declare function emitEvent(event: string, data: Record<string, any>): void;
325
+ ```
326
+
327
+ **参数:**
328
+
329
+ - `event` - 事件名称
330
+ - `data` - 事件数据
331
+
332
+ **网页端示例:**
333
+
334
+ ```javascript
335
+ // 发送自定义事件
336
+ ms.emitEvent("user.login", { username: "admin", timestamp: Date.now() });
337
+
338
+ // 发送操作完成事件
339
+ ms.emitEvent("task.completed", { taskId: "task001", result: "success" });
340
+
341
+ // 发送错误事件
342
+ ms.emitEvent("error.occurred", { message: "网络连接失败", code: 500 });
343
+ ```
344
+
345
+ ### startTask - 启动脚本
346
+
347
+ ```typescript
348
+ declare function startTask(): Promise<boolean>;
349
+ ```
350
+
351
+ **返回值:**
352
+
353
+ | 类型 | 描述 |
354
+ | ------------------ | ------------------------------------- |
355
+ | `Promise<boolean>` | 如果启动成功返回 true,否则返回 false |
356
+
357
+ **说明:**
358
+
359
+ 启动脚本任务。
360
+
361
+ **网页端示例:**
362
+
363
+ ```javascript
364
+ // 启动脚本
365
+ ms.startTask()
366
+ .then((result) => {
367
+ if (result) {
368
+ console.log("脚本启动成功");
369
+ } else {
370
+ console.log("脚本启动失败");
371
+ }
372
+ })
373
+ .catch((error) => {
374
+ console.error("启动脚本出错:", error);
375
+ });
376
+ ```
377
+
378
+ ### stopTask - 停止脚本
379
+
380
+ ```typescript
381
+ declare function stopTask(): Promise<boolean>;
382
+ ```
383
+
384
+ **返回值:**
385
+
386
+ | 类型 | 描述 |
387
+ | ------------------ | ------------------------------------- |
388
+ | `Promise<boolean>` | 如果停止成功返回 false,否则返回 true |
389
+
390
+ **说明:**
391
+
392
+ 停止当前运行的脚本任务。
393
+
394
+ **网页端示例:**
395
+
396
+ ```javascript
397
+ // 停止脚本
398
+ ms.stopTask()
399
+ .then((result) => {
400
+ if (!result) {
401
+ console.log("脚本停止成功");
402
+ } else {
403
+ console.log("脚本停止失败");
404
+ }
405
+ })
406
+ .catch((error) => {
407
+ console.error("停止脚本出错:", error);
408
+ });
409
+ ```
410
+
411
+ ### isTaskRunning - 检查脚本运行状态
412
+
413
+ ```typescript
414
+ declare function isTaskRunning(): Promise<boolean>;
415
+ ```
416
+
417
+ **返回值:**
418
+
419
+ | 类型 | 描述 |
420
+ | ------------------ | ----------------------------------------- |
421
+ | `Promise<boolean>` | 如果脚本正在运行返回 true,否则返回 false |
422
+
423
+ **说明:**
424
+
425
+ 检查脚本是否正在运行。
426
+
427
+ **网页端示例:**
428
+
429
+ ```javascript
430
+ // 检查脚本状态
431
+ ms.isTaskRunning()
432
+ .then((isRunning) => {
433
+ if (isRunning) {
434
+ console.log("脚本正在运行");
435
+ document.getElementById("task-status").textContent = "运行中";
436
+ } else {
437
+ console.log("脚本未运行");
438
+ document.getElementById("task-status").textContent = "已停止";
439
+ }
440
+ })
441
+ .catch((error) => {
442
+ console.error("获取脚本状态出错:", error);
443
+ });
444
+ ```
445
+
446
+ ### 配置管理方法
447
+
448
+ #### setConfig - 设置配置项
449
+
450
+ ```typescript
451
+ declare function setConfig(key: string, value: any): Promise<boolean>;
452
+ ```
453
+
454
+ **参数:**
455
+
456
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
457
+ | ------- | ------ | -------- | ------ | -------- |
458
+ | `key` | string | 是 | | 配置项键 |
459
+ | `value` | any | 是 | | 配置项值 |
460
+
461
+ **返回值:**
462
+
463
+ | 类型 | 描述 |
464
+ | ------------------ | ------------------------------------- |
465
+ | `Promise<boolean>` | 如果设置成功返回 true,否则返回 false |
466
+
467
+ **网页端示例:**
468
+
469
+ ```javascript
470
+ // 设置配置项
471
+ ms.setConfig("theme", "dark").then((success) => {
472
+ if (success) {
473
+ console.log("配置设置成功");
474
+ }
475
+ });
476
+ ```
477
+
478
+ #### getConfig - 获取配置项
479
+
480
+ ```typescript
481
+ declare function getConfig(key: string): Promise<any>;
482
+ ```
483
+
484
+ **参数:**
485
+
486
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
487
+ | ------ | ------ | -------- | ------ | -------- |
488
+ | `key` | string | 是 | | 配置项键 |
489
+
490
+ **返回值:**
491
+
492
+ | 类型 | 描述 |
493
+ | -------------- | -------- |
494
+ | `Promise<any>` | 配置项值 |
495
+
496
+ **网页端示例:**
497
+
498
+ ```javascript
499
+ // 获取配置项
500
+ ms.getConfig("theme").then((value) => {
501
+ console.log("当前主题:", value);
502
+ });
503
+ ```
504
+
505
+ #### removeConfig - 移除配置项
506
+
507
+ ```typescript
508
+ declare function removeConfig(key: string): Promise<boolean>;
509
+ ```
510
+
511
+ **参数:**
512
+
513
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
514
+ | ------ | ------ | -------- | ------ | -------- |
515
+ | `key` | string | 是 | | 配置项键 |
516
+
517
+ **返回值:**
518
+
519
+ | 类型 | 描述 |
520
+ | ------------------ | ------------------------------------- |
521
+ | `Promise<boolean>` | 如果移除成功返回 true,否则返回 false |
522
+
523
+ **网页端示例:**
524
+
525
+ ```javascript
526
+ // 移除配置项
527
+ ms.removeConfig("theme").then((success) => {
528
+ if (success) {
529
+ console.log("配置移除成功");
530
+ }
531
+ });
532
+ ```
533
+
534
+ #### getAllConfig - 获取所有配置
535
+
536
+ ```typescript
537
+ declare function getAllConfig(): Promise<Record<string, any>>;
538
+ ```
539
+
540
+ **返回值:**
541
+
542
+ | 类型 | 描述 |
543
+ | ------------------------------ | ------------------ |
544
+ | `Promise<Record<string, any>>` | 包含所有配置的字典 |
545
+
546
+ **网页端示例:**
547
+
548
+ ```javascript
549
+ // 获取所有配置
550
+ ms.getAllConfig().then((configs) => {
551
+ console.log("所有配置:", configs);
552
+ });
553
+ ```
554
+
555
+ ### 快点 Agent 控制方法
556
+
557
+ #### startAgent - 启动 快点 Agent 服务
558
+
559
+ ```typescript
560
+ declare function startAgent(): Promise<boolean>;
561
+ ```
562
+
563
+ **返回值:**
564
+
565
+ | 类型 | 描述 |
566
+ | ------------------ | ------------------------------------- |
567
+ | `Promise<boolean>` | 如果调用成功返回 true,否则返回 false |
568
+
569
+ **说明:**
570
+
571
+ 启动 快点 Agent 服务。注意:返回值仅表示调用是否成功,不代表 快点 Agent 服务是否启动成功。
572
+
573
+ **网页端示例:**
574
+
575
+ ```javascript
576
+ // 启动 快点 Agent 服务
577
+ ms.startAgent()
578
+ .then((result) => {
579
+ if (result) {
580
+ console.log("快点 Agent 启动调用成功");
581
+ // 可以通过 getAgentStatus() 检查实际状态
582
+ checkAgentStatus();
583
+ } else {
584
+ console.log("快点 Agent 启动调用失败");
585
+ }
586
+ })
587
+ .catch((error) => {
588
+ console.error("快点 Agent 启动出错:", error);
589
+ });
590
+ ```
591
+
592
+ #### getAgentStatus - 获取 快点 Agent 状态
593
+
594
+ ```typescript
595
+ declare function getAgentStatus(): Promise<boolean>;
596
+ ```
597
+
598
+ **返回值:**
599
+
600
+ | 类型 | 描述 |
601
+ | ------------------ | ------------------------------------------------- |
602
+ | `Promise<boolean>` | 如果 快点 Agent 正在运行返回 true,否则返回 false |
603
+
604
+ **说明:**
605
+
606
+ 检查 快点 Agent 服务的当前运行状态。
607
+
608
+ **网页端示例:**
609
+
610
+ ```javascript
611
+ // 检查 快点 Agent 状态
612
+ ms.getAgentStatus()
613
+ .then((isRunning) => {
614
+ if (isRunning) {
615
+ console.log("快点 Agent 服务正在运行");
616
+ document.getElementById("agent-status").textContent = "已连接";
617
+ document.getElementById("agent-status").className = "status-online";
618
+ } else {
619
+ console.log("快点 Agent 服务未运行");
620
+ document.getElementById("agent-status").textContent = "未连接";
621
+ document.getElementById("agent-status").className = "status-offline";
622
+ }
623
+ })
624
+ .catch((error) => {
625
+ console.error("获取 快点 Agent 状态出错:", error);
626
+ });
627
+
628
+ // 定期检查 快点 Agent 状态
629
+ function checkAgentStatus() {
630
+ ms.getAgentStatus().then((isRunning) => {
631
+ updateAgentStatusUI(isRunning);
632
+ });
633
+ }
634
+
635
+ // 每 5 秒检查一次状态
636
+ setInterval(checkAgentStatus, 5000);
637
+ ```
638
+
639
+ ### 系统功能
640
+
641
+ #### getServerDeviceId - 获取服务器设备 ID
642
+
643
+ ```typescript
644
+ declare function getServerDeviceId(): Promise<string>;
645
+ ```
646
+
647
+ **返回值:**
648
+
649
+ | 类型 | 描述 |
650
+ | ----------------- | ------------- |
651
+ | `Promise<string>` | 服务器设备 ID |
652
+
653
+ **说明:**
654
+
655
+ 获取当前运行脚本的服务器设备 ID。
656
+
657
+ **网页端示例:**
658
+
659
+ ```javascript
660
+ // 获取服务器设备ID
661
+ ms.getServerDeviceId()
662
+ .then((deviceId) => {
663
+ console.log("当前服务器设备ID:", deviceId);
664
+ })
665
+ .catch((error) => {
666
+ console.error("获取服务器设备ID出错:", error);
667
+ });
668
+ ```
669
+
670
+ #### openURL - 调用浏览器打开 URL
671
+
672
+ ```typescript
673
+ declare function openURL(url: string): Promise<boolean>;
674
+ ```
675
+
676
+ **参数:**
677
+
678
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
679
+ | ------ | ------ | -------- | ------ | ----------------- |
680
+ | `url` | string | 是 | | 要打开的 URL 地址 |
681
+
682
+ **返回值:**
683
+
684
+ | 类型 | 描述 |
685
+ | ------------------ | ------------------------------------- |
686
+ | `Promise<boolean>` | 如果调用成功返回 true,否则返回 false |
687
+
688
+ **说明:**
689
+
690
+ 打开指定的 URL 地址。
691
+
692
+ **网页端示例:**
693
+
694
+ ```javascript
695
+ // 打开URL
696
+ ms.openURL("https://www.baidu.com")
697
+ .then((success) => {
698
+ if (success) {
699
+ console.log("URL打开成功");
700
+ } else {
701
+ console.log("URL打开失败");
702
+ }
703
+ })
704
+ .catch((error) => {
705
+ console.error("打开URL出错:", error);
706
+ });
707
+ ```
708
+
709
+ ### 完整示例
710
+
711
+ **完整的控制面板示例:**
712
+
713
+ ```html
714
+ <!DOCTYPE html>
715
+ <html>
716
+ <head>
717
+ <title>快点JS 控制面板</title>
718
+ <style>
719
+ .status-online {
720
+ color: green;
721
+ }
722
+ .status-offline {
723
+ color: red;
724
+ }
725
+ .button {
726
+ padding: 10px 20px;
727
+ margin: 5px;
728
+ cursor: pointer;
729
+ }
730
+ .panel {
731
+ margin: 20px 0;
732
+ padding: 15px;
733
+ border: 1px solid #ccc;
734
+ }
735
+ </style>
736
+ </head>
737
+ <body>
738
+ <h1>快点JS 控制面板</h1>
739
+
740
+ <!-- 脚本控制 -->
741
+ <div class="panel">
742
+ <h3>脚本控制</h3>
743
+ <p>脚本状态: <span id="task-status">检查中...</span></p>
744
+ <button class="button" onclick="startScript()">启动脚本</button>
745
+ <button class="button" onclick="stopScript()">停止脚本</button>
746
+ <button class="button" onclick="checkTaskStatus()">检查状态</button>
747
+ </div>
748
+
749
+ <!-- 快点 Agent 控制 -->
750
+ <div class="panel">
751
+ <h3>快点 Agent 控制</h3>
752
+ <p>状态: <span id="agent-status">检查中...</span></p>
753
+ <button class="button" onclick="startAgentService()">
754
+ 启动 快点 Agent
755
+ </button>
756
+ <button class="button" onclick="checkAgentStatus()">检查状态</button>
757
+ </div>
758
+
759
+ <!-- 配置管理 -->
760
+ <div class="panel">
761
+ <h3>配置管理</h3>
762
+ <input type="text" id="config-key" placeholder="配置键" />
763
+ <input type="text" id="config-value" placeholder="配置值" />
764
+ <button class="button" onclick="setConfigItem()">设置配置</button>
765
+ <button class="button" onclick="getConfigItem()">获取配置</button>
766
+ <button class="button" onclick="showAllConfigs()">显示所有配置</button>
767
+ </div>
768
+
769
+ <!-- 对话框测试 -->
770
+ <div class="panel">
771
+ <h3>对话框测试</h3>
772
+ <button class="button" onclick="showToastMessage()">显示Toast</button>
773
+ <button class="button" onclick="showConfirmDialog()">
774
+ 显示确认对话框
775
+ </button>
776
+ <button class="button" onclick="showInputDialog()">显示输入对话框</button>
777
+ <button class="button" onclick="showAlertDialog()">显示警告对话框</button>
778
+ </div>
779
+
780
+ <div id="log-container"></div>
781
+
782
+ <script>
783
+ // 脚本控制函数
784
+ function startScript() {
785
+ addLog("正在启动脚本...");
786
+ ms.startTask()
787
+ .then((result) => {
788
+ addLog(result ? "脚本启动成功" : "脚本启动失败");
789
+ checkTaskStatus();
790
+ })
791
+ .catch((error) => {
792
+ addLog("启动脚本出错: " + error);
793
+ });
794
+ }
795
+
796
+ function stopScript() {
797
+ addLog("正在停止脚本...");
798
+ ms.stopTask()
799
+ .then((result) => {
800
+ addLog(!result ? "脚本停止成功" : "脚本停止失败");
801
+ checkTaskStatus();
802
+ })
803
+ .catch((error) => {
804
+ addLog("停止脚本出错: " + error);
805
+ });
806
+ }
807
+
808
+ function checkTaskStatus() {
809
+ ms.isTaskRunning()
810
+ .then((isRunning) => {
811
+ const statusElement = document.getElementById("task-status");
812
+ statusElement.textContent = isRunning ? "运行中" : "已停止";
813
+ statusElement.className = isRunning
814
+ ? "status-online"
815
+ : "status-offline";
816
+ addLog("脚本状态: " + (isRunning ? "运行中" : "已停止"));
817
+ })
818
+ .catch((error) => {
819
+ addLog("获取脚本状态出错: " + error);
820
+ });
821
+ }
822
+
823
+ // 快点 Agent 控制函数
824
+ function startAgentService() {
825
+ addLog("正在启动 快点 Agent 服务...");
826
+ ms.startAgent()
827
+ .then((result) => {
828
+ if (result) {
829
+ addLog("快点 Agent 启动调用成功");
830
+ setTimeout(() => {
831
+ checkAgentStatus();
832
+ }, 2000);
833
+ } else {
834
+ addLog("快点 Agent 启动调用失败");
835
+ }
836
+ })
837
+ .catch((error) => {
838
+ addLog("启动 快点 Agent 服务出错: " + error);
839
+ });
840
+ }
841
+
842
+ function checkAgentStatus() {
843
+ ms.getAgentStatus()
844
+ .then((isRunning) => {
845
+ const statusElement = document.getElementById("agent-status");
846
+ statusElement.textContent = isRunning ? "已连接" : "未连接";
847
+ statusElement.className = isRunning
848
+ ? "status-online"
849
+ : "status-offline";
850
+ addLog("快点 Agent 状态: " + (isRunning ? "已连接" : "未连接"));
851
+ })
852
+ .catch((error) => {
853
+ addLog("获取 快点 Agent 状态出错: " + error);
854
+ });
855
+ }
856
+
857
+ // 配置管理函数
858
+ function setConfigItem() {
859
+ const key = document.getElementById("config-key").value;
860
+ const value = document.getElementById("config-value").value;
861
+ if (!key) {
862
+ alert("请输入配置键");
863
+ return;
864
+ }
865
+
866
+ ms.setConfig(key, value)
867
+ .then((success) => {
868
+ addLog(`设置配置 [${key}=${value}]: ${success ? "成功" : "失败"}`);
869
+ })
870
+ .catch((error) => {
871
+ addLog("设置配置出错: " + error);
872
+ });
873
+ }
874
+
875
+ function getConfigItem() {
876
+ const key = document.getElementById("config-key").value;
877
+ if (!key) {
878
+ alert("请输入配置键");
879
+ return;
880
+ }
881
+
882
+ ms.getConfig(key)
883
+ .then((value) => {
884
+ addLog(`获取配置 [${key}]: ${value}`);
885
+ document.getElementById("config-value").value = value || "";
886
+ })
887
+ .catch((error) => {
888
+ addLog("获取配置出错: " + error);
889
+ });
890
+ }
891
+
892
+ function showAllConfigs() {
893
+ ms.getAllConfig()
894
+ .then((configs) => {
895
+ addLog("所有配置: " + JSON.stringify(configs));
896
+ })
897
+ .catch((error) => {
898
+ addLog("获取所有配置出错: " + error);
899
+ });
900
+ }
901
+
902
+ // 对话框测试函数
903
+ function showToastMessage() {
904
+ // 注意:这里只是演示,实际上 showToast 是脚本端 API
905
+ // 网页端可以通过 emitEvent 通知脚本端显示 Toast
906
+ ms.emitEvent("show_toast", { message: "来自网页的 Toast" });
907
+ addLog("已发送显示 Toast 事件");
908
+ }
909
+
910
+ function showConfirmDialog() {
911
+ ms.emitEvent("show_confirm", {
912
+ title: "网页确认",
913
+ message: "来自网页的确认框",
914
+ });
915
+ addLog("已发送显示确认框事件");
916
+ }
917
+
918
+ function showInputDialog() {
919
+ ms.emitEvent("show_input", {
920
+ title: "网页输入",
921
+ message: "来自网页的输入框",
922
+ });
923
+ addLog("已发送显示输入框事件");
924
+ }
925
+
926
+ function showAlertDialog() {
927
+ ms.emitEvent("show_alert", {
928
+ title: "网页警告",
929
+ message: "来自网页的警告框",
930
+ });
931
+ addLog("已发送显示警告框事件");
932
+ }
933
+
934
+ // 辅助函数
935
+ function addLog(message) {
936
+ const container = document.getElementById("log-container");
937
+ const logEntry = document.createElement("div");
938
+ logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
939
+ container.appendChild(logEntry);
940
+ container.scrollTop = container.scrollHeight;
941
+ }
942
+
943
+ // 初始化
944
+ checkTaskStatus();
945
+ checkAgentStatus();
946
+ </script>
947
+ </body>
948
+ </html>
949
+ ```