From 4c81148df89406073647f326bb2a3f90983c2ff9 Mon Sep 17 00:00:00 2001 From: imbytecat Date: Sat, 17 Jan 2026 02:59:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BE=85=E5=8A=9E?= =?UTF-8?q?=E4=BA=8B=E9=A1=B9=E5=88=97=E8=A1=A8=E5=8A=9F=E8=83=BD=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将运行时环境变量源从 import.meta.env 更新为 process.env。 - 添加待办事项列表功能,包含进度条、任务状态显示、完成统计和响应式界面设计。 --- src/env.ts | 2 +- src/routes/todo.tsx | 181 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 179 insertions(+), 4 deletions(-) diff --git a/src/env.ts b/src/env.ts index 2465614..e8825d9 100644 --- a/src/env.ts +++ b/src/env.ts @@ -9,6 +9,6 @@ export const env = createEnv({ client: { VITE_APP_TITLE: z.string().min(1).optional(), }, - runtimeEnv: import.meta.env, + runtimeEnv: process.env, emptyStringAsUndefined: true, }) diff --git a/src/routes/todo.tsx b/src/routes/todo.tsx index 4128205..cc4531f 100644 --- a/src/routes/todo.tsx +++ b/src/routes/todo.tsx @@ -1,9 +1,9 @@ +import { useSuspenseQuery } from '@tanstack/react-query' import { createFileRoute } from '@tanstack/react-router' import { createServerFn } from '@tanstack/react-start' import { db } from '@/db' -import { todoTable } from '@/db/schema' -const getTodos = createServerFn().handler(async () => { +const getTodos = createServerFn({ method: 'GET' }).handler(async () => { const todos = await db.query.todoTable.findMany() return todos }) @@ -13,5 +13,180 @@ export const Route = createFileRoute('/todo')({ }) function Todo() { - return
Hello "/todo"!
+ const { data: todos } = useSuspenseQuery({ + queryKey: ['todos'], + queryFn: () => getTodos(), + }) + + const completedCount = todos.filter((todo) => todo.completed).length + const totalCount = todos.length + + return ( +
+
+ {/* Header */} +
+

+ 我的待办事项 +

+

+ 已完成 {completedCount} / {totalCount} 项任务 +

+
+ + {/* Progress Bar */} +
+
+ 完成进度 + + {totalCount > 0 + ? Math.round((completedCount / totalCount) * 100) + : 0} + % + +
+
+
0 ? (completedCount / totalCount) * 100 : 0}%`, + }} + /> +
+
+ + {/* Todo List */} +
+ {todos.length === 0 ? ( +
+
+ +
+

暂无待办事项

+

+ 添加你的第一个任务开始吧! +

+
+ ) : ( + todos.map((todo) => ( +
+
+ {/* Checkbox */} +
+
+ {todo.completed && ( + + )} +
+
+ + {/* Todo Content */} +
+

+ {todo.title} +

+
+ + + {new Date(todo.createdAt).toLocaleDateString('zh-CN')} + +
+
+ + {/* Status Badge */} +
+ + {todo.completed ? '已完成' : '进行中'} + +
+
+
+ )) + )} +
+ + {/* Footer Stats */} + {todos.length > 0 && ( +
+
+

+ {totalCount - completedCount} +

+

待完成

+
+
+

+ {completedCount} +

+

已完成

+
+
+ )} +
+
+ ) }