mirror of
				https://github.com/continew-org/continew-admin-ui.git
				synced 2025-10-31 22:57:15 +08:00 
			
		
		
		
	chore:优化文件管理分页
This commit is contained in:
		| @@ -3,11 +3,12 @@ import { useBreakpoint } from '@/hooks' | ||||
|  | ||||
| type Callback = () => void | ||||
|  | ||||
| type Options = { | ||||
| export type Options = { | ||||
|   defaultPageSize: number | ||||
|   defaultSizeOptions: number[] | ||||
| } | ||||
|  | ||||
| export function usePagination(callback: Callback, options: Options = { defaultPageSize: 10 }) { | ||||
| export function usePagination(callback: Callback, options: Options = { defaultPageSize: 10, defaultSizeOptions: [10, 20, 30, 40, 50] }) { | ||||
|   const { breakpoint } = useBreakpoint() | ||||
|  | ||||
|   const pagination = reactive({ | ||||
| @@ -15,6 +16,7 @@ export function usePagination(callback: Callback, options: Options = { defaultPa | ||||
|     showTotal: true, | ||||
|     current: 1, | ||||
|     pageSize: options.defaultPageSize, | ||||
|     pageSizeOptions: options.defaultSizeOptions, | ||||
|     total: 0, | ||||
|     simple: false, | ||||
|     onChange: (size: number) => { | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| import type { TableData, TableInstance } from '@arco-design/web-vue' | ||||
| import { Message, Modal } from '@arco-design/web-vue' | ||||
| import type { Options as paginationOptions } from './usePagination' | ||||
| import { usePagination } from '@/hooks' | ||||
|  | ||||
| interface Options<T> { | ||||
| @@ -7,6 +8,7 @@ interface Options<T> { | ||||
|   onSuccess?: () => void | ||||
|   immediate?: boolean | ||||
|   rowKey?: keyof T | ||||
|   paginationOption: paginationOptions | ||||
| } | ||||
|  | ||||
| type PaginationParams = { page: number, size: number } | ||||
| @@ -14,7 +16,7 @@ type Api<T> = (params: PaginationParams) => Promise<ApiRes<PageRes<T[]>>> | Prom | ||||
|  | ||||
| export function useTable<T>(api: Api<T>, options?: Options<T>) { | ||||
|   const { formatResult, onSuccess, immediate, rowKey } = options || {} | ||||
|   const { pagination, setTotal } = usePagination(() => getTableData()) | ||||
|   const { pagination, setTotal } = usePagination(() => getTableData(), options?.paginationOption) | ||||
|   const loading = ref(false) | ||||
|   const tableData = ref<T[]>([]) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 秋帆
					秋帆