@doubao-apps/create 0.0.25 → 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/dist/36.js +4 -4
- package/dist/template-empty/.ai/examples/common-patterns.md +53 -43
- package/dist/template-empty/.ai/examples/component-basics.md +0 -17
- package/dist/template-empty/.ai/guides/component-development.md +96 -214
- package/dist/template-empty/.ai/guides/system-prompt.md +14 -14
- package/dist/template-empty/.ai/reference/framework-api-quick-ref.md +46 -85
- package/dist/template-empty/.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/template-empty/.ai/reference/open-api/02-/345/255/230/345/202/250.md +409 -0
- package/dist/template-empty/.ai/reference/open-api/03-/350/267/257/347/224/261.md +165 -0
- package/dist/template-empty/.ai/reference/open-api/04-/347/225/214/351/235/242-/344/272/244/344/272/222.md +432 -0
- package/dist/template-empty/.ai/reference/open-api/05-/347/225/214/351/235/242-/350/276/223/345/205/245.md +42 -0
- package/dist/template-empty/.ai/reference/open-api/06-/347/275/221/347/273/234.md +148 -0
- package/dist/template-empty/.ai/reference/open-api/07-/345/252/222/344/275/223.md +346 -0
- package/dist/template-empty/.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/template-empty/.ai/reference/open-api/09-/350/256/276/345/244/207-/350/223/235/347/211/231.md +961 -0
- package/dist/template-empty/.ai/reference/open-api/10-/350/256/276/345/244/207-wi-fi.md +277 -0
- package/dist/template-empty/.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/template-empty/.ai/reference/open-api/12-/350/256/276/345/244/207-ibeacon.md +148 -0
- package/dist/template-empty/.ai/reference/open-api/13-/350/256/276/345/244/207-/347/275/227/347/233/230.md +82 -0
- package/dist/template-empty/.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/template-empty/.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/template-empty/.ai/reference/open-api/16-ui-/350/276/223/345/205/245.md +65 -0
- package/dist/template-empty/.ai/reference/open-api/17-/350/256/276/345/244/207-/347/275/221/347/273/234.md +164 -0
- package/dist/template-empty/.ai/reference/open-api/18-/350/256/276/345/244/207-/347/237/255/344/277/241.md +62 -0
- package/dist/template-empty/.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/template-empty/.ai/reference/open-api/20-/350/256/276/345/244/207-/347/224/265/346/261/240.md +83 -0
- package/dist/template-empty/.ai/reference/open-api/21-/350/256/276/345/244/207-/346/227/245/345/216/206.md +215 -0
- package/dist/template-empty/.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/template-empty/.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/template-empty/.ai/reference/open-api/24-/350/256/276/345/244/207-/345/212/240/345/257/206.md +56 -0
- package/dist/template-empty/.ai/reference/open-api/25-/350/256/276/345/244/207-/347/224/265/350/257/235.md +41 -0
- package/dist/template-empty/.ai/reference/open-api/26-/350/256/276/345/244/207-/346/211/253/347/240/201.md +100 -0
- package/dist/template-empty/.ai/reference/open-api/27-/350/256/276/345/244/207-/345/261/217/345/271/225.md +173 -0
- package/dist/template-empty/.ai/reference/open-api/28-/350/256/276/345/244/207-/351/234/207/345/212/250.md +66 -0
- package/dist/template-empty/.ai/reference/open-api/README.md +36 -0
- package/dist/template-empty/.ai/reference/open-api.md +1758 -266
- package/dist/template-empty/.ai/rules/dos-and-donts.md +50 -37
- package/dist/template-empty/AGENTS.md +56 -33
- package/dist/template-empty/README.md +57 -10
- package/dist/template-empty/package.json +2 -2
- package/dist/template-empty/src/app.config.ts +6 -0
- package/dist/template-empty/src/app.ts +0 -6
- package/dist/template-empty/tsconfig.json +2 -0
- package/dist/template-starter/.ai/examples/common-patterns.md +53 -43
- package/dist/template-starter/.ai/examples/component-basics.md +0 -17
- package/dist/template-starter/.ai/guides/component-development.md +96 -214
- package/dist/template-starter/.ai/guides/system-prompt.md +14 -14
- package/dist/template-starter/.ai/reference/framework-api-quick-ref.md +46 -85
- package/dist/template-starter/.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/template-starter/.ai/reference/open-api/02-/345/255/230/345/202/250.md +409 -0
- package/dist/template-starter/.ai/reference/open-api/03-/350/267/257/347/224/261.md +165 -0
- package/dist/template-starter/.ai/reference/open-api/04-/347/225/214/351/235/242-/344/272/244/344/272/222.md +432 -0
- package/dist/template-starter/.ai/reference/open-api/05-/347/225/214/351/235/242-/350/276/223/345/205/245.md +42 -0
- package/dist/template-starter/.ai/reference/open-api/06-/347/275/221/347/273/234.md +148 -0
- package/dist/template-starter/.ai/reference/open-api/07-/345/252/222/344/275/223.md +346 -0
- package/dist/template-starter/.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/template-starter/.ai/reference/open-api/09-/350/256/276/345/244/207-/350/223/235/347/211/231.md +961 -0
- package/dist/template-starter/.ai/reference/open-api/10-/350/256/276/345/244/207-wi-fi.md +277 -0
- package/dist/template-starter/.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/template-starter/.ai/reference/open-api/12-/350/256/276/345/244/207-ibeacon.md +148 -0
- package/dist/template-starter/.ai/reference/open-api/13-/350/256/276/345/244/207-/347/275/227/347/233/230.md +82 -0
- package/dist/template-starter/.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/template-starter/.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/template-starter/.ai/reference/open-api/16-ui-/350/276/223/345/205/245.md +65 -0
- package/dist/template-starter/.ai/reference/open-api/17-/350/256/276/345/244/207-/347/275/221/347/273/234.md +164 -0
- package/dist/template-starter/.ai/reference/open-api/18-/350/256/276/345/244/207-/347/237/255/344/277/241.md +62 -0
- package/dist/template-starter/.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/template-starter/.ai/reference/open-api/20-/350/256/276/345/244/207-/347/224/265/346/261/240.md +83 -0
- package/dist/template-starter/.ai/reference/open-api/21-/350/256/276/345/244/207-/346/227/245/345/216/206.md +215 -0
- package/dist/template-starter/.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/template-starter/.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/template-starter/.ai/reference/open-api/24-/350/256/276/345/244/207-/345/212/240/345/257/206.md +56 -0
- package/dist/template-starter/.ai/reference/open-api/25-/350/256/276/345/244/207-/347/224/265/350/257/235.md +41 -0
- package/dist/template-starter/.ai/reference/open-api/26-/350/256/276/345/244/207-/346/211/253/347/240/201.md +100 -0
- package/dist/template-starter/.ai/reference/open-api/27-/350/256/276/345/244/207-/345/261/217/345/271/225.md +173 -0
- package/dist/template-starter/.ai/reference/open-api/28-/350/256/276/345/244/207-/351/234/207/345/212/250.md +66 -0
- package/dist/template-starter/.ai/reference/open-api/README.md +36 -0
- package/dist/template-starter/.ai/reference/open-api.md +1758 -266
- package/dist/template-starter/.ai/rules/dos-and-donts.md +50 -37
- package/dist/template-starter/AGENTS.md +56 -33
- package/dist/template-starter/README.md +6 -1
- package/dist/template-starter/package.json +2 -2
- package/dist/template-starter/src/app.config.ts +35 -0
- package/dist/template-starter/src/app.ts +0 -6
- package/dist/template-starter/src/pages/applet/index.tsx +0 -5
- package/dist/template-starter/src/pages/home/index.tsx +0 -5
- package/dist/template-starter/src/pages/lynx/index.tsx +0 -4
- package/dist/template-starter/src/pages/react-lynx/index.tsx +0 -5
- package/dist/template-starter/src/widgets/weather-card/index.tsx +0 -4
- package/dist/template-starter/tsconfig.json +2 -0
- package/package.json +1 -1
|
@@ -124,45 +124,31 @@ export default definePage({
|
|
|
124
124
|
});
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
-
###
|
|
127
|
+
### 页面导航
|
|
128
128
|
|
|
129
129
|
```tsx
|
|
130
|
-
import {
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
mode: 'full', // 或省略此参数,默认为 'full'
|
|
136
|
-
pageData: JSON.stringify({ userId: '123' }),
|
|
137
|
-
context: {},
|
|
138
|
-
pageSettings: {
|
|
139
|
-
title: '页面标题'
|
|
140
|
-
}
|
|
130
|
+
import { navigateTo, redirectTo, reLaunch } from '@doubao-apps/framework/api';
|
|
131
|
+
|
|
132
|
+
// 保留当前页面,打开新页面
|
|
133
|
+
navigateTo({
|
|
134
|
+
url: 'user-detail?userId=123&tab=profile'
|
|
141
135
|
});
|
|
142
136
|
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
mode: 'popup',
|
|
147
|
-
context: {},
|
|
148
|
-
pageSettings: {
|
|
149
|
-
title: '设置',
|
|
150
|
-
heightPercent: 60 // 高度百分比
|
|
151
|
-
}
|
|
137
|
+
// 替换当前页面
|
|
138
|
+
redirectTo({
|
|
139
|
+
url: 'settings'
|
|
152
140
|
});
|
|
153
141
|
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
mode: 'floating',
|
|
158
|
-
context: {},
|
|
159
|
-
pageSettings: {
|
|
160
|
-
width: 300,
|
|
161
|
-
height: 200
|
|
162
|
-
}
|
|
142
|
+
// 关闭所有页面并回到首页
|
|
143
|
+
reLaunch({
|
|
144
|
+
url: 'home'
|
|
163
145
|
});
|
|
164
146
|
```
|
|
165
147
|
|
|
148
|
+
`url` 在常规页面跳转里填写页面的 `pageId`,与该页面的 `aiMeta.id` 一致;需要传参时可直接在后面拼接 query string。
|
|
149
|
+
|
|
150
|
+
页面内可继续通过 `getViewData<PageInput>()` 读取 URL 中传入的参数。
|
|
151
|
+
|
|
166
152
|
### 常用模式
|
|
167
153
|
|
|
168
154
|
**1. 数据加载**
|
|
@@ -207,7 +193,7 @@ function MyPage({ userId }: { userId: string }) {
|
|
|
207
193
|
|
|
208
194
|
```tsx
|
|
209
195
|
import { useState } from '@doubao-apps/framework';
|
|
210
|
-
import {
|
|
196
|
+
import { navigateBack, request, showToast } from '@doubao-apps/framework/api';
|
|
211
197
|
|
|
212
198
|
function FormPage() {
|
|
213
199
|
const [formData, setFormData] = useState({
|
|
@@ -225,7 +211,7 @@ function FormPage() {
|
|
|
225
211
|
data: formData
|
|
226
212
|
});
|
|
227
213
|
showToast({ message: '提交成功' });
|
|
228
|
-
|
|
214
|
+
navigateBack(); // 返回上一页
|
|
229
215
|
} catch (err) {
|
|
230
216
|
showToast({ message: '提交失败' });
|
|
231
217
|
} finally {
|
|
@@ -257,40 +243,38 @@ function FormPage() {
|
|
|
257
243
|
|
|
258
244
|
## 🎴 Widget 开发指南
|
|
259
245
|
|
|
246
|
+
### Metadata 配置
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
import { defineAppConfig } from '@doubao-apps/kit';
|
|
250
|
+
|
|
251
|
+
export default defineAppConfig({
|
|
252
|
+
widgets: {
|
|
253
|
+
'widgets/my-widget': {
|
|
254
|
+
id: 'my-widget', // 卡片唯一标识
|
|
255
|
+
name: '我的卡片', // 卡片名称
|
|
256
|
+
description: '卡片功能描述', // 卡片描述
|
|
257
|
+
boxType: 'inbox', // 卡片类型: inbox | full_box
|
|
258
|
+
border: true,
|
|
259
|
+
keywords: ['demo', 'widget'],
|
|
260
|
+
titleType: 'normal'
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
260
266
|
### 基本结构
|
|
261
267
|
|
|
262
268
|
```tsx
|
|
263
|
-
import { defineWidget, getViewData
|
|
269
|
+
import { defineWidget, getViewData } from '@doubao-apps/framework';
|
|
264
270
|
import './index.scss';
|
|
265
271
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
name: '我的卡片', // 卡片名称
|
|
271
|
-
description: '卡片功能描述', // 卡片描述
|
|
272
|
-
boxType: 'inbox', // 卡片类型: inbox | full_box
|
|
273
|
-
|
|
274
|
-
// 2. 输入数据 Schema(JSON Schema 格式)
|
|
275
|
-
input: {
|
|
276
|
-
type: 'object',
|
|
277
|
-
properties: {
|
|
278
|
-
title: {
|
|
279
|
-
type: 'string',
|
|
280
|
-
title: '标题',
|
|
281
|
-
description: '卡片标题文本'
|
|
282
|
-
},
|
|
283
|
-
content: {
|
|
284
|
-
type: 'string',
|
|
285
|
-
title: '内容',
|
|
286
|
-
description: '卡片内容文本'
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
required: ['title'] // 必填字段
|
|
290
|
-
}
|
|
291
|
-
},
|
|
272
|
+
interface MyWidgetData {
|
|
273
|
+
title: string;
|
|
274
|
+
content?: string;
|
|
275
|
+
}
|
|
292
276
|
|
|
293
|
-
|
|
277
|
+
export default defineWidget({
|
|
294
278
|
onShow() {
|
|
295
279
|
console.log('卡片显示');
|
|
296
280
|
},
|
|
@@ -316,10 +300,8 @@ export default defineWidget({
|
|
|
316
300
|
console.log('卡片销毁');
|
|
317
301
|
},
|
|
318
302
|
|
|
319
|
-
// 4. 渲染函数
|
|
320
303
|
render() {
|
|
321
|
-
const input = getViewData();
|
|
322
|
-
|
|
304
|
+
const input = getViewData<MyWidgetData>();
|
|
323
305
|
return <MyWidgetComponent {...input} />;
|
|
324
306
|
}
|
|
325
307
|
});
|
|
@@ -336,23 +318,26 @@ export default defineWidget({
|
|
|
336
318
|
- 不需要占用整行宽度,希望保持对话流的紧凑阅读体验
|
|
337
319
|
- 交互以按钮、简单表单项为主
|
|
338
320
|
|
|
321
|
+
```ts
|
|
322
|
+
// src/app.config.ts
|
|
323
|
+
import { defineAppConfig } from '@doubao-apps/kit';
|
|
324
|
+
|
|
325
|
+
export default defineAppConfig({
|
|
326
|
+
widgets: {
|
|
327
|
+
'widgets/info-card': {
|
|
328
|
+
id: 'info-card',
|
|
329
|
+
name: '信息卡片',
|
|
330
|
+
boxType: 'inbox'
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
```
|
|
335
|
+
|
|
339
336
|
```tsx
|
|
340
337
|
export default defineWidget({
|
|
341
|
-
aiMeta: {
|
|
342
|
-
id: 'info-card',
|
|
343
|
-
name: '信息卡片',
|
|
344
|
-
boxType: 'inbox',
|
|
345
|
-
input: {
|
|
346
|
-
type: 'object',
|
|
347
|
-
properties: {
|
|
348
|
-
title: { type: 'string', title: '标题' },
|
|
349
|
-
content: { type: 'string', title: '内容' }
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
338
|
render() {
|
|
354
339
|
const input = getViewData<{ title: string; content: string }>();
|
|
355
|
-
|
|
340
|
+
|
|
356
341
|
return (
|
|
357
342
|
<view className="info-card">
|
|
358
343
|
<text className="title">{input.title}</text>
|
|
@@ -367,20 +352,23 @@ export default defineWidget({
|
|
|
367
352
|
|
|
368
353
|
适用于需要更大展示空间的卡片(例如图表、图片墙、复杂表单等)。
|
|
369
354
|
|
|
355
|
+
```ts
|
|
356
|
+
// src/app.config.ts
|
|
357
|
+
import { defineAppConfig } from '@doubao-apps/kit';
|
|
358
|
+
|
|
359
|
+
export default defineAppConfig({
|
|
360
|
+
widgets: {
|
|
361
|
+
'widgets/user-action-card': {
|
|
362
|
+
id: 'user-action-card',
|
|
363
|
+
name: '全宽卡片示例',
|
|
364
|
+
boxType: 'full_box'
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
```
|
|
369
|
+
|
|
370
370
|
```tsx
|
|
371
371
|
export default defineWidget({
|
|
372
|
-
aiMeta: {
|
|
373
|
-
id: 'user-action-card',
|
|
374
|
-
name: '全宽卡片示例',
|
|
375
|
-
boxType: 'full_box',
|
|
376
|
-
input: {
|
|
377
|
-
type: 'object',
|
|
378
|
-
properties: {
|
|
379
|
-
action: { type: 'string', title: '操作' },
|
|
380
|
-
result: { type: 'string', title: '结果' }
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
},
|
|
384
372
|
render() {
|
|
385
373
|
const input = getViewData<{ action: string; result: string }>();
|
|
386
374
|
return (
|
|
@@ -393,127 +381,26 @@ export default defineWidget({
|
|
|
393
381
|
});
|
|
394
382
|
```
|
|
395
383
|
|
|
396
|
-
###
|
|
384
|
+
### 输入数据类型
|
|
397
385
|
|
|
398
|
-
|
|
386
|
+
Widget 输入数据通过 `getViewData<T>()` 的泛型参数和 TypeScript 接口表达。
|
|
399
387
|
|
|
400
388
|
```tsx
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
// 数字
|
|
412
|
-
{
|
|
413
|
-
type: 'number',
|
|
414
|
-
title: '数量',
|
|
415
|
-
minimum: 0,
|
|
416
|
-
maximum: 100,
|
|
417
|
-
default: 1
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// 布尔值
|
|
421
|
-
{
|
|
422
|
-
type: 'boolean',
|
|
423
|
-
title: '是否启用',
|
|
424
|
-
default: false
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
// 枚举
|
|
428
|
-
{
|
|
429
|
-
type: 'string',
|
|
430
|
-
enum: ['option1', 'option2', 'option3'],
|
|
431
|
-
title: '选项'
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// 数组
|
|
435
|
-
{
|
|
436
|
-
type: 'array',
|
|
437
|
-
items: {
|
|
438
|
-
type: 'string'
|
|
439
|
-
},
|
|
440
|
-
title: '标签列表',
|
|
441
|
-
minItems: 1,
|
|
442
|
-
maxItems: 5
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
// 对象
|
|
446
|
-
{
|
|
447
|
-
type: 'object',
|
|
448
|
-
properties: {
|
|
449
|
-
name: { type: 'string', title: '名称' },
|
|
450
|
-
age: { type: 'number', title: '年龄' }
|
|
451
|
-
},
|
|
452
|
-
required: ['name']
|
|
389
|
+
interface ProductCardData {
|
|
390
|
+
name: string;
|
|
391
|
+
price: number;
|
|
392
|
+
images?: string[];
|
|
393
|
+
category: '电子' | '服装' | '食品' | '图书';
|
|
394
|
+
inStock: boolean;
|
|
395
|
+
specs?: {
|
|
396
|
+
color?: string;
|
|
397
|
+
size?: string;
|
|
398
|
+
};
|
|
453
399
|
}
|
|
454
|
-
```
|
|
455
|
-
|
|
456
|
-
**复杂 Schema 示例**
|
|
457
400
|
|
|
458
|
-
```tsx
|
|
459
401
|
export default defineWidget({
|
|
460
|
-
aiMeta: {
|
|
461
|
-
id: 'product-card',
|
|
462
|
-
name: '商品卡片',
|
|
463
|
-
boxType: 'inbox',
|
|
464
|
-
input: {
|
|
465
|
-
type: 'object',
|
|
466
|
-
properties: {
|
|
467
|
-
name: {
|
|
468
|
-
type: 'string',
|
|
469
|
-
title: '商品名称',
|
|
470
|
-
description: '商品的显示名称'
|
|
471
|
-
},
|
|
472
|
-
price: {
|
|
473
|
-
type: 'number',
|
|
474
|
-
title: '价格',
|
|
475
|
-
minimum: 0,
|
|
476
|
-
description: '商品价格(元)'
|
|
477
|
-
},
|
|
478
|
-
images: {
|
|
479
|
-
type: 'array',
|
|
480
|
-
items: { type: 'string' },
|
|
481
|
-
title: '商品图片',
|
|
482
|
-
description: '商品图片 URL 列表',
|
|
483
|
-
minItems: 1,
|
|
484
|
-
maxItems: 5
|
|
485
|
-
},
|
|
486
|
-
category: {
|
|
487
|
-
type: 'string',
|
|
488
|
-
enum: ['电子', '服装', '食品', '图书'],
|
|
489
|
-
title: '分类'
|
|
490
|
-
},
|
|
491
|
-
inStock: {
|
|
492
|
-
type: 'boolean',
|
|
493
|
-
title: '是否有货',
|
|
494
|
-
default: true
|
|
495
|
-
},
|
|
496
|
-
specs: {
|
|
497
|
-
type: 'object',
|
|
498
|
-
properties: {
|
|
499
|
-
color: { type: 'string', title: '颜色' },
|
|
500
|
-
size: { type: 'string', title: '尺寸' }
|
|
501
|
-
},
|
|
502
|
-
title: '规格'
|
|
503
|
-
}
|
|
504
|
-
},
|
|
505
|
-
required: ['name', 'price']
|
|
506
|
-
}
|
|
507
|
-
},
|
|
508
402
|
render() {
|
|
509
|
-
const input = getViewData<
|
|
510
|
-
name: string;
|
|
511
|
-
price: number;
|
|
512
|
-
images?: string[];
|
|
513
|
-
category: string;
|
|
514
|
-
inStock: boolean;
|
|
515
|
-
specs?: { color?: string; size?: string };
|
|
516
|
-
}>();
|
|
403
|
+
const input = getViewData<ProductCardData>();
|
|
517
404
|
return (
|
|
518
405
|
<view className="product-card">
|
|
519
406
|
<text className="name">{input.name}</text>
|
|
@@ -579,16 +466,17 @@ function WeatherWidget({ city }: { city: string }) {
|
|
|
579
466
|
**2. 用户交互**
|
|
580
467
|
|
|
581
468
|
```tsx
|
|
469
|
+
import { sendQueryMessage } from '@doubao-apps/framework/api';
|
|
470
|
+
|
|
582
471
|
function InteractiveWidget({ initialCount }: { initialCount: number }) {
|
|
583
472
|
const [count, setCount] = useState(initialCount);
|
|
584
473
|
|
|
585
474
|
const handleIncrement = () => {
|
|
586
475
|
setCount(count + 1);
|
|
587
|
-
//
|
|
476
|
+
// 发送一条用户消息到当前会话
|
|
588
477
|
sendQueryMessage({
|
|
589
478
|
content: `计数增加到 ${count + 1}`,
|
|
590
|
-
type: 'text'
|
|
591
|
-
context: {}
|
|
479
|
+
type: 'text'
|
|
592
480
|
});
|
|
593
481
|
};
|
|
594
482
|
|
|
@@ -604,18 +492,12 @@ function InteractiveWidget({ initialCount }: { initialCount: number }) {
|
|
|
604
492
|
**3. 打开页面**
|
|
605
493
|
|
|
606
494
|
```tsx
|
|
607
|
-
import {
|
|
495
|
+
import { navigateTo } from '@doubao-apps/framework/api';
|
|
608
496
|
|
|
609
497
|
function ActionWidget({ itemId }: { itemId: string }) {
|
|
610
498
|
const handleViewDetail = () => {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
mode: 'full', // 全屏页面,可省略(默认)
|
|
614
|
-
pageData: JSON.stringify({ id: itemId }),
|
|
615
|
-
context: {},
|
|
616
|
-
pageSettings: {
|
|
617
|
-
title: '详情'
|
|
618
|
-
}
|
|
499
|
+
navigateTo({
|
|
500
|
+
url: `item-detail?id=${itemId}`
|
|
619
501
|
});
|
|
620
502
|
};
|
|
621
503
|
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
### **项目文档系统**
|
|
23
23
|
本地项目文档(按优先级):
|
|
24
|
-
1. **
|
|
24
|
+
1. **SKILL.md** - 项目主入口,包含快速开始和核心规则
|
|
25
25
|
2. **.ai/rules/** - 框架规则和约束
|
|
26
26
|
3. **.ai/guides/** - 开发指南
|
|
27
27
|
4. **.ai/examples/** - 代码示例库
|
|
@@ -50,7 +50,7 @@ LynxBase MCP 提供:
|
|
|
50
50
|
## 知识体系
|
|
51
51
|
|
|
52
52
|
### 知识优先级
|
|
53
|
-
1. **项目本地文档**(
|
|
53
|
+
1. **项目本地文档**(SKILL.md 及 .ai/ 目录)
|
|
54
54
|
2. **LynxBase MCP**(Lynx 官方/内部文档)
|
|
55
55
|
3. **通用编程知识**
|
|
56
56
|
|
|
@@ -64,7 +64,7 @@ LynxBase MCP 提供:
|
|
|
64
64
|
|
|
65
65
|
[生成代码]
|
|
66
66
|
|
|
67
|
-
详细的开发规范请参考:[
|
|
67
|
+
详细的开发规范请参考:[component-development.md](component-development.md)
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
**错误做法**:
|
|
@@ -191,7 +191,7 @@ ReactLynx 镜像 React API(`useState`、`useEffect` 等),但所有生命
|
|
|
191
191
|
|
|
192
192
|
**4. 项目结构问题** → 引用本地文档
|
|
193
193
|
- 示例:"如何组织组件?"
|
|
194
|
-
- 响应:简短说明 + 引用
|
|
194
|
+
- 响应:简短说明 + 引用 SKILL.md 或 .ai/rules/
|
|
195
195
|
|
|
196
196
|
**5. 问题诊断** → 分析 + 解决方案 + 预防措施
|
|
197
197
|
- 示例:"报错了"
|
|
@@ -209,7 +209,7 @@ ReactLynx 镜像 React API(`useState`、`useEffect` 等),但所有生命
|
|
|
209
209
|
|
|
210
210
|
2. **规划方法**
|
|
211
211
|
- **Lynx 相关** → 查询 **LynxBase MCP** 获取支持数据
|
|
212
|
-
- **项目结构/规则** → 引用本地文档(
|
|
212
|
+
- **项目结构/规则** → 引用本地文档(SKILL.md、.ai/)
|
|
213
213
|
|
|
214
214
|
3. **调用适当工具**
|
|
215
215
|
- Lynx 相关 → **LynxBase MCP**
|
|
@@ -261,7 +261,7 @@ ReactLynx 镜像 React API(`useState`、`useEffect` 等),但所有生命
|
|
|
261
261
|
- 提供错误处理代码
|
|
262
262
|
|
|
263
263
|
4. ❌ **不要违反框架规则**
|
|
264
|
-
- 严格遵守
|
|
264
|
+
- 严格遵守 SKILL.md 和 Lynx 规范
|
|
265
265
|
- 不要为了方便走捷径
|
|
266
266
|
|
|
267
267
|
5. ❌ **不要过度工程化**
|
|
@@ -280,13 +280,13 @@ ReactLynx 镜像 React API(`useState`、`useEffect` 等),但所有生命
|
|
|
280
280
|
|
|
281
281
|
| 用户请求 | 查阅文档 | 你的动作 |
|
|
282
282
|
|---------|---------|---------|
|
|
283
|
-
| "创建页面" | `.ai/
|
|
284
|
-
| "创建卡片" | `.ai/
|
|
283
|
+
| "创建页面" | `.ai/guides/component-development.md` (Page) + LynxBase MCP | 生成代码 + 引用文档 |
|
|
284
|
+
| "创建卡片" | `.ai/guides/component-development.md` (Widget) + LynxBase MCP | 生成代码 + 引用文档 |
|
|
285
285
|
| "Lynx 组件如何用" | LynxBase MCP → `query-assets` → `get-assets` | 查询 + 提供示例 |
|
|
286
286
|
| "如何调用 API" | `.ai/examples/common-patterns.md` + Doubao Bridge 文档 | 提供示例 + 引用文档 |
|
|
287
|
-
| "性能优化" | `.ai/
|
|
288
|
-
| "报错了" | `.ai/
|
|
289
|
-
| "框架规则" | `.ai/rules/dos-and-donts.md` +
|
|
287
|
+
| "性能优化" | `.ai/guides/performance-optimization.md` + Lynx 性能指南 | 分析问题 + 引用文档 |
|
|
288
|
+
| "报错了" | `.ai/guides/troubleshooting.md` + 错误分析 | 诊断 + 修复 + 引用文档 |
|
|
289
|
+
| "框架规则" | `.ai/rules/dos-and-donts.md` + SKILL.md | 简要说明 + 引用文档 |
|
|
290
290
|
|
|
291
291
|
---
|
|
292
292
|
|
|
@@ -309,7 +309,7 @@ ReactLynx 镜像 React API(`useState`、`useEffect` 等),但所有生命
|
|
|
309
309
|
1. 调用 **LynxBase MCP** 查询主线程相关文档
|
|
310
310
|
2. 简短解释:"主线程脚本是在 Lynx 主线程执行的 JS 代码,用于高频交互和实时更新..."
|
|
311
311
|
3. 提供简单示例
|
|
312
|
-
4. 引用详细文档:"更多详情请查阅 LynxBase 文档或参考 [性能优化指南](
|
|
312
|
+
4. 引用详细文档:"更多详情请查阅 LynxBase 文档或参考 [性能优化指南](performance-optimization.md)"
|
|
313
313
|
|
|
314
314
|
### 示例 3:项目规则
|
|
315
315
|
**用户**:"组件应该放在哪里?"
|
|
@@ -324,8 +324,8 @@ ReactLynx 镜像 React API(`useState`、`useEffect` 等),但所有生命
|
|
|
324
324
|
- `index.scss` - 样式文件
|
|
325
325
|
- `types.ts` - 类型定义(可选)
|
|
326
326
|
|
|
327
|
-
详细规范请参考:[
|
|
327
|
+
详细规范请参考:[SKILL.md](../../SKILL.md) 和 [组件开发指南](component-development.md)"
|
|
328
328
|
|
|
329
329
|
---
|
|
330
330
|
|
|
331
|
-
*系统提示词版本: 2.0.0 | 集成: Lynx + Doubao Apps SDK | 维护: Doubao Apps SDK 团队*
|
|
331
|
+
*系统提示词版本: 2.0.0 | 集成: Lynx + Doubao Apps SDK | 维护: Doubao Apps SDK 团队*
|
|
@@ -136,7 +136,7 @@ console.log(info.keys, info.currentSize, info.limitSize);
|
|
|
136
136
|
## 引入依赖
|
|
137
137
|
|
|
138
138
|
```ts
|
|
139
|
-
import { getLocation, getPhoneNumber,
|
|
139
|
+
import { getLocation, getPhoneNumber, navigateTo, navigateBack, request, showToast, setStorage, getStorage } from '@doubao-apps/framework/api';
|
|
140
140
|
```
|
|
141
141
|
|
|
142
142
|
## 使用示例
|
|
@@ -144,7 +144,8 @@ import { getLocation, getPhoneNumber, openPage, request, showToast, setStorage,
|
|
|
144
144
|
```ts
|
|
145
145
|
await showToast({ message: '保存成功' });
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
await navigateTo({ url: 'detail?id=123' });
|
|
148
|
+
await navigateBack();
|
|
148
149
|
|
|
149
150
|
const res = await request({ url: '/api/data', method: 'GET' });
|
|
150
151
|
|
|
@@ -155,85 +156,57 @@ const phone = await getPhoneNumber();
|
|
|
155
156
|
|
|
156
157
|
以下为常用端能力 API 的节选,完整以 `@doubao-apps/framework/api` 类型定义为准。
|
|
157
158
|
|
|
158
|
-
###
|
|
159
|
+
### navigateTo
|
|
159
160
|
|
|
160
161
|
**参数**:
|
|
161
162
|
```typescript
|
|
162
163
|
{
|
|
163
|
-
/**
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
/** 打开页面时传入的数据,运行时通过 getViewData 获取 */
|
|
167
|
-
pageData?: string;
|
|
168
|
-
|
|
169
|
-
/** view context 对象,在全页和卡片中通过 getViewContext() 获取 */
|
|
170
|
-
context: object;
|
|
171
|
-
|
|
172
|
-
/** 打开 Page 时配置页面参数 */
|
|
173
|
-
pageSettings?: {
|
|
174
|
-
/**
|
|
175
|
-
* 悬浮窗口在横向上的吸附位置
|
|
176
|
-
*
|
|
177
|
-
* @deprecated 最新的 Lynx 悬浮窗中已失效
|
|
178
|
-
*/
|
|
179
|
-
align?: 'left' | 'right';
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* 设置 Lynx 悬浮窗的宽度,单位是 `px`
|
|
183
|
-
*/
|
|
184
|
-
width?: number;
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* 设置 Lynx 悬浮窗的高度,单位是 `px`
|
|
188
|
-
*/
|
|
189
|
-
height?: number;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* 优先级。越高代表优先级越高,取值-2~2
|
|
193
|
-
*/
|
|
194
|
-
priority?: number;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* 是否自动恢复展示。在被高优悬浮窗打断时会发挥作用,只有为 true 才会得到恢复的机会,否则直接释放
|
|
198
|
-
*/
|
|
199
|
-
autoReshow?: boolean;
|
|
200
|
-
};
|
|
164
|
+
/** 跳转目标,填写页面的 pageId,可拼接 query,如 'detail?id=123' */
|
|
165
|
+
url: string;
|
|
201
166
|
}
|
|
202
167
|
```
|
|
203
168
|
|
|
204
|
-
**返回值**:
|
|
169
|
+
**返回值**: Promise
|
|
170
|
+
|
|
171
|
+
### redirectTo
|
|
172
|
+
|
|
173
|
+
**参数**:
|
|
205
174
|
```typescript
|
|
206
175
|
{
|
|
207
|
-
/**
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* 返回展示悬浮窗的结果
|
|
212
|
-
* 0: 展示失败
|
|
213
|
-
* 1: 展示成功
|
|
214
|
-
* 2: 排队中
|
|
215
|
-
*/
|
|
216
|
-
floatingShowResult?: number;
|
|
176
|
+
/** 跳转目标,填写页面的 pageId,如 'settings' */
|
|
177
|
+
url: string;
|
|
217
178
|
}
|
|
218
179
|
```
|
|
219
180
|
|
|
220
|
-
|
|
181
|
+
**返回值**: Promise
|
|
182
|
+
|
|
183
|
+
### reLaunch
|
|
221
184
|
|
|
222
185
|
**参数**:
|
|
223
186
|
```typescript
|
|
224
187
|
{
|
|
225
|
-
/**
|
|
226
|
-
|
|
227
|
-
/** 要关闭的多个页面 id */
|
|
228
|
-
viewIDs?: string[];
|
|
229
|
-
/**
|
|
230
|
-
* @default false
|
|
231
|
-
*/
|
|
232
|
-
animated?: boolean;
|
|
188
|
+
/** 跳转目标,填写页面的 pageId,如 'home' */
|
|
189
|
+
url: string;
|
|
233
190
|
}
|
|
234
191
|
```
|
|
235
192
|
|
|
236
|
-
**返回值**:
|
|
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。
|
|
237
210
|
|
|
238
211
|
### showToast
|
|
239
212
|
|
|
@@ -413,7 +386,7 @@ const phone = await getPhoneNumber();
|
|
|
413
386
|
|
|
414
387
|
| API | 功能 | 示例 |
|
|
415
388
|
|-----|------|------|
|
|
416
|
-
| `sendQueryMessage(params)` | 发送用户消息 | `sendQueryMessage({ content: '查询天气', type: 'text'
|
|
389
|
+
| `sendQueryMessage(params)` | 发送用户消息 | `sendQueryMessage({ content: '查询天气', type: 'text' })` |
|
|
417
390
|
| `setAdditionalContext(params)` | 设置上下文 | `setAdditionalContext({ additionalContext: '...' })` |
|
|
418
391
|
|
|
419
392
|
### sendQueryMessage
|
|
@@ -426,12 +399,6 @@ const phone = await getPhoneNumber();
|
|
|
426
399
|
|
|
427
400
|
/** 消息类型,目前仅支持 text */
|
|
428
401
|
type: 'text';
|
|
429
|
-
|
|
430
|
-
/** Plugin tool 或 Page/Widget 携带的上下文信息 */
|
|
431
|
-
context: object;
|
|
432
|
-
|
|
433
|
-
/** 扩展信息 */
|
|
434
|
-
ext?: Record<string, string>;
|
|
435
402
|
}
|
|
436
403
|
```
|
|
437
404
|
|
|
@@ -500,21 +467,7 @@ interface PageInput {
|
|
|
500
467
|
[key: string]: any; // URL 参数
|
|
501
468
|
}
|
|
502
469
|
|
|
503
|
-
//
|
|
504
|
-
interface WidgetInputSchema {
|
|
505
|
-
type: 'object';
|
|
506
|
-
properties: {
|
|
507
|
-
[key: string]: {
|
|
508
|
-
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
509
|
-
title: string;
|
|
510
|
-
description?: string;
|
|
511
|
-
default?: any;
|
|
512
|
-
};
|
|
513
|
-
};
|
|
514
|
-
required?: string[];
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// aiMeta 配置
|
|
470
|
+
// src/app.config.ts 中的 metadata 配置
|
|
518
471
|
interface PageAIMeta {
|
|
519
472
|
id: string; // 页面唯一标识
|
|
520
473
|
title?: string; // 页面标题
|
|
@@ -526,7 +479,15 @@ interface WidgetAIMeta {
|
|
|
526
479
|
name?: string; // 卡片名称
|
|
527
480
|
description?: string; // 卡片描述
|
|
528
481
|
boxType?: 'inbox' | 'full_box'; // 卡片类型
|
|
529
|
-
|
|
482
|
+
border?: boolean; // 是否显示边框
|
|
483
|
+
keywords?: string[]; // 搜索关键词
|
|
484
|
+
titleType?: 'none' | 'normal' | 'float';
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// Widget 渲染数据类型
|
|
488
|
+
interface WidgetViewData {
|
|
489
|
+
title: string;
|
|
490
|
+
content?: string;
|
|
530
491
|
}
|
|
531
492
|
```
|
|
532
493
|
|