@doubao-apps/ai 0.0.33 → 0.0.34

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 (69) hide show
  1. package/README.md +1 -32
  2. package/dist/733.js +7 -15
  3. package/dist/cli.js +1 -1
  4. package/dist/manifest.json +3 -11
  5. package/dist/skills/doubao-apps-dev/SKILL.md +103 -227
  6. package/dist/skills/doubao-apps-dev/references/examples/common-patterns.md +80 -66
  7. package/dist/skills/doubao-apps-dev/references/examples/component-basics.md +24 -3
  8. package/dist/skills/doubao-apps-dev/references/examples/component-recipes.md +71 -0
  9. package/dist/skills/doubao-apps-dev/references/examples/open-api-recipes.md +203 -0
  10. package/dist/skills/doubao-apps-dev/references/guides/component-development.md +66 -42
  11. package/dist/skills/doubao-apps-dev/references/guides/expired-widget.md +113 -0
  12. package/dist/skills/doubao-apps-dev/references/guides/mcp-ui.md +275 -0
  13. package/dist/skills/doubao-apps-dev/references/guides/performance-optimization.md +24 -7
  14. package/dist/skills/doubao-apps-dev/references/reference/components-quick-ref.md +18 -7
  15. package/dist/skills/doubao-apps-dev/references/reference/framework-api-quick-ref.md +125 -107
  16. package/dist/skills/doubao-apps-dev/references/reference/open-api/01-/345/237/272/347/241/200.md +136 -0
  17. package/dist/skills/doubao-apps-dev/references/reference/open-api/02-/347/263/273/347/273/237.md +257 -0
  18. package/dist/skills/doubao-apps-dev/references/reference/open-api/03-/345/256/232/344/275/215.md +326 -0
  19. package/dist/skills/doubao-apps-dev/references/reference/open-api/04-/345/255/230/345/202/250.md +284 -0
  20. package/dist/skills/doubao-apps-dev/references/reference/open-api/05-/350/267/257/347/224/261.md +162 -0
  21. package/dist/skills/doubao-apps-dev/references/reference/open-api/06-/344/272/244/344/272/222.md +290 -0
  22. package/dist/skills/doubao-apps-dev/references/reference/open-api/07-/350/276/223/345/205/245.md +63 -0
  23. package/dist/skills/doubao-apps-dev/references/reference/open-api/08-/347/275/221/347/273/234.md +124 -0
  24. package/dist/skills/doubao-apps-dev/references/reference/open-api/09-/345/252/222/344/275/223.md +192 -0
  25. package/dist/skills/doubao-apps-dev/references/reference/open-api/10-/344/270/232/345/212/241/350/203/275/345/212/233.md +431 -0
  26. package/dist/skills/doubao-apps-dev/references/reference/open-api/11-/347/231/273/345/275/225.md +110 -0
  27. package/dist/skills/doubao-apps-dev/references/reference/open-api/12-/346/224/257/344/273/230.md +224 -0
  28. package/dist/skills/doubao-apps-dev/references/reference/open-api/13-/346/225/260/346/215/256/345/210/206/346/236/220.md +43 -0
  29. package/dist/skills/doubao-apps-dev/references/reference/open-api/14-/350/223/235/347/211/231.md +598 -0
  30. package/dist/skills/doubao-apps-dev/references/reference/open-api/15-wi-fi.md +210 -0
  31. package/dist/skills/doubao-apps-dev/references/reference/open-api/16-/345/212/240/351/200/237/345/272/246/350/256/241.md +87 -0
  32. package/dist/skills/doubao-apps-dev/references/reference/open-api/17-ibeacon.md +97 -0
  33. package/dist/skills/doubao-apps-dev/references/reference/open-api/18-/347/275/227/347/233/230.md +78 -0
  34. package/dist/skills/doubao-apps-dev/references/reference/open-api/19-/350/256/276/345/244/207/346/226/271/345/220/221.md +86 -0
  35. package/dist/skills/doubao-apps-dev/references/reference/open-api/20-/351/231/200/350/236/272/344/273/252.md +87 -0
  36. package/dist/skills/doubao-apps-dev/references/reference/open-api/21-/350/256/276/345/244/207-/347/275/221/347/273/234.md +102 -0
  37. package/dist/skills/doubao-apps-dev/references/reference/open-api/22-/347/237/255/344/277/241.md +40 -0
  38. package/dist/skills/doubao-apps-dev/references/reference/open-api/23-/346/227/240/351/232/234/347/242/215.md +40 -0
  39. package/dist/skills/doubao-apps-dev/references/reference/open-api/24-/345/237/272/347/241/200/344/277/241/346/201/257.md +86 -0
  40. package/dist/skills/doubao-apps-dev/references/reference/open-api/25-/347/224/265/346/261/240.md +63 -0
  41. package/dist/skills/doubao-apps-dev/references/reference/open-api/26-/346/227/245/345/216/206.md +95 -0
  42. package/dist/skills/doubao-apps-dev/references/reference/open-api/27-/345/211/252/350/264/264/346/235/277.md +64 -0
  43. package/dist/skills/doubao-apps-dev/references/reference/open-api/28-/350/201/224/347/263/273/344/272/272.md +101 -0
  44. package/dist/skills/doubao-apps-dev/references/reference/open-api/29-/345/212/240/345/257/206.md +43 -0
  45. package/dist/skills/doubao-apps-dev/references/reference/open-api/30-/347/224/265/350/257/235.md +36 -0
  46. package/dist/skills/doubao-apps-dev/references/reference/open-api/31-/346/211/253/347/240/201.md +58 -0
  47. package/dist/skills/doubao-apps-dev/references/reference/open-api/32-/345/261/217/345/271/225.md +136 -0
  48. package/dist/skills/doubao-apps-dev/references/reference/open-api/33-/351/234/207/345/212/250.md +62 -0
  49. package/dist/skills/doubao-apps-dev/references/reference/open-api/34-/346/226/207/344/273/266/347/263/273/347/273/237.md +73 -0
  50. package/dist/skills/doubao-apps-dev/references/reference/open-api/README.md +34 -0
  51. package/dist/skills/doubao-apps-dev/references/reference/open-api.md +384 -2
  52. package/dist/skills/doubao-apps-dev/references/rules/dos-and-donts.md +44 -27
  53. package/dist/skills/h5-to-doubao/SKILL.md +8 -4
  54. package/dist/skills/weixin-to-doubao/SKILL.md +8 -4
  55. package/dist/skills/weixin-to-doubao/assets/migration-checklist-template.md +1 -1
  56. package/package.json +2 -3
  57. package/dist/contexts/doubao-apps-dev/AGENTS.md +0 -300
  58. package/dist/contexts/doubao-apps-dev/CLAUDE.md +0 -31
  59. package/dist/contexts/doubao-apps-dev/references/examples/common-patterns.md +0 -589
  60. package/dist/contexts/doubao-apps-dev/references/examples/component-basics.md +0 -526
  61. package/dist/contexts/doubao-apps-dev/references/guides/best-practices.md +0 -571
  62. package/dist/contexts/doubao-apps-dev/references/guides/component-development.md +0 -891
  63. package/dist/contexts/doubao-apps-dev/references/guides/performance-optimization.md +0 -402
  64. package/dist/contexts/doubao-apps-dev/references/guides/troubleshooting.md +0 -287
  65. package/dist/contexts/doubao-apps-dev/references/reference/components-quick-ref.md +0 -103
  66. package/dist/contexts/doubao-apps-dev/references/reference/framework-api-quick-ref.md +0 -550
  67. package/dist/contexts/doubao-apps-dev/references/reference/open-api/README.md +0 -8
  68. package/dist/contexts/doubao-apps-dev/references/reference/open-api.md +0 -11
  69. package/dist/contexts/doubao-apps-dev/references/rules/dos-and-donts.md +0 -467
@@ -91,23 +91,42 @@ import type { AIViewContext } from '@doubao-apps/framework';
91
91
  引入依赖
92
92
 
93
93
  ```ts
94
- import { setStorage, getStorage, removeStorage, clearStorage, getStorageInfo } from '@doubao-apps/framework/api';
94
+ import {
95
+ setStorage,
96
+ setStorageSync,
97
+ getStorage,
98
+ getStorageSync,
99
+ removeStorage,
100
+ removeStorageSync,
101
+ clearStorage,
102
+ clearStorageSync,
103
+ getStorageInfo,
104
+ getStorageInfoSync
105
+ } from '@doubao-apps/framework/api';
95
106
  ```
96
107
 
108
+ `setStorage` / `setStorageSync` 支持写入 JSON 可序列化数据;`getStorage<T>` / `getStorageSync<T>` 会返回
109
+ `{ data: T }`,SDK 会在写入和读取时处理 JSON 编码与解析。
110
+
97
111
  ### API 列表
98
112
 
99
113
  | API | 功能 | 示例 |
100
114
  |-----|------|------|
101
115
  | `setStorage({ key, data })` | 写入本地缓存 | `setStorage({ key: 'profile', data: { name: 'Tom' } })` |
116
+ | `setStorageSync({ key, data })` | 同步写入本地缓存 | `setStorageSync({ key: 'profile', data: { name: 'Tom' } })` |
102
117
  | `getStorage({ key })` | 读取本地缓存 | `getStorage<T>({ key: 'profile' })` → `{ data: T }` |
118
+ | `getStorageSync({ key })` | 同步读取本地缓存 | `getStorageSync<T>({ key: 'profile' })` → `{ data: T }` |
103
119
  | `removeStorage({ key })` | 删除指定缓存 | `removeStorage({ key: 'profile' })` |
120
+ | `removeStorageSync({ key })` | 同步删除指定缓存 | `removeStorageSync({ key: 'profile' })` |
104
121
  | `clearStorage()` | 清空所有缓存 | `clearStorage()` |
122
+ | `clearStorageSync()` | 同步清空所有缓存 | `clearStorageSync()` |
105
123
  | `getStorageInfo()` | 获取缓存信息 | `getStorageInfo()` → `{ keys, currentSize, limitSize }` |
124
+ | `getStorageInfoSync()` | 同步获取缓存信息 | `getStorageInfoSync()` → `{ keys, currentSize, limitSize }` |
106
125
 
107
126
  ### 使用示例
108
127
 
109
128
  ```ts
110
- import { setStorage, getStorage, removeStorage, getStorageInfo } from '@doubao-apps/framework/api';
129
+ import { getStorage, getStorageInfo, getStorageSync, removeStorage, setStorage } from '@doubao-apps/framework/api';
111
130
 
112
131
  // 写入数据
113
132
  await setStorage({
@@ -127,31 +146,87 @@ await removeStorage({ key: 'profile' });
127
146
  // 获取缓存信息
128
147
  const info = await getStorageInfo();
129
148
  console.log(info.keys, info.currentSize, info.limitSize);
149
+
150
+ // 同步读取只适合少量、即时读取场景
151
+ const cachedProfile = getStorageSync<{ name: string; age: number }>({ key: 'profile' });
152
+ console.log(cachedProfile.data.name);
130
153
  ```
131
154
 
132
155
  # 端能力(系统能力)API
133
156
 
134
- 端能力 API 推荐从 `@doubao-apps/framework/api` 引入(运行时调用 + 类型),以 IDE 类型提示为准。
157
+ 端能力 API `@doubao-apps/framework/api` 引入(运行时调用 + 类型),以 IDE 类型提示为准。
135
158
 
136
159
  ## 引入依赖
137
160
 
138
161
  ```ts
139
- import { getLocation, getPhoneNumber, navigateTo, navigateBack, request, showToast, setStorage, getStorage } from '@doubao-apps/framework/api';
162
+ import { getLocation, navigateTo, navigateBack, request, showToast, setStorage, getStorage } from '@doubao-apps/framework/api';
140
163
  ```
141
164
 
165
+ ## 调用位置
166
+
167
+ `request`、`getLocation`、`setStorage`、`getStorage`、`setStorageSync`、`getStorageSync`、`showToast`、
168
+ `navigateTo` 等异步或系统 API
169
+ 不要直接写在 `render()` 中。首次加载放在 `useEffect` 或生命周期钩子;用户动作放在事件处理函数;
170
+ 同时保留 loading、error、success 等可见状态。
171
+
172
+ 按钮触发端能力时,内置 `button` 使用 `onClick` 绑定事件函数,不要写 `onTap`、`bindtap` 或 `catchtap`。
173
+
142
174
  ## 使用示例
143
175
 
144
176
  ```ts
145
177
  await showToast({ message: '保存成功' });
146
178
 
147
- await navigateTo({ url: 'detail?id=123' });
179
+ await navigateTo({ url: '/pages/detail/index?id=123' });
148
180
  await navigateBack();
149
181
 
150
- const res = await request({ url: '/api/data', method: 'GET' });
182
+ const res = await request({ url: 'https://api.example.com/data', method: 'GET' });
183
+ console.log(res.statusCode, res.data);
151
184
 
152
185
  const location = await getLocation();
153
- const phone = await getPhoneNumber();
186
+ console.log(location.latitude, location.longitude, location.timestamp);
154
187
  ```
188
+
189
+ ```tsx
190
+ import { definePage, getViewData, useState } from '@doubao-apps/framework';
191
+ import { navigateTo, showToast } from '@doubao-apps/framework/api';
192
+
193
+ interface NavigationData {
194
+ title: string;
195
+ targetUrl: string;
196
+ }
197
+
198
+ function NavigationPage() {
199
+ const viewData = getViewData<NavigationData>();
200
+ const [status, setStatus] = useState<'idle' | 'running' | 'success' | 'error'>('idle');
201
+
202
+ const handleNavigate = async () => {
203
+ setStatus('running');
204
+ try {
205
+ await showToast({ message: '准备跳转' });
206
+ await navigateTo({ url: viewData.targetUrl });
207
+ setStatus('success');
208
+ } catch {
209
+ setStatus('error');
210
+ await showToast({ message: '跳转失败' });
211
+ }
212
+ };
213
+
214
+ return (
215
+ <view>
216
+ <text>{viewData.title}</text>
217
+ <text>{status}</text>
218
+ <button text="显示提示并跳转" onClick={handleNavigate} />
219
+ </view>
220
+ );
221
+ }
222
+
223
+ export default definePage({
224
+ render() {
225
+ return <NavigationPage />;
226
+ }
227
+ });
228
+ ```
229
+
155
230
  ## API 速查(节选)
156
231
 
157
232
  以下为常用端能力 API 的节选,完整以 `@doubao-apps/framework/api` 类型定义为准。
@@ -161,7 +236,7 @@ const phone = await getPhoneNumber();
161
236
  **参数**:
162
237
  ```typescript
163
238
  {
164
- /** 跳转目标,填写页面的 pageId,可拼接 query,如 'detail?id=123' */
239
+ /** 跳转目标,填写 Page 路径,可拼接 query,如 '/pages/detail/index?id=123' */
165
240
  url: string;
166
241
  }
167
242
  ```
@@ -173,7 +248,7 @@ const phone = await getPhoneNumber();
173
248
  **参数**:
174
249
  ```typescript
175
250
  {
176
- /** 跳转目标,填写页面的 pageId,如 'settings' */
251
+ /** 跳转目标,填写 Page 路径,如 '/pages/settings/index' */
177
252
  url: string;
178
253
  }
179
254
  ```
@@ -185,7 +260,7 @@ const phone = await getPhoneNumber();
185
260
  **参数**:
186
261
  ```typescript
187
262
  {
188
- /** 跳转目标,填写页面的 pageId,如 'home' */
263
+ /** 跳转目标,填写 Page 路径,如 '/pages/home/index' */
189
264
  url: string;
190
265
  }
191
266
  ```
@@ -204,9 +279,9 @@ const phone = await getPhoneNumber();
204
279
 
205
280
  **返回值**: Promise
206
281
 
207
- > `close()` 已废弃,公开路由场景请优先使用 `navigateBack()`。
282
+ > 公开路由场景优先使用 `navigateBack()`。
208
283
  >
209
- > 常规页面跳转场景下,`url` 直接使用目标页面的 `pageId`。显式配置时取 `src/app.config.ts` 中对应 page 的 `id`;不配置时取入口目录名,例如 `src/pages/detail/index.tsx` 默认为 `detail`。需要传参时可直接拼接 query string。
284
+ > 常规页面跳转场景下,`url` 使用目标 Page 路径,通常和 `src/pages/<page-name>/index.tsx` 对应,例如 `/pages/detail/index`。需要传参时可直接拼接 query string。
210
285
 
211
286
  ### showToast
212
287
 
@@ -216,7 +291,7 @@ const phone = await getPhoneNumber();
216
291
  /** 提示的内容 */
217
292
  message: string;
218
293
  /** Toast 的类型 */
219
- type?: 'success' | 'error';
294
+ type?: 'default' | 'success' | 'error' | 'warning';
220
295
  /** 图标,通常和 Toast 类型这个选项二选一 */
221
296
  icon?: 'success' | 'error' | 'warn';
222
297
  /** 自定义图标的 URL 或 base64 字符串 */
@@ -226,7 +301,9 @@ const phone = await getPhoneNumber();
226
301
  }
227
302
  ```
228
303
 
229
- **返回值**: 无(空对象)
304
+ **返回值**: `Promise<object>`(无业务字段)
305
+
306
+ 提示文案字段是 `message`;不需要图标时省略 `icon`。
230
307
 
231
308
  ### showModal
232
309
 
@@ -256,35 +333,14 @@ const phone = await getPhoneNumber();
256
333
  }
257
334
  ```
258
335
 
259
- ### setTitleBar
260
-
261
- **参数**:
262
- ```typescript
263
- {
264
- /** 是否隐藏TitleBar。 true: 隐藏, false:显示 */
265
- hideTitleBar?: boolean;
266
- /** 设置TitleBar的样式, light: 返回按钮为黑色,文字为黑色, dark: 返回按钮为黑色,文字为白色 */
267
- mode?: 'light' | 'dark';
268
- /** 标题 */
269
- title?: string;
270
- /** 背景颜色值,有效值为十六进制颜色, 例如 "#ffffff", "#00ffffff" (带透明度) */
271
- backgroundColor?: string;
272
- /** 是否隐藏返回按钮。 true: 隐藏, false:显示 */
273
- hideBackButton?: boolean;
274
- }
275
- ```
276
-
277
- > 注:所有字段留空表示不改变
278
-
279
- **返回值**: 无(空对象)
280
-
281
- ---
282
-
283
336
  ## 网络请求
284
337
 
285
338
  | API | 功能 | 示例 |
286
339
  |-----|------|------|
287
- | `request(options)` | 发起请求 | `request({ url: '/api/data', method: 'GET' })` |
340
+ | `request(options)` | 发起请求 | `request({ url: 'https://api.example.com/data', method: 'GET' })` |
341
+
342
+ `request` 不接受泛型参数,不要写 `request<T>()`。需要业务数据类型时,先接收返回值,再对 `response.data`
343
+ 做类型收窄或断言。
288
344
 
289
345
  ### request
290
346
 
@@ -294,7 +350,7 @@ const phone = await getPhoneNumber();
294
350
  url: string;
295
351
  header?: Record<string, string>;
296
352
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
297
- data?: Record<string, any> | string | ArrayBuffer;
353
+ data?: Record<string, unknown> | string | ArrayBuffer;
298
354
  dataType?: 'json' | 'string';
299
355
  }
300
356
  ```
@@ -316,45 +372,42 @@ const phone = await getPhoneNumber();
316
372
 
317
373
  | API | 功能 | 示例 |
318
374
  |-----|------|------|
319
- | `getLocation(params)` | 获取位置 | `getLocation() → { enable, latitude, longitude }` |
320
- | `getPhoneNumber()` | 获取手机号 | - |
375
+ | `getLocation(params)` | 获取位置 | `getLocation() → { latitude, longitude, timestamp, speed, accuracy }` |
321
376
  | `openApp(params)` | 跳转外部应用 | - |
322
377
 
323
378
  ### getLocation
324
379
 
325
- **参数**:
380
+ 参数包含 `source`、`mode`、`timeoutMs`、`maxCacheMs`。`mode` 为数字枚举:`0` 低功耗、`1` 仅设备、`2`
381
+ 高精度(默认)。返回值中的 `timestamp` 是字符串。
382
+ 连续位置更新需要坐标系时使用 `startLocationUpdate({ type: 'wgs84' | 'gcj02' })`。
326
383
 
327
- **返回值**:
384
+ **参数**:
328
385
  ```typescript
329
386
  {
330
- /**
331
- * 是否有定位功能和权限
332
- */
333
- enable: boolean;
334
- /**
335
- * 纬度
336
- */
337
- latitude?: number;
338
- /**
339
- * 经度
340
- */
341
- longitude?: number;
387
+ /** 调用业务方 */
388
+ source?: string;
389
+ /** 定位模式:0 低功耗、1 仅设备、2 高精度(默认) */
390
+ mode?: number;
391
+ /** 超时时间,单位毫秒,默认 30000 */
392
+ timeoutMs?: number;
393
+ /** 缓存时间,单位毫秒,默认 0 */
394
+ maxCacheMs?: number;
342
395
  }
343
396
  ```
344
397
 
345
- ### getPhoneNumber
346
-
347
- **参数**: 无
348
-
349
398
  **返回值**:
350
399
  ```typescript
351
400
  {
352
- /** List of phone infos; key name follows Android bridge */
353
- phone_info_list: {
354
- phoneNumber: string;
355
- purePhoneNumber: string;
356
- countryCode: number;
357
- }[];
401
+ /** 纬度 */
402
+ latitude: number;
403
+ /** 经度 */
404
+ longitude: number;
405
+ /** 时间戳 */
406
+ timestamp: string;
407
+ /** 行进速度,单位:米/秒 */
408
+ speed: number;
409
+ /** 定位精度,单位:米 */
410
+ accuracy: number;
358
411
  }
359
412
  ```
360
413
 
@@ -402,7 +455,7 @@ const phone = await getPhoneNumber();
402
455
  }
403
456
  ```
404
457
 
405
- **返回值**: 无(空对象)
458
+ **返回值**: 无返回值
406
459
 
407
460
  ### setAdditionalContext
408
461
 
@@ -416,43 +469,7 @@ const phone = await getPhoneNumber();
416
469
  }
417
470
  ```
418
471
 
419
- **返回值**: 无(空对象)
420
-
421
- ---
422
-
423
- ## 悬浮窗
424
-
425
- | API | 功能 | 示例 |
426
- |-----|------|------|
427
- | `closeFloatingWindow()` | 关闭悬浮窗 | `closeFloatingWindow()` |
428
- | `setFloatingWindowVisible(visible)` | 显示/隐藏 | `setFloatingWindowVisible(false)` |
429
-
430
- ### closeFloatingWindow
431
-
432
- **参数**:
433
- ```typescript
434
- {
435
- /** 目标悬浮窗,传空表示当前悬浮窗 */
436
- viewId?: string;
437
- }
438
- ```
439
-
440
- **返回值**: 无(空对象)
441
-
442
- ### setFloatingWindowVisible
443
-
444
- **参数**:
445
- ```typescript
446
- {
447
- /** 目标悬浮窗,传空表示当前悬浮窗 */
448
- viewId?: string;
449
-
450
- /** 是否显示悬浮窗 */
451
- visible: boolean;
452
- }
453
- ```
454
-
455
- **返回值**: 无(空对象)
472
+ **返回值**: `Promise<object>`(无业务字段)
456
473
 
457
474
 
458
475
 
@@ -461,13 +478,14 @@ const phone = await getPhoneNumber();
461
478
 
462
479
  # 常用类型
463
480
 
464
- `src/app.config.ts` 需要配置 `appId` 和 `name`。Page / Widget metadata 使用可选的 `pages`、`widgets` 数组声明:
481
+ `src/app.config.ts` 需要配置 `appId` 和 `name`,`appId` 使用开放平台 `db_xxxxxx` 风格。AI 生成 Page / Widget metadata 时使用
482
+ `pages`、`widgets` 数组写法;entry 写到 `index`,不要省略入口文件名:
465
483
 
466
484
  ```typescript
467
485
  import { defineAppConfig } from '@doubao-apps/kit';
468
486
 
469
487
  export default defineAppConfig({
470
- appId: 'com.example.my-doubao-app',
488
+ appId: 'db_xxxxxx',
471
489
  name: '我的豆包应用',
472
490
  pages: [
473
491
  'pages/home/index',
@@ -509,7 +527,7 @@ export default defineAppConfig({
509
527
  import { defineAppConfig } from '@doubao-apps/kit';
510
528
 
511
529
  export default defineAppConfig({
512
- appId: 'com.doubao.react-lynx-template',
530
+ appId: 'db_xxxxxx',
513
531
  name: 'Doubao Apps SDK Template',
514
532
  description: 'React Lynx 开发模板',
515
533
  keywords: ['react', 'lynx', 'template', 'doubao']
@@ -0,0 +1,136 @@
1
+ # Open API: 基础
2
+
3
+ 账号、授权、宿主基础信息、窗口信息和能力可用性。
4
+
5
+ [返回目录](./README.md) | [返回速查](../open-api.md)
6
+
7
+ ## 速查
8
+
9
+ | API | 说明 |
10
+ | --- | --- |
11
+ | [getAccountInfo](#getaccountinfo) | 异步获取账号信息。 |
12
+ | [getAccountInfoSync](#getaccountinfosync) | 同步获取账号信息。<br><br>同步 API。 |
13
+ | [authorize](#authorize) | 初始化授权。 |
14
+ | [canIUse](#caniuse) | 检测当前宿主是否支持指定 API 或能力。 |
15
+
16
+ ## API 详情
17
+
18
+ <a id="getaccountinfo"></a>
19
+ ### getAccountInfo()
20
+
21
+ 异步获取账号信息。
22
+
23
+ ## 代码示例
24
+
25
+ ```typescript
26
+ import { getAccountInfo } from '@doubao-apps/framework/api';
27
+
28
+ const result = await getAccountInfo();
29
+ console.log(result.miniProgram.appId);
30
+ ```
31
+
32
+ ## 入参
33
+
34
+ 无入参。
35
+
36
+ ## 返回值
37
+
38
+ 返回 `Promise<GetAccountInfoResult>`。
39
+
40
+ |字段名|类型|说明|
41
+ |---|---|---|
42
+ |miniProgram|`DoubaoAppAccountInfo`|豆包 App账号信息|
43
+ |miniProgram.appId|`string`|豆包 App appId|
44
+ |miniProgram.envVersion|`"develop" \| "trial" \| "release"`|豆包 App 运行环境。<br><br>- develop: 开发版<br>- trial: 体验版<br>- release: 正式版|
45
+ |miniProgram.version|`string`|线上豆包 App 版本号。|
46
+ |plugin|`PluginAccountInfo`|插件账号信息(仅在插件中调用时包含)|
47
+ |plugin.appId|`string`|插件 appId|
48
+ |plugin.version|`string`|插件版本号,'a.b.c' 形式|
49
+
50
+ <a id="getaccountinfosync"></a>
51
+ ### getAccountInfoSync()
52
+
53
+ 同步获取账号信息。
54
+
55
+ ## 代码示例
56
+
57
+ ```typescript
58
+ import { getAccountInfoSync } from '@doubao-apps/framework/api';
59
+
60
+ const result = getAccountInfoSync();
61
+ console.log(result.miniProgram.appId, result.miniProgram.envVersion, result.miniProgram.version);
62
+ ```
63
+
64
+ ## 入参
65
+
66
+ 无入参。
67
+
68
+ ## 返回值
69
+
70
+ 返回 `GetAccountInfoResult`。
71
+
72
+ |字段名|类型|说明|
73
+ |---|---|---|
74
+ |miniProgram|`DoubaoAppAccountInfo`|豆包 App账号信息|
75
+ |miniProgram.appId|`string`|豆包 App appId|
76
+ |miniProgram.envVersion|`"develop" \| "trial" \| "release"`|豆包 App 运行环境。<br><br>- develop: 开发版<br>- trial: 体验版<br>- release: 正式版|
77
+ |miniProgram.version|`string`|线上豆包 App 版本号。|
78
+ |plugin|`PluginAccountInfo`|插件账号信息(仅在插件中调用时包含)|
79
+ |plugin.appId|`string`|插件 appId|
80
+ |plugin.version|`string`|插件版本号,'a.b.c' 形式|
81
+
82
+ <a id="authorize"></a>
83
+ ### authorize()
84
+
85
+ 初始化授权
86
+
87
+ ## 代码示例
88
+
89
+ ```typescript
90
+ import { authorize } from '@doubao-apps/framework/api';
91
+
92
+ await authorize({ scope: 'scope.userLocation' });
93
+ ```
94
+
95
+ ## 入参
96
+
97
+ |参数名|类型|必填|说明|
98
+ |---|---|---|---|
99
+ |scope|`Scope`|是|授权范围|
100
+
101
+ **类型说明**
102
+
103
+ - `Scope`: `"scope.userLocation" | "scope.userFuzzyLocation" | "scope.userLocationBackground" | "scope.payment" | "scope.record" | "scope.bluetooth" | "scope.camera" | "scope.addPhoneContact" | "scope.addPhoneCalendar"`
104
+
105
+ ## 返回值
106
+
107
+ Promise 对象,授权成功时会返回授权结果
108
+
109
+ <a id="caniuse"></a>
110
+ ### canIUse()
111
+
112
+ 检测当前宿主是否支持指定 API 或能力。
113
+
114
+ ## 代码示例
115
+
116
+ ```typescript
117
+ import { canIUse } from '@doubao-apps/framework/api';
118
+
119
+ const { result } = await canIUse({ schema: 'doubao.getLocation' });
120
+
121
+ console.log(result);
122
+ ```
123
+
124
+ ## 入参
125
+
126
+ |参数名|类型|必填|说明|
127
+ |---|---|---|---|
128
+ |schema|`string`|是|-|
129
+
130
+ ## 返回值
131
+
132
+ 返回 `Promise<CanIUseResult>`。
133
+
134
+ |字段名|类型|说明|
135
+ |---|---|---|
136
+ |result|`boolean`|-|