@hw-component/table 1.10.13 → 1.10.16
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/.eslintcache +1 -1
- package/es/DialogTable/Content.js +2 -33
- package/es/EditTable/hooks.d.ts +12 -2
- package/es/EditTable/hooks.js +88 -45
- package/es/EditTable/index.js +16 -20
- package/es/EditTable/modal.d.ts +1 -1
- package/lib/DialogTable/Content.js +0 -31
- package/lib/EditTable/hooks.d.ts +12 -2
- package/lib/EditTable/hooks.js +87 -44
- package/lib/EditTable/index.js +16 -20
- package/lib/EditTable/modal.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/DialogTable/Content.tsx +3 -3
- package/src/components/EditTable/hooks.ts +59 -21
- package/src/components/EditTable/index.tsx +15 -19
- package/src/components/EditTable/modal.ts +1 -1
- package/src/pages/EditTable/index.tsx +52 -48
- package/src/pages/ModalEditTable/index.tsx +38 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Table from "
|
|
1
|
+
import Table from "../Table";
|
|
2
2
|
import type { ModalTableProps } from "../modal";
|
|
3
|
-
import
|
|
3
|
+
import EditTable from "../EditTable";
|
|
4
4
|
import { ProColumns } from "@ant-design/pro-table/lib/typing";
|
|
5
5
|
|
|
6
6
|
export const TableContent = ({
|
|
@@ -32,7 +32,7 @@ export const EditTableContent = ({
|
|
|
32
32
|
dataSource,
|
|
33
33
|
}: ModalTableProps<ProColumns[]>) => {
|
|
34
34
|
const node = (
|
|
35
|
-
<
|
|
35
|
+
<EditTable
|
|
36
36
|
{...editTableProps}
|
|
37
37
|
configData={configData || []}
|
|
38
38
|
request={request}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { useRequest } from "ahooks";
|
|
2
2
|
import { HEditTableProps } from "./modal";
|
|
3
|
-
import {MutableRefObject, useEffect, useMemo, useRef} from "react";
|
|
3
|
+
import {MutableRefObject, useEffect, useMemo, useRef, useState} from "react";
|
|
4
4
|
import type { ActionType } from "@ant-design/pro-table";
|
|
5
5
|
import { EditableFormInstance } from "@ant-design/pro-table/lib/components/EditableTable";
|
|
6
6
|
import config from "../render/config";
|
|
7
|
+
import {ResultModal} from "../modal";
|
|
7
8
|
|
|
8
|
-
export const useListRequest = ({
|
|
9
|
-
|
|
9
|
+
export const useListRequest = ({
|
|
10
|
+
request,
|
|
11
|
+
dataSource,
|
|
12
|
+
manual,
|
|
13
|
+
}: HEditTableProps) => {
|
|
14
|
+
const [tableDataSource,setTableDataSource]=useState<ResultModal>({
|
|
15
|
+
records:[],
|
|
16
|
+
total:"0",
|
|
17
|
+
size:"10",
|
|
18
|
+
current:"1"
|
|
19
|
+
});
|
|
10
20
|
const saveParams = useMemo(() => {
|
|
11
21
|
return {
|
|
12
22
|
params: {
|
|
@@ -15,7 +25,7 @@ export const useListRequest = ({ request, dataSource ,manual}: HEditTableProps)
|
|
|
15
25
|
},
|
|
16
26
|
};
|
|
17
27
|
}, []);
|
|
18
|
-
|
|
28
|
+
const {loading,error,run}=useRequest(
|
|
19
29
|
async (params = {}) => {
|
|
20
30
|
const newParams = {
|
|
21
31
|
...saveParams.params,
|
|
@@ -23,15 +33,32 @@ export const useListRequest = ({ request, dataSource ,manual}: HEditTableProps)
|
|
|
23
33
|
};
|
|
24
34
|
saveParams.params = newParams;
|
|
25
35
|
if (request) {
|
|
26
|
-
|
|
36
|
+
const result=await request(newParams);
|
|
37
|
+
setTableDataSource(result);
|
|
38
|
+
return ;
|
|
27
39
|
}
|
|
28
40
|
if (Array.isArray(dataSource)) {
|
|
29
|
-
|
|
41
|
+
setTableDataSource({
|
|
42
|
+
...tableDataSource,
|
|
43
|
+
records:dataSource,
|
|
44
|
+
})
|
|
45
|
+
return ;
|
|
30
46
|
}
|
|
31
|
-
return dataSource;
|
|
47
|
+
return setTableDataSource(dataSource||tableDataSource);
|
|
32
48
|
},
|
|
33
|
-
{ manual:
|
|
49
|
+
{ manual:true}
|
|
34
50
|
);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!manual){
|
|
53
|
+
run();
|
|
54
|
+
}
|
|
55
|
+
}, [dataSource]);
|
|
56
|
+
return {
|
|
57
|
+
loading,
|
|
58
|
+
error,
|
|
59
|
+
run,
|
|
60
|
+
data:tableDataSource
|
|
61
|
+
}
|
|
35
62
|
};
|
|
36
63
|
|
|
37
64
|
export const useCuRef = ({ actionRef, editableFormRef }: HEditTableProps) => {
|
|
@@ -46,23 +73,34 @@ export const useCuRef = ({ actionRef, editableFormRef }: HEditTableProps) => {
|
|
|
46
73
|
cuEditableFormRef,
|
|
47
74
|
};
|
|
48
75
|
};
|
|
76
|
+
interface ColProps extends HEditTableProps{
|
|
77
|
+
reload:VoidFunction;
|
|
78
|
+
}
|
|
49
79
|
|
|
50
|
-
export const useColsMk = ({ configData }:
|
|
80
|
+
export const useColsMk = ({ configData,reload }: ColProps) => {
|
|
51
81
|
return configData?.map((item) => {
|
|
52
82
|
const { valueType, render } = item;
|
|
53
83
|
const configType = valueType as string;
|
|
54
|
-
if (
|
|
55
|
-
|
|
84
|
+
if (config[configType]) {
|
|
85
|
+
return {
|
|
86
|
+
...item,
|
|
87
|
+
render: (dom, entity, index, action, schema) => {
|
|
88
|
+
const node = config[configType](item, entity, index);
|
|
89
|
+
if (render) {
|
|
90
|
+
return render(node, entity, index, {...action,reload}, schema);
|
|
91
|
+
}
|
|
92
|
+
return node;
|
|
93
|
+
},
|
|
94
|
+
};
|
|
56
95
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
96
|
+
if (render){
|
|
97
|
+
return {
|
|
98
|
+
...item,
|
|
99
|
+
render: (dom, entity, index, action, schema) => {
|
|
100
|
+
return render(dom, entity, index, {...action,reload}, schema);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return item;
|
|
67
105
|
});
|
|
68
106
|
};
|
|
@@ -41,20 +41,18 @@ export default ({
|
|
|
41
41
|
errorRender: tableErrorRender = errorDefaultRender,
|
|
42
42
|
} = useHTableConfigContext({ emptyRender, errorRender });
|
|
43
43
|
|
|
44
|
-
const isLocalData = Array.isArray(data);
|
|
45
|
-
const values = isLocalData ? data : data?.records;
|
|
46
44
|
const { cuActionRef, cuEditableFormRef } = useCuRef({
|
|
47
45
|
actionRef,
|
|
48
46
|
editableFormRef,
|
|
49
47
|
});
|
|
50
|
-
const columns = useColsMk({ configData
|
|
48
|
+
const columns = useColsMk({ configData,reload:run});
|
|
51
49
|
return (
|
|
52
50
|
<div className={tableBody}>
|
|
53
51
|
<ConfigProvider
|
|
54
52
|
renderEmpty={() => {
|
|
55
53
|
if (error) {
|
|
56
54
|
return tableErrorRender?.({
|
|
57
|
-
reload:
|
|
55
|
+
reload: run,
|
|
58
56
|
error,
|
|
59
57
|
});
|
|
60
58
|
}
|
|
@@ -66,10 +64,8 @@ export default ({
|
|
|
66
64
|
loading={loading}
|
|
67
65
|
rowKey={rowKey}
|
|
68
66
|
editableFormRef={cuEditableFormRef}
|
|
69
|
-
manualRequest={true}
|
|
70
|
-
request={run}
|
|
71
67
|
actionRef={cuActionRef}
|
|
72
|
-
value={
|
|
68
|
+
value={data?.records}
|
|
73
69
|
recordCreatorProps={{
|
|
74
70
|
position: "bottom",
|
|
75
71
|
record: () => ({ id: "add", ...defaultRecordValue }),
|
|
@@ -89,7 +85,7 @@ export default ({
|
|
|
89
85
|
if (key === "add") {
|
|
90
86
|
await onAdd?.(oRow);
|
|
91
87
|
cuEditableFormRef.current?.resetFields(["add"]);
|
|
92
|
-
|
|
88
|
+
run();
|
|
93
89
|
return;
|
|
94
90
|
}
|
|
95
91
|
await onEdit?.({
|
|
@@ -97,23 +93,23 @@ export default ({
|
|
|
97
93
|
...oRow,
|
|
98
94
|
});
|
|
99
95
|
cuEditableFormRef.current?.resetFields([key]);
|
|
100
|
-
|
|
96
|
+
run();
|
|
101
97
|
},
|
|
102
98
|
...editable,
|
|
103
99
|
}}
|
|
104
100
|
{...props}
|
|
105
101
|
/>
|
|
106
102
|
</ConfigProvider>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
/>
|
|
103
|
+
{pagination===false?null:<HTablePagination
|
|
104
|
+
data={data}
|
|
105
|
+
{...pagination}
|
|
106
|
+
onChange={(page, pageSize) => {
|
|
107
|
+
run({
|
|
108
|
+
size: pageSize,
|
|
109
|
+
current: page,
|
|
110
|
+
});
|
|
111
|
+
}}
|
|
112
|
+
/>}
|
|
117
113
|
</div>
|
|
118
114
|
);
|
|
119
115
|
};
|
|
@@ -16,7 +16,7 @@ export interface HEditTableProps<T = any>
|
|
|
16
16
|
>;
|
|
17
17
|
dataSource?: any[];
|
|
18
18
|
request?: (params: Record<string, any>) => Promise<T>;
|
|
19
|
-
pagination?: IPaginationProps;
|
|
19
|
+
pagination?: IPaginationProps|false;
|
|
20
20
|
manual?: boolean;
|
|
21
21
|
emptyRender?: EmptyPageRender;
|
|
22
22
|
errorRender?: ErrorPageRender;
|
|
@@ -7,60 +7,64 @@ const dataSource = [
|
|
|
7
7
|
id: 1,
|
|
8
8
|
title: "1",
|
|
9
9
|
time: "1757574280",
|
|
10
|
-
}
|
|
10
|
+
},
|
|
11
11
|
];
|
|
12
12
|
export default () => {
|
|
13
13
|
const defaultActionRef = useRef<ActionType>();
|
|
14
14
|
const [cuData, setCuData] = useState(dataSource);
|
|
15
|
-
console.log(defaultActionRef,"defaultActionRef")
|
|
15
|
+
console.log(defaultActionRef, "defaultActionRef");
|
|
16
16
|
return (
|
|
17
17
|
<div>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
18
|
+
<div
|
|
19
|
+
onClick={() => {
|
|
20
|
+
|
|
21
|
+
}}
|
|
22
|
+
>
|
|
23
|
+
刷新
|
|
24
|
+
</div>
|
|
25
|
+
<HEditTable
|
|
26
|
+
manual
|
|
27
|
+
onAdd={async (data) => {
|
|
28
|
+
const newData = [...cuData];
|
|
29
|
+
newData.push({
|
|
30
|
+
id: new Date().valueOf(),
|
|
31
|
+
...data,
|
|
32
|
+
});
|
|
33
|
+
setCuData(newData);
|
|
34
|
+
}}
|
|
35
|
+
onEdit={async (data) => {}}
|
|
36
|
+
request={() => {
|
|
37
|
+
return {
|
|
38
|
+
records: [
|
|
39
|
+
{
|
|
40
|
+
id: 1,
|
|
41
|
+
title: "1",
|
|
42
|
+
time: "1757574280",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
}}
|
|
47
|
+
configData={[
|
|
48
|
+
{ title: "标题", dataIndex: "title" },
|
|
49
|
+
{ title: "标题2", dataIndex: "time", valueType: "date" },
|
|
50
|
+
{
|
|
51
|
+
title: "操作",
|
|
52
|
+
valueType: "option",
|
|
53
|
+
align: "center",
|
|
54
|
+
render: (text: any, record: any, index: any, action: any) => [
|
|
55
|
+
<a
|
|
56
|
+
key="editable"
|
|
57
|
+
type={"link"}
|
|
58
|
+
onClick={() => {
|
|
59
|
+
action?.startEditable?.(record.id);
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
编辑
|
|
63
|
+
</a>,
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
]}
|
|
67
|
+
/>
|
|
64
68
|
</div>
|
|
65
69
|
);
|
|
66
70
|
};
|
|
@@ -40,25 +40,26 @@ export default () => {
|
|
|
40
40
|
</div>
|
|
41
41
|
<HDwEditTable
|
|
42
42
|
title="编辑"
|
|
43
|
-
request={
|
|
44
|
-
return {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
request={() => {
|
|
44
|
+
return new Promise(resolve => {
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
resolve( {
|
|
47
|
+
records: [
|
|
48
|
+
{
|
|
49
|
+
id: "213213",
|
|
50
|
+
title: "100",
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
current: "1",
|
|
54
|
+
size: "10",
|
|
55
|
+
total: "10",
|
|
56
|
+
})
|
|
57
|
+
},2000)
|
|
58
|
+
})
|
|
55
59
|
}}
|
|
56
60
|
editTableProps={{
|
|
57
61
|
onAdd: async (data) => {},
|
|
58
62
|
onEdit: async (data) => {},
|
|
59
|
-
defaultRecordValue: {
|
|
60
|
-
title: "21312",
|
|
61
|
-
},
|
|
62
63
|
}}
|
|
63
64
|
dialogTable={dialogTable}
|
|
64
65
|
configData={[
|
|
@@ -68,17 +69,28 @@ export default () => {
|
|
|
68
69
|
title: "操作",
|
|
69
70
|
valueType: "option",
|
|
70
71
|
align: "center",
|
|
71
|
-
render: (text: any, record: any, _: any, action: any) =>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
render: (text: any, record: any, _: any, action: any) =>{
|
|
73
|
+
return <>
|
|
74
|
+
<a
|
|
75
|
+
key="editable"
|
|
76
|
+
type={"link"}
|
|
77
|
+
onClick={() => {
|
|
78
|
+
action?.startEditable?.(record.id);
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
编辑
|
|
82
|
+
</a>
|
|
83
|
+
<a
|
|
84
|
+
key="editable"
|
|
85
|
+
type={"link"}
|
|
86
|
+
onClick={() => {
|
|
87
|
+
action.reload()
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
刷新
|
|
91
|
+
</a>
|
|
92
|
+
</>
|
|
93
|
+
}
|
|
82
94
|
},
|
|
83
95
|
]}
|
|
84
96
|
/>
|