mirror of
https://github.com/LiuYuYang01/ThriveX-Blog.git
synced 2026-05-06 22:03:08 +08:00
重构(api):更新文章和分类 API 方法,使用 GET 请求
- 将文章列表和分页 API 方法从 POST 改为 GET,以提高清晰度和性能。 - 更新了 RSS 路由和 ArticleLayout 组件中的 API 调用结构,以反映新的方法签名。
This commit is contained in:
@@ -8,12 +8,13 @@ export const getArticleDataAPI = async (id: number, password?: string) => {
|
||||
|
||||
// 获取文章列表
|
||||
export const getArticleListAPI = async () => {
|
||||
return await Request<Article[]>('POST', `/article/list`);
|
||||
return await Request<Article[]>('GET', `/article?page=1&size=9999999999`,);
|
||||
}
|
||||
|
||||
// 分页获取文章数据
|
||||
export const getArticlePagingAPI = async (data: QueryData) => {
|
||||
return await Request<Paginate<Article[]>>('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<Paginate<Article[]>>('GET', `/article?page=${data.page}&size=${data.size}`);
|
||||
}
|
||||
|
||||
// 获取随机文章列表
|
||||
|
||||
@@ -4,7 +4,7 @@ import Request from '@/utils/request'
|
||||
|
||||
// 获取分类列表
|
||||
export const getCateListAPI = async () => {
|
||||
return await Request<Cate[]>('POST', '/cate/list')
|
||||
return await Request<Cate[]>('GET', '/cate?pattern=tree')
|
||||
}
|
||||
|
||||
// 获取指定分类中的所有文章
|
||||
|
||||
@@ -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 ?? [];
|
||||
|
||||
@@ -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' && <Card data={data} />}
|
||||
{theme.is_article_layout === 'waterfall' && <Waterfall data={data} />}
|
||||
|
||||
{data.total && <Pagination total={data?.pages} page={page} className="flex justify-center mt-5" />}
|
||||
{!!data.total && <Pagination total={data?.pages} page={page} className="flex justify-center mt-5" />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user