mirror of
https://github.com/LiuYuYang01/ThriveX-Blog.git
synced 2026-06-06 13:49:11 +08:00
refactor: 统一分页参数命名为pageNum和pageSize
1. 重构了分页相关的类型定义,将原page、size改为pageNum、pageSize 2. 更新所有接口调用和实现,替换旧的分页参数名 3. 调整了评论相关API的参数默认值和请求格式 4. 重命名了说说列表的API函数名以保持语义一致
This commit is contained in:
@@ -12,9 +12,9 @@ export const getArticleListAPI = async () => {
|
||||
}
|
||||
|
||||
// 分页获取文章数据
|
||||
export const getArticlePagingAPI = async (data: { page: number, size: number, key?: string }) => {
|
||||
export const getArticlePagingAPI = async (data: Page & { key?: string }) => {
|
||||
return await Request<Paginate<Article[]>>('GET', `/article`, {
|
||||
params: { page: data.page, size: data.size, key: data.key }
|
||||
params: { pageNum: data.pageNum, pageSize: data.pageSize, key: data.key }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,22 @@ export const addCommentDataAPI = async (data: Comment) => {
|
||||
return await Request('POST', `/comment`, data);
|
||||
}
|
||||
|
||||
|
||||
// 获取评论列表
|
||||
export const getCommentListAPI = () => Request<Paginate<Comment[]>>('GET', `/comment`)
|
||||
export const getCommentListAPI = async (paginate?: Page) => {
|
||||
return await Request<Paginate<Comment[]>>('GET', `/comment`, {
|
||||
params: paginate ? {
|
||||
pageNum: paginate.pageNum ?? 1,
|
||||
pageSize: paginate.pageSize ?? 5,
|
||||
} : {}
|
||||
});
|
||||
}
|
||||
|
||||
// 获取当前文章中所有评论
|
||||
export const getArticleCommentListAPI = async (articleId: number, paginate: Page) => {
|
||||
return await Request<Paginate<Comment[]>>('POST', `/comment/article/${articleId}?page=${paginate.page}&pageSize=${paginate.size}`);
|
||||
export const getArticleCommentListAPI = async (articleId: number, paginate?: Page) => {
|
||||
return await Request<Paginate<Comment[]>>('POST', `/comment/article/${articleId}`, {
|
||||
params: paginate ? {
|
||||
pageNum: paginate.pageNum ?? 1,
|
||||
pageSize: paginate.pageSize ?? 5,
|
||||
} : {}
|
||||
});
|
||||
}
|
||||
@@ -2,6 +2,4 @@ import { Request } from '@/utils'
|
||||
import { Record } from '@/types/app/record'
|
||||
|
||||
// 分页获取说说列表
|
||||
export const getRecordPagingAPI = (params?: Page) => Request<Paginate<Record[]>>('GET', `/record`, { params })
|
||||
|
||||
// export const getRecordPagingAPI = (data?: QueryData) => Request<Paginate<Record[]>>('GET', `/record?page=${data?.pagination?.page}&size=${data?.pagination?.size ? data.pagination?.size : 8}`)
|
||||
export const getRecordListAPI = (params?: Page) => Request<Paginate<Record[]>>('GET', `/record`, { params })
|
||||
|
||||
@@ -6,14 +6,14 @@ import { Web } from '@/types/app/config';
|
||||
import { getArticlePagingAPI } from '@/api/article';
|
||||
import { getWebConfigDataAPI } from '@/api/config';
|
||||
import { getAuthorDataAPI } from '@/api/user';
|
||||
import { getRecordPagingAPI } from '@/api/record';
|
||||
import { getRecordListAPI } from '@/api/record';
|
||||
|
||||
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({ page: 1, size: 8 });
|
||||
const { data: record } = await getRecordPagingAPI({ page: 1, size: 8 });
|
||||
const { data: article } = await getArticlePagingAPI({ pageNum: 1, pageSize: 8 });
|
||||
const { data: record } = await getRecordListAPI({ pageNum: 1, pageSize: 8 });
|
||||
|
||||
const articleList = article?.result ?? [];
|
||||
const recordList = record?.result ?? [];
|
||||
|
||||
@@ -20,7 +20,7 @@ interface Props {
|
||||
const CommentList = forwardRef(({ id, reply }: Props, ref) => {
|
||||
const [data, setData] = useState<Paginate<Comment[]>>({} as Paginate<Comment[]>);
|
||||
const getCommentList = async (page: number = 1) => {
|
||||
const { data } = await getArticleCommentListAPI(+id!, { page, size: 8 });
|
||||
const { data } = await getArticleCommentListAPI(+id!, { pageNum: page, pageSize: 8 });
|
||||
setData(data);
|
||||
};
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ export default async (props: Props) => {
|
||||
const page = +(searchParams.page ?? 1);
|
||||
const name = searchParams.name;
|
||||
|
||||
const { data } = await getCateArticleListAPI(id, { page, size: 8 });
|
||||
const { data } = await getCateArticleListAPI(id, { pageNum: page, pageSize: 8 });
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import RecordCard from './components/RecordCard';
|
||||
import { getRecordPagingAPI } from '@/api/record';
|
||||
import { getRecordListAPI } from '@/api/record';
|
||||
import { getAuthorDataAPI } from '@/api/user';
|
||||
import { Record } from '@/types/app/record';
|
||||
import { User } from '@/types/app/user';
|
||||
@@ -26,7 +26,7 @@ export default () => {
|
||||
const fetchRecordList = useCallback(async (page: number, append: boolean = false) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const { data: recordData } = await getRecordPagingAPI({ page, size: 8 });
|
||||
const { data: recordData } = await getRecordListAPI({ pageNum: page, pageSize: 8 });
|
||||
|
||||
if (recordData?.result && recordData?.result?.length > 0) {
|
||||
if (append) {
|
||||
|
||||
@@ -16,7 +16,7 @@ export default async (props: Props) => {
|
||||
const page = searchParams.page ?? 1;
|
||||
const name = searchParams.name;
|
||||
|
||||
const { data } = await getTagArticleListAPI(id, { page, size: 8 });
|
||||
const { data } = await getTagArticleListAPI(id, { pageNum: page, pageSize: 8 });
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -48,8 +48,8 @@ export default () => {
|
||||
setWalls(tallList?.result);
|
||||
}
|
||||
setTotalPages(tallList.pages || 1);
|
||||
setHasMore((params.page ?? 1) < (tallList.pages ?? 1));
|
||||
currentPageRef.current = params.page ?? 1;
|
||||
setHasMore((params.pageNum ?? 1) < (tallList.pages ?? 1));
|
||||
currentPageRef.current = params.pageSize ?? 1;
|
||||
} else {
|
||||
setHasMore(false);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ export default () => {
|
||||
setHasMore(true);
|
||||
setInitialLoading(true);
|
||||
currentPageRef.current = 1;
|
||||
getWallList({ page: 1, size: 8 }, false);
|
||||
getWallList({ pageNum: 1, pageSize: 8 }, false);
|
||||
}
|
||||
}, [cate, cateList, getWallList]);
|
||||
|
||||
@@ -89,7 +89,7 @@ export default () => {
|
||||
if (scrollTop + windowHeight >= documentHeight - 100) {
|
||||
const nextPage = currentPageRef.current + 1;
|
||||
if (nextPage <= totalPages) {
|
||||
getWallList({ page: nextPage, size: 8 }, true);
|
||||
getWallList({ pageNum: nextPage, pageSize: 8 }, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useState, useEffect, useRef } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { HiOutlineSpeakerphone } from 'react-icons/hi';
|
||||
import { FiChevronRight } from 'react-icons/fi';
|
||||
import { getRecordPagingAPI } from '@/api/record';
|
||||
import { getRecordListAPI } from '@/api/record';
|
||||
import { Record } from '@/types/app/record';
|
||||
import { extractText } from '@/utils';
|
||||
|
||||
@@ -20,7 +20,7 @@ export default function Dynamic({ className = '' }: { className?: string }) {
|
||||
|
||||
const getRecordList = async () => {
|
||||
try {
|
||||
const { data } = await getRecordPagingAPI({ page: 1, size: 8 });
|
||||
const { data } = await getRecordListAPI({ pageNum: 1, pageSize: 8 });
|
||||
setList(data?.result ?? []);
|
||||
} catch (error) {
|
||||
console.error('获取说说失败:', error);
|
||||
|
||||
@@ -15,11 +15,11 @@ export default async ({ page }: { page: number }) => {
|
||||
const themeResponse = await getWebConfigDataAPI<{ value: Theme }>('theme');
|
||||
const theme = themeResponse?.data?.value as Theme;
|
||||
const sidebar = theme?.right_sidebar ?? [];
|
||||
|
||||
|
||||
// 如果是瀑布流布局就显示28条数据,否则显示8条
|
||||
const { data } = await getArticlePagingAPI({
|
||||
page,
|
||||
size: theme.is_article_layout === 'waterfall' ? 28 : 8
|
||||
pageNum: page || 1,
|
||||
pageSize: theme.is_article_layout === 'waterfall' ? 28 : 8
|
||||
});
|
||||
// 过滤掉不显示在首页的文章
|
||||
data.result = data?.result?.filter((item) => item.config.status !== 'no_home') ?? [];
|
||||
|
||||
@@ -2,7 +2,7 @@ import HCaptcha from '@hcaptcha/react-hcaptcha';
|
||||
import { forwardRef, Ref } from 'react';
|
||||
import { useConfigStore } from '@/stores';
|
||||
|
||||
export default forwardRef(({ setToken }: { setToken: () => void }, ref: Ref<HCaptcha>) => {
|
||||
export default forwardRef(({ setToken }: { setToken: (token: string) => void }, ref: Ref<HCaptcha>) => {
|
||||
const config = useConfigStore();
|
||||
const sitekey = config?.other?.hcaptcha_key;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ const NewComments = () => {
|
||||
const [list, setList] = useState<Comment[]>([]);
|
||||
|
||||
const getCommentList = async () => {
|
||||
const { data } = await getCommentListAPI();
|
||||
const { data } = await getCommentListAPI({ pageNum: 1, pageSize: 5 });
|
||||
setList(data?.result ?? []);
|
||||
};
|
||||
|
||||
|
||||
4
src/types/response.d.ts
vendored
4
src/types/response.d.ts
vendored
@@ -15,8 +15,8 @@ interface Paginate<T> {
|
||||
}
|
||||
|
||||
interface Page {
|
||||
page?: number,
|
||||
size?: number,
|
||||
pageNum?: number,
|
||||
pageSize?: number,
|
||||
}
|
||||
|
||||
interface FilterData {
|
||||
|
||||
Reference in New Issue
Block a user