From 57c164560b40da6de51976ff277faf89356bb31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E9=98=B3?= Date: Sun, 15 Mar 2026 12:21:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=88api=EF=BC=89?= =?UTF-8?q?=EF=BC=9A=E6=9B=B4=E6=96=B0=E6=96=87=E7=AB=A0=E5=92=8C=E5=88=86?= =?UTF-8?q?=E7=B1=BB=20API=20=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20GET=20=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将文章列表和分页 API 方法从 POST 改为 GET,以提高清晰度和性能。 - 更新了 RSS 路由和 ArticleLayout 组件中的 API 调用结构,以反映新的方法签名。 --- src/api/article.ts | 7 ++++--- src/api/cate.ts | 2 +- src/app/api/rss/route.ts | 2 +- src/components/ArticleLayout/index.tsx | 8 +++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/api/article.ts b/src/api/article.ts index b4ceadf..16f1fd6 100755 --- a/src/api/article.ts +++ b/src/api/article.ts @@ -8,12 +8,13 @@ export const getArticleDataAPI = async (id: number, password?: string) => { // 获取文章列表 export const getArticleListAPI = async () => { - return await Request('POST', `/article/list`); + return await Request('GET', `/article?page=1&size=9999999999`,); } // 分页获取文章数据 -export const getArticlePagingAPI = async (data: QueryData) => { - return await Request>('POST', `/article/paging?page=${data.pagination?.page}&size=${data.pagination?.size ? data.pagination?.size : 8}`, data.query); +export const getArticlePagingAPI = async (data: { page: number, size: number, key?: string }) => { + // 搜索暂时,晚点修复,先上线 + return await Request>('GET', `/article?page=${data.page}&size=${data.size}`); } // 获取随机文章列表 diff --git a/src/api/cate.ts b/src/api/cate.ts index f10ef5c..6468d0a 100755 --- a/src/api/cate.ts +++ b/src/api/cate.ts @@ -4,7 +4,7 @@ import Request from '@/utils/request' // 获取分类列表 export const getCateListAPI = async () => { - return await Request('POST', '/cate/list') + return await Request('GET', '/cate?pattern=tree') } // 获取指定分类中的所有文章 diff --git a/src/app/api/rss/route.ts b/src/app/api/rss/route.ts index 91af844..e64a3d8 100755 --- a/src/app/api/rss/route.ts +++ b/src/app/api/rss/route.ts @@ -12,7 +12,7 @@ export async function GET() { const webResponse = await getWebConfigDataAPI<{ value: Web }>('web'); const web = webResponse?.data?.value as Web; const { data: user } = await getAuthorDataAPI(); - const { data: article } = await getArticlePagingAPI({ pagination: { page: 1, size: 8 } }); + const { data: article } = await getArticlePagingAPI({ page: 1, size: 8 }); const { data: record } = await getRecordPagingAPI({ pagination: { page: 1, size: 8 } }); const articleList = article?.result ?? []; diff --git a/src/components/ArticleLayout/index.tsx b/src/components/ArticleLayout/index.tsx index 5f96089..3219acb 100755 --- a/src/components/ArticleLayout/index.tsx +++ b/src/components/ArticleLayout/index.tsx @@ -18,10 +18,8 @@ export default async ({ page }: { page: number }) => { // 如果是瀑布流布局就显示28条数据,否则显示8条 const { data } = await getArticlePagingAPI({ - pagination: { - page, - size: theme.is_article_layout === 'waterfall' ? 28 : 8 - } + page, + size: theme.is_article_layout === 'waterfall' ? 28 : 8 }); // 过滤掉不显示在首页的文章 data.result = data?.result?.filter((item) => item.config.status !== 'no_home') ?? []; @@ -35,7 +33,7 @@ export default async ({ page }: { page: number }) => { {theme.is_article_layout === 'card' && } {theme.is_article_layout === 'waterfall' && } - {data.total && } + {!!data.total && } ); };