mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
✨ 更新(Category/index.tsx): 优化快捷操作按钮的展示
✨ 更新(Category/index.tsx): 调整导航栏样式 ✨ 更新(ContentListLoader.ts): 优化SQL查询逻辑 ♻️ 重构(ContentList/index.tsx): 精简代码 ♻️ 重构(router/index.tsx): 更新路由配置中的路径匹配逻辑
This commit is contained in:
@@ -7,17 +7,22 @@ export const Category = () => {
|
||||
return (
|
||||
<main className="category-page">
|
||||
<div className="categories">
|
||||
{/* 加 end 是避免子路由被选中时,父路由也被选中 */}
|
||||
<NavLink to={`/config/category/contentList`} end>
|
||||
<AllApplication theme="outline" size="22" strokeWidth={3}/>
|
||||
<div className="truncate">所有内容</div>
|
||||
<div className="px-2 mt-2 opacity-90 mb-1">快捷操作</div>
|
||||
{/* 加 end 表示路径完全匹配时,才会被选中 */}
|
||||
<NavLink to={`/config/category/contentList`} end className="font-blod mb-1">
|
||||
<div className="flex items-center gap-1">
|
||||
<AllApplication theme="outline" size="12" strokeWidth={3}/>
|
||||
<div className="truncate">所有内容</div>
|
||||
</div>
|
||||
</NavLink>
|
||||
{categories.map((category) => (
|
||||
<NavLink
|
||||
to={`/config/category/contentList/${category.id}`}
|
||||
key={category.id} >
|
||||
<div className="flex items-center gap-1">
|
||||
<FolderClose theme="outline" size="12" strokeWidth={3}></FolderClose>
|
||||
<div className="truncate">{category.name}</div>
|
||||
</div>
|
||||
</NavLink>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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 (<main className="contentList-page">
|
||||
<div className="list">
|
||||
{contentList.map(content => (
|
||||
|
||||
@@ -30,7 +30,7 @@ const router = createHashRouter([
|
||||
element: <Welcome />
|
||||
},
|
||||
{
|
||||
path: "contentList/:cid",
|
||||
path: "contentList/:cid?",
|
||||
loader: ContentListLoader,
|
||||
element: <ContentList />,
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user