@hw-component/table 1.10.23 → 1.10.25
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/EditTable/hooks.d.ts +53 -44
- package/es/EditTable/hooks.js +33 -14
- package/es/EditTable/index.d.ts +1 -1
- package/es/EditTable/index.js +23 -18
- package/es/EditTable/modal.d.ts +9 -3
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/lib/EditTable/hooks.d.ts +53 -44
- package/lib/EditTable/hooks.js +34 -13
- package/lib/EditTable/index.d.ts +1 -1
- package/lib/EditTable/index.js +22 -17
- package/lib/EditTable/modal.d.ts +9 -3
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
- package/src/components/EditTable/hooks.ts +38 -2
- package/src/components/EditTable/index.tsx +32 -23
- package/src/components/EditTable/modal.ts +10 -3
- package/src/components/index.tsx +1 -0
- package/src/pages/EditTable/index.tsx +11 -16
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRequest } from "ahooks";
|
|
2
|
-
import { HEditTableProps
|
|
3
|
-
import { MutableRefObject, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import {EditTableInstance, HEditTableProps} from "./modal";
|
|
3
|
+
import React, { 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";
|
|
@@ -73,6 +73,42 @@ export const useCuRef = ({ actionRef, editableFormRef }: HEditTableProps) => {
|
|
|
73
73
|
cuEditableFormRef,
|
|
74
74
|
};
|
|
75
75
|
};
|
|
76
|
+
|
|
77
|
+
export const useEditTable = ():EditTableInstance => {
|
|
78
|
+
return {
|
|
79
|
+
reload:()=>{
|
|
80
|
+
return Promise.resolve();
|
|
81
|
+
},
|
|
82
|
+
editableForm:{},
|
|
83
|
+
action:{}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export const useCuEditTable=({table}:HEditTableProps)=>{
|
|
87
|
+
const cuTable=useEditTable();
|
|
88
|
+
return table||cuTable;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface EditTableInitParams {
|
|
92
|
+
table:EditTableInstance;
|
|
93
|
+
actionRef:MutableRefObject<ActionType | undefined>;
|
|
94
|
+
editableFormRef:MutableRefObject<EditableFormInstance | undefined>;
|
|
95
|
+
request:VoidFunction;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const useEditTableInit = ({table,actionRef, editableFormRef,request }:EditTableInitParams) => {
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (!table) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
table.editableForm=editableFormRef?.current||{};
|
|
105
|
+
table.reload=()=>{
|
|
106
|
+
request();
|
|
107
|
+
}
|
|
108
|
+
table.action=actionRef?.current||{};
|
|
109
|
+
},[actionRef,editableFormRef,table])
|
|
110
|
+
}
|
|
111
|
+
|
|
76
112
|
interface ColProps extends HEditTableProps {
|
|
77
113
|
reload: VoidFunction;
|
|
78
114
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { EditableProTable
|
|
1
|
+
import {type ActionType, EditableProTable} from "@ant-design/pro-table";
|
|
2
2
|
import { HEditTableProps } from "./modal";
|
|
3
|
-
import { useClassName } from "
|
|
3
|
+
import { useClassName } from "../hooks";
|
|
4
4
|
import HTablePagination from "../HTablePagination";
|
|
5
5
|
import { ConfigProvider } from "antd";
|
|
6
6
|
import {
|
|
7
7
|
emptyDefaultRender,
|
|
8
8
|
errorDefaultRender,
|
|
9
|
-
} from "
|
|
10
|
-
import { useHTableConfigContext } from "
|
|
11
|
-
import {
|
|
12
|
-
import React from "react";
|
|
9
|
+
} from "../HTableBody/defaultRender";
|
|
10
|
+
import { useHTableConfigContext } from "../TableConfig";
|
|
11
|
+
import {useColsMk, useCuEditTable, useEditTableInit, useListRequest} from "./hooks";
|
|
12
|
+
import React, {useRef} from "react";
|
|
13
|
+
import {EditableFormInstance} from "@ant-design/pro-table/lib/components/EditableTable";
|
|
13
14
|
|
|
14
15
|
export default ({
|
|
15
16
|
configData,
|
|
@@ -26,11 +27,11 @@ export default ({
|
|
|
26
27
|
errorRender,
|
|
27
28
|
onAdd,
|
|
28
29
|
onEdit,
|
|
29
|
-
actionRef,
|
|
30
|
-
editableFormRef,
|
|
31
30
|
style,
|
|
31
|
+
table,
|
|
32
32
|
...props
|
|
33
33
|
}: HEditTableProps) => {
|
|
34
|
+
const cuTable=useCuEditTable({table});
|
|
34
35
|
const tableBody = useClassName("hw-table-body");
|
|
35
36
|
const { loading, data, error, run } = useListRequest({
|
|
36
37
|
request,
|
|
@@ -41,11 +42,15 @@ export default ({
|
|
|
41
42
|
emptyRender: tableEmptyRender = emptyDefaultRender,
|
|
42
43
|
errorRender: tableErrorRender = errorDefaultRender,
|
|
43
44
|
} = useHTableConfigContext({ emptyRender, errorRender });
|
|
45
|
+
const defaultActionRef = useRef<ActionType>();
|
|
46
|
+
const defaultEditableFormRef = useRef<EditableFormInstance>();
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
editableFormRef,
|
|
48
|
-
|
|
48
|
+
useEditTableInit({
|
|
49
|
+
actionRef:defaultActionRef,
|
|
50
|
+
editableFormRef:defaultEditableFormRef,
|
|
51
|
+
table:cuTable,
|
|
52
|
+
request:run
|
|
53
|
+
})
|
|
49
54
|
const columns = useColsMk({ configData, reload: run });
|
|
50
55
|
return (
|
|
51
56
|
<div className={tableBody} style={style}>
|
|
@@ -64,19 +69,23 @@ export default ({
|
|
|
64
69
|
columns={columns}
|
|
65
70
|
loading={loading}
|
|
66
71
|
rowKey={rowKey}
|
|
67
|
-
editableFormRef={
|
|
68
|
-
actionRef={
|
|
72
|
+
editableFormRef={defaultEditableFormRef}
|
|
73
|
+
actionRef={defaultActionRef}
|
|
69
74
|
value={data?.records}
|
|
70
|
-
recordCreatorProps={
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
recordCreatorProps={
|
|
76
|
+
recordCreatorProps === false
|
|
77
|
+
? recordCreatorProps
|
|
78
|
+
: {
|
|
79
|
+
position: "bottom",
|
|
80
|
+
record: () => ({ id: "add", ...defaultRecordValue }),
|
|
81
|
+
creatorButtonText,
|
|
82
|
+
...recordCreatorProps,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
76
85
|
editable={{
|
|
77
86
|
type: "single",
|
|
78
87
|
onCancel: async (keys) => {
|
|
79
|
-
|
|
88
|
+
defaultEditableFormRef.current?.resetFields([keys]);
|
|
80
89
|
},
|
|
81
90
|
actionRender: (trow, tconfig, defaultDoms) => {
|
|
82
91
|
return [defaultDoms.save, defaultDoms.cancel];
|
|
@@ -85,7 +94,7 @@ export default ({
|
|
|
85
94
|
const { index, id, ...oRow } = row;
|
|
86
95
|
if (key === "add") {
|
|
87
96
|
await onAdd?.(oRow);
|
|
88
|
-
|
|
97
|
+
defaultEditableFormRef.current?.resetFields(["add"]);
|
|
89
98
|
run();
|
|
90
99
|
return;
|
|
91
100
|
}
|
|
@@ -93,7 +102,7 @@ export default ({
|
|
|
93
102
|
id,
|
|
94
103
|
...oRow,
|
|
95
104
|
});
|
|
96
|
-
|
|
105
|
+
defaultEditableFormRef.current?.resetFields([key]);
|
|
97
106
|
run();
|
|
98
107
|
},
|
|
99
108
|
...editable,
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { EditableProTableProps
|
|
1
|
+
import {EditableFormInstance, EditableProTableProps} from "@ant-design/pro-table/lib/components/EditableTable";
|
|
2
2
|
import { ParamsType } from "@ant-design/pro-provider";
|
|
3
3
|
import { IPaginationProps } from "../HTablePagination";
|
|
4
4
|
import { EmptyPageRender, ErrorPageRender } from "../modal";
|
|
5
|
-
import { ProColumns
|
|
5
|
+
import {ActionType, ProColumns} from "@ant-design/pro-table/lib/typing";
|
|
6
|
+
|
|
7
|
+
export interface EditTableInstance {
|
|
8
|
+
editableForm:EditableFormInstance|{};
|
|
9
|
+
action:ActionType|{};
|
|
10
|
+
reload:()=>void;
|
|
11
|
+
}
|
|
6
12
|
|
|
7
13
|
export interface HEditTableProps<T = any>
|
|
8
14
|
extends Omit<
|
|
@@ -15,7 +21,7 @@ export interface HEditTableProps<T = any>
|
|
|
15
21
|
EditableProTableProps<T, ParamsType>["recordCreatorProps"]
|
|
16
22
|
>;
|
|
17
23
|
dataSource?: any[];
|
|
18
|
-
request?: (params
|
|
24
|
+
request?: (params?: Record<string, any>) => Promise<T>;
|
|
19
25
|
pagination?: IPaginationProps | false;
|
|
20
26
|
manual?: boolean;
|
|
21
27
|
emptyRender?: EmptyPageRender;
|
|
@@ -23,4 +29,5 @@ export interface HEditTableProps<T = any>
|
|
|
23
29
|
onAdd?: (data: T) => Promise<void>;
|
|
24
30
|
onEdit?: (data: T) => Promise<void>;
|
|
25
31
|
configData?: ProColumns<T>[];
|
|
32
|
+
table?:EditTableInstance;
|
|
26
33
|
}
|
package/src/components/index.tsx
CHANGED
|
@@ -15,3 +15,4 @@ export { DefaultSubComponent as HTableHeaderSubBtn } from "./HTableHeader/defaul
|
|
|
15
15
|
export { default as HEditTable } from "./EditTable";
|
|
16
16
|
export { default as HModalEditTable } from "./DialogTable/ModalEditTable";
|
|
17
17
|
export { default as HDwEditTable } from "./DialogTable/DwEditTable";
|
|
18
|
+
export { useEditTable } from "./EditTable/hooks";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HEditTable } from "@/components";
|
|
1
|
+
import { HEditTable ,useEditTable} from "@/components";
|
|
2
2
|
import { useRef, useState } from "react";
|
|
3
3
|
import type { ActionType } from "@ant-design/pro-table";
|
|
4
4
|
|
|
@@ -10,15 +10,15 @@ const dataSource = [
|
|
|
10
10
|
},
|
|
11
11
|
];
|
|
12
12
|
export default () => {
|
|
13
|
-
const defaultActionRef = useRef<ActionType>();
|
|
14
13
|
const [cuData, setCuData] = useState(dataSource);
|
|
15
|
-
|
|
14
|
+
const editTableInstance=useEditTable();
|
|
16
15
|
return (
|
|
17
16
|
<div>
|
|
18
|
-
<div onClick={() => {
|
|
17
|
+
<div onClick={() => {
|
|
18
|
+
editTableInstance.reload()
|
|
19
|
+
}}>刷新</div>
|
|
19
20
|
<HEditTable
|
|
20
|
-
|
|
21
|
-
recordCreatorProps={false}
|
|
21
|
+
table={editTableInstance}
|
|
22
22
|
onAdd={async (data) => {
|
|
23
23
|
const newData = [...cuData];
|
|
24
24
|
newData.push({
|
|
@@ -28,16 +28,11 @@ export default () => {
|
|
|
28
28
|
setCuData(newData);
|
|
29
29
|
}}
|
|
30
30
|
onEdit={async (data) => {}}
|
|
31
|
-
request={()
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
title: "1",
|
|
37
|
-
time: "1757574280",
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
};
|
|
31
|
+
request={()=>{
|
|
32
|
+
console.log("fffff")
|
|
33
|
+
return {
|
|
34
|
+
|
|
35
|
+
}
|
|
41
36
|
}}
|
|
42
37
|
configData={[
|
|
43
38
|
{ title: "标题", dataIndex: "title" },
|