listpage-next 0.0.42 → 0.0.44
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 +31 -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 +3 -12
- package/dist/demos/demo6.d.ts +1 -0
- package/dist/demos/demo6.js +58 -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: 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,31 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Card, Table } from "antd";
|
|
3
|
+
import { useData } from "./hooks/useData.js";
|
|
4
|
+
const DataTable = (props)=>{
|
|
5
|
+
const { title, extra, dataSource, request, refreshDeps, ...restProps } = props;
|
|
6
|
+
const { data, loading, pagination } = useData({
|
|
7
|
+
dataSource,
|
|
8
|
+
request,
|
|
9
|
+
refreshDeps,
|
|
10
|
+
pagination: restProps.pagination
|
|
11
|
+
});
|
|
12
|
+
return /*#__PURE__*/ jsx(Card, {
|
|
13
|
+
title: title,
|
|
14
|
+
extra: extra,
|
|
15
|
+
styles: {
|
|
16
|
+
body: {
|
|
17
|
+
padding: 0
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
children: /*#__PURE__*/ jsx(Table, {
|
|
21
|
+
loading: loading,
|
|
22
|
+
...restProps,
|
|
23
|
+
dataSource: data,
|
|
24
|
+
pagination: {
|
|
25
|
+
...pagination,
|
|
26
|
+
...restProps?.pagination
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
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
|
|
@@ -23,7 +23,7 @@ function useActiveMenuKey(items, baseUrl = '') {
|
|
|
23
23
|
}
|
|
24
24
|
const paths = findKeyPath(items, []);
|
|
25
25
|
const urlPath = paths.map((p)=>getPaths(p)).flat().join('/');
|
|
26
|
-
navigate(
|
|
26
|
+
navigate(urlPath);
|
|
27
27
|
}, [
|
|
28
28
|
items,
|
|
29
29
|
navigate
|
|
@@ -43,17 +43,8 @@ function useActiveMenuKey(items, baseUrl = '') {
|
|
|
43
43
|
];
|
|
44
44
|
}
|
|
45
45
|
const removeBaseUrl = (pathname, baseUrl)=>{
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
if (!baseUrl.startsWith('/')) normalizedBaseUrl = '/' + baseUrl;
|
|
49
|
-
let normalizedPathname = pathname;
|
|
50
|
-
if (!pathname.startsWith('/')) normalizedPathname = '/' + pathname;
|
|
51
|
-
if (normalizedPathname.startsWith(normalizedBaseUrl)) {
|
|
52
|
-
if (normalizedPathname === normalizedBaseUrl || '/' === normalizedPathname.charAt(normalizedBaseUrl.length)) {
|
|
53
|
-
const result = normalizedPathname.substring(normalizedBaseUrl.length);
|
|
54
|
-
return '' === result ? '/' : result.startsWith('/') ? result : '/' + result;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
46
|
+
if (!baseUrl) return pathname;
|
|
47
|
+
if (pathname.startsWith(baseUrl)) return pathname.slice(baseUrl.length);
|
|
57
48
|
return pathname;
|
|
58
49
|
};
|
|
59
50
|
const matchRoutes = (routes, paths)=>{
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Demo6: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,58 @@
|
|
|
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 request = async (params)=>{
|
|
22
|
+
console.log(params);
|
|
23
|
+
return {
|
|
24
|
+
list: [
|
|
25
|
+
{
|
|
26
|
+
key: '1',
|
|
27
|
+
name: 'John Brown',
|
|
28
|
+
age: 32,
|
|
29
|
+
address: 'New York No. 1 Lake Park'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: '2',
|
|
33
|
+
name: 'Jim Green',
|
|
34
|
+
age: 42,
|
|
35
|
+
address: 'London No. 1 Lake Park'
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
total: 10,
|
|
39
|
+
current: 1,
|
|
40
|
+
pageSize: 2
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const Demo6 = ()=>/*#__PURE__*/ jsx(DataTable, {
|
|
44
|
+
title: "测试标题",
|
|
45
|
+
extra: /*#__PURE__*/ jsx(Button, {
|
|
46
|
+
children: "操作"
|
|
47
|
+
}),
|
|
48
|
+
columns: columns,
|
|
49
|
+
request: request,
|
|
50
|
+
pagination: {
|
|
51
|
+
showSizeChanger: true,
|
|
52
|
+
defaultPageSize: 2,
|
|
53
|
+
showTotal (total, range) {
|
|
54
|
+
return `共${total}条数据`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
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";
|