listpage-next 0.0.52 → 0.0.53
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/components/DataTable.js +6 -2
- package/dist/components/DataTable/context/index.js +18 -11
- package/dist/components/DataTable/hooks/useData.d.ts +2 -0
- package/dist/components/DataTable/hooks/useData.js +3 -1
- package/dist/components/DataTable/typings/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -19,15 +19,19 @@ const TableContainer = styled_components.div`
|
|
|
19
19
|
`;
|
|
20
20
|
const DataTableComponent = (props)=>{
|
|
21
21
|
const { title, extra, dataSource, request, refreshDeps, ...restProps } = props;
|
|
22
|
-
const { data, loading, pagination, onPaginationChange } = useData({
|
|
22
|
+
const { data, loading, pagination, onPaginationChange, refresh } = useData({
|
|
23
23
|
dataSource,
|
|
24
24
|
request,
|
|
25
25
|
refreshDeps,
|
|
26
26
|
pagination: restProps.pagination
|
|
27
27
|
});
|
|
28
28
|
const floatCtx = useFloatContext();
|
|
29
|
+
const actions = {
|
|
30
|
+
refresh
|
|
31
|
+
};
|
|
29
32
|
const columns = useColumns(props, {
|
|
30
|
-
...floatCtx
|
|
33
|
+
...floatCtx,
|
|
34
|
+
...actions
|
|
31
35
|
});
|
|
32
36
|
return /*#__PURE__*/ jsxs(Card, {
|
|
33
37
|
title: title,
|
|
@@ -10,27 +10,34 @@ const FloatProvider = (props)=>{
|
|
|
10
10
|
const { floats = [], children } = props;
|
|
11
11
|
const floatsMapRef = useRef({});
|
|
12
12
|
const [eles, setEles] = useState([]);
|
|
13
|
+
const hideFloat = useCallback((key)=>{
|
|
14
|
+
if (!floatsMapRef.current[key]) return;
|
|
15
|
+
setEles(eles.filter((i)=>i !== floatsMapRef.current[key]));
|
|
16
|
+
delete floatsMapRef.current[key];
|
|
17
|
+
}, [
|
|
18
|
+
eles
|
|
19
|
+
]);
|
|
13
20
|
const showFloat = useCallback((key, record)=>{
|
|
14
21
|
if (!floatsMapRef.current[key]) {
|
|
15
22
|
const content = floats.find((i)=>i.key === key)?.content;
|
|
16
23
|
if (!content) return;
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
const onClose = ()=>{
|
|
25
|
+
hideFloat(key);
|
|
26
|
+
};
|
|
27
|
+
const newContent = /*#__PURE__*/ cloneElement(content, {
|
|
28
|
+
record,
|
|
29
|
+
onClose,
|
|
30
|
+
visible: true
|
|
19
31
|
});
|
|
32
|
+
floatsMapRef.current[key] = newContent;
|
|
20
33
|
setEles([
|
|
21
34
|
...eles,
|
|
22
|
-
|
|
35
|
+
newContent
|
|
23
36
|
]);
|
|
24
37
|
}
|
|
25
38
|
}, [
|
|
26
|
-
eles
|
|
27
|
-
|
|
28
|
-
const hideFloat = useCallback((key)=>{
|
|
29
|
-
if (!floatsMapRef.current[key]) return;
|
|
30
|
-
setEles(eles.filter((i)=>i !== floatsMapRef.current[key]));
|
|
31
|
-
delete floatsMapRef.current[key];
|
|
32
|
-
}, [
|
|
33
|
-
eles
|
|
39
|
+
eles,
|
|
40
|
+
hideFloat
|
|
34
41
|
]);
|
|
35
42
|
return /*#__PURE__*/ jsx(FloatContext.Provider, {
|
|
36
43
|
value: {
|
|
@@ -4,10 +4,12 @@ export declare function useData<T = any>(props: DataTableProps<T>): {
|
|
|
4
4
|
data: T[];
|
|
5
5
|
loading: boolean;
|
|
6
6
|
pagination: BaseQueryParams;
|
|
7
|
+
refresh: () => void;
|
|
7
8
|
onPaginationChange: (page: number, pageSize: number) => void;
|
|
8
9
|
} | {
|
|
9
10
|
data: T[] | undefined;
|
|
10
11
|
loading: boolean;
|
|
12
|
+
refresh: () => void;
|
|
11
13
|
pagination: {
|
|
12
14
|
current?: number;
|
|
13
15
|
pageSize?: number;
|
|
@@ -7,7 +7,7 @@ function useData(props) {
|
|
|
7
7
|
current: pagination.current || pagination.defaultCurrent || 1,
|
|
8
8
|
pageSize: pagination.pageSize || pagination.defaultPageSize || 10
|
|
9
9
|
});
|
|
10
|
-
const { loading, data: response } = useRequest(async ()=>{
|
|
10
|
+
const { loading, data: response, refresh } = useRequest(async ()=>{
|
|
11
11
|
const response = await request?.(params);
|
|
12
12
|
return response;
|
|
13
13
|
}, {
|
|
@@ -38,12 +38,14 @@ function useData(props) {
|
|
|
38
38
|
data: dataSource,
|
|
39
39
|
loading: false,
|
|
40
40
|
pagination: params,
|
|
41
|
+
refresh,
|
|
41
42
|
onPaginationChange: onChange
|
|
42
43
|
};
|
|
43
44
|
const { list, total } = response || {};
|
|
44
45
|
return {
|
|
45
46
|
data: list,
|
|
46
47
|
loading,
|
|
48
|
+
refresh,
|
|
47
49
|
pagination: {
|
|
48
50
|
total,
|
|
49
51
|
...params
|