@ant-design/pro-components 3.0.1-0 → 3.1.0-0
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/pro-components.min.js +1 -1
- package/es/card/ProCard.js +4 -2
- package/es/card/components/Actions/style.d.ts +1 -1
- package/es/card/components/Card/index.js +8 -4
- package/es/card/components/Card/style.d.ts +1 -1
- package/es/card/components/CheckCard/index.d.ts +6 -0
- package/es/card/components/CheckCard/index.js +2 -1
- package/es/card/components/CheckCard/style.d.ts +1 -1
- package/es/card/components/Divider/style.d.ts +1 -1
- package/es/card/components/Loading/style.d.ts +1 -1
- package/es/card/components/Operation/style.d.ts +1 -1
- package/es/card/components/Statistic/style.d.ts +1 -1
- package/es/card/components/Statistic/style.js +2 -6
- package/es/card/components/StatisticCard/index.js +4 -2
- package/es/card/components/StatisticCard/style.d.ts +1 -1
- package/es/card/typing.d.ts +5 -0
- package/es/descriptions/index.js +2 -1
- package/es/field/ValueTypeToComponent.js +4 -4
- package/es/field/components/Cascader/index.d.ts +0 -1
- package/es/field/components/Checkbox/index.d.ts +0 -1
- package/es/field/components/ColorPicker/index.d.ts +1 -1
- package/es/field/components/Percent/util.d.ts +1 -1
- package/es/field/components/Radio/index.d.ts +0 -1
- package/es/field/components/Segmented/index.d.ts +0 -1
- package/es/field/components/Select/LightSelect/index.js +1 -2
- package/es/field/components/Select/SearchSelect/index.d.ts +6 -1
- package/es/field/components/Select/SearchSelect/index.js +101 -15
- package/es/field/components/Select/index.d.ts +0 -3
- package/es/field/components/Select/index.js +5 -3
- package/es/field/components/TreeSelect/index.d.ts +0 -1
- package/es/form/BaseForm/BaseForm.d.ts +3 -0
- package/es/form/BaseForm/BaseForm.js +9 -2
- package/es/form/BaseForm/LightWrapper/style.d.ts +1 -1
- package/es/form/components/Captcha/index.d.ts +8 -2
- package/es/form/components/Captcha/index.js +9 -1
- package/es/form/components/DatePicker/BaseDatePicker.js +20 -12
- package/es/form/components/DateRangePicker/BaseDateRanger.js +38 -13
- package/es/form/components/FormItem/Group/index.js +1 -1
- package/es/form/components/FormItem/Group/style.d.ts +1 -1
- package/es/form/components/List/index.d.ts +1 -1
- package/es/form/components/List/style.d.ts +1 -1
- package/es/form/components/SchemaForm/index.js +1 -2
- package/es/form/components/Text/index.js +4 -2
- package/es/form/components/UploadButton/index.d.ts +1 -1
- package/es/form/components/UploadButton/index.js +3 -3
- package/es/form/index.d.ts +1 -0
- package/es/form/layouts/DrawerForm/index.d.ts +1 -1
- package/es/form/layouts/DrawerForm/index.js +3 -2
- package/es/form/layouts/DrawerForm/style.d.ts +1 -1
- package/es/form/layouts/LightFilter/style.d.ts +1 -1
- package/es/form/layouts/LoginForm/index.d.ts +1 -1
- package/es/form/layouts/LoginForm/style.d.ts +1 -1
- package/es/form/layouts/LoginFormPage/index.d.ts +1 -1
- package/es/form/layouts/LoginFormPage/style.d.ts +1 -1
- package/es/form/layouts/ModalForm/index.js +2 -1
- package/es/form/layouts/ProForm/index.d.ts +1 -1
- package/es/form/layouts/QueryFilter/index.d.ts +2 -1
- package/es/form/layouts/QueryFilter/style.d.ts +1 -1
- package/es/form/layouts/StepsForm/index.js +15 -2
- package/es/form/layouts/StepsForm/style.d.ts +1 -1
- package/es/layout/components/AppsLogoComponents/index.js +3 -1
- package/es/layout/components/AppsLogoComponents/style/index.d.ts +1 -1
- package/es/layout/components/CollapsedIcon/style.d.ts +1 -1
- package/es/layout/components/FooterToolbar/style/index.d.ts +1 -1
- package/es/layout/components/FooterToolbar/style/stylish.d.ts +1 -1
- package/es/layout/components/GlobalFooter/index.d.ts +1 -1
- package/es/layout/components/GlobalFooter/style.d.ts +1 -1
- package/es/layout/components/GlobalHeader/rightContentStyle.d.ts +1 -1
- package/es/layout/components/GlobalHeader/style.d.ts +1 -1
- package/es/layout/components/GridContent/style.d.ts +1 -1
- package/es/layout/components/Header/style/header.d.ts +1 -1
- package/es/layout/components/Header/style/stylish.d.ts +1 -1
- package/es/layout/components/Help/ProHelpDrawer.d.ts +1 -1
- package/es/layout/components/Help/ProHelpDrawer.js +3 -1
- package/es/layout/components/Help/ProHelpPopover.js +1 -1
- package/es/layout/components/Help/style.d.ts +1 -1
- package/es/layout/components/PageContainer/style/index.d.ts +1 -1
- package/es/layout/components/PageContainer/style/stylish.d.ts +1 -1
- package/es/layout/components/PageHeader/style/index.d.ts +1 -1
- package/es/layout/components/SettingDrawer/index.js +2 -2
- package/es/layout/components/SettingDrawer/style/index.d.ts +1 -1
- package/es/layout/components/SiderMenu/BaseMenu.d.ts +1 -1
- package/es/layout/components/SiderMenu/BaseMenu.js +3 -3
- package/es/layout/components/SiderMenu/SiderMenu.js +8 -8
- package/es/layout/components/SiderMenu/index.js +11 -6
- package/es/layout/components/SiderMenu/style/index.d.ts +1 -1
- package/es/layout/components/SiderMenu/style/menu.d.ts +1 -1
- package/es/layout/components/SiderMenu/style/stylish.d.ts +1 -1
- package/es/layout/components/TopNavHeader/style.d.ts +1 -1
- package/es/layout/defaultSettings.d.ts +6 -0
- package/es/layout/style/index.d.ts +1 -1
- package/es/list/style/index.d.ts +1 -1
- package/es/provider/index.d.ts +1 -0
- package/es/provider/index.js +11 -6
- package/es/provider/useStyle/index.d.ts +2 -1
- package/es/provider/useStyle/index.js +20 -12
- package/es/table/Table.js +412 -280
- package/es/table/components/Alert/index.d.ts +1 -1
- package/es/table/components/Alert/style.d.ts +1 -1
- package/es/table/components/ColumnSetting/index.d.ts +1 -1
- package/es/table/components/ColumnSetting/index.js +15 -3
- package/es/table/components/ColumnSetting/style.d.ts +1 -1
- package/es/table/components/DragSortTable/index.d.ts +1 -1
- package/es/table/components/DragSortTable/style.d.ts +1 -1
- package/es/table/components/EditableTable/index.js +530 -197
- package/es/table/components/ListToolBar/style.d.ts +1 -1
- package/es/table/style/index.d.ts +1 -1
- package/es/table/typing.d.ts +37 -12
- package/es/table/useFetchData.js +8 -13
- package/es/table/utils/columnRender.d.ts +1 -1
- package/es/table/utils/genProColumnToColumn.d.ts +2 -2
- package/es/table/utils/genProColumnToColumn.js +5 -17
- package/es/table/utils/index.d.ts +60 -5
- package/es/table/utils/index.js +157 -18
- package/es/utils/components/DropdownFooter/style.d.ts +1 -1
- package/es/utils/components/FieldLabel/style.d.ts +1 -1
- package/es/utils/components/FilterDropdown/index.js +1 -1
- package/es/utils/components/FilterDropdown/style.d.ts +1 -1
- package/es/utils/components/InlineErrorFormItem/style.d.ts +1 -1
- package/es/utils/components/LabelIconTip/style.d.ts +1 -1
- package/es/utils/conversionMomentValue/index.js +14 -2
- package/es/utils/proFieldParsingText/index.js +1 -1
- package/es/utils/typing.d.ts +1 -1
- package/es/utils/useEditableArray/index.d.ts +3 -6
- package/es/utils/useEditableArray/index.js +562 -318
- package/es/utils/useEditableMap/index.js +82 -25
- package/es/utils/useMediaQuery/query.js +11 -5
- package/lib/card/ProCard.js +4 -2
- package/lib/card/components/Actions/style.d.ts +1 -1
- package/lib/card/components/Card/index.js +8 -4
- package/lib/card/components/Card/style.d.ts +1 -1
- package/lib/card/components/CheckCard/index.d.ts +6 -0
- package/lib/card/components/CheckCard/index.js +2 -1
- package/lib/card/components/CheckCard/style.d.ts +1 -1
- package/lib/card/components/Divider/style.d.ts +1 -1
- package/lib/card/components/Loading/style.d.ts +1 -1
- package/lib/card/components/Operation/style.d.ts +1 -1
- package/lib/card/components/Statistic/style.d.ts +1 -1
- package/lib/card/components/Statistic/style.js +2 -6
- package/lib/card/components/StatisticCard/index.js +4 -2
- package/lib/card/components/StatisticCard/style.d.ts +1 -1
- package/lib/card/typing.d.ts +5 -0
- package/lib/descriptions/index.js +2 -1
- package/lib/field/ValueTypeToComponent.js +4 -4
- package/lib/field/components/Cascader/index.d.ts +0 -1
- package/lib/field/components/Checkbox/index.d.ts +0 -1
- package/lib/field/components/ColorPicker/index.d.ts +1 -1
- package/lib/field/components/Percent/util.d.ts +1 -1
- package/lib/field/components/Radio/index.d.ts +0 -1
- package/lib/field/components/Segmented/index.d.ts +0 -1
- package/lib/field/components/Select/LightSelect/index.js +1 -2
- package/lib/field/components/Select/SearchSelect/index.d.ts +6 -1
- package/lib/field/components/Select/SearchSelect/index.js +101 -15
- package/lib/field/components/Select/index.d.ts +0 -3
- package/lib/field/components/Select/index.js +5 -3
- package/lib/field/components/TreeSelect/index.d.ts +0 -1
- package/lib/form/BaseForm/BaseForm.d.ts +3 -0
- package/lib/form/BaseForm/BaseForm.js +9 -2
- package/lib/form/BaseForm/LightWrapper/style.d.ts +1 -1
- package/lib/form/components/Captcha/index.d.ts +8 -2
- package/lib/form/components/Captcha/index.js +9 -1
- package/lib/form/components/DatePicker/BaseDatePicker.js +19 -11
- package/lib/form/components/DateRangePicker/BaseDateRanger.js +37 -12
- package/lib/form/components/Digit/DigitRange.d.ts +1 -1
- package/lib/form/components/FormItem/Group/index.js +1 -1
- package/lib/form/components/FormItem/Group/style.d.ts +1 -1
- package/lib/form/components/List/index.d.ts +1 -1
- package/lib/form/components/List/style.d.ts +1 -1
- package/lib/form/components/SchemaForm/index.js +1 -2
- package/lib/form/components/Text/index.js +4 -2
- package/lib/form/components/UploadButton/index.d.ts +1 -1
- package/lib/form/components/UploadButton/index.js +3 -3
- package/lib/form/index.d.ts +1 -0
- package/lib/form/layouts/DrawerForm/index.d.ts +1 -1
- package/lib/form/layouts/DrawerForm/index.js +3 -2
- package/lib/form/layouts/DrawerForm/style.d.ts +1 -1
- package/lib/form/layouts/LightFilter/style.d.ts +1 -1
- package/lib/form/layouts/LoginForm/index.d.ts +1 -1
- package/lib/form/layouts/LoginForm/style.d.ts +1 -1
- package/lib/form/layouts/LoginFormPage/index.d.ts +1 -1
- package/lib/form/layouts/LoginFormPage/style.d.ts +1 -1
- package/lib/form/layouts/ModalForm/index.js +2 -1
- package/lib/form/layouts/ProForm/index.d.ts +2 -2
- package/lib/form/layouts/QueryFilter/index.d.ts +2 -1
- package/lib/form/layouts/QueryFilter/style.d.ts +1 -1
- package/lib/form/layouts/StepsForm/index.js +15 -2
- package/lib/form/layouts/StepsForm/style.d.ts +1 -1
- package/lib/layout/components/AppsLogoComponents/index.js +3 -1
- package/lib/layout/components/AppsLogoComponents/style/index.d.ts +1 -1
- package/lib/layout/components/CollapsedIcon/style.d.ts +1 -1
- package/lib/layout/components/FooterToolbar/style/index.d.ts +1 -1
- package/lib/layout/components/FooterToolbar/style/stylish.d.ts +1 -1
- package/lib/layout/components/GlobalFooter/index.d.ts +1 -1
- package/lib/layout/components/GlobalFooter/style.d.ts +1 -1
- package/lib/layout/components/GlobalHeader/rightContentStyle.d.ts +1 -1
- package/lib/layout/components/GlobalHeader/style.d.ts +1 -1
- package/lib/layout/components/GridContent/style.d.ts +1 -1
- package/lib/layout/components/Header/style/header.d.ts +1 -1
- package/lib/layout/components/Header/style/stylish.d.ts +1 -1
- package/lib/layout/components/Help/ProHelpDrawer.d.ts +1 -1
- package/lib/layout/components/Help/ProHelpDrawer.js +3 -1
- package/lib/layout/components/Help/ProHelpPopover.js +1 -1
- package/lib/layout/components/Help/style.d.ts +1 -1
- package/lib/layout/components/PageContainer/style/index.d.ts +1 -1
- package/lib/layout/components/PageContainer/style/stylish.d.ts +1 -1
- package/lib/layout/components/PageHeader/style/index.d.ts +1 -1
- package/lib/layout/components/SettingDrawer/index.js +2 -2
- package/lib/layout/components/SettingDrawer/style/index.d.ts +1 -1
- package/lib/layout/components/SiderMenu/BaseMenu.d.ts +1 -1
- package/lib/layout/components/SiderMenu/BaseMenu.js +3 -3
- package/lib/layout/components/SiderMenu/SiderMenu.js +8 -8
- package/lib/layout/components/SiderMenu/index.js +11 -6
- package/lib/layout/components/SiderMenu/style/index.d.ts +1 -1
- package/lib/layout/components/SiderMenu/style/menu.d.ts +1 -1
- package/lib/layout/components/SiderMenu/style/stylish.d.ts +1 -1
- package/lib/layout/components/TopNavHeader/style.d.ts +1 -1
- package/lib/layout/defaultSettings.d.ts +6 -0
- package/lib/layout/style/index.d.ts +1 -1
- package/lib/list/style/index.d.ts +1 -1
- package/lib/provider/index.d.ts +1 -0
- package/lib/provider/index.js +11 -6
- package/lib/provider/useStyle/index.d.ts +2 -1
- package/lib/provider/useStyle/index.js +20 -12
- package/lib/table/Table.js +422 -290
- package/lib/table/components/Alert/index.d.ts +1 -1
- package/lib/table/components/Alert/style.d.ts +1 -1
- package/lib/table/components/ColumnSetting/index.d.ts +1 -1
- package/lib/table/components/ColumnSetting/index.js +15 -3
- package/lib/table/components/ColumnSetting/style.d.ts +1 -1
- package/lib/table/components/DragSortTable/index.d.ts +1 -1
- package/lib/table/components/DragSortTable/style.d.ts +1 -1
- package/lib/table/components/EditableTable/index.js +529 -196
- package/lib/table/components/ListToolBar/style.d.ts +1 -1
- package/lib/table/style/index.d.ts +1 -1
- package/lib/table/typing.d.ts +37 -12
- package/lib/table/useFetchData.js +8 -13
- package/lib/table/utils/columnRender.d.ts +1 -1
- package/lib/table/utils/genProColumnToColumn.d.ts +2 -2
- package/lib/table/utils/genProColumnToColumn.js +4 -16
- package/lib/table/utils/index.d.ts +60 -5
- package/lib/table/utils/index.js +159 -20
- package/lib/utils/components/DropdownFooter/style.d.ts +1 -1
- package/lib/utils/components/FieldLabel/style.d.ts +1 -1
- package/lib/utils/components/FilterDropdown/index.js +1 -1
- package/lib/utils/components/FilterDropdown/style.d.ts +1 -1
- package/lib/utils/components/InlineErrorFormItem/style.d.ts +1 -1
- package/lib/utils/components/LabelIconTip/style.d.ts +1 -1
- package/lib/utils/conversionMomentValue/index.js +14 -2
- package/lib/utils/proFieldParsingText/index.js +1 -1
- package/lib/utils/typing.d.ts +1 -1
- package/lib/utils/useEditableArray/index.d.ts +3 -6
- package/lib/utils/useEditableArray/index.js +568 -324
- package/lib/utils/useEditableMap/index.js +82 -25
- package/lib/utils/useMediaQuery/query.js +10 -4
- package/package.json +45 -45
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
4
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
4
5
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
5
6
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
6
7
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
7
|
-
var _excluded = ["
|
|
8
|
-
_excluded2 = ["
|
|
8
|
+
var _excluded = ["record", "position", "creatorButtonText", "newRecordType", "parentKey", "style"],
|
|
9
|
+
_excluded2 = ["onTableChange", "maxLength", "formItemProps", "recordCreatorProps", "rowKey", "controlled", "defaultValue", "onChange", "editableFormRef"];
|
|
9
10
|
import { PlusOutlined } from '@ant-design/icons';
|
|
10
11
|
import { get, set, useMergedState } from '@rc-component/util';
|
|
11
12
|
import { Button, Form } from 'antd';
|
|
12
13
|
import React, { useContext, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
13
14
|
import ProForm, { ProFormDependency } from "../../../form";
|
|
14
15
|
import { useIntl } from "../../../provider";
|
|
15
|
-
import { isDeepEqualReact, runFunction,
|
|
16
|
+
import { isDeepEqualReact, runFunction, useDeepCompareEffect, useRefFunction } from "../../../utils";
|
|
17
|
+
import { editableRowByKey, recordKeyToString } from "../../../utils/useEditableArray";
|
|
16
18
|
import ProTable from "../../Table";
|
|
17
19
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
20
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -30,7 +32,7 @@ function RecordCreator(props) {
|
|
|
30
32
|
return /*#__PURE__*/React.cloneElement(children, _objectSpread(_objectSpread({}, children.props), {}, {
|
|
31
33
|
onClick: function () {
|
|
32
34
|
var _onClick = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(e) {
|
|
33
|
-
var _children$props$onCli, _children$props
|
|
35
|
+
var _children$props$onCli, _children$props;
|
|
34
36
|
var isOk;
|
|
35
37
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
36
38
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -45,11 +47,13 @@ function RecordCreator(props) {
|
|
|
45
47
|
}
|
|
46
48
|
return _context.abrupt("return");
|
|
47
49
|
case 5:
|
|
48
|
-
actionRef
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if (actionRef !== null && actionRef !== void 0 && actionRef.current) {
|
|
51
|
+
actionRef.current.addEditRecord(record, {
|
|
52
|
+
position: position,
|
|
53
|
+
newRecordType: newRecordType,
|
|
54
|
+
parentKey: parentKey
|
|
55
|
+
});
|
|
56
|
+
}
|
|
53
57
|
case 6:
|
|
54
58
|
case "end":
|
|
55
59
|
return _context.stop();
|
|
@@ -64,13 +68,195 @@ function RecordCreator(props) {
|
|
|
64
68
|
}));
|
|
65
69
|
}
|
|
66
70
|
|
|
71
|
+
/**
|
|
72
|
+
* 处理嵌套行的新增
|
|
73
|
+
*/
|
|
74
|
+
function handleNestedRowInsert(baseData, defaultValue, newLineOptions, getRowKey, childrenColumnName) {
|
|
75
|
+
var _recordKeyToString;
|
|
76
|
+
if (!newLineOptions.recordKey) {
|
|
77
|
+
return baseData;
|
|
78
|
+
}
|
|
79
|
+
var actionProps = {
|
|
80
|
+
data: baseData,
|
|
81
|
+
getRowKey: getRowKey,
|
|
82
|
+
row: _objectSpread(_objectSpread({}, defaultValue), {}, {
|
|
83
|
+
map_row_parentKey: (_recordKeyToString = recordKeyToString(newLineOptions.parentKey)) === null || _recordKeyToString === void 0 ? void 0 : _recordKeyToString.toString()
|
|
84
|
+
}),
|
|
85
|
+
key: newLineOptions.recordKey,
|
|
86
|
+
childrenColumnName: childrenColumnName
|
|
87
|
+
};
|
|
88
|
+
return editableRowByKey(actionProps, newLineOptions.position === 'top' ? 'top' : 'update');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 处理分页场景下的新增
|
|
93
|
+
*/
|
|
94
|
+
function handlePaginationInsert(baseData, defaultValue, pageConfig) {
|
|
95
|
+
if (pageConfig.pageSize > baseData.length) {
|
|
96
|
+
return [].concat(_toConsumableArray(baseData), [defaultValue]);
|
|
97
|
+
}
|
|
98
|
+
var insertIndex = pageConfig.current * pageConfig.pageSize - 1;
|
|
99
|
+
var result = _toConsumableArray(baseData);
|
|
100
|
+
result.splice(insertIndex, 0, defaultValue);
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
function useEditableDataSource(_ref) {
|
|
104
|
+
var actionDataSource = _ref.actionDataSource,
|
|
105
|
+
editableUtils = _ref.editableUtils,
|
|
106
|
+
pagination = _ref.pagination,
|
|
107
|
+
getRowKey = _ref.getRowKey,
|
|
108
|
+
childrenColumnName = _ref.childrenColumnName;
|
|
109
|
+
return useMemo(function () {
|
|
110
|
+
var newLineConfig = editableUtils === null || editableUtils === void 0 ? void 0 : editableUtils.newLineRecord;
|
|
111
|
+
var baseData = Array.isArray(actionDataSource) ? _toConsumableArray(actionDataSource) : [];
|
|
112
|
+
if (!(newLineConfig !== null && newLineConfig !== void 0 && newLineConfig.defaultValue)) {
|
|
113
|
+
return baseData;
|
|
114
|
+
}
|
|
115
|
+
var newLineOptions = newLineConfig.options,
|
|
116
|
+
defaultValue = newLineConfig.defaultValue;
|
|
117
|
+
if (newLineOptions !== null && newLineOptions !== void 0 && newLineOptions.parentKey) {
|
|
118
|
+
return handleNestedRowInsert(baseData, defaultValue, newLineOptions, getRowKey, childrenColumnName || 'children');
|
|
119
|
+
}
|
|
120
|
+
if ((newLineOptions === null || newLineOptions === void 0 ? void 0 : newLineOptions.position) === 'top') {
|
|
121
|
+
return [defaultValue].concat(_toConsumableArray(baseData));
|
|
122
|
+
}
|
|
123
|
+
var pageConfig = pagination && _typeof(pagination) === 'object' ? pagination : undefined;
|
|
124
|
+
if (pageConfig !== null && pageConfig !== void 0 && pageConfig.current && pageConfig !== null && pageConfig !== void 0 && pageConfig.pageSize) {
|
|
125
|
+
return handlePaginationInsert(baseData, defaultValue, pageConfig);
|
|
126
|
+
}
|
|
127
|
+
return [].concat(_toConsumableArray(baseData), [defaultValue]);
|
|
128
|
+
}, [actionDataSource, childrenColumnName, editableUtils === null || editableUtils === void 0 ? void 0 : editableUtils.newLineRecord, getRowKey, pagination]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 检查是否应该显示创建按钮
|
|
133
|
+
*/
|
|
134
|
+
function shouldShowCreatorButton(maxLength, valueLength, recordCreatorProps) {
|
|
135
|
+
if (typeof maxLength === 'number' && maxLength <= valueLength) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return recordCreatorProps !== false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 创建按钮 DOM
|
|
143
|
+
*/
|
|
144
|
+
function createButtonDom(recordCreatorProps, value, intl) {
|
|
145
|
+
var record = recordCreatorProps.record,
|
|
146
|
+
position = recordCreatorProps.position,
|
|
147
|
+
creatorButtonText = recordCreatorProps.creatorButtonText,
|
|
148
|
+
newRecordType = recordCreatorProps.newRecordType,
|
|
149
|
+
parentKey = recordCreatorProps.parentKey,
|
|
150
|
+
style = recordCreatorProps.style,
|
|
151
|
+
restButtonProps = _objectWithoutProperties(recordCreatorProps, _excluded);
|
|
152
|
+
return /*#__PURE__*/_jsx(RecordCreator, {
|
|
153
|
+
record: runFunction(record, value === null || value === void 0 ? void 0 : value.length, value) || {},
|
|
154
|
+
position: position,
|
|
155
|
+
parentKey: runFunction(parentKey, value === null || value === void 0 ? void 0 : value.length, value),
|
|
156
|
+
newRecordType: newRecordType,
|
|
157
|
+
children: /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({
|
|
158
|
+
type: "dashed",
|
|
159
|
+
style: _objectSpread({
|
|
160
|
+
display: 'block',
|
|
161
|
+
margin: '10px 0',
|
|
162
|
+
width: '100%'
|
|
163
|
+
}, style),
|
|
164
|
+
icon: /*#__PURE__*/_jsx(PlusOutlined, {})
|
|
165
|
+
}, restButtonProps), {}, {
|
|
166
|
+
children: creatorButtonText || intl.getMessage('editableTable.action.add', '添加一行数据')
|
|
167
|
+
}))
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 创建顶部按钮的渲染属性
|
|
173
|
+
*/
|
|
174
|
+
function createTopButtonProps(creatorButtonDom, columnsLength) {
|
|
175
|
+
return {
|
|
176
|
+
components: {
|
|
177
|
+
header: {
|
|
178
|
+
wrapper: function wrapper(_ref2) {
|
|
179
|
+
var className = _ref2.className,
|
|
180
|
+
children = _ref2.children;
|
|
181
|
+
return /*#__PURE__*/_jsxs("thead", {
|
|
182
|
+
className: className,
|
|
183
|
+
children: [children, /*#__PURE__*/_jsxs("tr", {
|
|
184
|
+
style: {
|
|
185
|
+
position: 'relative'
|
|
186
|
+
},
|
|
187
|
+
children: [/*#__PURE__*/_jsx("td", {
|
|
188
|
+
colSpan: 0,
|
|
189
|
+
style: {
|
|
190
|
+
visibility: 'hidden'
|
|
191
|
+
},
|
|
192
|
+
children: creatorButtonDom
|
|
193
|
+
}), /*#__PURE__*/_jsx("td", {
|
|
194
|
+
style: {
|
|
195
|
+
position: 'absolute',
|
|
196
|
+
left: 0,
|
|
197
|
+
width: '100%'
|
|
198
|
+
},
|
|
199
|
+
colSpan: columnsLength,
|
|
200
|
+
children: creatorButtonDom
|
|
201
|
+
})]
|
|
202
|
+
})]
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 创建底部按钮的渲染属性
|
|
212
|
+
*/
|
|
213
|
+
function createBottomButtonProps(creatorButtonDom, _tableViewRender) {
|
|
214
|
+
return {
|
|
215
|
+
tableViewRender: function tableViewRender(_, dom) {
|
|
216
|
+
var _tableViewRender2;
|
|
217
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
218
|
+
children: [(_tableViewRender2 = _tableViewRender === null || _tableViewRender === void 0 ? void 0 : _tableViewRender(_, dom)) !== null && _tableViewRender2 !== void 0 ? _tableViewRender2 : dom, creatorButtonDom]
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function useCreatorButton(_ref3) {
|
|
224
|
+
var recordCreatorProps = _ref3.recordCreatorProps,
|
|
225
|
+
maxLength = _ref3.maxLength,
|
|
226
|
+
value = _ref3.value,
|
|
227
|
+
intl = _ref3.intl,
|
|
228
|
+
isTop = _ref3.isTop,
|
|
229
|
+
columnsLength = _ref3.columnsLength,
|
|
230
|
+
tableViewRender = _ref3.tableViewRender;
|
|
231
|
+
var creatorButtonDom = useMemo(function () {
|
|
232
|
+
if (!shouldShowCreatorButton(maxLength, (value === null || value === void 0 ? void 0 : value.length) || 0, recordCreatorProps)) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
if (!recordCreatorProps) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
return createButtonDom(recordCreatorProps, value, intl);
|
|
239
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
240
|
+
}, [maxLength, recordCreatorProps, value === null || value === void 0 ? void 0 : value.length, intl]);
|
|
241
|
+
var buttonRenderProps = useMemo(function () {
|
|
242
|
+
if (!creatorButtonDom) {
|
|
243
|
+
return {};
|
|
244
|
+
}
|
|
245
|
+
return isTop ? createTopButtonProps(creatorButtonDom, columnsLength) : createBottomButtonProps(creatorButtonDom, tableViewRender);
|
|
246
|
+
}, [columnsLength, creatorButtonDom, isTop, tableViewRender]);
|
|
247
|
+
return {
|
|
248
|
+
creatorButtonDom: creatorButtonDom,
|
|
249
|
+
buttonRenderProps: buttonRenderProps
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
67
253
|
/**
|
|
68
254
|
* 可以直接放到 Form 中的可编辑表格
|
|
69
255
|
* A React component that is used to create a table.
|
|
70
256
|
* @param props
|
|
71
257
|
*/
|
|
72
258
|
function EditableTable(props) {
|
|
73
|
-
var _props$editable2,
|
|
259
|
+
var _props$editable2, _rest$columns;
|
|
74
260
|
var intl = useIntl();
|
|
75
261
|
var onTableChange = props.onTableChange,
|
|
76
262
|
maxLength = props.maxLength,
|
|
@@ -81,20 +267,40 @@ function EditableTable(props) {
|
|
|
81
267
|
defaultValue = props.defaultValue,
|
|
82
268
|
onChange = props.onChange,
|
|
83
269
|
editableFormRef = props.editableFormRef,
|
|
84
|
-
rest = _objectWithoutProperties(props,
|
|
270
|
+
rest = _objectWithoutProperties(props, _excluded2);
|
|
85
271
|
var preData = useRef(undefined);
|
|
86
272
|
var actionRef = useRef();
|
|
87
273
|
var formRef = useRef();
|
|
274
|
+
var form = Form.useFormInstance();
|
|
88
275
|
|
|
89
276
|
// 设置 ref
|
|
90
277
|
useImperativeHandle(rest.actionRef, function () {
|
|
91
278
|
return actionRef.current;
|
|
92
279
|
}, [actionRef.current]);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
280
|
+
|
|
281
|
+
// 在 name 模式下,如果没有传递 value prop,尝试从表单值中获取初始值
|
|
282
|
+
var getInitialValue = function getInitialValue() {
|
|
283
|
+
if (props.value) {
|
|
284
|
+
return props.value;
|
|
285
|
+
}
|
|
286
|
+
if (defaultValue) {
|
|
287
|
+
return defaultValue;
|
|
288
|
+
}
|
|
289
|
+
// 如果使用了 name 且没有 value,尝试从表单获取初始值
|
|
290
|
+
if (props.name && form) {
|
|
291
|
+
var namePath = [props.name].flat(1).filter(Boolean);
|
|
292
|
+
var formValue = form.getFieldValue(namePath);
|
|
293
|
+
if (Array.isArray(formValue)) {
|
|
294
|
+
return formValue;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return [];
|
|
298
|
+
};
|
|
299
|
+
var _useMergedState = useMergedState(getInitialValue, {
|
|
96
300
|
value: props.value,
|
|
97
|
-
onChange
|
|
301
|
+
// 在非受控模式下,onChange 应该在 onDataSourceChange 中触发
|
|
302
|
+
// 这样可以确保数据已经正确更新
|
|
303
|
+
onChange: props.controlled ? props.onChange : undefined
|
|
98
304
|
}),
|
|
99
305
|
_useMergedState2 = _slicedToArray(_useMergedState, 2),
|
|
100
306
|
value = _useMergedState2[0],
|
|
@@ -109,207 +315,305 @@ function EditableTable(props) {
|
|
|
109
315
|
}, [rowKey]);
|
|
110
316
|
|
|
111
317
|
/**
|
|
112
|
-
*
|
|
113
|
-
* @param finlayRowKey
|
|
114
|
-
* @returns string | number
|
|
318
|
+
* 创建编辑 keys 的 Set,用于快速查找
|
|
115
319
|
*/
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
320
|
+
var createEditingKeysSet = useRefFunction(function (editingKeys) {
|
|
321
|
+
return new Set((editingKeys || []).map(function (key) {
|
|
322
|
+
return String(key);
|
|
323
|
+
}));
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* 同步表单值,排除正在编辑的行
|
|
328
|
+
*/
|
|
329
|
+
var syncFormValuesExcludingEditing = useRefFunction(function (dataSource, editingKeysSet, namePath) {
|
|
330
|
+
if (!formRef.current) return;
|
|
331
|
+
try {
|
|
332
|
+
if (namePath && namePath.length > 0) {
|
|
333
|
+
// name 模式:需要保留正在编辑的行
|
|
334
|
+
var currentFormValues = formRef.current.getFieldsValue() || {};
|
|
335
|
+
var currentList = get(currentFormValues, namePath);
|
|
336
|
+
if (currentList && Array.isArray(currentList)) {
|
|
337
|
+
// 构建新的表单值,保留正在编辑的行
|
|
338
|
+
// 使用 Map 优化查找性能,将 O(n²) 降低到 O(n)
|
|
339
|
+
var currentListMap = new Map();
|
|
340
|
+
currentList.forEach(function (item, idx) {
|
|
341
|
+
var key = getRowKey(item, idx);
|
|
342
|
+
currentListMap.set(String(key), item);
|
|
343
|
+
});
|
|
344
|
+
var newList = dataSource.map(function (item, index) {
|
|
345
|
+
var key = getRowKey(item, index);
|
|
346
|
+
var keyStr = String(key);
|
|
347
|
+
|
|
348
|
+
// 如果该行正在编辑,保留表单中的值
|
|
349
|
+
if (editingKeysSet.has(keyStr)) {
|
|
350
|
+
return currentListMap.get(keyStr) || item;
|
|
351
|
+
}
|
|
352
|
+
return item;
|
|
353
|
+
});
|
|
354
|
+
var newValue = set({}, namePath, newList);
|
|
355
|
+
formRef.current.setFieldsValue(newValue);
|
|
356
|
+
} else {
|
|
357
|
+
var _newValue = set({}, namePath, dataSource);
|
|
358
|
+
formRef.current.setFieldsValue(_newValue);
|
|
359
|
+
}
|
|
360
|
+
} else {
|
|
361
|
+
// 非 name 模式:直接设置值
|
|
362
|
+
var formValues = {};
|
|
363
|
+
dataSource.forEach(function (current, index) {
|
|
364
|
+
var key = getRowKey(current, index);
|
|
365
|
+
var keyStr = String(key);
|
|
366
|
+
if (!editingKeysSet.has(keyStr)) {
|
|
367
|
+
formValues[keyStr] = current;
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
if (Object.keys(formValues).length > 0) {
|
|
371
|
+
formRef.current.setFieldsValue(formValues);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
} catch (error) {
|
|
375
|
+
console.warn('Failed to sync form values:', error);
|
|
124
376
|
}
|
|
377
|
+
});
|
|
125
378
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
379
|
+
/**
|
|
380
|
+
* 将数字索引转换为实际的 rowKey(非 name 模式)
|
|
381
|
+
*/
|
|
382
|
+
var convertIndexToRowKey = useRefFunction(function (index) {
|
|
383
|
+
var _value$length;
|
|
384
|
+
var dataLength = (_value$length = value === null || value === void 0 ? void 0 : value.length) !== null && _value$length !== void 0 ? _value$length : 0;
|
|
385
|
+
if (index >= dataLength) return index;
|
|
386
|
+
var rowData = value === null || value === void 0 ? void 0 : value[index];
|
|
387
|
+
return getRowKey === null || getRowKey === void 0 ? void 0 : getRowKey(rowData, index);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* 将 rowKey 转换为数字索引(name 模式)
|
|
392
|
+
*/
|
|
393
|
+
var convertRowKeyToIndex = useRefFunction(function (rowKey) {
|
|
394
|
+
var _value$length2;
|
|
395
|
+
var dataLength = (_value$length2 = value === null || value === void 0 ? void 0 : value.length) !== null && _value$length2 !== void 0 ? _value$length2 : 0;
|
|
396
|
+
if (typeof rowKey === 'string' || rowKey >= dataLength) {
|
|
130
397
|
var _rowIndex = value.findIndex(function (item, index) {
|
|
131
398
|
var _getRowKey;
|
|
132
|
-
return (getRowKey === null || getRowKey === void 0 || (_getRowKey = getRowKey(item, index)) === null || _getRowKey === void 0 ? void 0 : _getRowKey.toString()) === (
|
|
399
|
+
return (getRowKey === null || getRowKey === void 0 || (_getRowKey = getRowKey(item, index)) === null || _getRowKey === void 0 ? void 0 : _getRowKey.toString()) === (rowKey === null || rowKey === void 0 ? void 0 : rowKey.toString());
|
|
133
400
|
});
|
|
134
401
|
if (_rowIndex !== -1) return _rowIndex;
|
|
135
402
|
}
|
|
403
|
+
return rowKey;
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* 根据不同的情况返回不同的 rowKey
|
|
408
|
+
*/
|
|
409
|
+
var coverRowKey = useRefFunction(function (finlayRowKey) {
|
|
410
|
+
if (typeof finlayRowKey === 'number' && !props.name) {
|
|
411
|
+
return convertIndexToRowKey(finlayRowKey);
|
|
412
|
+
}
|
|
413
|
+
if (props.name) {
|
|
414
|
+
return convertRowKeyToIndex(finlayRowKey);
|
|
415
|
+
}
|
|
136
416
|
return finlayRowKey;
|
|
137
417
|
});
|
|
138
418
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
419
|
+
/**
|
|
420
|
+
* 构建表单字段路径
|
|
421
|
+
*/
|
|
422
|
+
var buildFormFieldPath = useRefFunction(function (rowKey) {
|
|
423
|
+
var _rowKey$toString;
|
|
424
|
+
return [props.name, (_rowKey$toString = rowKey === null || rowKey === void 0 ? void 0 : rowKey.toString()) !== null && _rowKey$toString !== void 0 ? _rowKey$toString : ''].flat(1).filter(Boolean);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* 获取一行数据
|
|
429
|
+
*/
|
|
430
|
+
var getRowData = useRefFunction(function (rowIndex) {
|
|
431
|
+
var _formRef$current;
|
|
432
|
+
if (rowIndex == null) {
|
|
433
|
+
throw new Error('rowIndex is required');
|
|
434
|
+
}
|
|
435
|
+
var finlayRowKey = coverRowKey(rowIndex);
|
|
436
|
+
var rowKeyName = buildFormFieldPath(finlayRowKey);
|
|
437
|
+
return (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.getFieldValue(rowKeyName);
|
|
438
|
+
});
|
|
155
439
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
var
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return
|
|
168
|
-
|
|
440
|
+
/**
|
|
441
|
+
* 获取整个表格的数据
|
|
442
|
+
*/
|
|
443
|
+
var getRowsData = useRefFunction(function () {
|
|
444
|
+
var _formRef$current3;
|
|
445
|
+
var rowKeyName = [props.name].flat(1).filter(Boolean);
|
|
446
|
+
if (Array.isArray(rowKeyName) && rowKeyName.length === 0) {
|
|
447
|
+
var _formRef$current2;
|
|
448
|
+
var rowData = (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : _formRef$current2.getFieldsValue();
|
|
449
|
+
if (Array.isArray(rowData)) return rowData;
|
|
450
|
+
return Object.keys(rowData).map(function (key) {
|
|
451
|
+
return rowData[key];
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
return (_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 ? void 0 : _formRef$current3.getFieldValue(rowKeyName);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* 设置一行数据
|
|
459
|
+
*/
|
|
460
|
+
var setRowData = useRefFunction(function (rowIndex, data) {
|
|
461
|
+
if (rowIndex == null) {
|
|
462
|
+
throw new Error('rowIndex is required');
|
|
463
|
+
}
|
|
464
|
+
var finlayRowKey = coverRowKey(rowIndex);
|
|
465
|
+
var rowKeyName = buildFormFieldPath(finlayRowKey);
|
|
466
|
+
var currentRowData = getRowData(rowIndex);
|
|
467
|
+
var newRowData = _objectSpread(_objectSpread({}, currentRowData), data || {});
|
|
468
|
+
|
|
469
|
+
// 在 name 模式下,需要更新整个数组
|
|
470
|
+
if (props.name) {
|
|
471
|
+
var _formRef$current4;
|
|
472
|
+
var tableName = [props.name].flat(1).filter(Boolean);
|
|
473
|
+
// 优先从 value prop 获取数据(受控模式),否则从表单值获取
|
|
474
|
+
var currentTableData = props.value || ((_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 ? void 0 : _formRef$current4.getFieldValue(tableName));
|
|
475
|
+
if (Array.isArray(currentTableData)) {
|
|
476
|
+
// 找到要更新的行的索引
|
|
477
|
+
var rowIndexToUpdate = typeof finlayRowKey === 'number' ? finlayRowKey : currentTableData.findIndex(function (row, index) {
|
|
478
|
+
var rowKey = getRowKey === null || getRowKey === void 0 ? void 0 : getRowKey(row, index);
|
|
479
|
+
return rowKey === finlayRowKey || (rowKey === null || rowKey === void 0 ? void 0 : rowKey.toString()) === (finlayRowKey === null || finlayRowKey === void 0 ? void 0 : finlayRowKey.toString());
|
|
169
480
|
});
|
|
481
|
+
if (rowIndexToUpdate >= 0 && rowIndexToUpdate < currentTableData.length) {
|
|
482
|
+
var _formRef$current5;
|
|
483
|
+
// 更新数组中的对应行
|
|
484
|
+
var updatedTableData = _toConsumableArray(currentTableData);
|
|
485
|
+
updatedTableData[rowIndexToUpdate] = newRowData;
|
|
486
|
+
|
|
487
|
+
// 设置整个数组,使用 set 来构建正确的路径
|
|
488
|
+
// 使用与 syncFormValuesExcludingEditing 相同的路径格式(数组路径)
|
|
489
|
+
// 这样可以确保 getFieldValue 能正确获取值
|
|
490
|
+
var updateValues = set({}, tableName, updatedTableData);
|
|
491
|
+
(_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 || _formRef$current5.setFieldsValue(updateValues);
|
|
492
|
+
|
|
493
|
+
// 在受控模式下,触发 onChange
|
|
494
|
+
if (props.controlled && props.onChange) {
|
|
495
|
+
props.onChange(updatedTableData);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
} else {
|
|
499
|
+
var _formRef$current6;
|
|
500
|
+
// 如果当前没有数据,直接设置单个字段
|
|
501
|
+
var _updateValues = set({}, rowKeyName, newRowData);
|
|
502
|
+
(_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 || _formRef$current6.setFieldsValue(_updateValues);
|
|
170
503
|
}
|
|
171
|
-
|
|
172
|
-
|
|
504
|
+
} else {
|
|
505
|
+
var _formRef$current7;
|
|
506
|
+
// 非 name 模式下,直接设置单个字段
|
|
507
|
+
var _updateValues2 = set({}, rowKeyName, newRowData);
|
|
508
|
+
(_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 || _formRef$current7.setFieldsValue(_updateValues2);
|
|
509
|
+
}
|
|
510
|
+
return true;
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
// 设置 editableFormRef
|
|
514
|
+
useImperativeHandle(editableFormRef, function () {
|
|
173
515
|
return _objectSpread(_objectSpread({}, formRef.current), {}, {
|
|
174
516
|
getRowData: getRowData,
|
|
175
517
|
getRowsData: getRowsData,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
518
|
+
setRowData: setRowData
|
|
519
|
+
});
|
|
520
|
+
}, [coverRowKey, props.name, getRowData, getRowsData, setRowData]);
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* 受控模式下同步表单值
|
|
524
|
+
* 在受控模式下,即使正在编辑的行也要同步更新,因为数据由外部完全控制
|
|
525
|
+
* 使用深度比较优化性能,避免频繁的序列化操作
|
|
526
|
+
* 注意:只有当 value 明确传递时才同步,避免覆盖表单中的初始值
|
|
527
|
+
*/
|
|
528
|
+
useDeepCompareEffect(function () {
|
|
529
|
+
if (!props.controlled || !formRef.current) return;
|
|
530
|
+
|
|
531
|
+
// 在受控模式下,只有当 value 明确传递时才同步
|
|
532
|
+
// 避免在 value 为 undefined 时覆盖表单中的初始值
|
|
533
|
+
if (value === undefined) return;
|
|
534
|
+
|
|
535
|
+
// 在受控模式下,同步所有值(包括正在编辑的行)
|
|
536
|
+
// 因为数据由外部完全控制,应该同步更新
|
|
537
|
+
try {
|
|
538
|
+
if (props.name) {
|
|
539
|
+
// name 模式:直接设置整个数组
|
|
540
|
+
var namePath = [props.name].flat(1);
|
|
541
|
+
var newValue = set({}, namePath, value);
|
|
542
|
+
formRef.current.setFieldsValue(newValue);
|
|
543
|
+
} else {
|
|
544
|
+
// 非 name 模式:直接设置值
|
|
545
|
+
var formValues = {};
|
|
546
|
+
value.forEach(function (item, index) {
|
|
547
|
+
var key = getRowKey(item, index);
|
|
548
|
+
var keyStr = String(key);
|
|
549
|
+
formValues[keyStr] = item;
|
|
550
|
+
});
|
|
551
|
+
if (Object.keys(formValues).length > 0) {
|
|
552
|
+
formRef.current.setFieldsValue(formValues);
|
|
186
553
|
}
|
|
187
|
-
var finlayRowKey = coverRowKey(rowIndex);
|
|
188
|
-
var rowKeyName = [props.name, (_finlayRowKey$toStrin2 = finlayRowKey === null || finlayRowKey === void 0 ? void 0 : finlayRowKey.toString()) !== null && _finlayRowKey$toStrin2 !== void 0 ? _finlayRowKey$toStrin2 : ''].flat(1).filter(Boolean);
|
|
189
|
-
var newRowData = Object.assign({}, _objectSpread(_objectSpread({}, getRowData(rowIndex)), data || {}));
|
|
190
|
-
var updateValues = set({}, rowKeyName, newRowData);
|
|
191
|
-
(_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 || _formRef$current4.setFieldsValue(updateValues);
|
|
192
|
-
return true;
|
|
193
554
|
}
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}, [stringify(value), props.controlled]);
|
|
555
|
+
} catch (error) {
|
|
556
|
+
console.warn('Failed to sync form values in controlled mode:', error);
|
|
557
|
+
}
|
|
558
|
+
}, [value, props.controlled, props.name, getRowKey]);
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* 同步表单实例引用
|
|
562
|
+
* 只在 name 模式下且 form 存在时更新
|
|
563
|
+
*/
|
|
204
564
|
useEffect(function () {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
formRef.current = props
|
|
565
|
+
var _props$editable;
|
|
566
|
+
if (props.name && props !== null && props !== void 0 && (_props$editable = props.editable) !== null && _props$editable !== void 0 && _props$editable.form) {
|
|
567
|
+
formRef.current = props.editable.form;
|
|
208
568
|
}
|
|
209
569
|
}, [(_props$editable2 = props.editable) === null || _props$editable2 === void 0 ? void 0 : _props$editable2.form, props.name]);
|
|
210
|
-
var
|
|
211
|
-
|
|
212
|
-
position = _ref.position,
|
|
213
|
-
creatorButtonText = _ref.creatorButtonText,
|
|
214
|
-
newRecordType = _ref.newRecordType,
|
|
215
|
-
parentKey = _ref.parentKey,
|
|
216
|
-
style = _ref.style,
|
|
217
|
-
restButtonProps = _objectWithoutProperties(_ref, _excluded2);
|
|
570
|
+
var _ref4 = recordCreatorProps || {},
|
|
571
|
+
position = _ref4.position;
|
|
218
572
|
var isTop = position === 'top';
|
|
219
|
-
var
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
style: _objectSpread({
|
|
231
|
-
display: 'block',
|
|
232
|
-
margin: '10px 0',
|
|
233
|
-
width: '100%'
|
|
234
|
-
}, style),
|
|
235
|
-
icon: /*#__PURE__*/_jsx(PlusOutlined, {})
|
|
236
|
-
}, restButtonProps), {}, {
|
|
237
|
-
children: creatorButtonText || intl.getMessage('editableTable.action.add', '添加一行数据')
|
|
238
|
-
}))
|
|
239
|
-
});
|
|
240
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
241
|
-
}, [recordCreatorProps, maxLength, value === null || value === void 0 ? void 0 : value.length]);
|
|
242
|
-
var buttonRenderProps = useMemo(function () {
|
|
243
|
-
if (!creatorButtonDom) {
|
|
244
|
-
return {};
|
|
245
|
-
}
|
|
246
|
-
if (isTop) {
|
|
247
|
-
return {
|
|
248
|
-
components: {
|
|
249
|
-
header: {
|
|
250
|
-
wrapper: function wrapper(_ref2) {
|
|
251
|
-
var _rest$columns;
|
|
252
|
-
var className = _ref2.className,
|
|
253
|
-
children = _ref2.children;
|
|
254
|
-
return /*#__PURE__*/_jsxs("thead", {
|
|
255
|
-
className: className,
|
|
256
|
-
children: [children, /*#__PURE__*/_jsxs("tr", {
|
|
257
|
-
style: {
|
|
258
|
-
position: 'relative'
|
|
259
|
-
},
|
|
260
|
-
children: [/*#__PURE__*/_jsx("td", {
|
|
261
|
-
colSpan: 0,
|
|
262
|
-
style: {
|
|
263
|
-
visibility: 'hidden'
|
|
264
|
-
},
|
|
265
|
-
children: creatorButtonDom
|
|
266
|
-
}), /*#__PURE__*/_jsx("td", {
|
|
267
|
-
style: {
|
|
268
|
-
position: 'absolute',
|
|
269
|
-
left: 0,
|
|
270
|
-
width: '100%'
|
|
271
|
-
},
|
|
272
|
-
colSpan: (_rest$columns = rest.columns) === null || _rest$columns === void 0 ? void 0 : _rest$columns.length,
|
|
273
|
-
children: creatorButtonDom
|
|
274
|
-
})]
|
|
275
|
-
})]
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
return {
|
|
283
|
-
tableViewRender: function tableViewRender(_, dom) {
|
|
284
|
-
var _props$tableViewRende, _props$tableViewRende2;
|
|
285
|
-
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
286
|
-
children: [(_props$tableViewRende = (_props$tableViewRende2 = props.tableViewRender) === null || _props$tableViewRende2 === void 0 ? void 0 : _props$tableViewRende2.call(props, _, dom)) !== null && _props$tableViewRende !== void 0 ? _props$tableViewRende : dom, creatorButtonDom]
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
291
|
-
}, [isTop, creatorButtonDom]);
|
|
292
|
-
var editableProps = _objectSpread({}, props.editable);
|
|
573
|
+
var _useCreatorButton = useCreatorButton({
|
|
574
|
+
recordCreatorProps: recordCreatorProps,
|
|
575
|
+
maxLength: maxLength,
|
|
576
|
+
value: value,
|
|
577
|
+
intl: intl,
|
|
578
|
+
isTop: isTop,
|
|
579
|
+
columnsLength: (_rest$columns = rest.columns) === null || _rest$columns === void 0 ? void 0 : _rest$columns.length,
|
|
580
|
+
tableViewRender: props.tableViewRender
|
|
581
|
+
}),
|
|
582
|
+
creatorButtonDom = _useCreatorButton.creatorButtonDom,
|
|
583
|
+
buttonRenderProps = _useCreatorButton.buttonRenderProps;
|
|
293
584
|
|
|
294
585
|
/**
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
586
|
+
* 处理值变化回调
|
|
587
|
+
* 注意:受控模式下不调用 onChange,避免循环更新
|
|
588
|
+
* onChange 应该由外部控制,而不是在内部触发
|
|
298
589
|
*/
|
|
299
|
-
var
|
|
590
|
+
var handleValuesChange = useRefFunction(function (r, dataSource) {
|
|
300
591
|
var _props$editable3, _props$editable3$onVa, _props$onValuesChange;
|
|
301
592
|
(_props$editable3 = props.editable) === null || _props$editable3 === void 0 || (_props$editable3$onVa = _props$editable3.onValuesChange) === null || _props$editable3$onVa === void 0 || _props$editable3$onVa.call(_props$editable3, r, dataSource);
|
|
302
593
|
(_props$onValuesChange = props.onValuesChange) === null || _props$onValuesChange === void 0 || _props$onValuesChange.call(props, dataSource, r);
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
594
|
+
|
|
595
|
+
// 在受控模式下,当表单值变化时也应该触发 onChange
|
|
596
|
+
// 这样外部可以同步更新 value,实现真正的受控
|
|
597
|
+
if (props.controlled && props !== null && props !== void 0 && props.onChange) {
|
|
598
|
+
props.onChange(dataSource);
|
|
306
599
|
}
|
|
600
|
+
// 非受控模式下,onChange 应该在 onDataSourceChange 中触发
|
|
601
|
+
// 这样可以确保数据已经正确更新
|
|
307
602
|
});
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* 构建可编辑属性
|
|
606
|
+
* 使用 useMemo 优化性能,避免不必要的重新创建
|
|
607
|
+
*/
|
|
608
|
+
var editableProps = useMemo(function () {
|
|
609
|
+
var _props$editable4;
|
|
610
|
+
var baseProps = _objectSpread({}, props.editable);
|
|
611
|
+
var hasOnValuesChange = Boolean(props === null || props === void 0 ? void 0 : props.onValuesChange) || Boolean((_props$editable4 = props.editable) === null || _props$editable4 === void 0 ? void 0 : _props$editable4.onValuesChange) || Boolean(props.controlled && (props === null || props === void 0 ? void 0 : props.onChange));
|
|
612
|
+
if (hasOnValuesChange) {
|
|
613
|
+
baseProps.onValuesChange = handleValuesChange;
|
|
614
|
+
}
|
|
615
|
+
return baseProps;
|
|
616
|
+
}, [props.editable, props.onValuesChange, props.controlled, props.onChange, handleValuesChange]);
|
|
313
617
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
314
618
|
children: [/*#__PURE__*/_jsx(EditableTableActionContext.Provider, {
|
|
315
619
|
value: actionRef,
|
|
@@ -330,34 +634,63 @@ function EditableTable(props) {
|
|
|
330
634
|
}),
|
|
331
635
|
dataSource: value,
|
|
332
636
|
onDataSourceChange: function onDataSourceChange(dataSource) {
|
|
637
|
+
// setValue 会触发 onChange,但我们需要确保数据已经正确更新
|
|
638
|
+
// 所以先设置数据,然后手动触发 onChange
|
|
333
639
|
setValue(dataSource);
|
|
640
|
+
|
|
334
641
|
/**
|
|
335
|
-
* 如果是
|
|
642
|
+
* 如果是 name 模式,需要同步表单值
|
|
643
|
+
* 避免表单值和数据源不一致
|
|
644
|
+
* 注意:不会覆盖正在编辑的行
|
|
336
645
|
*/
|
|
337
|
-
if (props.name &&
|
|
338
|
-
var
|
|
339
|
-
var
|
|
340
|
-
|
|
646
|
+
if (props.name && formRef.current) {
|
|
647
|
+
var _props$editable5;
|
|
648
|
+
var editingKeys = (_props$editable5 = props.editable) === null || _props$editable5 === void 0 ? void 0 : _props$editable5.editableKeys;
|
|
649
|
+
var editingKeysSet = createEditingKeysSet(editingKeys);
|
|
650
|
+
var namePath = [props.name].flat(1).filter(Boolean);
|
|
651
|
+
syncFormValuesExcludingEditing(dataSource, editingKeysSet, namePath);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// 在非受控模式下,通过 onDataSourceChange 触发 onChange
|
|
655
|
+
// 这样可以确保数据已经正确更新
|
|
656
|
+
if (!props.controlled && props.onChange) {
|
|
657
|
+
props.onChange(dataSource);
|
|
341
658
|
}
|
|
342
659
|
}
|
|
343
660
|
}))
|
|
344
661
|
}), props.name ? /*#__PURE__*/_jsx(ProFormDependency, {
|
|
345
662
|
name: [props.name],
|
|
346
663
|
children: function children(changeValue) {
|
|
347
|
-
|
|
664
|
+
// 初始化 preData
|
|
348
665
|
if (!preData.current) {
|
|
349
666
|
preData.current = value;
|
|
350
667
|
return null;
|
|
351
668
|
}
|
|
352
|
-
var
|
|
353
|
-
var
|
|
669
|
+
var namePath = [props.name].flat(1);
|
|
670
|
+
var list = get(changeValue, namePath);
|
|
671
|
+
|
|
672
|
+
// 添加空值检查,避免后续操作出错
|
|
673
|
+
if (!list || !Array.isArray(list)) {
|
|
674
|
+
preData.current = value;
|
|
675
|
+
return null;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// 在更新 preData 之前找到变化的项
|
|
679
|
+
// 使用 findIndex 可以同时获取变化的项和索引
|
|
680
|
+
var changeIndex = list.findIndex(function (item, index) {
|
|
354
681
|
var _preData$current;
|
|
355
682
|
return !isDeepEqualReact(item, (_preData$current = preData.current) === null || _preData$current === void 0 ? void 0 : _preData$current[index]);
|
|
356
683
|
});
|
|
684
|
+
|
|
685
|
+
// 只有在找到变化项时才触发回调
|
|
686
|
+
if (changeIndex !== -1) {
|
|
687
|
+
var _props$editable6, _props$editable6$onVa;
|
|
688
|
+
var changeItem = list[changeIndex];
|
|
689
|
+
props === null || props === void 0 || (_props$editable6 = props.editable) === null || _props$editable6 === void 0 || (_props$editable6$onVa = _props$editable6.onValuesChange) === null || _props$editable6$onVa === void 0 || _props$editable6$onVa.call(_props$editable6, changeItem, list);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// 在找到 changeItem 之后再更新 preData,确保后续比较正确
|
|
357
693
|
preData.current = value;
|
|
358
|
-
if (!changeItem) return null;
|
|
359
|
-
// 如果不存在 preData 说明是初始化,此时不需要触发 onValuesChange
|
|
360
|
-
props === null || props === void 0 || (_props$editable5 = props.editable) === null || _props$editable5 === void 0 || (_props$editable5$onVa = _props$editable5.onValuesChange) === null || _props$editable5$onVa === void 0 || _props$editable5$onVa.call(_props$editable5, changeItem, list);
|
|
361
694
|
return null;
|
|
362
695
|
}
|
|
363
696
|
}) : null]
|