@hw-component/table 1.9.93 → 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.
- package/.eslintcache +1 -1
- package/es/DialogTable/Content.d.ts +4 -3
- package/es/DialogTable/Content.js +52 -3
- package/es/DialogTable/DwTable.js +2 -2
- package/es/DialogTable/ModalEditTable.d.ts +5 -0
- package/es/DialogTable/ModalEditTable.js +120 -0
- package/es/DialogTable/ModalTable.js +2 -2
- package/es/DialogTable/hooks.d.ts +4 -15
- package/es/DialogTable/hooks.js +9 -2
- package/es/EditTable/hooks.d.ts +9 -0
- package/es/EditTable/hooks.js +76 -0
- package/es/EditTable/index.d.ts +4 -0
- package/es/EditTable/index.js +181 -0
- package/es/EditTable/modal.d.ts +19 -0
- package/es/HTableBody/defaultRender.d.ts +7 -1
- package/es/HTableBody/defaultRender.js +11 -4
- package/es/HTableBody/index.js +4 -1
- package/es/HTableBody/modal.d.ts +3 -3
- package/es/HTablePagination/index.d.ts +2 -1
- package/es/HTablePagination/index.js +6 -4
- package/es/TableConfig.d.ts +5 -5
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/modal.d.ts +14 -5
- package/lib/DialogTable/Content.d.ts +4 -3
- package/lib/DialogTable/Content.js +53 -5
- package/lib/DialogTable/DwTable.js +1 -1
- package/lib/DialogTable/ModalEditTable.d.ts +5 -0
- package/lib/DialogTable/ModalEditTable.js +123 -0
- package/lib/DialogTable/ModalTable.js +1 -1
- package/lib/DialogTable/hooks.d.ts +4 -15
- package/lib/DialogTable/hooks.js +9 -2
- package/lib/EditTable/hooks.d.ts +9 -0
- package/lib/EditTable/hooks.js +78 -0
- package/lib/EditTable/index.d.ts +4 -0
- package/lib/EditTable/index.js +184 -0
- package/lib/EditTable/modal.d.ts +19 -0
- package/lib/HTableBody/defaultRender.d.ts +7 -1
- package/lib/HTableBody/defaultRender.js +11 -4
- package/lib/HTableBody/index.js +4 -1
- package/lib/HTableBody/modal.d.ts +3 -3
- package/lib/HTablePagination/index.d.ts +2 -1
- package/lib/HTablePagination/index.js +6 -4
- package/lib/TableConfig.d.ts +5 -5
- package/lib/index.d.ts +2 -0
- package/lib/index.js +4 -0
- package/lib/modal.d.ts +14 -5
- package/package.json +4 -3
- package/src/components/DialogTable/Content.tsx +25 -2
- package/src/components/DialogTable/DwTable.tsx +3 -2
- package/src/components/DialogTable/ModalEditTable.tsx +99 -0
- package/src/components/DialogTable/ModalTable.tsx +3 -2
- package/src/components/DialogTable/hooks.ts +15 -4
- package/src/components/EditTable/hooks.ts +43 -0
- package/src/components/EditTable/index.tsx +118 -0
- package/src/components/EditTable/modal.ts +26 -0
- package/src/components/HTableBody/defaultRender.tsx +17 -7
- package/src/components/HTableBody/index.tsx +1 -1
- package/src/components/HTableBody/modal.ts +6 -7
- package/src/components/HTablePagination/index.tsx +7 -3
- package/src/components/Table.tsx +1 -0
- package/src/components/TableConfig.tsx +7 -3
- package/src/components/index.tsx +2 -0
- package/src/components/modal.ts +19 -8
- package/src/components/render/index.tsx +1 -0
- package/src/pages/DwTable/index.tsx +1 -0
- package/src/pages/EditTable/index.tsx +70 -0
- package/src/pages/ModalEditTable/index.tsx +84 -0
- package/src/pages/Table/index.tsx +14 -15
- package/src/routes.tsx +12 -0
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { HTableInstance } from "../modal";
|
|
3
3
|
export declare const emptyDefaultRender: () => JSX.Element;
|
|
4
|
-
|
|
4
|
+
interface errorDefaultRenderParams {
|
|
5
|
+
reload?: () => void;
|
|
6
|
+
error: Error;
|
|
7
|
+
tableInstance?: HTableInstance;
|
|
8
|
+
}
|
|
9
|
+
export declare const errorDefaultRender: ({ error, tableInstance, reload, }: errorDefaultRenderParams) => JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -30,7 +30,16 @@ var emptyDefaultRender = function emptyDefaultRender() {
|
|
|
30
30
|
description: "\u6682\u65E0\u6570\u636E~"
|
|
31
31
|
}, pubProps));
|
|
32
32
|
};
|
|
33
|
-
var errorDefaultRender = function errorDefaultRender(
|
|
33
|
+
var errorDefaultRender = function errorDefaultRender(_ref) {
|
|
34
|
+
var error = _ref.error,
|
|
35
|
+
tableInstance = _ref.tableInstance,
|
|
36
|
+
reload = _ref.reload;
|
|
37
|
+
var pageReload = function pageReload() {
|
|
38
|
+
if (tableInstance) {
|
|
39
|
+
return tableInstance.table.reloadWithParams();
|
|
40
|
+
}
|
|
41
|
+
return reload === null || reload === void 0 ? void 0 : reload();
|
|
42
|
+
};
|
|
34
43
|
return jsxRuntime.jsx(antd.Empty, _objectSpread(_objectSpread({
|
|
35
44
|
image: error_bg.default,
|
|
36
45
|
description: error.message
|
|
@@ -41,9 +50,7 @@ var errorDefaultRender = function errorDefaultRender(tableInstance, error) {
|
|
|
41
50
|
style: {
|
|
42
51
|
borderRadius: 16
|
|
43
52
|
},
|
|
44
|
-
onClick:
|
|
45
|
-
tableInstance.table.reloadWithParams();
|
|
46
|
-
},
|
|
53
|
+
onClick: pageReload,
|
|
47
54
|
children: "\u5237\u65B0"
|
|
48
55
|
})
|
|
49
56
|
}));
|
package/lib/HTableBody/index.js
CHANGED
|
@@ -158,7 +158,10 @@ var Body = (function (bodyProps) {
|
|
|
158
158
|
}), jsxRuntime.jsxs(antd.ConfigProvider, {
|
|
159
159
|
renderEmpty: function renderEmpty() {
|
|
160
160
|
if (error) {
|
|
161
|
-
return tableErrorRender === null || tableErrorRender === void 0 ? void 0 : tableErrorRender(
|
|
161
|
+
return tableErrorRender === null || tableErrorRender === void 0 ? void 0 : tableErrorRender({
|
|
162
|
+
tableInstance: tableInstance,
|
|
163
|
+
error: error
|
|
164
|
+
});
|
|
162
165
|
}
|
|
163
166
|
return tableEmptyRender === null || tableEmptyRender === void 0 ? void 0 : tableEmptyRender(tableInstance);
|
|
164
167
|
},
|
|
@@ -2,7 +2,7 @@ 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
|
|
5
|
+
import { ActionRenderFn, ConfigDataModal, EmptyPageRender, ErrorPageRender, HRowSelection, HTableInstance, ParamsModal } from "../modal";
|
|
6
6
|
import type { AffixProps } from "antd/lib/affix";
|
|
7
7
|
import type { IPaginationProps } from "@/components/HTablePagination";
|
|
8
8
|
export interface OptionModal extends OptionConfig {
|
|
@@ -11,8 +11,8 @@ export interface OptionModal extends OptionConfig {
|
|
|
11
11
|
export interface HTableBodyProps extends Omit<ProTableProps<any, any>, "dataSource" | "rowSelection" | "options" | "pagination"> {
|
|
12
12
|
configData?: ConfigDataModal;
|
|
13
13
|
onPageChange?: (params: ParamsModal) => void;
|
|
14
|
-
emptyRender?:
|
|
15
|
-
errorRender?:
|
|
14
|
+
emptyRender?: EmptyPageRender;
|
|
15
|
+
errorRender?: ErrorPageRender;
|
|
16
16
|
tableStyle?: React.CSSProperties;
|
|
17
17
|
paginationStyle?: React.CSSProperties;
|
|
18
18
|
actionRender?: ActionRenderFn;
|
|
@@ -10,6 +10,7 @@ export interface IPaginationProps extends Omit<PaginationProps, "showTotal"> {
|
|
|
10
10
|
actionRender?: (tableInstance: HTableInstance) => React.ReactNode;
|
|
11
11
|
table?: HTableInstance;
|
|
12
12
|
showTotal?: false | PaginationProps["showTotal"];
|
|
13
|
+
data?: Record<string, any>;
|
|
13
14
|
}
|
|
14
|
-
declare const _default: ({ onPageChange, paginationStyle, affixProps, goTop, actionRender, table, showTotal, ...props }: IPaginationProps) => JSX.Element;
|
|
15
|
+
declare const _default: ({ onPageChange, paginationStyle, affixProps, goTop, actionRender, table, showTotal, data, ...props }: IPaginationProps) => JSX.Element;
|
|
15
16
|
export default _default;
|
|
@@ -23,7 +23,7 @@ var React = require('react');
|
|
|
23
23
|
var index$1 = require('../GoTop/index.js');
|
|
24
24
|
var TableConfig = require('../TableConfig.js');
|
|
25
25
|
|
|
26
|
-
var _excluded = ["onPageChange", "paginationStyle", "affixProps", "goTop", "actionRender", "table", "showTotal"],
|
|
26
|
+
var _excluded = ["onPageChange", "paginationStyle", "affixProps", "goTop", "actionRender", "table", "showTotal", "data"],
|
|
27
27
|
_excluded2 = ["offsetBottom"];
|
|
28
28
|
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
29
29
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context4 = ownKeys(Object(t))).call(_context4, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -43,18 +43,20 @@ var HTablePagination = (function (_ref3) {
|
|
|
43
43
|
table = _ref3.table,
|
|
44
44
|
_ref3$showTotal = _ref3.showTotal,
|
|
45
45
|
showTotal = _ref3$showTotal === void 0 ? defaultShowTotal : _ref3$showTotal,
|
|
46
|
+
data = _ref3.data,
|
|
46
47
|
props = _objectWithoutProperties(_ref3, _excluded);
|
|
47
48
|
var _useHTableContext = context.useHTableContext(),
|
|
48
49
|
contextOnPageChange = _useHTableContext.onPageChange,
|
|
49
|
-
|
|
50
|
+
contextData = _useHTableContext.data,
|
|
50
51
|
contextTableInstance = _useHTableContext.tableInstance;
|
|
51
52
|
var _useHTableConfigConte = TableConfig.useHTableConfigContext({
|
|
52
53
|
paginationStyle: paginationStyle
|
|
53
54
|
}),
|
|
54
55
|
defaultPaginationStyle = _useHTableConfigConte.paginationStyle;
|
|
56
|
+
var cuData = data || contextData;
|
|
55
57
|
var tableInstance = table || contextTableInstance;
|
|
56
58
|
var tableOnPageChange = onPageChange || contextOnPageChange;
|
|
57
|
-
var _ref4 =
|
|
59
|
+
var _ref4 = cuData || {},
|
|
58
60
|
size = _ref4.size,
|
|
59
61
|
current = _ref4.current,
|
|
60
62
|
total = _ref4.total;
|
|
@@ -67,7 +69,7 @@ var HTablePagination = (function (_ref3) {
|
|
|
67
69
|
style = _useState2[0],
|
|
68
70
|
setStyle = _useState2[1];
|
|
69
71
|
var cuShowTotal = showTotal === false ? undefined : showTotal;
|
|
70
|
-
if (!
|
|
72
|
+
if (!cuData) {
|
|
71
73
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
72
74
|
}
|
|
73
75
|
if (affixProps === false) {
|
package/lib/TableConfig.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
2
|
+
import { EmptyPageRender, ErrorPageRender, ValueTypeConfigModal } from "./modal";
|
|
3
3
|
interface HTableConfigContextModal {
|
|
4
|
-
emptyRender?:
|
|
5
|
-
errorRender?:
|
|
4
|
+
emptyRender?: EmptyPageRender;
|
|
5
|
+
errorRender?: ErrorPageRender;
|
|
6
6
|
headerStyle?: React.CSSProperties;
|
|
7
7
|
tableStyle?: React.CSSProperties;
|
|
8
8
|
paginationStyle?: React.CSSProperties;
|
|
@@ -11,8 +11,8 @@ interface HTableConfigContextModal {
|
|
|
11
11
|
}
|
|
12
12
|
export declare const HTableConfigContext: React.Context<HTableConfigContextModal | null>;
|
|
13
13
|
export declare const useHTableConfigContext: ({ emptyRender, errorRender, headerStyle, tableStyle, paginationStyle, }: HTableConfigContextModal) => {
|
|
14
|
-
errorRender:
|
|
15
|
-
emptyRender:
|
|
14
|
+
errorRender: ErrorPageRender | undefined;
|
|
15
|
+
emptyRender: EmptyPageRender | undefined;
|
|
16
16
|
headerStyle: React.CSSProperties | undefined;
|
|
17
17
|
tableStyle: React.CSSProperties | undefined;
|
|
18
18
|
paginationStyle: React.CSSProperties | undefined;
|
package/lib/index.d.ts
CHANGED
|
@@ -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";
|
package/lib/index.js
CHANGED
|
@@ -12,6 +12,8 @@ var ModalTable = require('./DialogTable/ModalTable.js');
|
|
|
12
12
|
var hooks = require('./DialogTable/hooks.js');
|
|
13
13
|
var DwTable = require('./DialogTable/DwTable.js');
|
|
14
14
|
var defaultSubComponent = require('./HTableHeader/defaultSubComponent.js');
|
|
15
|
+
var index$4 = require('./EditTable/index.js');
|
|
16
|
+
var ModalEditTable = require('./DialogTable/ModalEditTable.js');
|
|
15
17
|
|
|
16
18
|
|
|
17
19
|
|
|
@@ -27,4 +29,6 @@ exports.HModalTable = ModalTable.default;
|
|
|
27
29
|
exports.useHDialogTable = hooks.useHDialogTable;
|
|
28
30
|
exports.HDwTable = DwTable.default;
|
|
29
31
|
exports.HTableHeaderSubBtn = defaultSubComponent.DefaultSubComponent;
|
|
32
|
+
exports.EditTable = index$4.default;
|
|
33
|
+
exports.ModalEditTable = ModalEditTable.default;
|
|
30
34
|
// powered by h
|
package/lib/modal.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ import type { TableProps } from "antd/lib/table";
|
|
|
9
9
|
import type { AffixProps } from "antd/lib/affix";
|
|
10
10
|
import type { OptionModal } from "./HTableBody/modal";
|
|
11
11
|
import type { DrawerProps } from "antd";
|
|
12
|
-
import type { IPaginationProps } from "
|
|
12
|
+
import type { IPaginationProps } from "./HTablePagination";
|
|
13
|
+
import { EditTableProps } from "./EditTable/modal";
|
|
13
14
|
export interface RowObj {
|
|
14
15
|
keys?: React.Key[];
|
|
15
16
|
rowData?: any[];
|
|
@@ -56,8 +57,8 @@ export interface HTableProps extends Omit<ProTableProps<any, any>, "request" | "
|
|
|
56
57
|
searchSpan?: ColProps;
|
|
57
58
|
table?: HTableInstance;
|
|
58
59
|
actionRender?: ActionRenderFn;
|
|
59
|
-
emptyRender?:
|
|
60
|
-
errorRender?:
|
|
60
|
+
emptyRender?: EmptyPageRender;
|
|
61
|
+
errorRender?: ErrorPageRender;
|
|
61
62
|
hideHeader?: boolean;
|
|
62
63
|
action?: Record<string, actionFn>;
|
|
63
64
|
headerStyle?: React.CSSProperties;
|
|
@@ -128,16 +129,24 @@ export interface DwTableProps extends DrawerProps {
|
|
|
128
129
|
request?: HTableProps["request"];
|
|
129
130
|
contentRender?: (node: React.ReactNode) => React.ReactNode;
|
|
130
131
|
}
|
|
131
|
-
export interface ModalTableProps extends Omit<ModalProps, "onOk"> {
|
|
132
|
+
export interface ModalTableProps<T = HTableProps["configData"]> extends Omit<ModalProps, "onOk"> {
|
|
132
133
|
tableProps?: Omit<HTableProps, "configData" | "request">;
|
|
133
134
|
dialogTable?: HDiaLogTableInstance;
|
|
134
135
|
params?: Record<string, any>;
|
|
135
|
-
configData?:
|
|
136
|
+
configData?: T;
|
|
136
137
|
request?: HTableProps["request"];
|
|
137
138
|
contentRender?: (node: React.ReactNode) => React.ReactNode;
|
|
138
139
|
dataSource?: any[];
|
|
139
140
|
onOk?: (e?: React.MouseEvent<HTMLElement>) => void;
|
|
141
|
+
editTableProps?: Omit<EditTableProps, "configData" | "request">;
|
|
140
142
|
}
|
|
141
143
|
export type ValueTypeConfigRenderFn = (config: ConfigItemModal, itemData: any, index: number, tableInstance: HTableInstance) => React.ReactNode;
|
|
142
144
|
export type ValueTypeConfigModal = Record<string, ValueTypeConfigRenderFn>;
|
|
145
|
+
interface ErrorRenderParams {
|
|
146
|
+
error: Error;
|
|
147
|
+
tableInstance?: HTableInstance;
|
|
148
|
+
reload?: VoidFunction;
|
|
149
|
+
}
|
|
150
|
+
export type ErrorPageRender = (params: ErrorRenderParams) => React.ReactNode;
|
|
151
|
+
export type EmptyPageRender = (tableInstance?: HTableInstance) => React.ReactNode;
|
|
143
152
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hw-component/table",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.94",
|
|
4
4
|
"description": "基于antd二次开发table组件",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"table"
|
|
@@ -23,8 +23,9 @@
|
|
|
23
23
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
24
24
|
},
|
|
25
25
|
"lint-staged": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"src/**/*.less": "npm run lint:style",
|
|
27
|
+
"src/**/*.{js,jsx,ts,tsx}": "npm run lint:js",
|
|
28
|
+
"src/**/*.{js,jsx,tsx,ts,less,md,json}": [
|
|
28
29
|
"prettier --write"
|
|
29
30
|
]
|
|
30
31
|
},
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import Table from "@/components/Table";
|
|
2
|
-
import type { ModalTableProps } from "
|
|
2
|
+
import type { ModalTableProps } from "../modal";
|
|
3
|
+
import { EditTable } from "@/components";
|
|
4
|
+
import { ProColumns } from "@ant-design/pro-table/lib/typing";
|
|
3
5
|
|
|
4
|
-
export
|
|
6
|
+
export const TableContent = ({
|
|
5
7
|
tableProps,
|
|
6
8
|
configData,
|
|
7
9
|
dialogTable,
|
|
@@ -21,3 +23,24 @@ export default ({
|
|
|
21
23
|
);
|
|
22
24
|
return <>{contentRender ? contentRender(node) : node}</>;
|
|
23
25
|
};
|
|
26
|
+
|
|
27
|
+
export const EditTableContent = ({
|
|
28
|
+
editTableProps,
|
|
29
|
+
configData,
|
|
30
|
+
request,
|
|
31
|
+
contentRender,
|
|
32
|
+
dataSource,
|
|
33
|
+
}: ModalTableProps<ProColumns[]>) => {
|
|
34
|
+
const node = (
|
|
35
|
+
<EditTable
|
|
36
|
+
{...editTableProps}
|
|
37
|
+
configData={configData || []}
|
|
38
|
+
request={request}
|
|
39
|
+
pagination={{
|
|
40
|
+
affixProps: false,
|
|
41
|
+
}}
|
|
42
|
+
dataSource={dataSource}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
return <>{contentRender ? contentRender(node) : node}</>;
|
|
46
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Drawer } from "antd";
|
|
2
2
|
import type { DwTableProps } from "../modal";
|
|
3
3
|
import { useCurrentTable, useTableProps, useVisible } from "./hooks";
|
|
4
|
-
import
|
|
4
|
+
import { TableContent } from "./Content";
|
|
5
5
|
import { CloseOutlined } from "@ant-design/icons";
|
|
6
6
|
import { useClassName } from "../hooks";
|
|
7
|
+
|
|
7
8
|
export default ({
|
|
8
9
|
configData: configDataProps,
|
|
9
10
|
request: requestProps,
|
|
@@ -96,7 +97,7 @@ export default ({
|
|
|
96
97
|
afterVisibleChange?.(changeVisible);
|
|
97
98
|
}}
|
|
98
99
|
>
|
|
99
|
-
<
|
|
100
|
+
<TableContent
|
|
100
101
|
contentRender={contentRender}
|
|
101
102
|
tableProps={tableProps}
|
|
102
103
|
configData={configData || []}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Modal } from "antd";
|
|
2
|
+
import type { ModalTableProps } from "../modal";
|
|
3
|
+
import { useCurrentTable, useTableProps, useVisible } from "./hooks";
|
|
4
|
+
import { EditTableContent } from "./Content";
|
|
5
|
+
import { ProColumns } from "@ant-design/pro-table/lib/typing";
|
|
6
|
+
|
|
7
|
+
export default ({
|
|
8
|
+
configData: configDataProps,
|
|
9
|
+
request: requestProps,
|
|
10
|
+
editTableProps = {},
|
|
11
|
+
dialogTable,
|
|
12
|
+
visible = false,
|
|
13
|
+
onCancel,
|
|
14
|
+
bodyStyle = {},
|
|
15
|
+
afterClose,
|
|
16
|
+
contentRender,
|
|
17
|
+
width = 666,
|
|
18
|
+
footer = null,
|
|
19
|
+
...props
|
|
20
|
+
}: ModalTableProps<ProColumns[]>) => {
|
|
21
|
+
const { modalVisible, setModalVisible } = useVisible(visible);
|
|
22
|
+
const { modalTableParams, setModalTableParams } = useTableProps<ProColumns[]>(
|
|
23
|
+
{
|
|
24
|
+
...props,
|
|
25
|
+
configData: configDataProps,
|
|
26
|
+
request: requestProps,
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
const currentTable = useCurrentTable({
|
|
30
|
+
show: (showParams) => {
|
|
31
|
+
if (showParams) {
|
|
32
|
+
setModalTableParams((oldParams) => {
|
|
33
|
+
const {
|
|
34
|
+
configData,
|
|
35
|
+
request,
|
|
36
|
+
title,
|
|
37
|
+
params: oldP,
|
|
38
|
+
dataSource: oldDataSource,
|
|
39
|
+
} = oldParams;
|
|
40
|
+
const {
|
|
41
|
+
title: showTitle = title,
|
|
42
|
+
configData: showConfigData = configData,
|
|
43
|
+
request: showReq = request,
|
|
44
|
+
dataSource = oldDataSource,
|
|
45
|
+
params = oldP,
|
|
46
|
+
} = showParams;
|
|
47
|
+
currentTable.params = params;
|
|
48
|
+
return {
|
|
49
|
+
title: showTitle,
|
|
50
|
+
request: showReq,
|
|
51
|
+
configData: showConfigData as any,
|
|
52
|
+
params,
|
|
53
|
+
dataSource,
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
setModalVisible(true);
|
|
58
|
+
},
|
|
59
|
+
hide: () => {
|
|
60
|
+
setModalVisible(false);
|
|
61
|
+
},
|
|
62
|
+
dialogTable,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const { configData, dataSource, request, title, params } = modalTableParams;
|
|
66
|
+
const req = request
|
|
67
|
+
? (reqParams) => {
|
|
68
|
+
return request({ ...params, ...reqParams });
|
|
69
|
+
}
|
|
70
|
+
: undefined;
|
|
71
|
+
return (
|
|
72
|
+
<Modal
|
|
73
|
+
{...props}
|
|
74
|
+
footer={footer}
|
|
75
|
+
visible={modalVisible}
|
|
76
|
+
onCancel={(e) => {
|
|
77
|
+
setModalVisible(false);
|
|
78
|
+
onCancel?.(e);
|
|
79
|
+
}}
|
|
80
|
+
destroyOnClose
|
|
81
|
+
title={title}
|
|
82
|
+
width={width}
|
|
83
|
+
bodyStyle={{ padding: "0px 0px 12px", ...bodyStyle }}
|
|
84
|
+
afterClose={() => {
|
|
85
|
+
currentTable.form.resetFields();
|
|
86
|
+
afterClose?.();
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
<EditTableContent
|
|
90
|
+
contentRender={contentRender}
|
|
91
|
+
editTableProps={editTableProps}
|
|
92
|
+
configData={configData || []}
|
|
93
|
+
dialogTable={currentTable}
|
|
94
|
+
request={req}
|
|
95
|
+
dataSource={dataSource}
|
|
96
|
+
/>
|
|
97
|
+
</Modal>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Modal } from "antd";
|
|
2
2
|
import type { ModalTableProps } from "../modal";
|
|
3
3
|
import { useCurrentTable, useTableProps, useVisible } from "./hooks";
|
|
4
|
-
import
|
|
4
|
+
import { TableContent } from "./Content";
|
|
5
|
+
|
|
5
6
|
export default ({
|
|
6
7
|
configData: configDataProps,
|
|
7
8
|
request: requestProps,
|
|
@@ -82,7 +83,7 @@ export default ({
|
|
|
82
83
|
afterClose?.();
|
|
83
84
|
}}
|
|
84
85
|
>
|
|
85
|
-
<
|
|
86
|
+
<TableContent
|
|
86
87
|
contentRender={contentRender}
|
|
87
88
|
tableProps={tableProps}
|
|
88
89
|
configData={configData || []}
|
|
@@ -21,14 +21,17 @@ export const useHDialogTable = () => {
|
|
|
21
21
|
interface ParamsModal extends HOnDiaLogTableInstance {
|
|
22
22
|
dialogTable?: HDiaLogTableInstance;
|
|
23
23
|
}
|
|
24
|
-
|
|
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
|
-
}:
|
|
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
|
+
}
|