chore: 优化部分代码

This commit is contained in:
2024-09-06 20:43:31 +08:00
parent 948158f1fa
commit cb03111c22
6 changed files with 11 additions and 24 deletions

View File

@@ -3,8 +3,8 @@ import { Message, Modal } from '@arco-design/web-vue'
import type { Options as paginationOptions } from './usePagination'
import { usePagination } from '@/hooks'
interface Options<T> {
formatResult?: (data: T[]) => any
interface Options<T, U> {
formatResult?: (data: T[]) => U[]
onSuccess?: () => void
immediate?: boolean
rowKey?: keyof T
@@ -14,11 +14,11 @@ interface Options<T> {
type PaginationParams = { page: number, size: number }
type Api<T> = (params: PaginationParams) => Promise<ApiRes<PageRes<T[]>>> | Promise<ApiRes<T[]>>
export function useTable<T>(api: Api<T>, options?: Options<T>) {
export function useTable<T extends U, U = T>(api: Api<T>, options?: Options<T, U>) {
const { formatResult, onSuccess, immediate, rowKey } = options || {}
const { pagination, setTotal } = usePagination(() => getTableData(), options?.paginationOption)
const loading = ref(false)
const tableData = ref<T[]>([])
const tableData: Ref<U[]> = ref([])
async function getTableData() {
try {