@doubao-apps/ai 0.0.26 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/994.js +3 -3
- package/dist/contexts/doubao-apps-dev/.ai/examples/common-patterns.md +600 -0
- package/dist/contexts/doubao-apps-dev/.ai/examples/component-basics.md +509 -0
- package/dist/contexts/doubao-apps-dev/.ai/guides/best-practices.md +571 -0
- package/dist/contexts/doubao-apps-dev/.ai/guides/component-development.md +857 -0
- package/dist/contexts/doubao-apps-dev/.ai/guides/performance-optimization.md +404 -0
- package/dist/contexts/doubao-apps-dev/.ai/guides/system-prompt.md +331 -0
- package/dist/contexts/doubao-apps-dev/.ai/guides/troubleshooting.md +291 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/components-quick-ref.md +103 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/framework-api-quick-ref.md +537 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/01-/345/237/272/347/241/200-/350/264/246/345/217/267-/347/263/273/347/273/237.md +699 -0
- package/dist/{skills/doubao-apps-dev/.ai/reference/open-api/02-storage.md → contexts/doubao-apps-dev/.ai/reference/open-api/02-/345/255/230/345/202/250.md} +13 -21
- package/dist/{skills/doubao-apps-dev/.ai/reference/open-api/03-router.md → contexts/doubao-apps-dev/.ai/reference/open-api/03-/350/267/257/347/224/261.md} +9 -9
- package/dist/{skills/doubao-apps-dev/.ai/reference/open-api/04-ui- → contexts/doubao-apps-dev/.ai/reference/open-api/04-/347/225/214/351/235/242-}/344/272/244/344/272/222.md +12 -12
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/05-/347/225/214/351/235/242-/350/276/223/345/205/245.md +42 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/06-/347/275/221/347/273/234.md +148 -0
- package/dist/{skills/doubao-apps-dev/.ai/reference/open-api/07-media.md → contexts/doubao-apps-dev/.ai/reference/open-api/07-/345/252/222/344/275/223.md} +8 -8
- package/dist/{skills/doubao-apps-dev/.ai/reference/open-api/08-open- → contexts/doubao-apps-dev/.ai/reference/open-api/08-/345/274/200/346/224/276/350/203/275/345/212/233-}/344/270/232/345/212/241/350/203/275/345/212/233.md +83 -14
- package/dist/{skills/doubao-apps-dev/.ai/reference/open-api/09-device-bluetooth.md → contexts/doubao-apps-dev/.ai/reference/open-api/09-/350/256/276/345/244/207-/350/223/235/347/211/231.md} +22 -46
- package/dist/{skills/doubao-apps-dev/.ai/reference/open-api/10-device-wi-fi.md → contexts/doubao-apps-dev/.ai/reference/open-api/10-/350/256/276/345/244/207-wi-fi.md} +9 -9
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/11-/350/256/276/345/244/207-/345/212/240/351/200/237/345/272/246/350/256/241.md +104 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/12-/350/256/276/345/244/207-ibeacon.md +148 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/13-/350/256/276/345/244/207-/347/275/227/347/233/230.md +82 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/14-/350/256/276/345/244/207-/350/256/276/345/244/207/346/226/271/345/220/221.md +70 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/15-/350/256/276/345/244/207-/351/231/200/350/236/272/344/273/252.md +104 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/16-ui-/350/276/223/345/205/245.md +65 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/17-/350/256/276/345/244/207-/347/275/221/347/273/234.md +164 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/18-/350/256/276/345/244/207-/347/237/255/344/277/241.md +62 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/19-/350/256/276/345/244/207-/346/227/240/351/232/234/347/242/215.md +43 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/20-/350/256/276/345/244/207-/347/224/265/346/261/240.md +83 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/21-/350/256/276/345/244/207-/346/227/245/345/216/206.md +215 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/22-/350/256/276/345/244/207-/345/211/252/350/264/264/346/235/277.md +70 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/23-/350/256/276/345/244/207-/350/201/224/347/263/273/344/272/272.md +270 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/24-/350/256/276/345/244/207-/345/212/240/345/257/206.md +56 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/25-/350/256/276/345/244/207-/347/224/265/350/257/235.md +41 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/26-/350/256/276/345/244/207-/346/211/253/347/240/201.md +100 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/27-/350/256/276/345/244/207-/345/261/217/345/271/225.md +173 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/28-/350/256/276/345/244/207-/351/234/207/345/212/250.md +66 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api/README.md +36 -0
- package/dist/contexts/doubao-apps-dev/.ai/reference/open-api.md +326 -0
- package/dist/contexts/doubao-apps-dev/.ai/rules/dos-and-donts.md +390 -0
- package/dist/{skills → contexts}/doubao-apps-dev/AGENTS.md +54 -31
- package/dist/manifest.json +45 -0
- package/dist/skills/doubao-apps-dev/.ai/examples/common-patterns.md +53 -43
- package/dist/skills/doubao-apps-dev/.ai/examples/component-basics.md +0 -17
- package/dist/skills/doubao-apps-dev/.ai/guides/component-development.md +96 -214
- package/dist/skills/doubao-apps-dev/.ai/guides/system-prompt.md +14 -14
- package/dist/skills/doubao-apps-dev/.ai/reference/framework-api-quick-ref.md +46 -85
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/01-/345/237/272/347/241/200-/350/264/246/345/217/267-/347/263/273/347/273/237.md +13 -13
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/02-/345/255/230/345/202/250.md +409 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/03-/350/267/257/347/224/261.md +165 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/04-/347/225/214/351/235/242-/344/272/244/344/272/222.md +432 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/05-/347/225/214/351/235/242-/350/276/223/345/205/245.md +42 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/06-/347/275/221/347/273/234.md +148 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/07-/345/252/222/344/275/223.md +346 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/08-/345/274/200/346/224/276/350/203/275/345/212/233-/344/270/232/345/212/241/350/203/275/345/212/233.md +546 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/09-/350/256/276/345/244/207-/350/223/235/347/211/231.md +961 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/10-/350/256/276/345/244/207-wi-fi.md +277 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/11-/350/256/276/345/244/207-/345/212/240/351/200/237/345/272/246/350/256/241.md +104 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/12-/350/256/276/345/244/207-ibeacon.md +148 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/13-/350/256/276/345/244/207-/347/275/227/347/233/230.md +82 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/14-/350/256/276/345/244/207-/350/256/276/345/244/207/346/226/271/345/220/221.md +70 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/15-/350/256/276/345/244/207-/351/231/200/350/236/272/344/273/252.md +104 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/16-ui-/350/276/223/345/205/245.md +65 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/17-/350/256/276/345/244/207-/347/275/221/347/273/234.md +164 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/18-/350/256/276/345/244/207-/347/237/255/344/277/241.md +62 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/19-/350/256/276/345/244/207-/346/227/240/351/232/234/347/242/215.md +43 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/20-/350/256/276/345/244/207-/347/224/265/346/261/240.md +83 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/21-/350/256/276/345/244/207-/346/227/245/345/216/206.md +215 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/22-/350/256/276/345/244/207-/345/211/252/350/264/264/346/235/277.md +70 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/23-/350/256/276/345/244/207-/350/201/224/347/263/273/344/272/272.md +270 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/24-/350/256/276/345/244/207-/345/212/240/345/257/206.md +56 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/25-/350/256/276/345/244/207-/347/224/265/350/257/235.md +41 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/26-/350/256/276/345/244/207-/346/211/253/347/240/201.md +100 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/27-/350/256/276/345/244/207-/345/261/217/345/271/225.md +173 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/28-/350/256/276/345/244/207-/351/234/207/345/212/250.md +66 -0
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/README.md +27 -11
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api.md +282 -166
- package/dist/skills/doubao-apps-dev/.ai/rules/dos-and-donts.md +50 -37
- package/dist/skills/doubao-apps-dev/SKILL.md +55 -27
- package/dist/skills/douyin-to-doubao/SKILL.md +2 -2
- package/dist/skills/h5-to-doubao/SKILL.md +2 -2
- package/dist/skills/uniapp-to-doubao/SKILL.md +2 -2
- package/dist/skills/weixin-to-doubao/SKILL.md +2 -2
- package/package.json +4 -2
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/05-ui-/350/276/223/345/205/245.md +0 -95
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/06-network.md +0 -298
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/11-device-/344/274/240/346/204/237/345/231/250.md +0 -372
- package/dist/skills/doubao-apps-dev/.ai/reference/open-api/12-device-/346/234/254/345/234/260/350/203/275/345/212/233.md +0 -1005
- /package/dist/{skills → contexts}/doubao-apps-dev/CLAUDE.md +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# 组件库快速参考
|
|
2
|
+
|
|
3
|
+
所有组件均已编译为全局变量,**无需任何 import**,直接像 `<view>`、`<text>` 一样使用小写标签即可。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 组件列表
|
|
8
|
+
|
|
9
|
+
| 组件标签 | 用途 | 关键属性 |
|
|
10
|
+
|---------|------|----------|
|
|
11
|
+
| `<button>` | 按钮交互 | `text`, `type`, `size`, `loading`, `disabled`, `openType`, `onClick` |
|
|
12
|
+
| `<switch>` | 开关切换 | `checked`, `defaultChecked`, `disabled`, `onChange` |
|
|
13
|
+
| `<slider>` | 滑块选择 | `value`(必填), `min`, `max`, `showValue`, `onChange` |
|
|
14
|
+
| `<swiper>` | 轮播容器 | `data`, `itemWidth`, `itemHeight`, `loop`, `duration`, `onChange` |
|
|
15
|
+
| `<swiper-item>` | 轮播项 | `index`, `realIndex` |
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## button 按钮
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
<button
|
|
23
|
+
text="提交"
|
|
24
|
+
type="primary" // primary | default | plain
|
|
25
|
+
size="default" // default | small | large
|
|
26
|
+
loading={false}
|
|
27
|
+
disabled={false}
|
|
28
|
+
icon={<IconNode />}
|
|
29
|
+
throttle={500} // 节流时间(ms)
|
|
30
|
+
onClick={() => {}}
|
|
31
|
+
/>
|
|
32
|
+
|
|
33
|
+
{/* 开放能力 */}
|
|
34
|
+
<button
|
|
35
|
+
openType="getPhoneNumber"
|
|
36
|
+
onGetPhoneNumber={(e) => console.log(e)}
|
|
37
|
+
/>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## switch 开关
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
{/* 非受控 */}
|
|
46
|
+
<switch defaultChecked onChange={(checked) => {}} />
|
|
47
|
+
|
|
48
|
+
{/* 受控 */}
|
|
49
|
+
<switch checked={value} onChange={(checked) => setChecked(checked)} />
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
> `onChange` 回调直接接收 `boolean` 值,而非事件对象。
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## slider 滑块
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
const [value, setValue] = useState(50);
|
|
60
|
+
|
|
61
|
+
<slider
|
|
62
|
+
value={value} // 必填,只支持受控
|
|
63
|
+
min={0}
|
|
64
|
+
max={100}
|
|
65
|
+
showValue={true}
|
|
66
|
+
onChange={(value) => setValue(value)}
|
|
67
|
+
/>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
> `onChange` 回调直接接收 `number` 值,而非事件对象。
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## swiper 轮播
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
<swiper
|
|
78
|
+
data={[{ img: 'url1' }, { img: 'url2' }]}
|
|
79
|
+
itemWidth={300}
|
|
80
|
+
itemHeight={200}
|
|
81
|
+
loop={true}
|
|
82
|
+
duration={500}
|
|
83
|
+
onChange={(index) => console.log(index)}
|
|
84
|
+
>
|
|
85
|
+
{({ item, index }) => (
|
|
86
|
+
<swiper-item index={index} key={index}>
|
|
87
|
+
<image src={item.img} />
|
|
88
|
+
</swiper-item>
|
|
89
|
+
)}
|
|
90
|
+
</swiper>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
> `onChange` 回调直接接收当前 `index: number`,而非事件对象。
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 注意事项
|
|
98
|
+
|
|
99
|
+
1. **无需 import**:所有组件直接使用小写标签,不需要从任何包导入
|
|
100
|
+
2. **onChange 回调签名**:switch/slider/swiper 的 `onChange` 直接接收值(boolean/number/number),不是事件对象
|
|
101
|
+
3. **Lynx 不支持 CSS 继承**:组件样式自包含,不依赖父元素样式
|
|
102
|
+
4. **受控/非受控**:switch 支持两种模式,slider 只支持受控模式
|
|
103
|
+
5. **节流处理**:button 内置 500ms 节流,可通过 `throttle` 自定义
|
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
# Framework API 快速参考
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# 框架 API 列表
|
|
6
|
+
## app 和 视图
|
|
7
|
+
|
|
8
|
+
| API | 用途 | 示例 |
|
|
9
|
+
|-----|------|------|
|
|
10
|
+
| `definePage()` | 定义 Page 组件 | `definePage({ aiMeta: {...}, render() {...} })` |
|
|
11
|
+
| `defineWidget()` | 定义 Widget 组件 | `defineWidget({ aiMeta: {...}, render() {...} })` |
|
|
12
|
+
| `defineApp()` | 定义 App 入口 | `defineApp({ onLaunch() {...} })` |
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Page 生命周期
|
|
17
|
+
|
|
18
|
+
| 钩子 | 触发时机 | 用途 |
|
|
19
|
+
|------|---------|------|
|
|
20
|
+
| `onCreated()` | View 创建时 | 初始化数据结构、注册订阅/监听 |
|
|
21
|
+
| `onMounted()` | 首次渲染后(仅一次) | 首次请求、埋点上报、启动一次性任务 |
|
|
22
|
+
| `onShow()` | 首次显示/再次显示时 | 刷新数据、恢复状态、恢复轮询/订阅 |
|
|
23
|
+
| `onHide()` | 页面隐藏时 | 暂停任务、保存草稿、停止轮询/订阅 |
|
|
24
|
+
| `onDestroy()` | 页面销毁时 | 清理资源、取消订阅、释放计时器 |
|
|
25
|
+
| `onError(e)` | 发生错误时 | 错误兜底、上报监控、提示用户 |
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Widget 生命周期
|
|
30
|
+
|
|
31
|
+
| 钩子 | 触发时机 | 用途 |
|
|
32
|
+
|------|---------|------|
|
|
33
|
+
| `onShow()` | 卡片显示时 | 刷新数据、恢复状态 |
|
|
34
|
+
| `onHide()` | 卡片隐藏时 | 暂停操作、保存草稿 |
|
|
35
|
+
| `onForeground()` | 应用回到前台 | 恢复订阅、刷新可见内容 |
|
|
36
|
+
| `onBackground()` | 应用进入后台 | 暂停任务、释放资源 |
|
|
37
|
+
| `onMounted()` | 卡片首次渲染后 | 初始化数据、订阅事件 |
|
|
38
|
+
| `onDestroy()` | 卡片销毁时 | 清理资源、取消订阅 |
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Hook
|
|
43
|
+
|
|
44
|
+
| Hook | 用途 | 示例 |
|
|
45
|
+
|------|------|------|
|
|
46
|
+
| `useState(initial)` | 状态管理 | `const [count, setCount] = useState(0)` |
|
|
47
|
+
| `useEffect(fn, deps)` | 副作用处理 | `useEffect(() => { fetchData() }, [id])` |
|
|
48
|
+
| `useReducer(reducer, initial)` | 复杂状态 | `const [state, dispatch] = useReducer(reducer, {})` |
|
|
49
|
+
| `useCallback(fn, deps)` | 缓存函数 | `const handleClick = useCallback(() => {...}, [])` |
|
|
50
|
+
| `useMemo(fn, deps)` | 缓存计算 | `const value = useMemo(() => compute(), [data])` |
|
|
51
|
+
| `useContext(Context)` | 跨组件状态 | `const theme = useContext(ThemeContext)` |
|
|
52
|
+
| `createContext(default)` | 创建 Context | `const ThemeContext = createContext('light')` |
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## View Context APIs
|
|
57
|
+
|
|
58
|
+
| API | 用途 | 返回类型 |
|
|
59
|
+
|-----|------|---------|
|
|
60
|
+
| `getViewContext()` | 获取视图上下文信息 | `AIViewContext` |
|
|
61
|
+
| `getViewData<T>()` | 获取视图数据(泛型) | `T` |
|
|
62
|
+
|
|
63
|
+
**使用示例**:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import type { AIViewContext } from '@doubao-apps/framework';
|
|
67
|
+
import { getViewContext, getViewData } from '@doubao-apps/framework';
|
|
68
|
+
|
|
69
|
+
// 获取视图上下文
|
|
70
|
+
const context = getViewContext();
|
|
71
|
+
console.log(context.pageName); // 页面名称
|
|
72
|
+
console.log(context.lang); // 语言设置
|
|
73
|
+
console.log(context.appSettings); // 应用配置
|
|
74
|
+
|
|
75
|
+
// 获取视图数据(类型安全)
|
|
76
|
+
interface MyData {
|
|
77
|
+
title: string;
|
|
78
|
+
count: number;
|
|
79
|
+
}
|
|
80
|
+
const data = getViewData<MyData>();
|
|
81
|
+
console.log(data.title, data.count);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**AIViewContext 类型**:
|
|
85
|
+
```typescript
|
|
86
|
+
import type { AIViewContext } from '@doubao-apps/framework';
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## 存储 Storage
|
|
90
|
+
|
|
91
|
+
引入依赖
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { setStorage, getStorage, removeStorage, clearStorage, getStorageInfo } from '@doubao-apps/framework/api';
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### API 列表
|
|
98
|
+
|
|
99
|
+
| API | 功能 | 示例 |
|
|
100
|
+
|-----|------|------|
|
|
101
|
+
| `setStorage({ key, data })` | 写入本地缓存 | `setStorage({ key: 'profile', data: { name: 'Tom' } })` |
|
|
102
|
+
| `getStorage({ key })` | 读取本地缓存 | `getStorage<T>({ key: 'profile' })` → `{ data: T }` |
|
|
103
|
+
| `removeStorage({ key })` | 删除指定缓存 | `removeStorage({ key: 'profile' })` |
|
|
104
|
+
| `clearStorage()` | 清空所有缓存 | `clearStorage()` |
|
|
105
|
+
| `getStorageInfo()` | 获取缓存信息 | `getStorageInfo()` → `{ keys, currentSize, limitSize }` |
|
|
106
|
+
|
|
107
|
+
### 使用示例
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { setStorage, getStorage, removeStorage, getStorageInfo } from '@doubao-apps/framework/api';
|
|
111
|
+
|
|
112
|
+
// 写入数据
|
|
113
|
+
await setStorage({
|
|
114
|
+
key: 'profile',
|
|
115
|
+
data: { name: 'Tom', age: 18 },
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// 读取数据(支持泛型)
|
|
119
|
+
const result = await getStorage<{ name: string; age: number }>({
|
|
120
|
+
key: 'profile',
|
|
121
|
+
});
|
|
122
|
+
console.log(result.data.name, result.data.age);
|
|
123
|
+
|
|
124
|
+
// 删除数据
|
|
125
|
+
await removeStorage({ key: 'profile' });
|
|
126
|
+
|
|
127
|
+
// 获取缓存信息
|
|
128
|
+
const info = await getStorageInfo();
|
|
129
|
+
console.log(info.keys, info.currentSize, info.limitSize);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
# 端能力(系统能力)API
|
|
133
|
+
|
|
134
|
+
端能力 API 推荐从 `@doubao-apps/framework/api` 引入(运行时调用 + 类型),以 IDE 类型提示为准。
|
|
135
|
+
|
|
136
|
+
## 引入依赖
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { getLocation, getPhoneNumber, navigateTo, navigateBack, request, showToast, setStorage, getStorage } from '@doubao-apps/framework/api';
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## 使用示例
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
await showToast({ message: '保存成功' });
|
|
146
|
+
|
|
147
|
+
await navigateTo({ url: 'detail?id=123' });
|
|
148
|
+
await navigateBack();
|
|
149
|
+
|
|
150
|
+
const res = await request({ url: '/api/data', method: 'GET' });
|
|
151
|
+
|
|
152
|
+
const location = await getLocation();
|
|
153
|
+
const phone = await getPhoneNumber();
|
|
154
|
+
```
|
|
155
|
+
## API 速查(节选)
|
|
156
|
+
|
|
157
|
+
以下为常用端能力 API 的节选,完整以 `@doubao-apps/framework/api` 类型定义为准。
|
|
158
|
+
|
|
159
|
+
### navigateTo
|
|
160
|
+
|
|
161
|
+
**参数**:
|
|
162
|
+
```typescript
|
|
163
|
+
{
|
|
164
|
+
/** 跳转目标,填写页面的 pageId,可拼接 query,如 'detail?id=123' */
|
|
165
|
+
url: string;
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**返回值**: Promise
|
|
170
|
+
|
|
171
|
+
### redirectTo
|
|
172
|
+
|
|
173
|
+
**参数**:
|
|
174
|
+
```typescript
|
|
175
|
+
{
|
|
176
|
+
/** 跳转目标,填写页面的 pageId,如 'settings' */
|
|
177
|
+
url: string;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**返回值**: Promise
|
|
182
|
+
|
|
183
|
+
### reLaunch
|
|
184
|
+
|
|
185
|
+
**参数**:
|
|
186
|
+
```typescript
|
|
187
|
+
{
|
|
188
|
+
/** 跳转目标,填写页面的 pageId,如 'home' */
|
|
189
|
+
url: string;
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**返回值**: Promise
|
|
194
|
+
|
|
195
|
+
### navigateBack
|
|
196
|
+
|
|
197
|
+
**参数**:
|
|
198
|
+
```typescript
|
|
199
|
+
{
|
|
200
|
+
/** 返回的页面数,默认为 1 */
|
|
201
|
+
delta?: number;
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**返回值**: Promise
|
|
206
|
+
|
|
207
|
+
> `close()` 已废弃,公开路由场景请优先使用 `navigateBack()`。
|
|
208
|
+
>
|
|
209
|
+
> 常规页面跳转场景下,`url` 直接使用目标页面的 `pageId`,该值一般与页面的 `aiMeta.id` 一致;需要传参时可直接拼接 query string。
|
|
210
|
+
|
|
211
|
+
### showToast
|
|
212
|
+
|
|
213
|
+
**参数**:
|
|
214
|
+
```typescript
|
|
215
|
+
{
|
|
216
|
+
/** 提示的内容 */
|
|
217
|
+
message: string;
|
|
218
|
+
/** Toast 的类型 */
|
|
219
|
+
type?: 'success' | 'error';
|
|
220
|
+
/** 图标,通常和 Toast 类型这个选项二选一 */
|
|
221
|
+
icon?: 'success' | 'error' | 'warn';
|
|
222
|
+
/** 自定义图标的 URL 或 base64 字符串 */
|
|
223
|
+
customIcon?: string;
|
|
224
|
+
/** 提示的延迟时间,单位毫秒 */
|
|
225
|
+
duration?: number;
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**返回值**: 无(空对象)
|
|
230
|
+
|
|
231
|
+
### showModal
|
|
232
|
+
|
|
233
|
+
**参数**:
|
|
234
|
+
```typescript
|
|
235
|
+
{
|
|
236
|
+
/** 模态对话框的标题 */
|
|
237
|
+
title?: string;
|
|
238
|
+
/** 模态对话框的内容 */
|
|
239
|
+
content: string;
|
|
240
|
+
/** 是否显示取消按钮,默认为 true */
|
|
241
|
+
showCancel?: boolean;
|
|
242
|
+
/** 取消按钮的文字,默认为“取消” */
|
|
243
|
+
cancelText?: string;
|
|
244
|
+
/** 确认按钮的文字,默认为“确定” */
|
|
245
|
+
confirmText?: string;
|
|
246
|
+
/** 是否允许点击蒙层关闭对话框,默认为 false */
|
|
247
|
+
tapMaskToDismiss?: boolean;
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**返回值**:
|
|
252
|
+
```typescript
|
|
253
|
+
{
|
|
254
|
+
/** 用户点击的行为:'confirm' 表示点击确认按钮,'cancel' 表示点击取消按钮,'mask' 表示点击蒙层 */
|
|
255
|
+
action: 'confirm' | 'cancel' | 'mask';
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
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
|
+
## 网络请求
|
|
284
|
+
|
|
285
|
+
| API | 功能 | 示例 |
|
|
286
|
+
|-----|------|------|
|
|
287
|
+
| `request(options)` | 发起请求 | `request({ url: '/api/data', method: 'GET' })` |
|
|
288
|
+
|
|
289
|
+
### request
|
|
290
|
+
|
|
291
|
+
**参数**:
|
|
292
|
+
```typescript
|
|
293
|
+
{
|
|
294
|
+
url: string;
|
|
295
|
+
header?: Record<string, string>;
|
|
296
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
297
|
+
data?: Record<string, any> | string | ArrayBuffer;
|
|
298
|
+
dataType?: 'json' | 'string';
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
> 注:`data` 会根据 `header['content-type']` 自动序列化(`application/json` 会做 JSON 序列化;`application/x-www-form-urlencoded` 会编码为 query string)。
|
|
303
|
+
|
|
304
|
+
**返回值**:
|
|
305
|
+
```typescript
|
|
306
|
+
{
|
|
307
|
+
statusCode: number;
|
|
308
|
+
header: Record<string, string>;
|
|
309
|
+
data?: string | ArrayBuffer | Record<string, any>;
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## 系统能力
|
|
316
|
+
|
|
317
|
+
| API | 功能 | 示例 |
|
|
318
|
+
|-----|------|------|
|
|
319
|
+
| `getLocation(params)` | 获取位置 | `getLocation() → { enable, latitude, longitude }` |
|
|
320
|
+
| `getPhoneNumber()` | 获取手机号 | - |
|
|
321
|
+
| `openApp(params)` | 跳转外部应用 | - |
|
|
322
|
+
|
|
323
|
+
### getLocation
|
|
324
|
+
|
|
325
|
+
**参数**: 无
|
|
326
|
+
|
|
327
|
+
**返回值**:
|
|
328
|
+
```typescript
|
|
329
|
+
{
|
|
330
|
+
/**
|
|
331
|
+
* 是否有定位功能和权限
|
|
332
|
+
*/
|
|
333
|
+
enable: boolean;
|
|
334
|
+
/**
|
|
335
|
+
* 纬度
|
|
336
|
+
*/
|
|
337
|
+
latitude?: number;
|
|
338
|
+
/**
|
|
339
|
+
* 经度
|
|
340
|
+
*/
|
|
341
|
+
longitude?: number;
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### getPhoneNumber
|
|
346
|
+
|
|
347
|
+
**参数**: 无
|
|
348
|
+
|
|
349
|
+
**返回值**:
|
|
350
|
+
```typescript
|
|
351
|
+
{
|
|
352
|
+
/** List of phone infos; key name follows Android bridge */
|
|
353
|
+
phone_info_list: {
|
|
354
|
+
phoneNumber: string;
|
|
355
|
+
purePhoneNumber: string;
|
|
356
|
+
countryCode: number;
|
|
357
|
+
}[];
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### openApp
|
|
362
|
+
|
|
363
|
+
**参数**:
|
|
364
|
+
```typescript
|
|
365
|
+
{
|
|
366
|
+
/** Target URI to open, e.g. scheme://path?query */
|
|
367
|
+
uri: string;
|
|
368
|
+
/** Optional target package name for Android */
|
|
369
|
+
targetPackage?: string;
|
|
370
|
+
/** Optional fallback URL when deep link fails */
|
|
371
|
+
fallbackUrl?: string;
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
**返回值**:
|
|
376
|
+
```typescript
|
|
377
|
+
{
|
|
378
|
+
/** Execution status from client */
|
|
379
|
+
status: 'deep_link' | 'market' | 'browser';
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
## 消息交互
|
|
386
|
+
|
|
387
|
+
| API | 功能 | 示例 |
|
|
388
|
+
|-----|------|------|
|
|
389
|
+
| `sendQueryMessage(params)` | 发送用户消息 | `sendQueryMessage({ content: '查询天气', type: 'text' })` |
|
|
390
|
+
| `setAdditionalContext(params)` | 设置上下文 | `setAdditionalContext({ additionalContext: '...' })` |
|
|
391
|
+
|
|
392
|
+
### sendQueryMessage
|
|
393
|
+
|
|
394
|
+
**参数**:
|
|
395
|
+
```typescript
|
|
396
|
+
{
|
|
397
|
+
/** 要发送的消息。根据类型不同,序列化方式可能不同 */
|
|
398
|
+
content: string;
|
|
399
|
+
|
|
400
|
+
/** 消息类型,目前仅支持 text */
|
|
401
|
+
type: 'text';
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
**返回值**: 无(空对象)
|
|
406
|
+
|
|
407
|
+
### setAdditionalContext
|
|
408
|
+
|
|
409
|
+
**参数**:
|
|
410
|
+
```typescript
|
|
411
|
+
{
|
|
412
|
+
/** 上下文内容 */
|
|
413
|
+
additionalContext: string;
|
|
414
|
+
/** 指定 bot id */
|
|
415
|
+
botId?: string;
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
|
|
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
|
+
**返回值**: 无(空对象)
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
---
|
|
461
|
+
|
|
462
|
+
# 常用类型
|
|
463
|
+
|
|
464
|
+
```typescript
|
|
465
|
+
// Page Input
|
|
466
|
+
interface PageInput {
|
|
467
|
+
[key: string]: any; // URL 参数
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/app.config.ts 中的 metadata 配置
|
|
471
|
+
interface PageAIMeta {
|
|
472
|
+
id: string; // 页面唯一标识
|
|
473
|
+
title?: string; // 页面标题
|
|
474
|
+
description?: string; // 页面描述
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
interface WidgetAIMeta {
|
|
478
|
+
id: string; // 卡片唯一标识
|
|
479
|
+
name?: string; // 卡片名称
|
|
480
|
+
description?: string; // 卡片描述
|
|
481
|
+
boxType?: 'inbox' | 'full_box'; // 卡片类型
|
|
482
|
+
border?: boolean; // 是否显示边框
|
|
483
|
+
keywords?: string[]; // 搜索关键词
|
|
484
|
+
titleType?: 'none' | 'normal' | 'float';
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// Widget 渲染数据类型
|
|
488
|
+
interface WidgetViewData {
|
|
489
|
+
title: string;
|
|
490
|
+
content?: string;
|
|
491
|
+
}
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
---
|
|
495
|
+
|
|
496
|
+
# 快速示例
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
## 最小 App
|
|
500
|
+
|
|
501
|
+
```tsx
|
|
502
|
+
import { defineApp } from "@doubao-apps/framework";
|
|
503
|
+
|
|
504
|
+
// Define AI Metadata
|
|
505
|
+
export default defineApp({
|
|
506
|
+
aiMeta: {
|
|
507
|
+
package: "com.doubao.react-lynx-template",
|
|
508
|
+
name: "Doubao Apps SDK Template",
|
|
509
|
+
description: "React Lynx 开发模板",
|
|
510
|
+
keywords: ["react", "lynx", "template", "doubao"],
|
|
511
|
+
},
|
|
512
|
+
onLaunch() {
|
|
513
|
+
console.log("App launched");
|
|
514
|
+
},
|
|
515
|
+
|
|
516
|
+
onPageOpened({ viewId }: { viewId: string }) {
|
|
517
|
+
console.log("On page opened: ", viewId);
|
|
518
|
+
},
|
|
519
|
+
|
|
520
|
+
onForeground() {
|
|
521
|
+
console.log("On foreground");
|
|
522
|
+
},
|
|
523
|
+
|
|
524
|
+
onBackground() {
|
|
525
|
+
console.log("On background");
|
|
526
|
+
},
|
|
527
|
+
|
|
528
|
+
onDestroy() {
|
|
529
|
+
console.log("On destroyed");
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
|
|
537
|
+
**详细指南**: `../guides/component-development.md`
|