Commit 04919f7e authored by XieZhiXiong's avatar XieZhiXiong

chore: 抽离并暴露类型声明

parent 9101327b
......@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2020-08-20 16:15:59
* @LastEditors: XieZhiXiong
* @LastEditTime: 2020-12-15 16:45:41
* @LastEditTime: 2021-07-16 14:27:55
* @Description: 基于 NormalTable 简单的可编辑列 Table
*/
import React, { useContext, useState, useEffect, useRef } from 'react';
......@@ -13,7 +13,7 @@ import {
Form,
message,
} from 'antd';
import { StandardTableProps, EditableCellProps, EditableColumns } from './interface';
import { NormalTableProps, EditableCellProps } from './interface';
import NormalTable from './NormalTable';
const EditableContext = React.createContext<any>({});
......@@ -122,7 +122,7 @@ const EditableCell: React.FC<EditableCellProps> = ({
return <td {...restProps}>{childNode}</td>;
};
const EditableCellTable: React.FC<StandardTableProps> = props => {
const EditableCellTable: React.FC<NormalTableProps<{}>> = props => {
const components = {
body: {
row: EditableRow,
......
......@@ -7,94 +7,20 @@
*/
import React, { useState, useEffect, useRef, useImperativeHandle } from 'react';
import { Table, Pagination } from 'antd';
import { TableProps } from 'antd/lib/table';
import { PaginationProps } from 'antd/lib/pagination';
import classNames from 'classnames';
import SearchForm, { SearchFormIProps } from './SearchForm';
import {
NormalTableRefHandleType,
NormalTableProps,
SearchValuesType,
FetchResponse,
FetchParamsType,
} from './interface';
import SearchForm from './SearchForm';
import styles from './index.less';
const PAGE_SIZE = 10;
export type PaginationPositionType = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight'
export type SearchValuesType = { [key: string]: any }
export type FetchParamsType = SearchValuesType & {
/**
* 当前页
*/
current?: number,
/**
* 当前页数
*/
pageSize?: number,
};
export type FetchResponse<T> = {
/**
* 数据
*/
data: T[],
/**
* 总条数
*/
totalCount: number,
};
export type NormalTableRefHandleType = {
/**
* 重新加载数据
*/
reload: (params?: FetchParamsType) => void,
}
export interface NormalTableProps<T> extends Omit<TableProps<T>, 'pagination'> {
/**
* 获取数据方法,如果外部有传入 dataSource 则无效
*/
fetchDataSource?: (params: FetchParamsType) => Promise<FetchResponse<T>>,
/**
* 查询formily表单props
*/
searchFormProps?: SearchFormIProps,
/**
* 自定义渲染查询Form
*/
customRenderSearchForm?: () => React.ReactNode,
/**
* 查询formily提交触发事件
*/
onSearchSubmit?: (values: SearchValuesType) => void,
/**
* 分页器props,默认 current 1,默认 pageSize 10
*/
pagination?: PaginationProps | null,
/**
* 分页器位置,默认 bottomRight
*/
paginationPosition?: PaginationPositionType,
/**
* 默认 current,只在首次请求生效
*/
defaultCurrent?: number,
/**
* 默认 pageSize
*/
defaultPageSize?: number,
/**
* 分页器改变触发事件
*/
onPaginationChange?: (page: number, size: number) => void,
/**
* 是否占满父容器,默认为false,注意当开启该属性会跟 scroll 属性冲突
*/
full?: boolean,
/**
* 渲染底部内容
*/
renderFootContent?: () => React.ReactNode,
}
const NormalTable: React.ForwardRefRenderFunction<NormalTableRefHandleType, NormalTableProps<{}>> = (<T extends {},>(props: NormalTableProps<T>, ref) => {
const {
fetchDataSource,
......
/*
* @Author: XieZhiXiong
* @Date: 2021-01-06 11:36:34
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-07-16 14:27:20
* @Description:
*/
import NormalTable from './NormalTable';
import EditableCellTable from './EditableCellTable';
export * from './interface';
export {
NormalTable as default,
EditableCellTable,
......
......@@ -6,10 +6,87 @@
* @Description:
*/
import { TableProps, TablePaginationConfig, ColumnType } from 'antd/lib/table';
import { PaginationProps } from 'antd/lib/pagination';
import { SearchFormIProps } from './SearchForm';
export interface StandardTableProps extends TableProps<any> {
pagination?: TablePaginationConfig;
onPaginationChange?: (page: number, size: number) => void;
export type PaginationPositionType = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight'
export type SearchValuesType = { [key: string]: any }
export type FetchParamsType = SearchValuesType & {
/**
* 当前页
*/
current?: number,
/**
* 当前页数
*/
pageSize?: number,
};
export type FetchResponse<T> = {
/**
* 数据
*/
data: T[],
/**
* 总条数
*/
totalCount: number,
};
export type NormalTableRefHandleType = {
/**
* 重新加载数据
*/
reload: (params?: FetchParamsType) => void,
}
export interface NormalTableProps<T> extends Omit<TableProps<T>, 'pagination'> {
/**
* 获取数据方法,如果外部有传入 dataSource 则无效
*/
fetchDataSource?: (params: FetchParamsType) => Promise<FetchResponse<T>>,
/**
* 查询formily表单props
*/
searchFormProps?: SearchFormIProps,
/**
* 自定义渲染查询Form
*/
customRenderSearchForm?: () => React.ReactNode,
/**
* 查询formily提交触发事件
*/
onSearchSubmit?: (values: SearchValuesType) => void,
/**
* 分页器props,默认 current 1,默认 pageSize 10
*/
pagination?: PaginationProps | null,
/**
* 分页器位置,默认 bottomRight
*/
paginationPosition?: PaginationPositionType,
/**
* 默认 current,只在首次请求生效
*/
defaultCurrent?: number,
/**
* 默认 pageSize
*/
defaultPageSize?: number,
/**
* 分页器改变触发事件
*/
onPaginationChange?: (page: number, size: number) => void,
/**
* 是否占满父容器,默认为false,注意当开启该属性会跟 scroll 属性冲突
*/
full?: boolean,
/**
* 渲染底部内容
*/
renderFootContent?: () => React.ReactNode,
}
export interface EditableCellProps {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment