@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.
Files changed (91) hide show
  1. package/dist/36.js +4 -4
  2. package/dist/template-empty/.ai/examples/common-patterns.md +53 -43
  3. package/dist/template-empty/.ai/examples/component-basics.md +0 -17
  4. package/dist/template-empty/.ai/guides/component-development.md +96 -214
  5. package/dist/template-empty/.ai/guides/system-prompt.md +14 -14
  6. package/dist/template-empty/.ai/reference/framework-api-quick-ref.md +46 -85
  7. 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
  8. package/dist/template-empty/.ai/reference/open-api/02-/345/255/230/345/202/250.md +409 -0
  9. package/dist/template-empty/.ai/reference/open-api/03-/350/267/257/347/224/261.md +165 -0
  10. package/dist/template-empty/.ai/reference/open-api/04-/347/225/214/351/235/242-/344/272/244/344/272/222.md +432 -0
  11. package/dist/template-empty/.ai/reference/open-api/05-/347/225/214/351/235/242-/350/276/223/345/205/245.md +42 -0
  12. package/dist/template-empty/.ai/reference/open-api/06-/347/275/221/347/273/234.md +148 -0
  13. package/dist/template-empty/.ai/reference/open-api/07-/345/252/222/344/275/223.md +346 -0
  14. 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
  15. package/dist/template-empty/.ai/reference/open-api/09-/350/256/276/345/244/207-/350/223/235/347/211/231.md +961 -0
  16. package/dist/template-empty/.ai/reference/open-api/10-/350/256/276/345/244/207-wi-fi.md +277 -0
  17. 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
  18. package/dist/template-empty/.ai/reference/open-api/12-/350/256/276/345/244/207-ibeacon.md +148 -0
  19. package/dist/template-empty/.ai/reference/open-api/13-/350/256/276/345/244/207-/347/275/227/347/233/230.md +82 -0
  20. 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
  21. 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
  22. package/dist/template-empty/.ai/reference/open-api/16-ui-/350/276/223/345/205/245.md +65 -0
  23. package/dist/template-empty/.ai/reference/open-api/17-/350/256/276/345/244/207-/347/275/221/347/273/234.md +164 -0
  24. package/dist/template-empty/.ai/reference/open-api/18-/350/256/276/345/244/207-/347/237/255/344/277/241.md +62 -0
  25. 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
  26. package/dist/template-empty/.ai/reference/open-api/20-/350/256/276/345/244/207-/347/224/265/346/261/240.md +83 -0
  27. package/dist/template-empty/.ai/reference/open-api/21-/350/256/276/345/244/207-/346/227/245/345/216/206.md +215 -0
  28. 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
  29. 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
  30. package/dist/template-empty/.ai/reference/open-api/24-/350/256/276/345/244/207-/345/212/240/345/257/206.md +56 -0
  31. package/dist/template-empty/.ai/reference/open-api/25-/350/256/276/345/244/207-/347/224/265/350/257/235.md +41 -0
  32. package/dist/template-empty/.ai/reference/open-api/26-/350/256/276/345/244/207-/346/211/253/347/240/201.md +100 -0
  33. package/dist/template-empty/.ai/reference/open-api/27-/350/256/276/345/244/207-/345/261/217/345/271/225.md +173 -0
  34. package/dist/template-empty/.ai/reference/open-api/28-/350/256/276/345/244/207-/351/234/207/345/212/250.md +66 -0
  35. package/dist/template-empty/.ai/reference/open-api/README.md +36 -0
  36. package/dist/template-empty/.ai/reference/open-api.md +1758 -266
  37. package/dist/template-empty/.ai/rules/dos-and-donts.md +50 -37
  38. package/dist/template-empty/AGENTS.md +56 -33
  39. package/dist/template-empty/README.md +57 -10
  40. package/dist/template-empty/package.json +2 -2
  41. package/dist/template-empty/src/app.config.ts +6 -0
  42. package/dist/template-empty/src/app.ts +0 -6
  43. package/dist/template-empty/tsconfig.json +2 -0
  44. package/dist/template-starter/.ai/examples/common-patterns.md +53 -43
  45. package/dist/template-starter/.ai/examples/component-basics.md +0 -17
  46. package/dist/template-starter/.ai/guides/component-development.md +96 -214
  47. package/dist/template-starter/.ai/guides/system-prompt.md +14 -14
  48. package/dist/template-starter/.ai/reference/framework-api-quick-ref.md +46 -85
  49. 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
  50. package/dist/template-starter/.ai/reference/open-api/02-/345/255/230/345/202/250.md +409 -0
  51. package/dist/template-starter/.ai/reference/open-api/03-/350/267/257/347/224/261.md +165 -0
  52. package/dist/template-starter/.ai/reference/open-api/04-/347/225/214/351/235/242-/344/272/244/344/272/222.md +432 -0
  53. package/dist/template-starter/.ai/reference/open-api/05-/347/225/214/351/235/242-/350/276/223/345/205/245.md +42 -0
  54. package/dist/template-starter/.ai/reference/open-api/06-/347/275/221/347/273/234.md +148 -0
  55. package/dist/template-starter/.ai/reference/open-api/07-/345/252/222/344/275/223.md +346 -0
  56. 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
  57. package/dist/template-starter/.ai/reference/open-api/09-/350/256/276/345/244/207-/350/223/235/347/211/231.md +961 -0
  58. package/dist/template-starter/.ai/reference/open-api/10-/350/256/276/345/244/207-wi-fi.md +277 -0
  59. 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
  60. package/dist/template-starter/.ai/reference/open-api/12-/350/256/276/345/244/207-ibeacon.md +148 -0
  61. package/dist/template-starter/.ai/reference/open-api/13-/350/256/276/345/244/207-/347/275/227/347/233/230.md +82 -0
  62. 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
  63. 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
  64. package/dist/template-starter/.ai/reference/open-api/16-ui-/350/276/223/345/205/245.md +65 -0
  65. package/dist/template-starter/.ai/reference/open-api/17-/350/256/276/345/244/207-/347/275/221/347/273/234.md +164 -0
  66. package/dist/template-starter/.ai/reference/open-api/18-/350/256/276/345/244/207-/347/237/255/344/277/241.md +62 -0
  67. 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
  68. package/dist/template-starter/.ai/reference/open-api/20-/350/256/276/345/244/207-/347/224/265/346/261/240.md +83 -0
  69. package/dist/template-starter/.ai/reference/open-api/21-/350/256/276/345/244/207-/346/227/245/345/216/206.md +215 -0
  70. 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
  71. 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
  72. package/dist/template-starter/.ai/reference/open-api/24-/350/256/276/345/244/207-/345/212/240/345/257/206.md +56 -0
  73. package/dist/template-starter/.ai/reference/open-api/25-/350/256/276/345/244/207-/347/224/265/350/257/235.md +41 -0
  74. package/dist/template-starter/.ai/reference/open-api/26-/350/256/276/345/244/207-/346/211/253/347/240/201.md +100 -0
  75. package/dist/template-starter/.ai/reference/open-api/27-/350/256/276/345/244/207-/345/261/217/345/271/225.md +173 -0
  76. package/dist/template-starter/.ai/reference/open-api/28-/350/256/276/345/244/207-/351/234/207/345/212/250.md +66 -0
  77. package/dist/template-starter/.ai/reference/open-api/README.md +36 -0
  78. package/dist/template-starter/.ai/reference/open-api.md +1758 -266
  79. package/dist/template-starter/.ai/rules/dos-and-donts.md +50 -37
  80. package/dist/template-starter/AGENTS.md +56 -33
  81. package/dist/template-starter/README.md +6 -1
  82. package/dist/template-starter/package.json +2 -2
  83. package/dist/template-starter/src/app.config.ts +35 -0
  84. package/dist/template-starter/src/app.ts +0 -6
  85. package/dist/template-starter/src/pages/applet/index.tsx +0 -5
  86. package/dist/template-starter/src/pages/home/index.tsx +0 -5
  87. package/dist/template-starter/src/pages/lynx/index.tsx +0 -4
  88. package/dist/template-starter/src/pages/react-lynx/index.tsx +0 -5
  89. package/dist/template-starter/src/widgets/weather-card/index.tsx +0 -4
  90. package/dist/template-starter/tsconfig.json +2 -0
  91. package/package.json +1 -1
@@ -87,19 +87,6 @@ interface UserInfo {
87
87
  }
88
88
 
89
89
  export default defineWidget({
90
- aiMeta: {
91
- id: 'user-card',
92
- name: '用户卡片',
93
- input: {
94
- type: 'object',
95
- properties: {
96
- name: { type: 'string', title: '姓名' },
97
- age: { type: 'number', title: '年龄' },
98
- avatar: { type: 'string', title: '头像' }
99
- },
100
- required: ['name', 'age']
101
- }
102
- },
103
90
  render() {
104
91
  const input = getViewData<UserInfo>();
105
92
  return <view>{input.name}</view>;
@@ -107,6 +94,21 @@ export default defineWidget({
107
94
  });
108
95
  ```
109
96
 
97
+ ```ts
98
+ // ✅ 把 metadata 写到 src/app.config.ts
99
+ import { defineAppConfig } from '@doubao-apps/kit';
100
+
101
+ export default defineAppConfig({
102
+ widgets: {
103
+ 'widgets/user-card': {
104
+ id: 'user-card',
105
+ name: '用户卡片',
106
+ description: '用户信息卡片'
107
+ }
108
+ }
109
+ });
110
+ ```
111
+
110
112
  ```tsx
111
113
  // ❌ 不好的做法
112
114
  export default defineWidget({
@@ -247,20 +249,26 @@ export default definePage({
247
249
  ```
248
250
 
249
251
  ```tsx
250
- // ✅ 正确 - 在生命周期钩子中请求
251
- export default definePage({
252
- data: {
253
- userData: null
254
- },
252
+ // ✅ 推荐 - 使用 Hook 管理请求和状态
253
+ import { useEffect, useState } from '@doubao-apps/framework';
255
254
 
256
- onShow() {
257
- fetch('/api/data').then(data => {
258
- this.setData({ userData: data });
259
- });
260
- },
255
+ function UserPage() {
256
+ const [userData, setUserData] = useState<{ name?: string } | null>(null);
257
+
258
+ useEffect(() => {
259
+ fetch('/api/data')
260
+ .then(res => res.json())
261
+ .then(data => {
262
+ setUserData(data);
263
+ });
264
+ }, []);
261
265
 
266
+ return <view>{userData?.name}</view>;
267
+ }
268
+
269
+ export default definePage({
262
270
  render() {
263
- return <view>{this.data.userData?.name}</view>;
271
+ return <UserPage />;
264
272
  }
265
273
  });
266
274
  ```
@@ -351,21 +359,26 @@ export default defineWidget({
351
359
  ```
352
360
 
353
361
  ```tsx
354
- // ✅ 正确 - 使用实例状态
362
+ // ✅ 推荐 - 使用组件内状态,实例之间互不影响
363
+ import { useState } from '@doubao-apps/framework';
364
+
365
+ function CounterWidget() {
366
+ const [count, setCount] = useState(0);
367
+
368
+ return (
369
+ <view
370
+ onClick={() => {
371
+ setCount(prev => prev + 1);
372
+ }}
373
+ >
374
+ Count: {count}
375
+ </view>
376
+ );
377
+ }
378
+
355
379
  export default defineWidget({
356
- data: {
357
- count: 0
358
- },
359
380
  render() {
360
- return (
361
- <view
362
- onClick={() => {
363
- this.setData({ count: this.data.count + 1 });
364
- }}
365
- >
366
- Count: {this.data.count}
367
- </view>
368
- );
381
+ return <CounterWidget />;
369
382
  }
370
383
  });
371
384
  ```
@@ -1,4 +1,4 @@
1
- # AGENTS.md - Doubao Apps SDK AI 开发指南
1
+ # Doubao Apps SDK AI 开发指南
2
2
 
3
3
  本文件专供 AI coding agents(如 Claude、Copilot、Cursor)和开发者使用,提供 Doubao Apps SDK 框架的快速入门、开发规则和文档导航。
4
4
 
@@ -31,7 +31,6 @@ pnpm install
31
31
 
32
32
  # 启动开发
33
33
  pnpm dev
34
-
35
34
  ```
36
35
 
37
36
  **开发服务器命令**:
@@ -66,9 +65,9 @@ my-doubao-app/
66
65
 
67
66
  - **优先使用 pnpm** 作为包管理器
68
67
  - **分离样式文件**:每个组件使用独立的 `.scss` 文件
69
- - **定义 aiMeta**:为 Page 和 Widget 提供完整的元数据
68
+ - **在 `src/app.config.ts` 中配置 metadata**:为 App、Page 和 Widget 统一配置元数据
70
69
  - **使用生命周期钩子**:合理使用 `onShow`、`onMounted` 等
71
- - **TypeScript 类型**:为 props 和 state 提供类型定义
70
+ - **TypeScript 类型**:使用 `getViewData<T>()`、为 props 和 state 提供类型定义
72
71
  - **错误处理**:处理边界情况和错误状态
73
72
 
74
73
  ### 禁止做法
@@ -92,22 +91,37 @@ my-doubao-app/
92
91
 
93
92
  Page 是全屏 UI 组件,支持九宫格、浮窗等变体。
94
93
 
95
- **基础结构**:
94
+ **metadata 配置**:
95
+ ```ts
96
+ import { defineAppConfig } from '@doubao-apps/kit';
97
+
98
+ export default defineAppConfig({
99
+ pages: {
100
+ 'pages/home': {
101
+ id: 'my-page',
102
+ title: '我的页面',
103
+ description: '页面功能描述'
104
+ }
105
+ }
106
+ });
107
+ ```
108
+
109
+ **页面实现**:
96
110
  ```tsx
97
111
  import { definePage, getViewData } from '@doubao-apps/framework';
98
112
  import './index.scss';
99
113
 
114
+ interface HomePageData {
115
+ title: string;
116
+ }
117
+
100
118
  export default definePage({
101
- aiMeta: {
102
- id: 'my-page',
103
- title: '我的页面',
104
- },
105
119
  onShow() {
106
120
  // 页面显示时触发
107
121
  },
108
122
  render() {
109
- const input = getViewData();
110
- return <view>页面内容</view>;
123
+ const input = getViewData<HomePageData>();
124
+ return <view>{input.title}</view>;
111
125
  }
112
126
  });
113
127
  ```
@@ -118,28 +132,38 @@ export default definePage({
118
132
 
119
133
  Widget 是聊天流中的卡片组件,在对话中展示。
120
134
 
121
- **基础结构**:
135
+ **metadata 配置**:
136
+ ```ts
137
+ import { defineAppConfig } from '@doubao-apps/kit';
138
+
139
+ export default defineAppConfig({
140
+ widgets: {
141
+ 'widgets/my-widget': {
142
+ id: 'my-widget',
143
+ name: '我的卡片',
144
+ description: '卡片功能描述',
145
+ boxType: 'inbox',
146
+ border: true
147
+ }
148
+ }
149
+ });
150
+ ```
151
+
152
+ **卡片实现**:
122
153
  ```tsx
123
154
  import { defineWidget, getViewData } from '@doubao-apps/framework';
124
155
  import './index.scss';
125
156
 
157
+ interface MyWidgetData {
158
+ title: string;
159
+ }
160
+
126
161
  export default defineWidget({
127
- aiMeta: {
128
- id: 'my-widget',
129
- name: '我的卡片',
130
- boxType: 'inbox',
131
- input: {
132
- type: 'object',
133
- properties: {
134
- title: { type: 'string', title: '标题' }
135
- }
136
- }
137
- },
138
162
  onMounted() {
139
163
  // 卡片挂载后触发
140
164
  },
141
165
  render() {
142
- const input = getViewData();
166
+ const input = getViewData<MyWidgetData>();
143
167
  return <view>{input.title}</view>;
144
168
  }
145
169
  });
@@ -171,7 +195,7 @@ export default defineWidget({
171
195
  完整的 Framework API(框架核心)和 Bridge API(系统能力)列表:
172
196
 
173
197
  - **[Framework API 快速参考](.ai/reference/framework-api-quick-ref.md)** - 核心 Framework API 速查
174
- - **[Open API 文档](.ai/reference/open-api.md)** - 公开可用的端能力(系统能力)定义
198
+ - **[Open API 目录](.ai/reference/open-api/README.md)** - 公开可用的端能力(系统能力)目录与详细文档
175
199
  - **[组件库快速参考](.ai/reference/components-quick-ref.md)** - SDK 内置组件(Button、Switch、Swiper 等)
176
200
 
177
201
  包含:
@@ -206,8 +230,7 @@ API 参考文档
206
230
 
207
231
  - **[Framework API](.ai/reference/framework-api-quick-ref.md)** - 核心 Framework API 速查
208
232
  - **[组件库](.ai/reference/components-quick-ref.md)** - SDK 内置组件速查
209
- - **[Open API](.ai/reference/open-api.md)** - 系统能力 API
210
-
233
+ - **[Open API](.ai/reference/open-api/README.md)** - 系统能力 API 目录与详细文档
211
234
 
212
235
  ### 依赖包
213
236
 
@@ -243,10 +266,10 @@ API 参考文档
243
266
 
244
267
  ```
245
268
  项目根目录/
246
- ├── AGENTS.md # 主入口文档(AI Agent 必读)
247
- └── .ai/ # 详细文档目录
248
- ├── guides/ # 开发指南
249
- ├── rules/ # 开发规则
250
- ├── examples/ # 代码示例
251
- └── reference/ # API 参考
269
+ ├── AGENTS.md # 主入口文档(AI Agent 必读)
270
+ └── .ai/ # 详细文档目录
271
+ ├── guides/ # 开发指南
272
+ ├── rules/ # 开发规则
273
+ ├── examples/ # 代码示例
274
+ └── reference/ # API 参考
252
275
  ```
@@ -1,6 +1,6 @@
1
1
  # Empty Doubao Apps Template
2
2
 
3
- A minimal template for creating Doubao Apps without example pages.
3
+ A minimal Doubao Apps template for starting from scratch.
4
4
 
5
5
  ## Getting Started
6
6
 
@@ -14,24 +14,71 @@ pnpm dev
14
14
 
15
15
  ## Project Structure
16
16
 
17
- ```
17
+ ```text
18
18
  src/
19
- ├── app.ts # App entry point with lifecycle hooks
20
- └── pages/ # Add your pages here
19
+ ├── app.config.ts # App, Page, and Widget metadata
20
+ ├── app.ts # App lifecycle entry
21
+ └── pages/ # Add your pages here
22
+ ```
23
+
24
+ ## Metadata Entry
25
+
26
+ Use `src/app.config.ts` as the metadata source of truth.
27
+
28
+ ```ts
29
+ import { defineAppConfig } from '@doubao-apps/kit';
30
+
31
+ export default defineAppConfig({
32
+ appId: 'com.example.demo',
33
+ name: 'Demo App',
34
+ pages: {
35
+ 'pages/home': {
36
+ id: 'home',
37
+ title: 'Home',
38
+ description: 'Home page'
39
+ }
40
+ }
41
+ });
21
42
  ```
22
43
 
23
44
  ## Creating Pages
24
45
 
25
- Create a new file in `src/pages/` directory:
46
+ 1. Create a page file under `src/pages/`.
47
+ 2. Register its metadata in `src/app.config.ts`.
26
48
 
27
49
  ```tsx
28
- // src/pages/my-page/index.tsx
50
+ // src/pages/home/index.tsx
29
51
  import { definePage } from '@doubao-apps/framework';
30
52
 
31
- export default definePage(() => {
32
- return <view>
33
- <text>Hello World!</text>
34
- </view>;
53
+ import './index.scss';
54
+
55
+ function HomePage() {
56
+ return (
57
+ <view>
58
+ <text>Hello World!</text>
59
+ </view>
60
+ );
61
+ }
62
+
63
+ export default definePage({
64
+ render() {
65
+ return <HomePage />;
66
+ }
67
+ });
68
+ ```
69
+
70
+ ```ts
71
+ // src/app.config.ts
72
+ import { defineAppConfig } from '@doubao-apps/kit';
73
+
74
+ export default defineAppConfig({
75
+ pages: {
76
+ 'pages/home': {
77
+ id: 'home',
78
+ title: 'Home',
79
+ description: 'Home page'
80
+ }
81
+ }
35
82
  });
36
83
  ```
37
84
 
@@ -6,10 +6,10 @@
6
6
  "build": "doubao build"
7
7
  },
8
8
  "dependencies": {
9
- "@doubao-apps/framework": "^0.0.25"
9
+ "@doubao-apps/framework": "^0.0.27"
10
10
  },
11
11
  "devDependencies": {
12
- "@doubao-apps/kit": "^0.0.25",
12
+ "@doubao-apps/kit": "^0.0.27",
13
13
  "typescript": "5.5.3"
14
14
  },
15
15
  "version": "0.0.16"
@@ -0,0 +1,6 @@
1
+ import { defineAppConfig } from '@doubao-apps/kit';
2
+
3
+ export default defineAppConfig({
4
+ appId: '<%= appId %>',
5
+ name: '<%= name %>'
6
+ });
@@ -1,12 +1,6 @@
1
1
  import { defineApp } from '@doubao-apps/framework';
2
2
 
3
- // Define AI Metadata
4
3
  export default defineApp({
5
- aiMeta: {
6
- package: '<%= appId %>',
7
- name: '<%= name %>'
8
- },
9
- // Watch life cycle
10
4
  onLaunch() {
11
5
  console.log('App launched');
12
6
  },
@@ -6,6 +6,8 @@
6
6
  "jsxImportSource": "@doubao-apps/framework",
7
7
  "esModuleInterop": true,
8
8
  "resolveJsonModule": true,
9
+ "module": "esnext",
10
+ "moduleResolution": "bundler",
9
11
  "lib": ["ES2020", "DOM"],
10
12
  "paths": {
11
13
  "@/*": ["./src/*"]
@@ -388,62 +388,73 @@ function UserProfile({ userId }) {
388
388
  ### 1. 打开新页面
389
389
 
390
390
  ```tsx
391
- import { close, openPage, openPopup } from '@doubao-apps/framework/api';
391
+ import { navigateTo, redirectTo, reLaunch } from '@doubao-apps/framework/api';
392
392
 
393
- // 打开全屏页面
393
+ // 保留当前页面,打开详情页
394
394
  function openFullPage() {
395
- openPage({
396
- pageId: 'user-profile',
397
- pageData: JSON.stringify({ userId: '12345' }),
398
- context: {},
399
- pageSettings: {
400
- title: '用户资料'
401
- }
395
+ navigateTo({
396
+ url: 'user-profile?userId=12345'
402
397
  });
403
398
  }
404
399
 
405
- // 打开弹窗页面
406
- function openSettingsPopup() {
407
- openPopup({
408
- pageId: 'settings',
409
- context: {},
410
- pageSettings: {
411
- title: '设置',
412
- heightPercent: 60 // 高度百分比,范围 (0, 100]
413
- }
400
+ // 替换当前页面
401
+ function openSettingsPage() {
402
+ redirectTo({
403
+ url: 'settings'
404
+ });
405
+ }
406
+
407
+ // 清空页面栈并回到首页
408
+ function relaunchHome() {
409
+ reLaunch({
410
+ url: 'home'
414
411
  });
415
412
  }
416
413
  ```
417
414
 
415
+ 这里的 `url` 直接使用目标页面的 `pageId`,与页面的 `aiMeta.id` 一致;如需传参,可继续拼接 query string。
416
+
418
417
  ### 2. 页面间传参
419
418
 
420
419
  ```tsx
420
+ import { navigateTo } from '@doubao-apps/framework/api';
421
+
422
+ function buildPageUrl(pageId: string, params: Record<string, string | number | boolean>) {
423
+ const query = Object.entries(params)
424
+ .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
425
+ .join('&');
426
+
427
+ return query ? `${pageId}?${query}` : pageId;
428
+ }
429
+
421
430
  // 发送方
422
431
  function navigateWithParams() {
423
- openPage({
424
- pageId: 'detail-page',
425
- pageData: JSON.stringify({
432
+ navigateTo({
433
+ url: buildPageUrl('detail-page', {
426
434
  id: '123',
427
435
  name: '商品名称',
428
436
  price: 99.99
429
- }),
430
- context: {}
437
+ })
431
438
  });
432
439
  }
433
440
 
434
441
  // 接收方 (detail-page)
435
442
  import { getViewData } from '@doubao-apps/framework';
436
443
 
444
+ interface DetailPageInput {
445
+ id: string;
446
+ name: string;
447
+ price: number;
448
+ }
449
+
437
450
  export default definePage({
438
451
  aiMeta: {
439
452
  id: 'detail-page',
440
453
  title: '详情页'
441
454
  },
442
455
  render() {
443
- // 使用 getViewData 获取传递的参数
444
- const viewData = getViewData();
445
- const params = JSON.parse(viewData.pageData || '{}');
446
- const { id, name, price } = params;
456
+ // getViewData() 直接返回传入页面的最终对象
457
+ const { id, name, price } = getViewData<DetailPageInput>();
447
458
 
448
459
  return (
449
460
  <view>
@@ -456,24 +467,29 @@ export default definePage({
456
467
  });
457
468
  ```
458
469
 
459
- ### 3. 关闭页面
470
+ ### 3. 返回上一页
460
471
 
461
472
  ```tsx
462
- import { close } from '@doubao-apps/framework/api';
473
+ import { navigateBack } from '@doubao-apps/framework/api';
463
474
 
464
475
  function closeCurrentPage() {
465
- close(); // 关闭当前页面
476
+ navigateBack();
466
477
  }
467
478
  ```
468
479
 
469
480
  ### 4. 页面栈管理
470
481
 
471
482
  ```tsx
472
- import { close } from '@doubao-apps/framework/api';
483
+ import { navigateBack } from '@doubao-apps/framework/api';
473
484
 
474
485
  // 场景 1: 返回上一页
475
486
  function goBack() {
476
- close();
487
+ navigateBack();
488
+ }
489
+
490
+ // 场景 2: 返回多级页面
491
+ function goBackTwoPages() {
492
+ navigateBack({ delta: 2 });
477
493
  }
478
494
  ```
479
495
 
@@ -509,13 +525,12 @@ export default definePage({
509
525
  ### 6. 九宫格页面导航
510
526
 
511
527
  ```tsx
528
+ import { navigateTo } from '@doubao-apps/framework/api';
529
+
512
530
  // 打开九宫格页面
513
531
  function openGridPage() {
514
- openPage({
515
- pageId: 'app-grid',
516
- pageSettings: {
517
- title: '应用中心'
518
- }
532
+ navigateTo({
533
+ url: 'app-grid'
519
534
  });
520
535
  }
521
536
 
@@ -538,12 +553,7 @@ export default definePage({
538
553
  <view
539
554
  key={app.id}
540
555
  className="grid-item"
541
- onClick={() =>
542
- openPage({
543
- pageId: app.id,
544
- context: {}
545
- })
546
- }
556
+ onClick={() => navigateTo({ url: app.id })}
547
557
  >
548
558
  <text className="icon">{app.icon}</text>
549
559
  <text className="name">{app.name}</text>
@@ -358,23 +358,6 @@ function WeatherCard({ city }: WeatherWidgetInput) {
358
358
  }
359
359
 
360
360
  export default defineWidget({
361
- aiMeta: {
362
- id: 'weather-card',
363
- name: '天气卡片',
364
- description: '显示指定城市的天气信息',
365
- boxType: 'inbox',
366
- input: {
367
- type: 'object',
368
- properties: {
369
- city: {
370
- type: 'string',
371
- title: '城市名称',
372
- description: '要查询天气的城市'
373
- }
374
- },
375
- required: ['city']
376
- }
377
- },
378
361
  onMounted() {
379
362
  console.log('卡片挂载');
380
363
  },