quinnz commited on
Commit
800a6f9
·
1 Parent(s): c0745a0

recover official README.md

Browse files
Files changed (2) hide show
  1. README.md +10 -358
  2. README.md-web +358 -0
README.md CHANGED
@@ -1,358 +1,10 @@
1
- # projects
2
-
3
- 这是一个基于 [Next.js 16](https://nextjs.org) + [shadcn/ui](https://ui.shadcn.com) 的全栈应用项目,由扣子编程 CLI 创建。
4
-
5
- ## 快速开始
6
-
7
- ### 启动开发服务器
8
-
9
- ```bash
10
- coze dev
11
- ```
12
-
13
- 启动后,在浏览器中打开 [http://localhost:5000](http://localhost:5000) 查看应用。
14
-
15
- 开发服务器支持热更新,修改代码后页面会自动刷新。
16
-
17
- ### 构建生产版本
18
-
19
- ```bash
20
- coze build
21
- ```
22
-
23
- ### 启动生产服务器
24
-
25
- ```bash
26
- coze start
27
- ```
28
-
29
- ## 项目结构
30
-
31
- ```
32
- src/
33
- ├── app/ # Next.js App Router 目录
34
- │ ├── layout.tsx # 根布局组件
35
- │ ├── page.tsx # 首页
36
- │ ├── globals.css # 全局样式(包含 shadcn 主题变量)
37
- │ └── [route]/ # 其他路由页面
38
- ├── components/ # React 组件目录
39
- │ └── ui/ # shadcn/ui 基础组件(优先使用)
40
- │ ├── button.tsx
41
- │ ├── card.tsx
42
- │ └── ...
43
- ├── lib/ # 工具函数库
44
- │ └── utils.ts # cn() 等工具函数
45
- └── hooks/ # 自定义 React Hooks(可选)
46
- ```
47
-
48
- ## 核心开发规范
49
-
50
- ### 1. 组件开发
51
-
52
- **优先使用 shadcn/ui 基础组件**
53
-
54
- 本项目已预装完整的 shadcn/ui 组件库,位于 `src/components/ui/` 目录。开发时应优先使用这些组件作为基础:
55
-
56
- ```tsx
57
- // ✅ 推荐:使用 shadcn 基础组件
58
- import { Button } from '@/components/ui/button';
59
- import { Card, CardContent, CardHeader } from '@/components/ui/card';
60
- import { Input } from '@/components/ui/input';
61
-
62
- export default function MyComponent() {
63
- return (
64
- <Card>
65
- <CardHeader>标题</CardHeader>
66
- <CardContent>
67
- <Input placeholder="输入内容" />
68
- <Button>提交</Button>
69
- </CardContent>
70
- </Card>
71
- );
72
- }
73
- ```
74
-
75
- **可用的 shadcn 组件清单**
76
-
77
- - 表单:`button`, `input`, `textarea`, `select`, `checkbox`, `radio-group`, `switch`, `slider`
78
- - 布局:`card`, `separator`, `tabs`, `accordion`, `collapsible`, `scroll-area`
79
- - 反馈:`alert`, `alert-dialog`, `dialog`, `toast`, `sonner`, `progress`
80
- - 导航:`dropdown-menu`, `menubar`, `navigation-menu`, `context-menu`
81
- - 数据展示:`table`, `avatar`, `badge`, `hover-card`, `tooltip`, `popover`
82
- - 其他:`calendar`, `command`, `carousel`, `resizable`, `sidebar`
83
-
84
- 详见 `src/components/ui/` 目录下的具体组件实现。
85
-
86
- ### 2. 路由开发
87
-
88
- Next.js 使用文件系统路由,在 `src/app/` 目录下创建文件夹即可添加路由:
89
-
90
- ```bash
91
- # 创建新路由 /about
92
- src/app/about/page.tsx
93
-
94
- # 创建动态路由 /posts/[id]
95
- src/app/posts/[id]/page.tsx
96
-
97
- # 创建路由组(不影响 URL)
98
- src/app/(marketing)/about/page.tsx
99
-
100
- # 创建 API 路由
101
- src/app/api/users/route.ts
102
- ```
103
-
104
- **页面组件示例**
105
-
106
- ```tsx
107
- // src/app/about/page.tsx
108
- import { Button } from '@/components/ui/button';
109
-
110
- export const metadata = {
111
- title: '关于我们',
112
- description: '关于页面描述',
113
- };
114
-
115
- export default function AboutPage() {
116
- return (
117
- <div>
118
- <h1>关于我们</h1>
119
- <Button>了解更多</Button>
120
- </div>
121
- );
122
- }
123
- ```
124
-
125
- **动态路由示例**
126
-
127
- ```tsx
128
- // src/app/posts/[id]/page.tsx
129
- export default async function PostPage({
130
- params,
131
- }: {
132
- params: Promise<{ id: string }>;
133
- }) {
134
- const { id } = await params;
135
-
136
- return <div>文章 ID: {id}</div>;
137
- }
138
- ```
139
-
140
- **API 路由示例**
141
-
142
- ```tsx
143
- // src/app/api/users/route.ts
144
- import { NextResponse } from 'next/server';
145
-
146
- export async function GET() {
147
- return NextResponse.json({ users: [] });
148
- }
149
-
150
- export async function POST(request: Request) {
151
- const body = await request.json();
152
- return NextResponse.json({ success: true });
153
- }
154
- ```
155
-
156
- ### 3. 依赖管理
157
-
158
- **必须使用 pnpm 管理依赖**
159
-
160
- ```bash
161
- # ✅ 安装依赖
162
- pnpm install
163
-
164
- # ✅ 添加新依赖
165
- pnpm add package-name
166
-
167
- # ✅ 添加开发依赖
168
- pnpm add -D package-name
169
-
170
- # ❌ 禁止使用 npm 或 yarn
171
- # npm install # 错误!
172
- # yarn add # 错误!
173
- ```
174
-
175
- 项目已配置 `preinstall` 脚本,使用其他包管理器会报错。
176
-
177
- ### 4. 样式开发
178
-
179
- **使用 Tailwind CSS v4**
180
-
181
- 本项目使用 Tailwind CSS v4 进行样式开发,并已配置 shadcn 主题变量。
182
-
183
- ```tsx
184
- // 使用 Tailwind 类名
185
- <div className="flex items-center gap-4 p-4 rounded-lg bg-background">
186
- <Button className="bg-primary text-primary-foreground">
187
- 主要按钮
188
- </Button>
189
- </div>
190
-
191
- // 使用 cn() 工具函数合并类名
192
- import { cn } from '@/lib/utils';
193
-
194
- <div className={cn(
195
- "base-class",
196
- condition && "conditional-class",
197
- className
198
- )}>
199
- 内容
200
- </div>
201
- ```
202
-
203
- **主题变量**
204
-
205
- 主题变量定义在 `src/app/globals.css` 中,支持亮色/暗色模式:
206
-
207
- - `--background`, `--foreground`
208
- - `--primary`, `--primary-foreground`
209
- - `--secondary`, `--secondary-foreground`
210
- - `--muted`, `--muted-foreground`
211
- - `--accent`, `--accent-foreground`
212
- - `--destructive`, `--destructive-foreground`
213
- - `--border`, `--input`, `--ring`
214
-
215
- ### 5. 表单开发
216
-
217
- 推荐使用 `react-hook-form` + `zod` 进行表单开发:
218
-
219
- ```tsx
220
- import { useForm } from 'react-hook-form';
221
- import { zodResolver } from '@hookform/resolvers/zod';
222
- import * as z from 'zod';
223
- import { Button } from '@/components/ui/button';
224
- import { Input } from '@/components/ui/input';
225
-
226
- const formSchema = z.object({
227
- username: z.string().min(2, '用户名至少 2 个字符'),
228
- email: z.string().email('请输入有效的邮箱'),
229
- });
230
-
231
- export default function MyForm() {
232
- const form = useForm({
233
- resolver: zodResolver(formSchema),
234
- defaultValues: { username: '', email: '' },
235
- });
236
-
237
- const onSubmit = (data: z.infer<typeof formSchema>) => {
238
- console.log(data);
239
- };
240
-
241
- return (
242
- <form onSubmit={form.handleSubmit(onSubmit)}>
243
- <Input {...form.register('username')} />
244
- <Input {...form.register('email')} />
245
- <Button type="submit">提交</Button>
246
- </form>
247
- );
248
- }
249
- ```
250
-
251
- ### 6. 数据获取
252
-
253
- **服务端组件(推荐)**
254
-
255
- ```tsx
256
- // src/app/posts/page.tsx
257
- async function getPosts() {
258
- const res = await fetch('https://api.example.com/posts', {
259
- cache: 'no-store', // 或 'force-cache'
260
- });
261
- return res.json();
262
- }
263
-
264
- export default async function PostsPage() {
265
- const posts = await getPosts();
266
-
267
- return (
268
- <div>
269
- {posts.map(post => (
270
- <div key={post.id}>{post.title}</div>
271
- ))}
272
- </div>
273
- );
274
- }
275
- ```
276
-
277
- **客户端组件**
278
-
279
- ```tsx
280
- 'use client';
281
-
282
- import { useEffect, useState } from 'react';
283
-
284
- export default function ClientComponent() {
285
- const [data, setData] = useState(null);
286
-
287
- useEffect(() => {
288
- fetch('/api/data')
289
- .then(res => res.json())
290
- .then(setData);
291
- }, []);
292
-
293
- return <div>{JSON.stringify(data)}</div>;
294
- }
295
- ```
296
-
297
- ## 常见开发场景
298
-
299
- ### 添加新页面
300
-
301
- 1. 在 `src/app/` 下创建文件夹和 `page.tsx`
302
- 2. 使用 shadcn 组件构建 UI
303
- 3. 根据需要添加 `layout.tsx` 和 `loading.tsx`
304
-
305
- ### 创建业务组件
306
-
307
- 1. 在 `src/components/` 下创建组件文件(非 UI 组件)
308
- 2. 优先组合使用 `src/components/ui/` 中的基础组件
309
- 3. 使用 TypeScript 定义 Props 类型
310
-
311
- ### 添加全局状态
312
-
313
- 推荐使用 React Context 或 Zustand:
314
-
315
- ```tsx
316
- // src/lib/store.ts
317
- import { create } from 'zustand';
318
-
319
- interface Store {
320
- count: number;
321
- increment: () => void;
322
- }
323
-
324
- export const useStore = create<Store>((set) => ({
325
- count: 0,
326
- increment: () => set((state) => ({ count: state.count + 1 })),
327
- }));
328
- ```
329
-
330
- ### 集成数据库
331
-
332
- 推荐使用 Prisma 或 Drizzle ORM,在 `src/lib/db.ts` 中配置。
333
-
334
- ## 技术栈
335
-
336
- - **框架**: Next.js 16.1.1 (App Router)
337
- - **UI 组件**: shadcn/ui (基于 Radix UI)
338
- - **样式**: Tailwind CSS v4
339
- - **表单**: React Hook Form + Zod
340
- - **图标**: Lucide React
341
- - **字体**: Geist Sans & Geist Mono
342
- - **包管理器**: pnpm 9+
343
- - **TypeScript**: 5.x
344
-
345
- ## 参考文档
346
-
347
- - [Next.js 官方文档](https://nextjs.org/docs)
348
- - [shadcn/ui 组件文档](https://ui.shadcn.com)
349
- - [Tailwind CSS 文档](https://tailwindcss.com/docs)
350
- - [React Hook Form](https://react-hook-form.com)
351
-
352
- ## 重要提示
353
-
354
- 1. **必须使用 pnpm** 作为包管理器
355
- 2. **优先使用 shadcn/ui 组件** 而不是从零开发基础组件
356
- 3. **遵循 Next.js App Router 规范**,正确区分服务端/客户端组件
357
- 4. **使用 TypeScript** 进行类型安全开发
358
- 5. **使用 `@/` 路径别名** 导入模块(已配置)
 
1
+ ---
2
+ title: Ai
3
+ emoji: 🔥
4
+ colorFrom: red
5
+ colorTo: green
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md-web ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # projects
2
+
3
+ 这是一个基于 [Next.js 16](https://nextjs.org) + [shadcn/ui](https://ui.shadcn.com) 的全栈应用项目,由扣子编程 CLI 创建。
4
+
5
+ ## 快速开始
6
+
7
+ ### 启动开发服务器
8
+
9
+ ```bash
10
+ coze dev
11
+ ```
12
+
13
+ 启动后,在浏览器中打开 [http://localhost:5000](http://localhost:5000) 查看应用。
14
+
15
+ 开发服务器支持热更新,修改代码后页面会自动刷新。
16
+
17
+ ### 构建生产版本
18
+
19
+ ```bash
20
+ coze build
21
+ ```
22
+
23
+ ### 启动生产服务器
24
+
25
+ ```bash
26
+ coze start
27
+ ```
28
+
29
+ ## 项目结构
30
+
31
+ ```
32
+ src/
33
+ ├── app/ # Next.js App Router 目录
34
+ │ ├── layout.tsx # 根布局组件
35
+ │ ├── page.tsx # 首页
36
+ │ ├── globals.css # 全局样式(包含 shadcn 主题变量)
37
+ │ └── [route]/ # 其他路由页面
38
+ ├── components/ # React 组件目录
39
+ │ └── ui/ # shadcn/ui 基础组件(优先使用)
40
+ │ ├── button.tsx
41
+ │ ├── card.tsx
42
+ │ └── ...
43
+ ├── lib/ # 工具函数库
44
+ │ └── utils.ts # cn() 等工具函数
45
+ └── hooks/ # 自定义 React Hooks(可选)
46
+ ```
47
+
48
+ ## 核心开发规范
49
+
50
+ ### 1. 组件开发
51
+
52
+ **优先使用 shadcn/ui 基础组件**
53
+
54
+ 本项目已预装完整的 shadcn/ui 组件库,位于 `src/components/ui/` 目录。开发时应优先使用这些组件作为基础:
55
+
56
+ ```tsx
57
+ // ✅ 推荐:使用 shadcn 基础组件
58
+ import { Button } from '@/components/ui/button';
59
+ import { Card, CardContent, CardHeader } from '@/components/ui/card';
60
+ import { Input } from '@/components/ui/input';
61
+
62
+ export default function MyComponent() {
63
+ return (
64
+ <Card>
65
+ <CardHeader>标题</CardHeader>
66
+ <CardContent>
67
+ <Input placeholder="输入内容" />
68
+ <Button>提交</Button>
69
+ </CardContent>
70
+ </Card>
71
+ );
72
+ }
73
+ ```
74
+
75
+ **可用的 shadcn 组件清单**
76
+
77
+ - 表单:`button`, `input`, `textarea`, `select`, `checkbox`, `radio-group`, `switch`, `slider`
78
+ - 布局:`card`, `separator`, `tabs`, `accordion`, `collapsible`, `scroll-area`
79
+ - 反馈:`alert`, `alert-dialog`, `dialog`, `toast`, `sonner`, `progress`
80
+ - 导航:`dropdown-menu`, `menubar`, `navigation-menu`, `context-menu`
81
+ - 数据展示:`table`, `avatar`, `badge`, `hover-card`, `tooltip`, `popover`
82
+ - 其他:`calendar`, `command`, `carousel`, `resizable`, `sidebar`
83
+
84
+ 详见 `src/components/ui/` 目录下的具体组件实现。
85
+
86
+ ### 2. 路由开发
87
+
88
+ Next.js 使用文件系统路由,在 `src/app/` 目录下创建文件夹即可添加路由:
89
+
90
+ ```bash
91
+ # 创建新路由 /about
92
+ src/app/about/page.tsx
93
+
94
+ # 创建动态路由 /posts/[id]
95
+ src/app/posts/[id]/page.tsx
96
+
97
+ # 创建路由组(不影响 URL)
98
+ src/app/(marketing)/about/page.tsx
99
+
100
+ # 创建 API 路由
101
+ src/app/api/users/route.ts
102
+ ```
103
+
104
+ **页面组件示例**
105
+
106
+ ```tsx
107
+ // src/app/about/page.tsx
108
+ import { Button } from '@/components/ui/button';
109
+
110
+ export const metadata = {
111
+ title: '关于我们',
112
+ description: '关于页面描述',
113
+ };
114
+
115
+ export default function AboutPage() {
116
+ return (
117
+ <div>
118
+ <h1>关于我们</h1>
119
+ <Button>了解更多</Button>
120
+ </div>
121
+ );
122
+ }
123
+ ```
124
+
125
+ **动态路由示例**
126
+
127
+ ```tsx
128
+ // src/app/posts/[id]/page.tsx
129
+ export default async function PostPage({
130
+ params,
131
+ }: {
132
+ params: Promise<{ id: string }>;
133
+ }) {
134
+ const { id } = await params;
135
+
136
+ return <div>文章 ID: {id}</div>;
137
+ }
138
+ ```
139
+
140
+ **API 路由示例**
141
+
142
+ ```tsx
143
+ // src/app/api/users/route.ts
144
+ import { NextResponse } from 'next/server';
145
+
146
+ export async function GET() {
147
+ return NextResponse.json({ users: [] });
148
+ }
149
+
150
+ export async function POST(request: Request) {
151
+ const body = await request.json();
152
+ return NextResponse.json({ success: true });
153
+ }
154
+ ```
155
+
156
+ ### 3. 依赖管理
157
+
158
+ **必须使用 pnpm 管理依赖**
159
+
160
+ ```bash
161
+ # ✅ 安装依赖
162
+ pnpm install
163
+
164
+ # ✅ 添加新依赖
165
+ pnpm add package-name
166
+
167
+ # ✅ 添加开发依赖
168
+ pnpm add -D package-name
169
+
170
+ # ❌ 禁止使用 npm 或 yarn
171
+ # npm install # 错误!
172
+ # yarn add # 错误!
173
+ ```
174
+
175
+ 项目已配置 `preinstall` 脚本,使用其他包管理器会报错。
176
+
177
+ ### 4. 样式开发
178
+
179
+ **使用 Tailwind CSS v4**
180
+
181
+ 本项目使用 Tailwind CSS v4 进行样式开发,并已配置 shadcn 主题变量。
182
+
183
+ ```tsx
184
+ // 使用 Tailwind 类名
185
+ <div className="flex items-center gap-4 p-4 rounded-lg bg-background">
186
+ <Button className="bg-primary text-primary-foreground">
187
+ 主要按钮
188
+ </Button>
189
+ </div>
190
+
191
+ // 使用 cn() 工具函数合并类名
192
+ import { cn } from '@/lib/utils';
193
+
194
+ <div className={cn(
195
+ "base-class",
196
+ condition && "conditional-class",
197
+ className
198
+ )}>
199
+ 内容
200
+ </div>
201
+ ```
202
+
203
+ **主题变量**
204
+
205
+ 主题变量定义在 `src/app/globals.css` 中,支持亮色/暗色模式:
206
+
207
+ - `--background`, `--foreground`
208
+ - `--primary`, `--primary-foreground`
209
+ - `--secondary`, `--secondary-foreground`
210
+ - `--muted`, `--muted-foreground`
211
+ - `--accent`, `--accent-foreground`
212
+ - `--destructive`, `--destructive-foreground`
213
+ - `--border`, `--input`, `--ring`
214
+
215
+ ### 5. 表单开发
216
+
217
+ 推荐使用 `react-hook-form` + `zod` 进行表单开发:
218
+
219
+ ```tsx
220
+ import { useForm } from 'react-hook-form';
221
+ import { zodResolver } from '@hookform/resolvers/zod';
222
+ import * as z from 'zod';
223
+ import { Button } from '@/components/ui/button';
224
+ import { Input } from '@/components/ui/input';
225
+
226
+ const formSchema = z.object({
227
+ username: z.string().min(2, '用户名至少 2 个字符'),
228
+ email: z.string().email('请输入有效的邮箱'),
229
+ });
230
+
231
+ export default function MyForm() {
232
+ const form = useForm({
233
+ resolver: zodResolver(formSchema),
234
+ defaultValues: { username: '', email: '' },
235
+ });
236
+
237
+ const onSubmit = (data: z.infer<typeof formSchema>) => {
238
+ console.log(data);
239
+ };
240
+
241
+ return (
242
+ <form onSubmit={form.handleSubmit(onSubmit)}>
243
+ <Input {...form.register('username')} />
244
+ <Input {...form.register('email')} />
245
+ <Button type="submit">提交</Button>
246
+ </form>
247
+ );
248
+ }
249
+ ```
250
+
251
+ ### 6. 数据获取
252
+
253
+ **服务端组件(推荐)**
254
+
255
+ ```tsx
256
+ // src/app/posts/page.tsx
257
+ async function getPosts() {
258
+ const res = await fetch('https://api.example.com/posts', {
259
+ cache: 'no-store', // 或 'force-cache'
260
+ });
261
+ return res.json();
262
+ }
263
+
264
+ export default async function PostsPage() {
265
+ const posts = await getPosts();
266
+
267
+ return (
268
+ <div>
269
+ {posts.map(post => (
270
+ <div key={post.id}>{post.title}</div>
271
+ ))}
272
+ </div>
273
+ );
274
+ }
275
+ ```
276
+
277
+ **客户端组件**
278
+
279
+ ```tsx
280
+ 'use client';
281
+
282
+ import { useEffect, useState } from 'react';
283
+
284
+ export default function ClientComponent() {
285
+ const [data, setData] = useState(null);
286
+
287
+ useEffect(() => {
288
+ fetch('/api/data')
289
+ .then(res => res.json())
290
+ .then(setData);
291
+ }, []);
292
+
293
+ return <div>{JSON.stringify(data)}</div>;
294
+ }
295
+ ```
296
+
297
+ ## 常见开发场景
298
+
299
+ ### 添加新页面
300
+
301
+ 1. 在 `src/app/` 下创建文件夹和 `page.tsx`
302
+ 2. 使用 shadcn 组件构建 UI
303
+ 3. 根据需要添加 `layout.tsx` 和 `loading.tsx`
304
+
305
+ ### 创建业务组件
306
+
307
+ 1. 在 `src/components/` 下创建组件文件(非 UI 组件)
308
+ 2. 优先组合使用 `src/components/ui/` 中的基础组件
309
+ 3. 使用 TypeScript 定义 Props 类型
310
+
311
+ ### 添加全局状态
312
+
313
+ 推荐使用 React Context 或 Zustand:
314
+
315
+ ```tsx
316
+ // src/lib/store.ts
317
+ import { create } from 'zustand';
318
+
319
+ interface Store {
320
+ count: number;
321
+ increment: () => void;
322
+ }
323
+
324
+ export const useStore = create<Store>((set) => ({
325
+ count: 0,
326
+ increment: () => set((state) => ({ count: state.count + 1 })),
327
+ }));
328
+ ```
329
+
330
+ ### 集成数据库
331
+
332
+ 推荐使用 Prisma 或 Drizzle ORM,在 `src/lib/db.ts` 中配置。
333
+
334
+ ## 技术栈
335
+
336
+ - **框架**: Next.js 16.1.1 (App Router)
337
+ - **UI 组件**: shadcn/ui (基于 Radix UI)
338
+ - **样式**: Tailwind CSS v4
339
+ - **表单**: React Hook Form + Zod
340
+ - **图标**: Lucide React
341
+ - **字体**: Geist Sans & Geist Mono
342
+ - **包管理器**: pnpm 9+
343
+ - **TypeScript**: 5.x
344
+
345
+ ## 参考文档
346
+
347
+ - [Next.js 官方文档](https://nextjs.org/docs)
348
+ - [shadcn/ui 组件文档](https://ui.shadcn.com)
349
+ - [Tailwind CSS 文档](https://tailwindcss.com/docs)
350
+ - [React Hook Form](https://react-hook-form.com)
351
+
352
+ ## 重要提示
353
+
354
+ 1. **必须使用 pnpm** 作为包管理器
355
+ 2. **优先使用 shadcn/ui 组件** 而不是从零开发基础组件
356
+ 3. **遵循 Next.js App Router 规范**,正确区分服务端/客户端组件
357
+ 4. **使用 TypeScript** 进行类型安全开发
358
+ 5. **使用 `@/` 路径别名** 导入模块(已配置)