listpage-next 0.0.43 → 0.0.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DataTable/hooks/useData.d.ts +21 -0
- package/dist/components/DataTable/hooks/useData.js +54 -0
- package/dist/components/DataTable/index.d.ts +2 -0
- package/dist/components/DataTable/index.js +60 -0
- package/dist/components/DataTable/typings/index.d.ts +10 -0
- package/dist/components/DataTable/typings/index.js +0 -0
- package/dist/components/Menu/hooks/useMenuNavigation.js +0 -1
- package/dist/demos/demo6.d.ts +1 -0
- package/dist/demos/demo6.js +57 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DataTableProps } from "../typings";
|
|
2
|
+
export declare function useData<T = any>(props: DataTableProps<T>): {
|
|
3
|
+
data: T[];
|
|
4
|
+
loading: boolean;
|
|
5
|
+
pagination: {
|
|
6
|
+
onChange: (page: number, pageSize: number) => void;
|
|
7
|
+
current?: number;
|
|
8
|
+
pageSize?: number;
|
|
9
|
+
sort?: string;
|
|
10
|
+
};
|
|
11
|
+
} | {
|
|
12
|
+
data: T[] | undefined;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
pagination: {
|
|
15
|
+
current?: number;
|
|
16
|
+
pageSize?: number;
|
|
17
|
+
sort?: string;
|
|
18
|
+
total: number | undefined;
|
|
19
|
+
onChange: (page: number, pageSize: number) => void;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useRequest, useUpdateEffect } from "ahooks";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
function useData(props) {
|
|
4
|
+
const { dataSource = [], request, refreshDeps = [] } = props;
|
|
5
|
+
const pagination = props.pagination;
|
|
6
|
+
const [params, setParams] = useState({
|
|
7
|
+
current: pagination.current || pagination.defaultCurrent || 1,
|
|
8
|
+
pageSize: pagination.pageSize || pagination.defaultPageSize || 10
|
|
9
|
+
});
|
|
10
|
+
const { loading, data: response } = useRequest(async ()=>{
|
|
11
|
+
const response = await request?.(params);
|
|
12
|
+
return response;
|
|
13
|
+
}, {
|
|
14
|
+
ready: !!request,
|
|
15
|
+
refreshDeps: [
|
|
16
|
+
...refreshDeps,
|
|
17
|
+
params
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
useUpdateEffect(()=>{
|
|
21
|
+
setParams({
|
|
22
|
+
current: 1,
|
|
23
|
+
pageSize: params.pageSize || pagination?.pageSize || pagination.defaultPageSize || 10
|
|
24
|
+
});
|
|
25
|
+
}, [
|
|
26
|
+
...refreshDeps
|
|
27
|
+
]);
|
|
28
|
+
const onChange = (page, pageSize)=>{
|
|
29
|
+
setParams({
|
|
30
|
+
...params,
|
|
31
|
+
current: pageSize !== params.pageSize ? 1 : page,
|
|
32
|
+
pageSize
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
if (!request) return {
|
|
36
|
+
data: dataSource,
|
|
37
|
+
loading: false,
|
|
38
|
+
pagination: {
|
|
39
|
+
...params,
|
|
40
|
+
onChange
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const { list, total, pageSize, current } = response || {};
|
|
44
|
+
return {
|
|
45
|
+
data: list,
|
|
46
|
+
loading,
|
|
47
|
+
pagination: {
|
|
48
|
+
total,
|
|
49
|
+
onChange,
|
|
50
|
+
...params
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export { useData };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Card, Pagination, Table } from "antd";
|
|
3
|
+
import zh_CN from "antd/locale/zh_CN";
|
|
4
|
+
import { useData } from "./hooks/useData.js";
|
|
5
|
+
import styled_components from "styled-components";
|
|
6
|
+
const PaginationContainer = styled_components.div`
|
|
7
|
+
padding: 12px 16px 12px 0;
|
|
8
|
+
border-top: 1px solid #f0f0f0;
|
|
9
|
+
`;
|
|
10
|
+
const TableContainer = styled_components.div`
|
|
11
|
+
table {
|
|
12
|
+
tr:last-child {
|
|
13
|
+
td {
|
|
14
|
+
border-bottom: none;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
const DataTable = (props)=>{
|
|
20
|
+
const { title, extra, dataSource, request, refreshDeps, ...restProps } = props;
|
|
21
|
+
const { data, loading, pagination } = useData({
|
|
22
|
+
dataSource,
|
|
23
|
+
request,
|
|
24
|
+
refreshDeps,
|
|
25
|
+
pagination: restProps.pagination
|
|
26
|
+
});
|
|
27
|
+
return /*#__PURE__*/ jsxs(Card, {
|
|
28
|
+
title: title,
|
|
29
|
+
extra: extra,
|
|
30
|
+
styles: {
|
|
31
|
+
body: {
|
|
32
|
+
padding: 0
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
children: [
|
|
36
|
+
/*#__PURE__*/ jsx(TableContainer, {
|
|
37
|
+
children: /*#__PURE__*/ jsx(Table, {
|
|
38
|
+
bordered: false,
|
|
39
|
+
loading: loading,
|
|
40
|
+
locale: zh_CN.Table,
|
|
41
|
+
...restProps,
|
|
42
|
+
dataSource: data,
|
|
43
|
+
pagination: false
|
|
44
|
+
})
|
|
45
|
+
}),
|
|
46
|
+
/*#__PURE__*/ jsx(PaginationContainer, {
|
|
47
|
+
children: /*#__PURE__*/ jsx(Pagination, {
|
|
48
|
+
style: {
|
|
49
|
+
border: 'none'
|
|
50
|
+
},
|
|
51
|
+
align: "end",
|
|
52
|
+
locale: zh_CN.Pagination,
|
|
53
|
+
...pagination,
|
|
54
|
+
...restProps?.pagination
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
export { DataTable };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TableProps } from "antd";
|
|
2
|
+
import { BaseQueryParams, PaginationData } from "../../../http-client";
|
|
3
|
+
import React from "react";
|
|
4
|
+
export interface DataTableProps<Record = any> extends Omit<TableProps<Record>, 'dataSource' | 'title'> {
|
|
5
|
+
dataSource?: Record[];
|
|
6
|
+
request?: (pageParams: BaseQueryParams) => Promise<PaginationData<Record>>;
|
|
7
|
+
refreshDeps?: any[];
|
|
8
|
+
title?: React.ReactNode;
|
|
9
|
+
extra?: React.ReactNode;
|
|
10
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Demo6: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "antd";
|
|
3
|
+
import { DataTable } from "../components/DataTable/index.js";
|
|
4
|
+
const columns = [
|
|
5
|
+
{
|
|
6
|
+
title: 'Name',
|
|
7
|
+
dataIndex: 'name',
|
|
8
|
+
key: 'name'
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
title: 'Age',
|
|
12
|
+
dataIndex: 'age',
|
|
13
|
+
key: 'age'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
title: 'Address',
|
|
17
|
+
dataIndex: 'address',
|
|
18
|
+
key: 'address'
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
const listdata = Array.from(new Array(100)).map((_, index)=>({
|
|
22
|
+
key: index,
|
|
23
|
+
name: `Edward King ${index}`,
|
|
24
|
+
age: 32,
|
|
25
|
+
address: `London, Park Lane no. ${index}`
|
|
26
|
+
}));
|
|
27
|
+
const request = async (params)=>{
|
|
28
|
+
const { current, pageSize } = params;
|
|
29
|
+
const take = pageSize;
|
|
30
|
+
const skip = (current - 1) * take;
|
|
31
|
+
const list = listdata.slice(skip, skip + take);
|
|
32
|
+
return {
|
|
33
|
+
list: list,
|
|
34
|
+
total: listdata.length,
|
|
35
|
+
current: current,
|
|
36
|
+
pageSize: pageSize
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const Demo6 = ()=>/*#__PURE__*/ jsx(DataTable, {
|
|
40
|
+
scroll: {
|
|
41
|
+
y: 300
|
|
42
|
+
},
|
|
43
|
+
title: "测试标题",
|
|
44
|
+
extra: /*#__PURE__*/ jsx(Button, {
|
|
45
|
+
children: "操作"
|
|
46
|
+
}),
|
|
47
|
+
columns: columns,
|
|
48
|
+
request: request,
|
|
49
|
+
pagination: {
|
|
50
|
+
showSizeChanger: true,
|
|
51
|
+
defaultPageSize: 10,
|
|
52
|
+
showTotal (total, range) {
|
|
53
|
+
return `共${total}条数据`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
export { Demo6 };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,4 +3,5 @@ export * from "./components/FilterGroup/index.js";
|
|
|
3
3
|
export * from "./components/Page/index.js";
|
|
4
4
|
export * from "./components/InfiniteList/index.js";
|
|
5
5
|
export * from "./components/Menu/index.js";
|
|
6
|
+
export * from "./components/DataTable/index.js";
|
|
6
7
|
export * from "./http-client/index.js";
|