mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-11-04 22:57:10 +08:00
chore: 优化部分代码
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user