From 754939aec433d41e67d17e90b8bf577ff07fa6a6 Mon Sep 17 00:00:00 2001 From: yuruo Date: Tue, 18 Jun 2024 17:14:46 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=9B=B4=E6=96=B0(Category/index.t?= =?UTF-8?q?sx):=20=E4=BC=98=E5=8C=96=E5=BF=AB=E6=8D=B7=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E7=9A=84=E5=B1=95=E7=A4=BA=20=E2=9C=A8=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0(Category/index.tsx):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E6=A0=8F=E6=A0=B7=E5=BC=8F=20=E2=9C=A8=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0(ContentListLoader.ts):=20=E4=BC=98=E5=8C=96S?= =?UTF-8?q?QL=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91=20=E2=99=BB=EF=B8=8F=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84(ContentList/index.tsx):=20=E7=B2=BE=E7=AE=80?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=20=E2=99=BB=EF=B8=8F=20=E9=87=8D=E6=9E=84(ro?= =?UTF-8?q?uter/index.tsx):=20=E6=9B=B4=E6=96=B0=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=AD=E7=9A=84=E8=B7=AF=E5=BE=84=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/renderer/src/pages/Category/index.tsx | 13 +++++++++---- .../src/pages/ContentList/ContentListLoader.ts | 7 ++++++- .../src/renderer/src/pages/ContentList/index.tsx | 9 +-------- ui/autoMate/src/renderer/src/router/index.tsx | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ui/autoMate/src/renderer/src/pages/Category/index.tsx b/ui/autoMate/src/renderer/src/pages/Category/index.tsx index bd741c6..cbee85a 100644 --- a/ui/autoMate/src/renderer/src/pages/Category/index.tsx +++ b/ui/autoMate/src/renderer/src/pages/Category/index.tsx @@ -7,17 +7,22 @@ export const Category = () => { return (
- {/* 加 end 是避免子路由被选中时,父路由也被选中 */} - - -
所有内容
+
快捷操作
+ {/* 加 end 表示路径完全匹配时,才会被选中 */} + +
+ +
所有内容
+
{categories.map((category) => ( +
{category.name}
+
))}
diff --git a/ui/autoMate/src/renderer/src/pages/ContentList/ContentListLoader.ts b/ui/autoMate/src/renderer/src/pages/ContentList/ContentListLoader.ts index 9963786..1746dcc 100644 --- a/ui/autoMate/src/renderer/src/pages/ContentList/ContentListLoader.ts +++ b/ui/autoMate/src/renderer/src/pages/ContentList/ContentListLoader.ts @@ -1,4 +1,9 @@ export default async({params}) => { - const res = await window.api.sql(`select * from contents where category_id=${params.cid}`, "findAll") + let sql = "select * from contents" + if (params.cid) { + sql += ` where category_id=${params.cid}` + } + sql += " order by id desc" + const res = await window.api.sql(sql, "findAll") return res } \ No newline at end of file diff --git a/ui/autoMate/src/renderer/src/pages/ContentList/index.tsx b/ui/autoMate/src/renderer/src/pages/ContentList/index.tsx index 9a72287..73e7ebf 100644 --- a/ui/autoMate/src/renderer/src/pages/ContentList/index.tsx +++ b/ui/autoMate/src/renderer/src/pages/ContentList/index.tsx @@ -1,16 +1,9 @@ -import { NavLink, Outlet, useLoaderData, useNavigate } from "react-router-dom" +import { NavLink, Outlet, useLoaderData} from "react-router-dom" import "./contentList.scss" -import { useEffect } from "react" import dayjs from "dayjs" export const ContentList = () => { const contentList = useLoaderData() as ContentType[] - // const navigate = useNavigate() - // useEffect(() => { - // if (contentList) { - // navigate(`/config/category/contentList/${contentList[0].category_id}/content/${contentList[0].id}`) - // } - // }, [contentList]) return (
{contentList.map(content => ( diff --git a/ui/autoMate/src/renderer/src/router/index.tsx b/ui/autoMate/src/renderer/src/router/index.tsx index 186ee92..440f752 100644 --- a/ui/autoMate/src/renderer/src/router/index.tsx +++ b/ui/autoMate/src/renderer/src/router/index.tsx @@ -30,7 +30,7 @@ const router = createHashRouter([ element: }, { - path: "contentList/:cid", + path: "contentList/:cid?", loader: ContentListLoader, element: , children: [