Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:alibaba/form-render into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
FateRiddle committed Aug 11, 2021
2 parents c9f350e + 5ce9bfa commit 805e9f8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
8 changes: 4 additions & 4 deletions docs/table-render/demo/advanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const schema = {
const Demo = () => {
const { refresh, tableState }: any = useTable();

const searchApi = params => {
console.log('params >>> ', params);
const searchApi = (params, sorter) => {
console.group(sorter);
return request
.get(
'https://www.fastmock.site/mock/62ab96ff94bc013592db1f67667e9c76/getTableList/api/basic',
Expand Down Expand Up @@ -106,6 +106,7 @@ const Demo = () => {
{
title: '酒店GMV',
key: 'money',
sorter: true,
dataIndex: 'money',
valueType: 'money',
},
Expand Down Expand Up @@ -153,8 +154,6 @@ const Demo = () => {
<Search
schema={schema}
displayType="row"
onSearch={search => console.log('onSearch', search)}
afterSearch={params => console.log('afterSearch', params)}
api={[
{
name: '全部数据',
Expand All @@ -168,6 +167,7 @@ const Demo = () => {
/>
<Table
// size="small"
pagination={{ pageSize: 4 }}
columns={columns}
// headerTitle="高级表单"
rowKey="id"
Expand Down
2 changes: 1 addition & 1 deletion packages/table-render/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "table-render",
"version": "1.1.3",
"version": "1.1.4",
"description": "中后台表格解决方案",
"scripts": {
"start": "dumi dev",
Expand Down
9 changes: 5 additions & 4 deletions packages/table-render/src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ const ProTable = (props: ProTableProps) => {
const { dataSource, pagination, loading, api, tableSize } = tableState;
const rootRef = useRef<HTMLDivElement>(null); // ProTable组件的ref

const onPageChange = (page: any, pageSize: any) => {
setTable({ pagination: { ...pagination, current: page, pageSize } });
const onChange = ({ current, pageSize }, filters, sorter) => {
setTable({ pagination: { ...pagination, current, pageSize } });
if (
!props.pageChangeWithRequest &&
props.pageChangeWithRequest !== undefined
)
return;
doSearch({ current: page, pageSize });
doSearch({ current, pageSize, sorter });
};

const {
Expand Down Expand Up @@ -67,13 +67,14 @@ const ProTable = (props: ProTableProps) => {
});
const tableProps = {
...props,
onChange,
// dataSource不准在使用ProTable时用props赋值
dataSource,
pagination:
props.pagination === false
? false
: {
onChange: onPageChange,
// onChange: onPageChange,
size: 'small',
...props.pagination,
pageSize: props.pagination?.pageSize || pagination.pageSize,
Expand Down
13 changes: 9 additions & 4 deletions packages/table-render/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ const useTableRoot = props => {
const table = useTable();

const doSearch = (
params: { current?: any; tab?: any; pageSize?: any },
params: {
current?: number;
tab?: number | string;
pageSize?: number;
sorter?: any;
},
customSearch?: any
) => {
// console.log(checkPassed);
// if (!checkPassed) return;
const { current, pageSize, tab, ...extraSearch } = params || {};
const { current, pageSize, tab, sorter, ...extraSearch } = params || {};
const _current = current || 1;
const _pageSize = pageSize || 10;
let _tab = currentTab;
Expand All @@ -62,7 +67,7 @@ const useTableRoot = props => {
message.warning('api 不是函数,检查 <Search /> 的 props');
}

function basicSearch(api: (arg0: any) => any) {
function basicSearch(api: (arg0: any, sorter: any) => any) {
set({ loading: true });
let _params = {
...form.getValues(),
Expand All @@ -74,7 +79,7 @@ const useTableRoot = props => {
if (Array.isArray(api)) {
_params = { ..._params, tab };
}
Promise.resolve(api(_params))
Promise.resolve(api(_params, sorter))
.then(res => {
// TODO:这里校验res是否规范
const { rows, total, pageSize, ...extraData } = res;
Expand Down

0 comments on commit 805e9f8

Please sign in to comment.