@hw-component/table 1.9.92 → 1.9.94

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.
Files changed (77) hide show
  1. package/.eslintcache +1 -1
  2. package/es/DialogTable/Content.d.ts +4 -3
  3. package/es/DialogTable/Content.js +52 -3
  4. package/es/DialogTable/DwTable.js +2 -2
  5. package/es/DialogTable/ModalEditTable.d.ts +5 -0
  6. package/es/DialogTable/ModalEditTable.js +120 -0
  7. package/es/DialogTable/ModalTable.js +2 -2
  8. package/es/DialogTable/hooks.d.ts +4 -15
  9. package/es/DialogTable/hooks.js +9 -2
  10. package/es/EditTable/hooks.d.ts +9 -0
  11. package/es/EditTable/hooks.js +76 -0
  12. package/es/EditTable/index.d.ts +4 -0
  13. package/es/EditTable/index.js +181 -0
  14. package/es/EditTable/modal.d.ts +19 -0
  15. package/es/HTableBody/Options/hooks.d.ts +1 -1
  16. package/es/HTableBody/defaultRender.d.ts +7 -1
  17. package/es/HTableBody/defaultRender.js +11 -4
  18. package/es/HTableBody/index.js +4 -1
  19. package/es/HTableBody/modal.d.ts +3 -3
  20. package/es/HTablePagination/index.d.ts +2 -1
  21. package/es/HTablePagination/index.js +6 -4
  22. package/es/Table.js +1 -1
  23. package/es/TableConfig.d.ts +5 -5
  24. package/es/index.d.ts +2 -0
  25. package/es/index.js +2 -0
  26. package/es/modal.d.ts +14 -5
  27. package/lib/DialogTable/Content.d.ts +4 -3
  28. package/lib/DialogTable/Content.js +53 -5
  29. package/lib/DialogTable/DwTable.js +1 -1
  30. package/lib/DialogTable/ModalEditTable.d.ts +5 -0
  31. package/lib/DialogTable/ModalEditTable.js +123 -0
  32. package/lib/DialogTable/ModalTable.js +1 -1
  33. package/lib/DialogTable/hooks.d.ts +4 -15
  34. package/lib/DialogTable/hooks.js +9 -2
  35. package/lib/EditTable/hooks.d.ts +9 -0
  36. package/lib/EditTable/hooks.js +78 -0
  37. package/lib/EditTable/index.d.ts +4 -0
  38. package/lib/EditTable/index.js +184 -0
  39. package/lib/EditTable/modal.d.ts +19 -0
  40. package/lib/HTableBody/Options/hooks.d.ts +1 -1
  41. package/lib/HTableBody/defaultRender.d.ts +7 -1
  42. package/lib/HTableBody/defaultRender.js +11 -4
  43. package/lib/HTableBody/index.js +4 -1
  44. package/lib/HTableBody/modal.d.ts +3 -3
  45. package/lib/HTablePagination/index.d.ts +2 -1
  46. package/lib/HTablePagination/index.js +6 -4
  47. package/lib/Table.js +1 -1
  48. package/lib/TableConfig.d.ts +5 -5
  49. package/lib/index.d.ts +2 -0
  50. package/lib/index.js +4 -0
  51. package/lib/modal.d.ts +14 -5
  52. package/package.json +4 -3
  53. package/src/components/DialogTable/Content.tsx +25 -2
  54. package/src/components/DialogTable/DwTable.tsx +3 -2
  55. package/src/components/DialogTable/ModalEditTable.tsx +99 -0
  56. package/src/components/DialogTable/ModalTable.tsx +3 -2
  57. package/src/components/DialogTable/hooks.ts +15 -4
  58. package/src/components/EditTable/hooks.ts +43 -0
  59. package/src/components/EditTable/index.tsx +118 -0
  60. package/src/components/EditTable/modal.ts +26 -0
  61. package/src/components/HTableBody/Options/Content.tsx +11 -11
  62. package/src/components/HTableBody/Options/ContentTree.tsx +1 -5
  63. package/src/components/HTableBody/Options/hooks.tsx +5 -8
  64. package/src/components/HTableBody/defaultRender.tsx +17 -7
  65. package/src/components/HTableBody/index.tsx +1 -1
  66. package/src/components/HTableBody/modal.ts +6 -7
  67. package/src/components/HTablePagination/index.tsx +7 -3
  68. package/src/components/Table.tsx +2 -2
  69. package/src/components/TableConfig.tsx +7 -3
  70. package/src/components/index.tsx +2 -0
  71. package/src/components/modal.ts +19 -8
  72. package/src/components/render/index.tsx +1 -0
  73. package/src/pages/DwTable/index.tsx +1 -0
  74. package/src/pages/EditTable/index.tsx +70 -0
  75. package/src/pages/ModalEditTable/index.tsx +84 -0
  76. package/src/pages/Table/index.tsx +30 -1
  77. package/src/routes.tsx +12 -0
@@ -21,14 +21,17 @@ export const useHDialogTable = () => {
21
21
  interface ParamsModal extends HOnDiaLogTableInstance {
22
22
  dialogTable?: HDiaLogTableInstance;
23
23
  }
24
- export const useTableProps = ({
24
+
25
+ type TablePropsModal<T> = Omit<ModalTableProps<T>, "tableProps">;
26
+
27
+ export function useTableProps<T>({
25
28
  configData,
26
29
  params,
27
30
  title,
28
31
  request,
29
32
  dataSource,
30
- }: Omit<ModalTableProps, "tableProps">) => {
31
- const [modalTableParams, setModalTableParams] = useState({
33
+ }: TablePropsModal<T>) {
34
+ const [modalTableParams, setModalTableParams] = useState<TablePropsModal<T>>({
32
35
  params,
33
36
  title,
34
37
  configData,
@@ -45,11 +48,19 @@ export const useTableProps = ({
45
48
  });
46
49
  }
47
50
  }, [configData]);
51
+ useEffect(() => {
52
+ setModalTableParams((oldVal) => {
53
+ return {
54
+ ...oldVal,
55
+ dataSource,
56
+ };
57
+ });
58
+ }, [dataSource]);
48
59
  return {
49
60
  modalTableParams,
50
61
  setModalTableParams,
51
62
  };
52
- };
63
+ }
53
64
  export const useCurrentTable = ({ show, hide, dialogTable }: ParamsModal) => {
54
65
  const cuDialogTableInstance = useHDialogTable();
55
66
  const dialogTableInstance = dialogTable || cuDialogTableInstance;
@@ -0,0 +1,43 @@
1
+ import { useRequest } from "ahooks";
2
+ import { EditTableProps } from "./modal";
3
+ import { MutableRefObject, useMemo, useRef } from "react";
4
+ import type { ActionType } from "@ant-design/pro-table";
5
+ import { EditableFormInstance } from "@ant-design/pro-table/lib/components/EditableTable";
6
+
7
+ export const useListRequest = ({ request, dataSource }: EditTableProps) => {
8
+ const saveParams = useMemo(() => {
9
+ return {
10
+ params: {},
11
+ };
12
+ }, []);
13
+ return useRequest(
14
+ async (params) => {
15
+ const newParams = {
16
+ ...saveParams.params,
17
+ ...params,
18
+ };
19
+ saveParams.params = newParams;
20
+ if (request) {
21
+ return request(newParams);
22
+ }
23
+ if (Array.isArray(dataSource)) {
24
+ return dataSource;
25
+ }
26
+ return dataSource;
27
+ },
28
+ { manual: true, refreshDeps: [dataSource] }
29
+ );
30
+ };
31
+
32
+ export const useCuRef = ({ actionRef, editableFormRef }: EditTableProps) => {
33
+ const defaultActionRef = useRef<ActionType>();
34
+ const defaultTableRef = useRef<EditableFormInstance>();
35
+ const cuActionRef = (actionRef ||
36
+ defaultActionRef) as MutableRefObject<ActionType>;
37
+ const cuEditableFormRef = (editableFormRef ||
38
+ defaultTableRef) as MutableRefObject<EditableFormInstance>;
39
+ return {
40
+ cuActionRef,
41
+ cuEditableFormRef,
42
+ };
43
+ };
@@ -0,0 +1,118 @@
1
+ import { EditableProTable } from "@ant-design/pro-table";
2
+ import { EditTableProps } from "./modal";
3
+ import { useClassName } from "@/components/hooks";
4
+ import HTablePagination from "../HTablePagination";
5
+ import { ConfigProvider } from "antd";
6
+ import {
7
+ emptyDefaultRender,
8
+ errorDefaultRender,
9
+ } from "@/components/HTableBody/defaultRender";
10
+ import { useHTableConfigContext } from "@/components/TableConfig";
11
+ import { useCuRef, useListRequest } from "./hooks";
12
+ import React from "react";
13
+
14
+ export default ({
15
+ configData,
16
+ rowKey = "id",
17
+ creatorButtonText = "新增一列",
18
+ recordCreatorProps = {},
19
+ defaultRecordValue = {},
20
+ pagination,
21
+ editable = {},
22
+ dataSource,
23
+ request,
24
+ manual,
25
+ emptyRender,
26
+ errorRender,
27
+ onAdd,
28
+ onEdit,
29
+ actionRef,
30
+ editableFormRef,
31
+ ...props
32
+ }: EditTableProps) => {
33
+ const tableBody = useClassName("hw-table-body");
34
+ const { loading, data, error, run } = useListRequest({
35
+ request,
36
+ dataSource,
37
+ });
38
+ const {
39
+ emptyRender: tableEmptyRender = emptyDefaultRender,
40
+ errorRender: tableErrorRender = errorDefaultRender,
41
+ } = useHTableConfigContext({ emptyRender, errorRender });
42
+
43
+ const isLocalData = Array.isArray(data);
44
+ const values = isLocalData ? data : data?.record;
45
+ const { cuActionRef, cuEditableFormRef } = useCuRef({
46
+ actionRef,
47
+ editableFormRef,
48
+ });
49
+
50
+ return (
51
+ <div className={tableBody}>
52
+ <ConfigProvider
53
+ renderEmpty={() => {
54
+ if (error) {
55
+ return tableErrorRender?.({
56
+ reload: cuActionRef.current.reload,
57
+ error,
58
+ });
59
+ }
60
+ return tableEmptyRender?.();
61
+ }}
62
+ >
63
+ <EditableProTable
64
+ columns={configData as any}
65
+ loading={loading}
66
+ rowKey={rowKey}
67
+ editableFormRef={cuEditableFormRef}
68
+ manualRequest={manual}
69
+ request={run}
70
+ actionRef={cuActionRef}
71
+ value={values}
72
+ recordCreatorProps={{
73
+ position: "bottom",
74
+ record: () => ({ id: "add" }),
75
+ creatorButtonText,
76
+ ...recordCreatorProps,
77
+ }}
78
+ editable={{
79
+ type: "single",
80
+ onCancel: async (keys) => {
81
+ cuEditableFormRef.current?.resetFields([keys]);
82
+ },
83
+ actionRender: (trow, tconfig, defaultDoms) => {
84
+ return [defaultDoms.save, defaultDoms.cancel];
85
+ },
86
+ onSave: async (key, row) => {
87
+ const { index, id, ...oRow } = row;
88
+ if (key === "add") {
89
+ await onAdd?.(oRow);
90
+ cuEditableFormRef.current?.resetFields(["add"]);
91
+ cuActionRef.current?.reload();
92
+ return;
93
+ }
94
+ await onEdit?.({
95
+ id,
96
+ ...oRow,
97
+ });
98
+ cuEditableFormRef.current?.resetFields(["key"]);
99
+ cuActionRef.current?.reload();
100
+ },
101
+ ...editable,
102
+ }}
103
+ {...props}
104
+ />
105
+ </ConfigProvider>
106
+ <HTablePagination
107
+ data={isLocalData ? null : data}
108
+ {...pagination}
109
+ onChange={(page, pageSize) => {
110
+ run({
111
+ size: pageSize,
112
+ current: page,
113
+ });
114
+ }}
115
+ />
116
+ </div>
117
+ );
118
+ };
@@ -0,0 +1,26 @@
1
+ import { EditableProTableProps } from "@ant-design/pro-table/lib/components/EditableTable";
2
+ import { ParamsType } from "@ant-design/pro-provider";
3
+ import { IPaginationProps } from "../HTablePagination";
4
+ import { EmptyPageRender, ErrorPageRender } from "../modal";
5
+ import { ProColumns } from "@ant-design/pro-table/lib/typing";
6
+
7
+ export interface EditTableProps<T = any>
8
+ extends Omit<
9
+ EditableProTableProps<T, ParamsType>,
10
+ "recordCreatorProps" | "request" | "pagination"
11
+ > {
12
+ creatorButtonText?: string;
13
+ defaultRecordValue?: T;
14
+ recordCreatorProps?: Partial<
15
+ EditableProTableProps<T, ParamsType>["recordCreatorProps"]
16
+ >;
17
+ dataSource?: any[];
18
+ request?: (params: Record<string, any>) => Promise<T>;
19
+ pagination?: IPaginationProps;
20
+ manual?: boolean;
21
+ emptyRender?: EmptyPageRender;
22
+ errorRender?: ErrorPageRender;
23
+ onAdd?: (data: T) => Promise<void>;
24
+ onEdit?: (data: T) => Promise<void>;
25
+ configData?: ProColumns<T>[];
26
+ }
@@ -70,35 +70,35 @@ export const ColsSettingContent = ({
70
70
  onDrop={onDropEnd}
71
71
  onCheck={(key) => {
72
72
  const curKey = key as string[];
73
- check([...curKey,...norCheckKeys,...rightCheckKeys]);
73
+ check([...curKey, ...norCheckKeys, ...rightCheckKeys]);
74
74
  }}
75
75
  />
76
76
  <ContentTree
77
77
  title="不固定"
78
78
  treeData={norContentTreeData}
79
79
  checkedKeys={norCheckKeys}
80
- onDrop={({ dragNodesKeys, dropPosition })=>{
81
- const cuDropPosition=leftContentTreeData.length+dropPosition;
82
- onDropEnd({dragNodesKeys, dropPosition:cuDropPosition});
80
+ onDrop={({ dragNodesKeys, dropPosition }) => {
81
+ const cuDropPosition = leftContentTreeData.length + dropPosition;
82
+ onDropEnd({ dragNodesKeys, dropPosition: cuDropPosition });
83
83
  }}
84
84
  onCheck={(key) => {
85
85
  const curKey = key as string[];
86
- check([...leftCheckKeys,...curKey,...rightCheckKeys]);
86
+ check([...leftCheckKeys, ...curKey, ...rightCheckKeys]);
87
87
  }}
88
88
  />
89
89
  <ContentTree
90
90
  title="固定在右侧"
91
91
  treeData={rightContentTreeData}
92
92
  checkedKeys={rightCheckKeys}
93
- onDrop={({ dragNodesKeys, dropPosition })=>{
94
- const leftLen=leftContentTreeData.length;
95
- const norLen=norContentTreeData.length;
96
- const cuDropPosition=leftLen+norLen+dropPosition;
97
- onDropEnd({dragNodesKeys, dropPosition:cuDropPosition});
93
+ onDrop={({ dragNodesKeys, dropPosition }) => {
94
+ const leftLen = leftContentTreeData.length;
95
+ const norLen = norContentTreeData.length;
96
+ const cuDropPosition = leftLen + norLen + dropPosition;
97
+ onDropEnd({ dragNodesKeys, dropPosition: cuDropPosition });
98
98
  }}
99
99
  onCheck={(key) => {
100
100
  const curKey = key as string[];
101
- check([...leftCheckKeys,...norCheckKeys,...curKey]);
101
+ check([...leftCheckKeys, ...norCheckKeys, ...curKey]);
102
102
  }}
103
103
  />
104
104
  </div>
@@ -15,11 +15,7 @@ export default ({ treeData, checkedKeys, onDrop, onCheck, title }: IProps) => {
15
15
  return null;
16
16
  }
17
17
  return (
18
- <Space
19
- className={treeItemContent}
20
- direction="vertical"
21
- size={12}
22
- >
18
+ <Space className={treeItemContent} direction="vertical" size={12}>
23
19
  <Typography.Text type={"secondary"} style={{ paddingLeft: 24 }}>
24
20
  {title}
25
21
  </Typography.Text>
@@ -58,15 +58,12 @@ export const useContentTree = ({ columns, matchKey }: UseContentTreeModal) => {
58
58
  }, [columns]);
59
59
  };
60
60
  interface UseTreeKeysModal {
61
- treeData:ColDataNode[];
62
- checkKeys:string[];
61
+ treeData: ColDataNode[];
62
+ checkKeys: string[];
63
63
  }
64
64
 
65
- export const useTreeKeys = ({
66
- treeData,
67
- checkKeys,
68
- }: UseTreeKeysModal) => {
69
- return useMemo(()=>{
65
+ export const useTreeKeys = ({ treeData, checkKeys }: UseTreeKeysModal) => {
66
+ return useMemo(() => {
70
67
  const newKeys: string[] = [];
71
68
  treeData.forEach(({ key }) => {
72
69
  const index = checkKeys.indexOf(key);
@@ -75,5 +72,5 @@ export const useTreeKeys = ({
75
72
  }
76
73
  });
77
74
  return newKeys;
78
- },[treeData, checkKeys])
75
+ }, [treeData, checkKeys]);
79
76
  };
@@ -10,19 +10,29 @@ const pubProps = {
10
10
  export const emptyDefaultRender = () => {
11
11
  return <Empty image={empty_bg} description="暂无数据~" {...pubProps} />;
12
12
  };
13
- export const errorDefaultRender = (
14
- tableInstance: HTableInstance,
15
- error: Error
16
- ) => {
13
+ interface errorDefaultRenderParams {
14
+ reload?: () => void;
15
+ error: Error;
16
+ tableInstance?: HTableInstance;
17
+ }
18
+ export const errorDefaultRender = ({
19
+ error,
20
+ tableInstance,
21
+ reload,
22
+ }: errorDefaultRenderParams) => {
23
+ const pageReload = () => {
24
+ if (tableInstance) {
25
+ return tableInstance.table.reloadWithParams();
26
+ }
27
+ return reload?.();
28
+ };
17
29
  return (
18
30
  <Empty image={errorBg} description={error.message} {...pubProps}>
19
31
  <Button
20
32
  type={"primary"}
21
33
  ghost
22
34
  style={{ borderRadius: 16 }}
23
- onClick={() => {
24
- tableInstance.table.reloadWithParams();
25
- }}
35
+ onClick={pageReload}
26
36
  >
27
37
  刷新
28
38
  </Button>
@@ -129,7 +129,7 @@ export default (bodyProps: HTableBodyProps) => {
129
129
  <ConfigProvider
130
130
  renderEmpty={() => {
131
131
  if (error) {
132
- return tableErrorRender?.(tableInstance, error);
132
+ return tableErrorRender?.({ tableInstance, error });
133
133
  }
134
134
  return tableEmptyRender?.(tableInstance);
135
135
  }}
@@ -2,13 +2,15 @@ import type { OptionConfig } from "@ant-design/pro-table/lib/components/ToolBar"
2
2
  import type { Key } from "react";
3
3
  import type React from "react";
4
4
  import type { ProTableProps } from "@ant-design/pro-table";
5
- import type {
5
+ import {
6
6
  ActionRenderFn,
7
7
  ConfigDataModal,
8
+ EmptyPageRender,
9
+ ErrorPageRender,
8
10
  HRowSelection,
9
11
  HTableInstance,
10
12
  ParamsModal,
11
- } from "@/components/modal";
13
+ } from "../modal";
12
14
  import type { AffixProps } from "antd/lib/affix";
13
15
  import type { IPaginationProps } from "@/components/HTablePagination";
14
16
 
@@ -22,11 +24,8 @@ export interface HTableBodyProps
22
24
  > {
23
25
  configData?: ConfigDataModal;
24
26
  onPageChange?: (params: ParamsModal) => void;
25
- emptyRender?: (tableInstance: HTableInstance) => React.ReactNode;
26
- errorRender?: (
27
- tableInstance: HTableInstance,
28
- error: Error
29
- ) => React.ReactNode;
27
+ emptyRender?: EmptyPageRender;
28
+ errorRender?: ErrorPageRender;
30
29
  tableStyle?: React.CSSProperties;
31
30
  paginationStyle?: React.CSSProperties;
32
31
  actionRender?: ActionRenderFn;
@@ -7,6 +7,7 @@ import React, { useState } from "react";
7
7
  import type { AffixProps } from "antd/lib/affix";
8
8
  import GoTop from "../GoTop";
9
9
  import { useHTableConfigContext } from "@/components/TableConfig";
10
+
10
11
  export interface IPaginationProps extends Omit<PaginationProps, "showTotal"> {
11
12
  onPageChange?: (params: ParamsModal) => void;
12
13
  paginationStyle?: React.CSSProperties;
@@ -15,6 +16,7 @@ export interface IPaginationProps extends Omit<PaginationProps, "showTotal"> {
15
16
  actionRender?: (tableInstance: HTableInstance) => React.ReactNode;
16
17
  table?: HTableInstance;
17
18
  showTotal?: false | PaginationProps["showTotal"];
19
+ data?: Record<string, any>;
18
20
  }
19
21
  const defaultShowTotal = (totalNum: number, [showCurrent, showCurrentEnd]) => {
20
22
  return `第${showCurrent}-${showCurrentEnd}/总共${totalNum}条`;
@@ -27,26 +29,28 @@ export default ({
27
29
  actionRender,
28
30
  table,
29
31
  showTotal = defaultShowTotal,
32
+ data,
30
33
  ...props
31
34
  }: IPaginationProps) => {
32
35
  const {
33
36
  onPageChange: contextOnPageChange,
34
- data,
37
+ data: contextData,
35
38
  tableInstance: contextTableInstance,
36
39
  } = useHTableContext();
37
40
  const { paginationStyle: defaultPaginationStyle } = useHTableConfigContext({
38
41
  paginationStyle,
39
42
  });
43
+ const cuData = data || contextData;
40
44
  const tableInstance = table || contextTableInstance;
41
45
  const tableOnPageChange = onPageChange || contextOnPageChange;
42
- const { size, current, total } = data || {};
46
+ const { size, current, total } = cuData || {};
43
47
  const pageCurrent = Number.parseInt(current || "1", 10);
44
48
  const pageSize = Number.parseInt(size || "10", 10);
45
49
  const pageTotal = Number.parseInt(total || "0", 10);
46
50
  const className = useClassName("hw-table-pagination");
47
51
  const [style, setStyle] = useState({});
48
52
  const cuShowTotal = showTotal === false ? undefined : showTotal;
49
- if (!data) {
53
+ if (!cuData) {
50
54
  return <></>;
51
55
  }
52
56
  if (affixProps === false) {
@@ -3,12 +3,12 @@ import Body from "./HTableBody";
3
3
  import useCurrentTable from "./hooks/useCurrentTable";
4
4
  import useRowObj from "./hooks/useRowObj";
5
5
  import { HTableContext } from "./context";
6
- import { Space } from "antd";
7
6
  import type { HTableProps } from "./modal";
8
7
  import useReq from "./hooks/useReq";
9
8
  import useDispatch from "./hooks/useDispatch";
10
9
  import { useState } from "react";
11
10
  import { useClassName } from "./hooks";
11
+
12
12
  export default ({
13
13
  request,
14
14
  configData,
@@ -85,7 +85,7 @@ export default ({
85
85
  configData,
86
86
  onFinish: (value) => {
87
87
  rowSelectionReload();
88
- return run({ ...saveParams.old, ...value, current: 1 });
88
+ return run({ ...value, current: 1 });
89
89
  },
90
90
  onPageChange: tableInstance.table.reloadWithParams,
91
91
  setSelectedRowData,
@@ -1,9 +1,13 @@
1
1
  import React, { useContext } from "react";
2
- import type { HTableInstance, ValueTypeConfigModal } from "./modal";
2
+ import {
3
+ EmptyPageRender,
4
+ ErrorPageRender,
5
+ ValueTypeConfigModal,
6
+ } from "./modal";
3
7
 
4
8
  interface HTableConfigContextModal {
5
- emptyRender?: (table: HTableInstance) => React.ReactNode;
6
- errorRender?: (table: HTableInstance, error: Error) => React.ReactNode;
9
+ emptyRender?: EmptyPageRender;
10
+ errorRender?: ErrorPageRender;
7
11
  headerStyle?: React.CSSProperties;
8
12
  tableStyle?: React.CSSProperties;
9
13
  paginationStyle?: React.CSSProperties;
@@ -12,3 +12,5 @@ export { default as HModalTable } from "./DialogTable/ModalTable";
12
12
  export { useHDialogTable } from "./DialogTable/hooks";
13
13
  export { default as HDwTable } from "./DialogTable/DwTable";
14
14
  export { DefaultSubComponent as HTableHeaderSubBtn } from "./HTableHeader/defaultSubComponent";
15
+ export { default as EditTable } from "./EditTable";
16
+ export { default as ModalEditTable } from "./DialogTable/ModalEditTable";
@@ -12,7 +12,8 @@ import type { TableProps } from "antd/lib/table";
12
12
  import type { AffixProps } from "antd/lib/affix";
13
13
  import type { OptionModal } from "./HTableBody/modal";
14
14
  import type { DrawerProps } from "antd";
15
- import type { IPaginationProps } from "@/components/HTablePagination";
15
+ import type { IPaginationProps } from "./HTablePagination";
16
+ import { EditTableProps } from "./EditTable/modal";
16
17
 
17
18
  export interface RowObj {
18
19
  keys?: React.Key[];
@@ -89,11 +90,8 @@ export interface HTableProps
89
90
  searchSpan?: ColProps;
90
91
  table?: HTableInstance;
91
92
  actionRender?: ActionRenderFn;
92
- emptyRender?: (tableInstance: HTableInstance) => React.ReactNode;
93
- errorRender?: (
94
- tableInstance: HTableInstance,
95
- error: Error
96
- ) => React.ReactNode;
93
+ emptyRender?: EmptyPageRender;
94
+ errorRender?: ErrorPageRender;
97
95
  hideHeader?: boolean;
98
96
  action?: Record<string, actionFn>;
99
97
  headerStyle?: React.CSSProperties;
@@ -165,15 +163,17 @@ export interface DwTableProps extends DrawerProps {
165
163
  contentRender?: (node: React.ReactNode) => React.ReactNode;
166
164
  }
167
165
 
168
- export interface ModalTableProps extends Omit<ModalProps, "onOk"> {
166
+ export interface ModalTableProps<T = HTableProps["configData"]>
167
+ extends Omit<ModalProps, "onOk"> {
169
168
  tableProps?: Omit<HTableProps, "configData" | "request">;
170
169
  dialogTable?: HDiaLogTableInstance;
171
170
  params?: Record<string, any>;
172
- configData?: HTableProps["configData"];
171
+ configData?: T;
173
172
  request?: HTableProps["request"];
174
173
  contentRender?: (node: React.ReactNode) => React.ReactNode;
175
174
  dataSource?: any[];
176
175
  onOk?: (e?: React.MouseEvent<HTMLElement>) => void;
176
+ editTableProps?: Omit<EditTableProps, "configData" | "request">;
177
177
  }
178
178
 
179
179
  export type ValueTypeConfigRenderFn = (
@@ -183,3 +183,14 @@ export type ValueTypeConfigRenderFn = (
183
183
  tableInstance: HTableInstance
184
184
  ) => React.ReactNode;
185
185
  export type ValueTypeConfigModal = Record<string, ValueTypeConfigRenderFn>;
186
+
187
+ interface ErrorRenderParams {
188
+ error: Error;
189
+ tableInstance?: HTableInstance;
190
+ reload?: VoidFunction;
191
+ }
192
+
193
+ export type ErrorPageRender = (params: ErrorRenderParams) => React.ReactNode;
194
+ export type EmptyPageRender = (
195
+ tableInstance?: HTableInstance
196
+ ) => React.ReactNode;
@@ -2,6 +2,7 @@ import type { ConfigItemModal, HTableInstance } from "@/components/modal";
2
2
  import type React from "react";
3
3
  import config from "./config";
4
4
  import type { ValueTypeConfigModal } from "../modal";
5
+
5
6
  export default (
6
7
  item: ConfigItemModal,
7
8
  tableInstance: HTableInstance,
@@ -1,5 +1,6 @@
1
1
  import { Button } from "antd";
2
2
  import { HDwTable, HModalTable, HTable, useHDialogTable } from "@/components";
3
+
3
4
  const configData = [
4
5
  {
5
6
  title: "座位",
@@ -0,0 +1,70 @@
1
+ import { EditTable } from "@/components";
2
+ import { useRef, useState } from "react";
3
+ import type { ActionType } from "@ant-design/pro-table";
4
+
5
+ const dataSource = [
6
+ {
7
+ id: 1,
8
+ title: "1",
9
+ },
10
+ {
11
+ id: 2,
12
+ title: "2",
13
+ },
14
+ {
15
+ id: 3,
16
+ title: "3",
17
+ },
18
+ {
19
+ id: 4,
20
+ title: "4",
21
+ },
22
+ {
23
+ id: 5,
24
+ title: "5",
25
+ },
26
+ ];
27
+ export default () => {
28
+ const defaultActionRef = useRef<ActionType>();
29
+ const [cuData, setCuData] = useState(dataSource);
30
+ return (
31
+ <EditTable
32
+ actionRef={defaultActionRef}
33
+ onAdd={async (data) => {
34
+ const newData = [...cuData];
35
+ newData.push({
36
+ id: newData.length + 1,
37
+ ...data,
38
+ });
39
+ setCuData(newData);
40
+ }}
41
+ onEdit={async (data) => {
42
+ const index = cuData.findIndex((e) => e.id === data.id);
43
+ cuData[index] = data;
44
+ setCuData([...cuData]);
45
+ }}
46
+ dataSource={cuData}
47
+ configData={[
48
+ { title: "标题", dataIndex: "title" },
49
+ { title: "标题2", dataIndex: "title1" },
50
+ {
51
+ title: "操作",
52
+ valueType: "option",
53
+ align: "center",
54
+ render: (text: any, record: any, _: any, action: any) => [
55
+ <a
56
+ key="editable"
57
+ type={"link"}
58
+ onClick={() => {
59
+ console.log(action);
60
+ action?.startEditable?.(record.id);
61
+ }}
62
+ >
63
+ 编辑
64
+ </a>,
65
+ ],
66
+ },
67
+ ]}
68
+ />
69
+ );
70
+ };