|
1 | 1 | import { LanguageTranslationMap } from '@/constants/common'; |
| 2 | +import { Pagination } from '@/interfaces/common'; |
2 | 3 | import { IKnowledgeFile } from '@/interfaces/database/knowledge'; |
3 | 4 | import { IChangeParserConfigRequestBody } from '@/interfaces/request/document'; |
4 | | -import { useCallback, useState } from 'react'; |
| 5 | +import { PaginationProps } from 'antd'; |
| 6 | +import { useCallback, useMemo, useState } from 'react'; |
5 | 7 | import { useTranslation } from 'react-i18next'; |
6 | | -import { useSetModalState } from './commonHooks'; |
| 8 | +import { useDispatch } from 'umi'; |
| 9 | +import { useSetModalState, useTranslate } from './commonHooks'; |
7 | 10 | import { useSetDocumentParser } from './documentHooks'; |
8 | 11 | import { useOneNamespaceEffectsLoading } from './storeHooks'; |
9 | 12 | import { useSaveSetting } from './userSettingHook'; |
@@ -62,3 +65,51 @@ export const useChangeLanguage = () => { |
62 | 65 |
|
63 | 66 | return changeLanguage; |
64 | 67 | }; |
| 68 | + |
| 69 | +export const useGetPagination = ( |
| 70 | + total: number, |
| 71 | + page: number, |
| 72 | + pageSize: number, |
| 73 | + onPageChange: PaginationProps['onChange'], |
| 74 | +) => { |
| 75 | + const { t } = useTranslate('common'); |
| 76 | + |
| 77 | + const pagination: PaginationProps = useMemo(() => { |
| 78 | + return { |
| 79 | + showQuickJumper: true, |
| 80 | + total, |
| 81 | + showSizeChanger: true, |
| 82 | + current: page, |
| 83 | + pageSize: pageSize, |
| 84 | + pageSizeOptions: [1, 2, 10, 20, 50, 100], |
| 85 | + onChange: onPageChange, |
| 86 | + showTotal: (total) => `${t('total')} ${total}`, |
| 87 | + }; |
| 88 | + }, [t, onPageChange, page, pageSize, total]); |
| 89 | + |
| 90 | + return { |
| 91 | + pagination, |
| 92 | + }; |
| 93 | +}; |
| 94 | + |
| 95 | +export const useSetPagination = (namespace: string) => { |
| 96 | + const dispatch = useDispatch(); |
| 97 | + |
| 98 | + const setPagination = useCallback( |
| 99 | + (pageNumber = 1, pageSize?: number) => { |
| 100 | + const pagination: Pagination = { |
| 101 | + current: pageNumber, |
| 102 | + } as Pagination; |
| 103 | + if (pageSize) { |
| 104 | + pagination.pageSize = pageSize; |
| 105 | + } |
| 106 | + dispatch({ |
| 107 | + type: `${namespace}/setPagination`, |
| 108 | + payload: pagination, |
| 109 | + }); |
| 110 | + }, |
| 111 | + [dispatch, namespace], |
| 112 | + ); |
| 113 | + |
| 114 | + return setPagination; |
| 115 | +}; |
0 commit comments