@zat-design/sisyphus-react 4.0.0-beta.7 → 4.0.0-beta.9
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/index.esm.css +1 -1
- package/dist/less.esm.css +1 -1
- package/es/ProEditTable/components/RcTable/DraggableTable.js +5 -3
- package/es/ProEditTable/components/RenderField/index.js +44 -9
- package/es/ProEditTable/index.js +11 -9
- package/es/ProEditTable/propsType.d.ts +6 -0
- package/es/ProEditTable/style/index.less +9 -3
- package/es/ProEditTable/utils/useShouldUpdateForTable.d.ts +15 -0
- package/es/ProEditTable/utils/useShouldUpdateForTable.js +132 -0
- package/es/ProForm/components/combination/FormList/components/ActionButton.d.ts +1 -0
- package/es/ProForm/components/combination/FormList/components/ActionButton.js +84 -3
- package/es/ProForm/components/combination/FormList/components/BlockFields.d.ts +2 -0
- package/es/ProForm/components/combination/FormList/components/BlockFields.js +63 -6
- package/es/ProForm/components/combination/FormList/components/Empty.js +11 -2
- package/es/ProForm/components/combination/FormList/components/LineFields.d.ts +1 -0
- package/es/ProForm/components/combination/FormList/components/LineFields.js +4 -2
- package/es/ProForm/components/combination/FormList/components/ToolbarButton.js +38 -9
- package/es/ProForm/components/combination/FormList/index.js +67 -57
- package/es/ProForm/components/combination/FormList/propsType.d.ts +7 -2
- package/es/ProForm/components/combination/FormList/style/index.less +41 -0
- package/es/ProForm/components/render/RenderFields.js +2 -1
- package/es/ProForm/index.js +1 -1
- package/es/ProForm/propsType.d.ts +1 -0
- package/es/ProForm/utils/useShouldUpdate.js +1 -2
- package/es/ProForm/utils/useWatch.js +3 -3
- package/es/ProLayout/components/Layout/Menu/FoldMenu/index.js +19 -9
- package/es/ProLayout/components/Layout/Menu/OpenMenu/index.js +6 -8
- package/es/ProLayout/components/ProHeader/index.js +19 -15
- package/es/ProTable/hooks/useAntdTable.js +52 -29
- package/es/ProTabs/style/index.less +5 -1
- package/es/utils/index.js +13 -1
- package/lib/ProEditTable/components/RcTable/DraggableTable.js +5 -3
- package/lib/ProEditTable/components/RenderField/index.js +44 -9
- package/lib/ProEditTable/index.js +11 -9
- package/lib/ProEditTable/propsType.d.ts +6 -0
- package/lib/ProEditTable/style/index.less +9 -3
- package/lib/ProEditTable/utils/useShouldUpdateForTable.d.ts +15 -0
- package/lib/ProEditTable/utils/useShouldUpdateForTable.js +139 -0
- package/lib/ProForm/components/combination/FormList/components/ActionButton.d.ts +1 -0
- package/lib/ProForm/components/combination/FormList/components/ActionButton.js +84 -3
- package/lib/ProForm/components/combination/FormList/components/BlockFields.d.ts +2 -0
- package/lib/ProForm/components/combination/FormList/components/BlockFields.js +62 -6
- package/lib/ProForm/components/combination/FormList/components/Empty.js +11 -2
- package/lib/ProForm/components/combination/FormList/components/LineFields.d.ts +1 -0
- package/lib/ProForm/components/combination/FormList/components/LineFields.js +4 -2
- package/lib/ProForm/components/combination/FormList/components/ToolbarButton.js +38 -9
- package/lib/ProForm/components/combination/FormList/index.js +67 -57
- package/lib/ProForm/components/combination/FormList/propsType.d.ts +7 -2
- package/lib/ProForm/components/combination/FormList/style/index.less +41 -0
- package/lib/ProForm/components/render/RenderFields.js +2 -1
- package/lib/ProForm/index.js +1 -1
- package/lib/ProForm/propsType.d.ts +1 -0
- package/lib/ProForm/utils/useShouldUpdate.js +1 -2
- package/lib/ProForm/utils/useWatch.js +3 -3
- package/lib/ProLayout/components/Layout/Menu/FoldMenu/index.js +18 -8
- package/lib/ProLayout/components/Layout/Menu/OpenMenu/index.js +5 -7
- package/lib/ProLayout/components/ProHeader/index.js +19 -15
- package/lib/ProTable/hooks/useAntdTable.js +52 -29
- package/lib/ProTabs/style/index.less +5 -1
- package/lib/utils/index.js +13 -1
- package/package.json +3 -4
|
@@ -38,8 +38,9 @@ var Row = props => {
|
|
|
38
38
|
ref: setNodeRef,
|
|
39
39
|
style: style
|
|
40
40
|
}, attributes), {}, {
|
|
41
|
-
children: React.Children.map(children, child => {
|
|
42
|
-
|
|
41
|
+
children: React.Children.map(children, (child, index) => {
|
|
42
|
+
// 在第一列(通常是rowSelection列)显示拖拽图标
|
|
43
|
+
if (index === 0 && !disabled) {
|
|
43
44
|
var _restProps$dataRowD;
|
|
44
45
|
var _ref = (child === null || child === void 0 ? void 0 : child.props) || {},
|
|
45
46
|
render = _ref.render,
|
|
@@ -60,7 +61,8 @@ var Row = props => {
|
|
|
60
61
|
}, listeners)) : /*#__PURE__*/_jsx(ProIcon, {
|
|
61
62
|
size: 20
|
|
62
63
|
}), props['data-hide'] ? null : render === null || render === void 0 ? void 0 : render(null, record, renderIndex)]
|
|
63
|
-
})
|
|
64
|
+
}),
|
|
65
|
+
className: 'pro-edit-table-drag-wrapper-cell'
|
|
64
66
|
});
|
|
65
67
|
}
|
|
66
68
|
return child;
|
|
@@ -23,6 +23,7 @@ import { isSelect, isTrim } from "../../../ProForm/utils";
|
|
|
23
23
|
import ConfirmWrapper from "../../../ProForm/components/render/ConfirmWrapper";
|
|
24
24
|
import { getDefaultProps } from "../../utils/getDefaultProps";
|
|
25
25
|
import ListChangedWrapper from "./ListChangedWrapper";
|
|
26
|
+
import useShouldUpdateForTable from "../../utils/useShouldUpdateForTable";
|
|
26
27
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
27
28
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
29
|
var RenderField = _ref => {
|
|
@@ -58,8 +59,6 @@ var RenderField = _ref => {
|
|
|
58
59
|
dependencies = column.dependencies,
|
|
59
60
|
desensitization = column.desensitization,
|
|
60
61
|
resetProps = _objectWithoutProperties(column, _excluded);
|
|
61
|
-
// editRender弃用使用component同ProForm
|
|
62
|
-
var _editRender = component || editRender;
|
|
63
62
|
var mode = config.mode,
|
|
64
63
|
cellName = config.cellName,
|
|
65
64
|
cellNamePath = config.cellNamePath,
|
|
@@ -76,13 +75,17 @@ var RenderField = _ref => {
|
|
|
76
75
|
validateTrigger = _config$validateTrigg === void 0 ? ['onChange', 'onBlur', 'onSubmit'] : _config$validateTrigg,
|
|
77
76
|
otherProps = config.otherProps,
|
|
78
77
|
diffConfig = config.diffConfig,
|
|
79
|
-
getIsNew = config.getIsNew
|
|
78
|
+
getIsNew = config.getIsNew,
|
|
79
|
+
shouldUpdateDebounce = config.shouldUpdateDebounce;
|
|
80
80
|
var _fieldProps = fieldProps || formItemProps || {};
|
|
81
81
|
var _rules = rules || [];
|
|
82
82
|
var _required = required;
|
|
83
83
|
var _valueType = valueType;
|
|
84
84
|
var _disabled = false;
|
|
85
85
|
var _desensitization = desensitization || [];
|
|
86
|
+
|
|
87
|
+
// editRender弃用使用component同ProForm
|
|
88
|
+
var _editRender = component || editRender;
|
|
86
89
|
var isCell = mode === 'cell';
|
|
87
90
|
if (isCell) {
|
|
88
91
|
record['is-view'] = !isEqual(cellNamePath, cellName);
|
|
@@ -112,21 +115,34 @@ var RenderField = _ref => {
|
|
|
112
115
|
// 行参数 - 使用useMemo优化
|
|
113
116
|
var rowParams = useMemo(() => [currentValue, rowData, options], [currentValue, rowData, options]);
|
|
114
117
|
|
|
118
|
+
// 使用 hook 处理动态属性(带选择性防抖)
|
|
119
|
+
var dynamicProps = useShouldUpdateForTable({
|
|
120
|
+
rowParams,
|
|
121
|
+
column,
|
|
122
|
+
shouldUpdateDebounce
|
|
123
|
+
});
|
|
124
|
+
|
|
115
125
|
// required & rules & fieldProps & disabled & valueType 函数化处理
|
|
126
|
+
// 优先使用 hook 返回的值,fallback 到原始值
|
|
116
127
|
if (isFunction(required)) {
|
|
117
|
-
|
|
128
|
+
var _dynamicProps$require;
|
|
129
|
+
_required = (_dynamicProps$require = dynamicProps.required) !== null && _dynamicProps$require !== void 0 ? _dynamicProps$require : required(...rowParams);
|
|
118
130
|
}
|
|
119
131
|
if (isFunction(fieldProps)) {
|
|
120
|
-
|
|
132
|
+
var _dynamicProps$fieldPr;
|
|
133
|
+
_fieldProps = (_dynamicProps$fieldPr = dynamicProps.fieldProps) !== null && _dynamicProps$fieldPr !== void 0 ? _dynamicProps$fieldPr : fieldProps(...rowParams);
|
|
121
134
|
}
|
|
122
135
|
if (isFunction(rules)) {
|
|
123
|
-
|
|
136
|
+
var _dynamicProps$rules;
|
|
137
|
+
_rules = (_dynamicProps$rules = dynamicProps.rules) !== null && _dynamicProps$rules !== void 0 ? _dynamicProps$rules : rules(...rowParams);
|
|
124
138
|
}
|
|
125
139
|
if (isFunction(valueType)) {
|
|
126
|
-
|
|
140
|
+
var _dynamicProps$valueTy;
|
|
141
|
+
_valueType = (_dynamicProps$valueTy = dynamicProps.valueType) !== null && _dynamicProps$valueTy !== void 0 ? _dynamicProps$valueTy : valueType(...rowParams);
|
|
127
142
|
}
|
|
128
143
|
if (isFunction(desensitization)) {
|
|
129
|
-
|
|
144
|
+
var _dynamicProps$desensi;
|
|
145
|
+
_desensitization = (_dynamicProps$desensi = dynamicProps.desensitization) !== null && _dynamicProps$desensi !== void 0 ? _dynamicProps$desensi : desensitization(...rowParams);
|
|
130
146
|
}
|
|
131
147
|
|
|
132
148
|
// 获取最终的disabled
|
|
@@ -138,8 +154,11 @@ var RenderField = _ref => {
|
|
|
138
154
|
columnFieldProps: _fieldProps,
|
|
139
155
|
params: rowParams
|
|
140
156
|
});
|
|
157
|
+
|
|
158
|
+
// isEditable 处理 - 优先使用 hook 返回的值
|
|
141
159
|
if (isFunction(isEditable)) {
|
|
142
|
-
|
|
160
|
+
var _dynamicProps$isEdita;
|
|
161
|
+
isEditable = (_dynamicProps$isEdita = dynamicProps.isEditable) !== null && _dynamicProps$isEdita !== void 0 ? _dynamicProps$isEdita : isEditable(...rowParams);
|
|
143
162
|
}
|
|
144
163
|
|
|
145
164
|
// 是否只读文本
|
|
@@ -756,5 +775,21 @@ export default /*#__PURE__*/memo(RenderField, (prevProps, nextProps) => {
|
|
|
756
775
|
return false;
|
|
757
776
|
}
|
|
758
777
|
}
|
|
778
|
+
|
|
779
|
+
// 特殊处理:当使用自定义 component 函数时,比较整个 record 对象
|
|
780
|
+
// 因为自定义组件可能依赖 record 中的其他字段(不只是当前列的 dataIndex)
|
|
781
|
+
if (isFunction(prevColumn === null || prevColumn === void 0 ? void 0 : prevColumn.component) || isFunction(nextColumn === null || nextColumn === void 0 ? void 0 : nextColumn.component)) {
|
|
782
|
+
// 浅比较 record 的所有属性
|
|
783
|
+
var prevKeys = Object.keys(prevRecord || {});
|
|
784
|
+
var nextKeys = Object.keys(nextRecord || {});
|
|
785
|
+
if (prevKeys.length !== nextKeys.length) {
|
|
786
|
+
return false;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// 使用 some 方法代替 for 循环
|
|
790
|
+
if (prevKeys.some(key => (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord[key]) !== (nextRecord === null || nextRecord === void 0 ? void 0 : nextRecord[key]))) {
|
|
791
|
+
return false;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
759
794
|
return true;
|
|
760
795
|
});
|
package/es/ProEditTable/index.js
CHANGED
|
@@ -20,7 +20,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
20
20
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
21
21
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
22
|
var ProEditTable = (_ref, ref) => {
|
|
23
|
-
var _resetProps$id, _resetProps$id$split, _themeConfig$data2, _resetProps$otherProp;
|
|
23
|
+
var _resetProps$id, _resetProps$id$split, _ref2, _formFieldProps$shoul, _themeConfig$data2, _resetProps$otherProp;
|
|
24
24
|
var _ref$value = _ref.value,
|
|
25
25
|
value = _ref$value === void 0 ? [] : _ref$value,
|
|
26
26
|
onChange = _ref.onChange,
|
|
@@ -73,6 +73,7 @@ var ProEditTable = (_ref, ref) => {
|
|
|
73
73
|
var affixRef = useRef(null);
|
|
74
74
|
var form = contentForm || (formFieldProps === null || formFieldProps === void 0 ? void 0 : formFieldProps.form) || (resetProps === null || resetProps === void 0 ? void 0 : resetProps.form);
|
|
75
75
|
var name = (formFieldProps === null || formFieldProps === void 0 ? void 0 : formFieldProps.name) || (resetProps === null || resetProps === void 0 ? void 0 : resetProps.name) || (resetProps === null || resetProps === void 0 || (_resetProps$id = resetProps.id) === null || _resetProps$id === void 0 || (_resetProps$id$split = _resetProps$id.split) === null || _resetProps$id$split === void 0 ? void 0 : _resetProps$id$split.call(_resetProps$id, '_'));
|
|
76
|
+
var shouldUpdateDebounce = (_ref2 = (_formFieldProps$shoul = formFieldProps === null || formFieldProps === void 0 ? void 0 : formFieldProps.shouldUpdateDebounce) !== null && _formFieldProps$shoul !== void 0 ? _formFieldProps$shoul : resetProps === null || resetProps === void 0 ? void 0 : resetProps.shouldUpdateDebounce) !== null && _ref2 !== void 0 ? _ref2 : 200;
|
|
76
77
|
var _formFieldProps$isVie = formFieldProps.isView,
|
|
77
78
|
isView = _formFieldProps$isVie === void 0 ? false : _formFieldProps$isVie,
|
|
78
79
|
_formFieldProps$viewE = formFieldProps.viewEmpty,
|
|
@@ -95,8 +96,8 @@ var ProEditTable = (_ref, ref) => {
|
|
|
95
96
|
_useLocalStorageState2 = _slicedToArray(_useLocalStorageState, 1),
|
|
96
97
|
themeConfig = _useLocalStorageState2[0];
|
|
97
98
|
var requiredAlign = useMemo(() => {
|
|
98
|
-
var
|
|
99
|
-
return (
|
|
99
|
+
var _ref3, _themeConfig$data$zau, _themeConfig$data;
|
|
100
|
+
return (_ref3 = (_themeConfig$data$zau = themeConfig === null || themeConfig === void 0 || (_themeConfig$data = themeConfig.data) === null || _themeConfig$data === void 0 ? void 0 : _themeConfig$data.zauiFormAlign) !== null && _themeConfig$data$zau !== void 0 ? _themeConfig$data$zau : configRequiredAlign) !== null && _ref3 !== void 0 ? _ref3 : 'left';
|
|
100
101
|
}, [themeConfig === null || themeConfig === void 0 || (_themeConfig$data2 = themeConfig.data) === null || _themeConfig$data2 === void 0 ? void 0 : _themeConfig$data2.zauiFormAlign, configRequiredAlign]);
|
|
101
102
|
var _useSetState = useSetState({
|
|
102
103
|
cellNamePath: [],
|
|
@@ -138,8 +139,8 @@ var ProEditTable = (_ref, ref) => {
|
|
|
138
139
|
var getRowKey = useCallback(record => {
|
|
139
140
|
var key = record.rowKey || getRandom();
|
|
140
141
|
if (rowKey) {
|
|
141
|
-
var
|
|
142
|
-
key = (
|
|
142
|
+
var _ref4;
|
|
143
|
+
key = (_ref4 = isFunction(rowKey) ? rowKey(record) : record[rowKey]) !== null && _ref4 !== void 0 ? _ref4 : key;
|
|
143
144
|
}
|
|
144
145
|
return key;
|
|
145
146
|
}, [rowKey]);
|
|
@@ -174,7 +175,7 @@ var ProEditTable = (_ref, ref) => {
|
|
|
174
175
|
|
|
175
176
|
// 分页变更
|
|
176
177
|
var handlePageChange = useCallback( /*#__PURE__*/function () {
|
|
177
|
-
var
|
|
178
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(current, pageSize) {
|
|
178
179
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
179
180
|
while (1) switch (_context.prev = _context.next) {
|
|
180
181
|
case 0:
|
|
@@ -220,7 +221,7 @@ var ProEditTable = (_ref, ref) => {
|
|
|
220
221
|
}, _callee, null, [[0, 10]]);
|
|
221
222
|
}));
|
|
222
223
|
return function (_x, _x2) {
|
|
223
|
-
return
|
|
224
|
+
return _ref5.apply(this, arguments);
|
|
224
225
|
};
|
|
225
226
|
}(), [pagination, page.pageSize, form, name]);
|
|
226
227
|
var config = _objectSpread({
|
|
@@ -257,6 +258,7 @@ var ProEditTable = (_ref, ref) => {
|
|
|
257
258
|
rowDisabled,
|
|
258
259
|
actionDirection,
|
|
259
260
|
diffConfig: _objectSpread(_objectSpread({}, resetProps === null || resetProps === void 0 || (_resetProps$otherProp = resetProps.otherProps) === null || _resetProps$otherProp === void 0 ? void 0 : _resetProps$otherProp.diffConfig), diffConfig),
|
|
261
|
+
shouldUpdateDebounce,
|
|
260
262
|
getIsNew,
|
|
261
263
|
handlePageChange
|
|
262
264
|
}, resetProps);
|
|
@@ -317,7 +319,7 @@ var ProEditTable = (_ref, ref) => {
|
|
|
317
319
|
|
|
318
320
|
// 空列表状态
|
|
319
321
|
var emptyDom = useMemo(() => () => {
|
|
320
|
-
var _filter,
|
|
322
|
+
var _filter, _ref6;
|
|
321
323
|
return /*#__PURE__*/_jsxs("div", {
|
|
322
324
|
className: "com-empty",
|
|
323
325
|
children: [/*#__PURE__*/_jsx("img", {
|
|
@@ -328,7 +330,7 @@ var ProEditTable = (_ref, ref) => {
|
|
|
328
330
|
className: "content",
|
|
329
331
|
children: disabled || isForbiddenBtn('add') ? locale.ProEditTable.noData : /*#__PURE__*/_jsxs(_Fragment, {
|
|
330
332
|
children: [locale.ProEditTable.noData, "\uFF0C", /*#__PURE__*/_jsx(RenderToolbar, _objectSpread({}, _objectSpread(_objectSpread({}, config), {}, {
|
|
331
|
-
toolbarProps: toolbarProps === null || toolbarProps === void 0 || (_filter = (
|
|
333
|
+
toolbarProps: toolbarProps === null || toolbarProps === void 0 || (_filter = (_ref6 = toolbarProps).filter) === null || _filter === void 0 ? void 0 : _filter.call(_ref6, item => item.type === 'add' || (item === null || item === void 0 ? void 0 : item.persistence)),
|
|
332
334
|
dataSource: []
|
|
333
335
|
})))]
|
|
334
336
|
})
|
|
@@ -402,6 +402,12 @@ export interface ProEditTableProps<T = any> extends Omit<TableProps<T>, 'onChang
|
|
|
402
402
|
/** 是否跟随父元素滚动 */
|
|
403
403
|
scrollFollowParent?: boolean;
|
|
404
404
|
};
|
|
405
|
+
/**
|
|
406
|
+
* 动态属性更新防抖时间(毫秒)
|
|
407
|
+
* 用于优化表格编辑时的性能,对 fieldProps、desensitization, required、rules、isEditable, valueType 等属性进行防抖处理, 当设置为 0 时禁用防抖,所有属性立即响应
|
|
408
|
+
* @default 200
|
|
409
|
+
*/
|
|
410
|
+
shouldUpdateDebounce?: number;
|
|
405
411
|
}
|
|
406
412
|
/**
|
|
407
413
|
* 基础操作按钮类型(基于接口)
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
.pro-edit-table {
|
|
3
|
+
.pro-edit-table-drag-wrapper-cell{
|
|
4
|
+
.@{ant-prefix}-btn{
|
|
5
|
+
&:hover{
|
|
6
|
+
background: transparent;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
3
10
|
td[rowspan]{
|
|
4
11
|
vertical-align: middle !important;
|
|
5
12
|
}
|
|
@@ -81,10 +88,9 @@
|
|
|
81
88
|
|
|
82
89
|
.pro-edit-table-drag-wrapper {
|
|
83
90
|
display: flex;
|
|
84
|
-
|
|
91
|
+
align-items: center;
|
|
85
92
|
.anticon {
|
|
86
|
-
margin-right: var(--zaui-space-size-
|
|
87
|
-
margin-left: var(--zaui-space-size-xs, 4px);
|
|
93
|
+
margin-right: var(--zaui-space-size-xs, 4px);
|
|
88
94
|
cursor: pointer;
|
|
89
95
|
}
|
|
90
96
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface UseShouldUpdateForTableProps {
|
|
2
|
+
rowParams: any[];
|
|
3
|
+
column: any;
|
|
4
|
+
shouldUpdateDebounce: number;
|
|
5
|
+
}
|
|
6
|
+
interface Result {
|
|
7
|
+
isEditable: any;
|
|
8
|
+
required: any;
|
|
9
|
+
rules: any;
|
|
10
|
+
fieldProps: any;
|
|
11
|
+
desensitization: any;
|
|
12
|
+
valueType: any;
|
|
13
|
+
}
|
|
14
|
+
declare const useShouldUpdateForTable: (props: UseShouldUpdateForTableProps) => Result;
|
|
15
|
+
export default useShouldUpdateForTable;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useRef, useState, useEffect } from 'react';
|
|
3
|
+
import { isFunction, isEqualWith, debounce } from 'lodash';
|
|
4
|
+
import { customEqualForFunction } from "../../utils";
|
|
5
|
+
var useShouldUpdateForTable = props => {
|
|
6
|
+
var _isEditableRef$curren, _requiredRef$current, _rulesRef$current, _fieldPropsRef$curren, _desensitizationRef$c, _valueTypeRef$current;
|
|
7
|
+
var rowParams = props.rowParams,
|
|
8
|
+
column = props.column,
|
|
9
|
+
shouldUpdateDebounce = props.shouldUpdateDebounce;
|
|
10
|
+
|
|
11
|
+
// refs 存储当前值
|
|
12
|
+
var isEditableRef = useRef();
|
|
13
|
+
var requiredRef = useRef();
|
|
14
|
+
var rulesRef = useRef();
|
|
15
|
+
var fieldPropsRef = useRef();
|
|
16
|
+
var desensitizationRef = useRef();
|
|
17
|
+
var valueTypeRef = useRef();
|
|
18
|
+
var _useState = useState({}),
|
|
19
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
+
reRender = _useState2[1];
|
|
21
|
+
var debouncedUpdateRef = useRef(null);
|
|
22
|
+
var pendingParamsRef = useRef(null);
|
|
23
|
+
|
|
24
|
+
// 统一处理所有动态属性的更新
|
|
25
|
+
var processUpdate = params => {
|
|
26
|
+
var hasChange = false;
|
|
27
|
+
|
|
28
|
+
// isEditable 处理
|
|
29
|
+
if (isFunction(column.isEditable)) {
|
|
30
|
+
var newIsEditable = column.isEditable(...params);
|
|
31
|
+
if (isEditableRef.current !== newIsEditable) {
|
|
32
|
+
isEditableRef.current = newIsEditable;
|
|
33
|
+
hasChange = true;
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
isEditableRef.current = column.isEditable;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// required 处理
|
|
40
|
+
if (isFunction(column.required)) {
|
|
41
|
+
var newRequired = column.required(...params);
|
|
42
|
+
if (requiredRef.current !== newRequired) {
|
|
43
|
+
requiredRef.current = newRequired;
|
|
44
|
+
hasChange = true;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
requiredRef.current = column.required;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// rules 处理
|
|
51
|
+
if (isFunction(column.rules)) {
|
|
52
|
+
var newRules = column.rules(...params);
|
|
53
|
+
if (!isEqualWith(rulesRef.current, newRules, customEqualForFunction)) {
|
|
54
|
+
rulesRef.current = newRules;
|
|
55
|
+
hasChange = true;
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
rulesRef.current = column.rules;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// fieldProps 处理
|
|
62
|
+
if (isFunction(column.fieldProps)) {
|
|
63
|
+
var newFieldProps = column.fieldProps(...params);
|
|
64
|
+
if (!isEqualWith(fieldPropsRef.current, newFieldProps, customEqualForFunction)) {
|
|
65
|
+
fieldPropsRef.current = newFieldProps;
|
|
66
|
+
hasChange = true;
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
fieldPropsRef.current = column.fieldProps;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// desensitization 处理
|
|
73
|
+
if (isFunction(column.desensitization)) {
|
|
74
|
+
var newDesensitization = column.desensitization(...params);
|
|
75
|
+
if (!isEqualWith(desensitizationRef.current, newDesensitization)) {
|
|
76
|
+
desensitizationRef.current = newDesensitization;
|
|
77
|
+
hasChange = true;
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
desensitizationRef.current = column.desensitization;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// valueType 处理
|
|
84
|
+
if (isFunction(column.valueType)) {
|
|
85
|
+
var newValueType = column.valueType(...params);
|
|
86
|
+
if (valueTypeRef.current !== newValueType) {
|
|
87
|
+
valueTypeRef.current = newValueType;
|
|
88
|
+
hasChange = true;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
valueTypeRef.current = column.valueType;
|
|
92
|
+
}
|
|
93
|
+
if (hasChange) {
|
|
94
|
+
reRender({});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// 创建防抖函数(统一处理所有动态属性)
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (shouldUpdateDebounce > 0 && (isFunction(column.isEditable) || isFunction(column.required) || isFunction(column.rules) || isFunction(column.fieldProps) || isFunction(column.desensitization) || isFunction(column.valueType))) {
|
|
101
|
+
debouncedUpdateRef.current = debounce(() => {
|
|
102
|
+
if (pendingParamsRef.current) {
|
|
103
|
+
processUpdate(pendingParamsRef.current);
|
|
104
|
+
pendingParamsRef.current = null;
|
|
105
|
+
}
|
|
106
|
+
}, shouldUpdateDebounce);
|
|
107
|
+
}
|
|
108
|
+
return () => {
|
|
109
|
+
var _debouncedUpdateRef$c;
|
|
110
|
+
(_debouncedUpdateRef$c = debouncedUpdateRef.current) === null || _debouncedUpdateRef$c === void 0 || _debouncedUpdateRef$c.cancel();
|
|
111
|
+
};
|
|
112
|
+
}, [shouldUpdateDebounce, column]);
|
|
113
|
+
|
|
114
|
+
// 统一的属性处理逻辑
|
|
115
|
+
if (shouldUpdateDebounce > 0 && debouncedUpdateRef.current) {
|
|
116
|
+
// 使用防抖延迟更新
|
|
117
|
+
pendingParamsRef.current = rowParams;
|
|
118
|
+
debouncedUpdateRef.current();
|
|
119
|
+
} else {
|
|
120
|
+
// 立即更新(shouldUpdateDebounce = 0 或无防抖函数)
|
|
121
|
+
processUpdate(rowParams);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
isEditable: (_isEditableRef$curren = isEditableRef.current) !== null && _isEditableRef$curren !== void 0 ? _isEditableRef$curren : column.isEditable,
|
|
125
|
+
required: (_requiredRef$current = requiredRef.current) !== null && _requiredRef$current !== void 0 ? _requiredRef$current : column.required,
|
|
126
|
+
rules: (_rulesRef$current = rulesRef.current) !== null && _rulesRef$current !== void 0 ? _rulesRef$current : column.rules,
|
|
127
|
+
fieldProps: (_fieldPropsRef$curren = fieldPropsRef.current) !== null && _fieldPropsRef$curren !== void 0 ? _fieldPropsRef$curren : column.fieldProps,
|
|
128
|
+
desensitization: (_desensitizationRef$c = desensitizationRef.current) !== null && _desensitizationRef$c !== void 0 ? _desensitizationRef$c : column.desensitization,
|
|
129
|
+
valueType: (_valueTypeRef$current = valueTypeRef.current) !== null && _valueTypeRef$current !== void 0 ? _valueTypeRef$current : column.valueType
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
export default useShouldUpdateForTable;
|
|
@@ -113,7 +113,8 @@ var ActionButton = props => {
|
|
|
113
113
|
min = props.min,
|
|
114
114
|
max = props.max,
|
|
115
115
|
mode = props.mode,
|
|
116
|
-
isView = props.isView
|
|
116
|
+
isView = props.isView,
|
|
117
|
+
hideStartEndActionProps = props.hideStartEndActionProps;
|
|
117
118
|
|
|
118
119
|
// 默认显示一个delete
|
|
119
120
|
var actionProps = useMemo(() => {
|
|
@@ -181,6 +182,10 @@ var ActionButton = props => {
|
|
|
181
182
|
});
|
|
182
183
|
};
|
|
183
184
|
var defaultActions = useMemo(() => getDefaultActions(mode), [mode]);
|
|
185
|
+
|
|
186
|
+
// 整体隐藏首尾 ActionButton
|
|
187
|
+
if (hideStartEndActionProps !== null && hideStartEndActionProps !== void 0 && hideStartEndActionProps[0] && index === 0) return null;
|
|
188
|
+
if (hideStartEndActionProps !== null && hideStartEndActionProps !== void 0 && hideStartEndActionProps[1] && index === fields.length - 1) return null;
|
|
184
189
|
return /*#__PURE__*/_jsx(Space, {
|
|
185
190
|
align: "start",
|
|
186
191
|
className: "pro-form-list-action",
|
|
@@ -229,11 +234,83 @@ var ActionButton = props => {
|
|
|
229
234
|
if (index + 1 === fields.length && type === 'moveDown') {
|
|
230
235
|
return false;
|
|
231
236
|
}
|
|
237
|
+
|
|
238
|
+
// 移动限制:防止将项移动到隐藏的首尾位置
|
|
239
|
+
if (hideStartEndActionProps !== null && hideStartEndActionProps !== void 0 && hideStartEndActionProps[0] && index === 1 && ['moveUp'].includes(type)) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
if (hideStartEndActionProps !== null && hideStartEndActionProps !== void 0 && hideStartEndActionProps[1] && index === fields.length - 2 && type === 'moveDown') {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 处理 add 操作的插入位置
|
|
247
|
+
var handleAddClick = /*#__PURE__*/function () {
|
|
248
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
249
|
+
var value, data, insertIndex, _insertIndex;
|
|
250
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
251
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
252
|
+
case 0:
|
|
253
|
+
value = form.getFieldValue(namePath);
|
|
254
|
+
_context2.next = 3;
|
|
255
|
+
return _onClick === null || _onClick === void 0 ? void 0 : _onClick(value, {
|
|
256
|
+
namePath,
|
|
257
|
+
index,
|
|
258
|
+
operation,
|
|
259
|
+
form
|
|
260
|
+
});
|
|
261
|
+
case 3:
|
|
262
|
+
data = _context2.sent;
|
|
263
|
+
if (!(!_onClick || data === true)) {
|
|
264
|
+
_context2.next = 7;
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
// 如果有 addIndex 配置,使用它计算插入位置
|
|
268
|
+
if (item.addIndex) {
|
|
269
|
+
insertIndex = typeof item.addIndex === 'function' ? item.addIndex(value, {
|
|
270
|
+
index,
|
|
271
|
+
namePath,
|
|
272
|
+
form,
|
|
273
|
+
operation
|
|
274
|
+
}) : item.addIndex;
|
|
275
|
+
operation.add(data, insertIndex);
|
|
276
|
+
} else {
|
|
277
|
+
operation.add(data, index + 1); // 默认插入到下一位置
|
|
278
|
+
}
|
|
279
|
+
return _context2.abrupt("return");
|
|
280
|
+
case 7:
|
|
281
|
+
if ((item === null || item === void 0 ? void 0 : item.type) === 'add') {
|
|
282
|
+
// 如果有 addIndex 配置,使用它计算插入位置
|
|
283
|
+
if (item.addIndex) {
|
|
284
|
+
_insertIndex = typeof item.addIndex === 'function' ? item.addIndex(value, {
|
|
285
|
+
index,
|
|
286
|
+
namePath,
|
|
287
|
+
form,
|
|
288
|
+
operation
|
|
289
|
+
}) : item.addIndex;
|
|
290
|
+
operation.add(data, _insertIndex);
|
|
291
|
+
} else {
|
|
292
|
+
operation.add(data, index + 1); // 默认插入到下一位置
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
case 8:
|
|
296
|
+
case "end":
|
|
297
|
+
return _context2.stop();
|
|
298
|
+
}
|
|
299
|
+
}, _callee2);
|
|
300
|
+
}));
|
|
301
|
+
return function handleAddClick() {
|
|
302
|
+
return _ref7.apply(this, arguments);
|
|
303
|
+
};
|
|
304
|
+
}();
|
|
232
305
|
return _needConfirm ? /*#__PURE__*/_jsx(Popconfirm, _objectSpread(_objectSpread({
|
|
233
306
|
title: title !== null && title !== void 0 ? title : `${locale.ProForm.formListConfirmMessage}`,
|
|
234
307
|
onCancel: e => e.stopPropagation(),
|
|
235
308
|
onConfirm: e => {
|
|
236
|
-
|
|
309
|
+
if (type === 'add') {
|
|
310
|
+
handleAddClick();
|
|
311
|
+
} else {
|
|
312
|
+
handleClick(internalOnClick, _onClick, index, item);
|
|
313
|
+
}
|
|
237
314
|
}
|
|
238
315
|
}, _confirmProps), {}, {
|
|
239
316
|
children: /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread(_objectSpread({}, defaultRest), omit(rest, filterKeys)), {}, {
|
|
@@ -251,7 +328,11 @@ var ActionButton = props => {
|
|
|
251
328
|
type: "text",
|
|
252
329
|
onClick: e => {
|
|
253
330
|
e.stopPropagation();
|
|
254
|
-
|
|
331
|
+
if (type === 'add') {
|
|
332
|
+
handleAddClick();
|
|
333
|
+
} else {
|
|
334
|
+
handleClick(internalOnClick, _onClick, index, item);
|
|
335
|
+
}
|
|
255
336
|
},
|
|
256
337
|
children: label || defaultLabel
|
|
257
338
|
}), `${item === null || item === void 0 ? void 0 : item.type}${index}`);
|
|
@@ -16,6 +16,8 @@ interface Props extends Omit<FormListType, 'toolbarProps'> {
|
|
|
16
16
|
level?: levelType;
|
|
17
17
|
towCollapse?: boolean;
|
|
18
18
|
diffConfig?: DiffConfigType;
|
|
19
|
+
hideStartEndActionProps?: [boolean, boolean];
|
|
20
|
+
titlePosition?: 'top' | 'left';
|
|
19
21
|
}
|
|
20
22
|
declare const BlockFields: React.FC<Props>;
|
|
21
23
|
export default BlockFields;
|
|
@@ -7,6 +7,7 @@ import RenderFields from "../../../render/RenderFields";
|
|
|
7
7
|
import ProCollapse from "../../../../../ProLayout/components/ProCollapse";
|
|
8
8
|
import { memoWith } from "../utils";
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
11
|
var MemoRenderFields = /*#__PURE__*/React.memo(RenderFields, memoWith);
|
|
11
12
|
var BlockFields = props => {
|
|
12
13
|
var title = props.title,
|
|
@@ -28,7 +29,9 @@ var BlockFields = props => {
|
|
|
28
29
|
level = _props$level === void 0 ? '2' : _props$level,
|
|
29
30
|
towCollapse = props.towCollapse,
|
|
30
31
|
id = props.id,
|
|
31
|
-
diffConfig = props.diffConfig
|
|
32
|
+
diffConfig = props.diffConfig,
|
|
33
|
+
hideStartEndActionProps = props.hideStartEndActionProps,
|
|
34
|
+
titlePosition = props.titlePosition;
|
|
32
35
|
var _title = useMemo(() => {
|
|
33
36
|
if (isFunction(title)) {
|
|
34
37
|
var record = form.getFieldValue(namePath);
|
|
@@ -37,8 +40,63 @@ var BlockFields = props => {
|
|
|
37
40
|
return title;
|
|
38
41
|
}, [title, index]);
|
|
39
42
|
var cls = classNames({
|
|
40
|
-
[`pro-form-list-mode-${mode}`]: mode === 'block' || mode === 'line' || mode === 'less'
|
|
43
|
+
[`pro-form-list-mode-${mode}`]: mode === 'block' || mode === 'line' || mode === 'less',
|
|
44
|
+
'pro-form-list-title-left': titlePosition === 'left'
|
|
41
45
|
});
|
|
46
|
+
|
|
47
|
+
// 左侧标题布局
|
|
48
|
+
if (titlePosition === 'left') {
|
|
49
|
+
return /*#__PURE__*/_jsx(Space, {
|
|
50
|
+
direction: "vertical",
|
|
51
|
+
className: cls,
|
|
52
|
+
id: id,
|
|
53
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
54
|
+
className: "pro-form-list-left-title-wrapper",
|
|
55
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
56
|
+
className: "pro-form-list-left-title",
|
|
57
|
+
children: _title
|
|
58
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
59
|
+
className: "pro-form-list-left-content",
|
|
60
|
+
children: /*#__PURE__*/_jsx(ProCollapse, {
|
|
61
|
+
title: _title,
|
|
62
|
+
index: index,
|
|
63
|
+
form: form,
|
|
64
|
+
level: level,
|
|
65
|
+
towCollapse: towCollapse,
|
|
66
|
+
extra: actionProps !== false && /*#__PURE__*/_jsx(ActionButton, {
|
|
67
|
+
min: min,
|
|
68
|
+
max: max,
|
|
69
|
+
index: index,
|
|
70
|
+
length: fields.length,
|
|
71
|
+
operation: operation,
|
|
72
|
+
namePath: namePath,
|
|
73
|
+
form: form,
|
|
74
|
+
field: field,
|
|
75
|
+
fields: fields,
|
|
76
|
+
actionProps: actionProps,
|
|
77
|
+
mode: mode,
|
|
78
|
+
disabled: disabled,
|
|
79
|
+
isView: isView,
|
|
80
|
+
hideStartEndActionProps: hideStartEndActionProps
|
|
81
|
+
}),
|
|
82
|
+
children: /*#__PURE__*/_jsx(Row, {
|
|
83
|
+
gutter: 24,
|
|
84
|
+
children: /*#__PURE__*/_jsx(MemoRenderFields, {
|
|
85
|
+
columns: columns,
|
|
86
|
+
form: form,
|
|
87
|
+
colProps: colProps,
|
|
88
|
+
disabled: disabled,
|
|
89
|
+
isView: isView,
|
|
90
|
+
diffConfig: diffConfig
|
|
91
|
+
})
|
|
92
|
+
}, field.key)
|
|
93
|
+
})
|
|
94
|
+
})]
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 默认顶部标题布局
|
|
42
100
|
return /*#__PURE__*/_jsx(Space, {
|
|
43
101
|
direction: "vertical",
|
|
44
102
|
className: cls,
|
|
@@ -46,9 +104,7 @@ var BlockFields = props => {
|
|
|
46
104
|
children: /*#__PURE__*/_jsx(ProCollapse, {
|
|
47
105
|
title: _title,
|
|
48
106
|
index: index,
|
|
49
|
-
form: form
|
|
50
|
-
// namePath={namePath}
|
|
51
|
-
,
|
|
107
|
+
form: form,
|
|
52
108
|
level: level,
|
|
53
109
|
towCollapse: towCollapse,
|
|
54
110
|
extra: actionProps !== false && /*#__PURE__*/_jsx(ActionButton, {
|
|
@@ -64,7 +120,8 @@ var BlockFields = props => {
|
|
|
64
120
|
actionProps: actionProps,
|
|
65
121
|
mode: mode,
|
|
66
122
|
disabled: disabled,
|
|
67
|
-
isView: isView
|
|
123
|
+
isView: isView,
|
|
124
|
+
hideStartEndActionProps: hideStartEndActionProps
|
|
68
125
|
}),
|
|
69
126
|
children: /*#__PURE__*/_jsx(Row, {
|
|
70
127
|
gutter: 24,
|