@doubao-apps/create 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.
- package/dist/421.js +4 -4
- package/dist/cli.js +74 -66
- package/dist/index.d.ts +1 -2
- package/dist/template-empty/README.md +1 -1
- package/dist/template-empty/package.json +2 -2
- package/dist/template-starter/README.md +48 -169
- package/dist/template-starter/package.json +2 -2
- package/dist/template-starter/src/app.config.ts +2 -3
- package/dist/template-starter/src/pages/home/index.scss +38 -172
- package/dist/template-starter/src/pages/home/index.tsx +20 -78
- package/dist/template-starter/src/widgets/hello-world/index.scss +23 -0
- package/dist/template-starter/src/widgets/hello-world/index.tsx +29 -0
- package/package.json +6 -2
- package/dist/template-empty/AGENTS.md +0 -299
- package/dist/template-empty/references/examples/common-patterns.md +0 -589
- package/dist/template-empty/references/examples/component-basics.md +0 -526
- package/dist/template-empty/references/guides/best-practices.md +0 -571
- package/dist/template-empty/references/guides/component-development.md +0 -891
- package/dist/template-empty/references/guides/performance-optimization.md +0 -402
- package/dist/template-empty/references/guides/troubleshooting.md +0 -287
- package/dist/template-empty/references/reference/components-quick-ref.md +0 -103
- package/dist/template-empty/references/reference/framework-api-quick-ref.md +0 -550
- package/dist/template-empty/references/reference/open-api/README.md +0 -8
- package/dist/template-empty/references/reference/open-api.md +0 -11
- package/dist/template-empty/references/rules/dos-and-donts.md +0 -467
- package/dist/template-starter/AGENTS.md +0 -299
- package/dist/template-starter/debug-scene/render-home-page-full.json +0 -6
- package/dist/template-starter/debug-scene/render-home-page.json +0 -5
- package/dist/template-starter/debug-scene/render-react-lynx-page-full.json +0 -6
- package/dist/template-starter/references/examples/common-patterns.md +0 -589
- package/dist/template-starter/references/examples/component-basics.md +0 -526
- package/dist/template-starter/references/guides/best-practices.md +0 -571
- package/dist/template-starter/references/guides/component-development.md +0 -891
- package/dist/template-starter/references/guides/performance-optimization.md +0 -402
- package/dist/template-starter/references/guides/troubleshooting.md +0 -287
- package/dist/template-starter/references/reference/components-quick-ref.md +0 -103
- package/dist/template-starter/references/reference/framework-api-quick-ref.md +0 -550
- package/dist/template-starter/references/reference/open-api/README.md +0 -8
- package/dist/template-starter/references/reference/open-api.md +0 -11
- package/dist/template-starter/references/rules/dos-and-donts.md +0 -467
- package/dist/template-starter/src/pages/applet/index.scss +0 -279
- package/dist/template-starter/src/pages/applet/index.tsx +0 -78
- package/dist/template-starter/src/pages/lynx/index.scss +0 -249
- package/dist/template-starter/src/pages/lynx/index.tsx +0 -78
- package/dist/template-starter/src/pages/react-lynx/index.scss +0 -335
- package/dist/template-starter/src/pages/react-lynx/index.tsx +0 -132
- package/dist/template-starter/src/widgets/weather-card/index.scss +0 -272
- package/dist/template-starter/src/widgets/weather-card/index.tsx +0 -193
|
@@ -1,103 +0,0 @@
|
|
|
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` 自定义
|
|
@@ -1,550 +0,0 @@
|
|
|
1
|
-
# Framework API 快速参考
|
|
2
|
-
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# 框架 API 列表
|
|
6
|
-
## app 和 视图
|
|
7
|
-
|
|
8
|
-
| API | 用途 | 示例 |
|
|
9
|
-
|-----|------|------|
|
|
10
|
-
| `definePage()` | 定义 Page 组件 | `definePage({ render() {...} })` |
|
|
11
|
-
| `defineWidget()` | 定义 Widget 组件 | `defineWidget({ 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 viewData = getViewData<MyData>();
|
|
81
|
-
console.log(viewData.title, viewData.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`。显式配置时取 `src/app.config.ts` 中对应 page 的 `id`;不配置时取入口目录名,例如 `src/pages/detail/index.tsx` 默认为 `detail`。需要传参时可直接拼接 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
|
-
`src/app.config.ts` 需要配置 `appId` 和 `name`。Page / Widget metadata 使用可选的 `pages`、`widgets` 数组声明:
|
|
465
|
-
|
|
466
|
-
```typescript
|
|
467
|
-
import { defineAppConfig } from '@doubao-apps/kit';
|
|
468
|
-
|
|
469
|
-
export default defineAppConfig({
|
|
470
|
-
appId: 'com.example.my-doubao-app',
|
|
471
|
-
name: '我的豆包应用',
|
|
472
|
-
pages: [
|
|
473
|
-
'pages/home/index',
|
|
474
|
-
{
|
|
475
|
-
entry: 'pages/account/demo/index',
|
|
476
|
-
id: 'account-demo',
|
|
477
|
-
title: '账号示例页',
|
|
478
|
-
description: '多级目录页面示例'
|
|
479
|
-
}
|
|
480
|
-
],
|
|
481
|
-
widgets: [
|
|
482
|
-
'widgets/user-card/index',
|
|
483
|
-
{
|
|
484
|
-
entry: 'widgets/order/detail/index',
|
|
485
|
-
id: 'order-detail',
|
|
486
|
-
name: '订单详情卡片',
|
|
487
|
-
description: '多级目录卡片示例',
|
|
488
|
-
boxType: 'inbox',
|
|
489
|
-
border: true,
|
|
490
|
-
keywords: ['order'],
|
|
491
|
-
titleType: 'normal'
|
|
492
|
-
}
|
|
493
|
-
]
|
|
494
|
-
});
|
|
495
|
-
```
|
|
496
|
-
|
|
497
|
-
字符串数组项只声明入口,不补 metadata;对象数组项用于同时声明入口和 metadata。
|
|
498
|
-
|
|
499
|
-
---
|
|
500
|
-
|
|
501
|
-
# 快速示例
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
## 最小 App
|
|
505
|
-
|
|
506
|
-
### src/app.config.ts
|
|
507
|
-
|
|
508
|
-
```ts
|
|
509
|
-
import { defineAppConfig } from '@doubao-apps/kit';
|
|
510
|
-
|
|
511
|
-
export default defineAppConfig({
|
|
512
|
-
appId: 'com.doubao.react-lynx-template',
|
|
513
|
-
name: 'Doubao Apps SDK Template',
|
|
514
|
-
description: 'React Lynx 开发模板',
|
|
515
|
-
keywords: ['react', 'lynx', 'template', 'doubao']
|
|
516
|
-
});
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
### src/app.ts
|
|
520
|
-
|
|
521
|
-
```tsx
|
|
522
|
-
import { defineApp } from "@doubao-apps/framework";
|
|
523
|
-
|
|
524
|
-
export default defineApp({
|
|
525
|
-
onLaunch() {
|
|
526
|
-
console.log("App launched");
|
|
527
|
-
},
|
|
528
|
-
|
|
529
|
-
onPageOpened({ viewId }: { viewId: string }) {
|
|
530
|
-
console.log("On page opened: ", viewId);
|
|
531
|
-
},
|
|
532
|
-
|
|
533
|
-
onForeground() {
|
|
534
|
-
console.log("On foreground");
|
|
535
|
-
},
|
|
536
|
-
|
|
537
|
-
onBackground() {
|
|
538
|
-
console.log("On background");
|
|
539
|
-
},
|
|
540
|
-
|
|
541
|
-
onDestroy() {
|
|
542
|
-
console.log("On destroyed");
|
|
543
|
-
},
|
|
544
|
-
});
|
|
545
|
-
```
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
---
|
|
549
|
-
|
|
550
|
-
**详细指南**: `../guides/component-development.md`
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# Open API
|
|
2
|
-
|
|
3
|
-
> 公开可用的端能力 API。默认从 `@doubao-apps/framework/api` 导入;本文件根据 `packages/open-api/src` 的导出结构自动生成,按模块列出 API 名称和说明。
|
|
4
|
-
|
|
5
|
-
覆盖 0 个函数。详细参数、返回值、示例和相关类型请查看 [Open API 目录](open-api/README.md),精确字段也可按参数/结果类型名查看 IDE 类型提示或 `@doubao-apps/framework/api` 类型定义。
|
|
6
|
-
|
|
7
|
-
## 使用方式
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
import { showToast, request, getStorage } from '@doubao-apps/framework/api';
|
|
11
|
-
```
|