@zat-design/sisyphus-react 3.11.6-beta.5 → 3.11.6-beta.6
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/es/ProEditTable/components/RcTable/BaseTable.js +19 -9
- package/es/ProEditTable/index.js +24 -15
- package/es/ProEditTable/propsType.d.ts +0 -1
- package/es/ProEditTable/utils/tools.d.ts +2 -2
- package/es/ProEditTable/utils/tools.js +4 -11
- package/es/ProEditTable/utils/useEditTableError.d.ts +7 -0
- package/es/ProEditTable/utils/useEditTableError.js +81 -0
- package/lib/ProEditTable/components/RcTable/BaseTable.js +19 -9
- package/lib/ProEditTable/index.js +24 -15
- package/lib/ProEditTable/propsType.d.ts +0 -1
- package/lib/ProEditTable/utils/tools.d.ts +2 -2
- package/lib/ProEditTable/utils/tools.js +4 -11
- package/lib/ProEditTable/utils/useEditTableError.d.ts +7 -0
- package/lib/ProEditTable/utils/useEditTableError.js +88 -0
- package/package.json +1 -1
@@ -3,10 +3,12 @@ import _Badge from "antd/es/badge";
|
|
3
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
4
4
|
import "antd/es/table/style";
|
5
5
|
import _Table from "antd/es/table";
|
6
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
6
7
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
7
8
|
var _excluded = ["tableProps"];
|
8
9
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
9
10
|
import { memo } from 'react';
|
11
|
+
import useEditTableError from '../../utils/useEditTableError';
|
10
12
|
var BaseTable = function BaseTable(_ref) {
|
11
13
|
var _value$;
|
12
14
|
var tableProps = _ref.tableProps,
|
@@ -29,8 +31,14 @@ var BaseTable = function BaseTable(_ref) {
|
|
29
31
|
page = tableProps.page,
|
30
32
|
formatMessage = tableProps.formatMessage,
|
31
33
|
locale = tableProps.locale,
|
32
|
-
handlePageChange = tableProps.handlePageChange
|
33
|
-
|
34
|
+
handlePageChange = tableProps.handlePageChange;
|
35
|
+
var _useEditTableError = useEditTableError({
|
36
|
+
containerNode: tableRef.current,
|
37
|
+
className: 'ant-form-item-explain-error',
|
38
|
+
isEnabled: pagination // 分页时启用
|
39
|
+
}),
|
40
|
+
_useEditTableError2 = _slicedToArray(_useEditTableError, 1),
|
41
|
+
errorLength = _useEditTableError2[0];
|
34
42
|
return _jsxs(_Fragment, {
|
35
43
|
children: [headerRender ? _jsx("div", {
|
36
44
|
className: "pro-edit-table-header",
|
@@ -51,10 +59,9 @@ var BaseTable = function BaseTable(_ref) {
|
|
51
59
|
};
|
52
60
|
}
|
53
61
|
}, resetProps), {}, {
|
54
|
-
pagination: pagination ? _objectSpread({
|
55
|
-
|
56
|
-
|
57
|
-
showSizeChanger: false,
|
62
|
+
pagination: pagination ? _objectSpread(_objectSpread({
|
63
|
+
showSizeChanger: true,
|
64
|
+
pageSizeOptions: [5, 10, 20, 50],
|
58
65
|
showQuickJumper: true,
|
59
66
|
total: value === null || value === void 0 ? void 0 : value.length,
|
60
67
|
showTotal: function showTotal(total) {
|
@@ -65,15 +72,18 @@ var BaseTable = function BaseTable(_ref) {
|
|
65
72
|
});
|
66
73
|
},
|
67
74
|
itemRender: function itemRender(index, type, originalElement) {
|
68
|
-
return type === 'page' && page.pageNum === index &&
|
75
|
+
return type === 'page' && page.pageNum === index && errorLength ? _jsxs("div", {
|
69
76
|
className: "pro-edit-table-pagination-item-badge",
|
70
77
|
children: [_jsx(_Badge, {
|
71
|
-
count:
|
78
|
+
count: errorLength
|
72
79
|
}), originalElement]
|
73
80
|
}) : originalElement;
|
74
81
|
},
|
75
82
|
onChange: handlePageChange
|
76
|
-
}, pagination)
|
83
|
+
}, pagination), {}, {
|
84
|
+
current: page.pageNum,
|
85
|
+
pageSize: page.pageSize
|
86
|
+
}) : false,
|
77
87
|
rowKey: "rowKey",
|
78
88
|
scroll: {
|
79
89
|
x: scroll === null || scroll === void 0 ? void 0 : scroll.x,
|
package/es/ProEditTable/index.js
CHANGED
@@ -99,8 +99,7 @@ var ProEditTable = function ProEditTable(_ref, ref) {
|
|
99
99
|
page: {
|
100
100
|
pageNum: 1,
|
101
101
|
pageSize: (pagination === null || pagination === void 0 ? void 0 : pagination.pageSize) || 10
|
102
|
-
}
|
103
|
-
pageErrorNum: 0
|
102
|
+
}
|
104
103
|
}),
|
105
104
|
_useSetState2 = _slicedToArray(_useSetState, 2),
|
106
105
|
state = _useSetState2[0],
|
@@ -111,8 +110,7 @@ var ProEditTable = function ProEditTable(_ref, ref) {
|
|
111
110
|
virtualKey = state.virtualKey,
|
112
111
|
selectedRowKeys = state.selectedRowKeys,
|
113
112
|
selectedRows = state.selectedRows,
|
114
|
-
page = state.page
|
115
|
-
pageErrorNum = state.pageErrorNum;
|
113
|
+
page = state.page;
|
116
114
|
var virtualRowName = getNamePath(isArray(name) ? name : [name], virtualKey);
|
117
115
|
// 样式处理
|
118
116
|
var _className = classnames({
|
@@ -171,32 +169,44 @@ var ProEditTable = function ProEditTable(_ref, ref) {
|
|
171
169
|
case 0:
|
172
170
|
_context.prev = 0;
|
173
171
|
if (!pagination) {
|
172
|
+
_context.next = 8;
|
173
|
+
break;
|
174
|
+
}
|
175
|
+
if (!(pageSize !== page.pageSize)) {
|
174
176
|
_context.next = 5;
|
175
177
|
break;
|
176
178
|
}
|
177
|
-
|
179
|
+
setState({
|
180
|
+
page: {
|
181
|
+
pageNum: current,
|
182
|
+
pageSize: pageSize
|
183
|
+
}
|
184
|
+
});
|
185
|
+
return _context.abrupt("return");
|
186
|
+
case 5:
|
187
|
+
_context.next = 7;
|
178
188
|
return form.validateFields([name], {
|
179
189
|
recursive: true
|
180
190
|
});
|
181
|
-
case
|
191
|
+
case 7:
|
182
192
|
setState({
|
183
193
|
page: {
|
184
194
|
pageNum: current,
|
185
195
|
pageSize: pageSize !== null && pageSize !== void 0 ? pageSize : page.pageSize
|
186
196
|
}
|
187
197
|
});
|
188
|
-
case
|
189
|
-
_context.next =
|
198
|
+
case 8:
|
199
|
+
_context.next = 13;
|
190
200
|
break;
|
191
|
-
case
|
192
|
-
_context.prev =
|
201
|
+
case 10:
|
202
|
+
_context.prev = 10;
|
193
203
|
_context.t0 = _context["catch"](0);
|
194
204
|
handleScrollToError();
|
195
|
-
case
|
205
|
+
case 13:
|
196
206
|
case "end":
|
197
207
|
return _context.stop();
|
198
208
|
}
|
199
|
-
}, _callee, null, [[0,
|
209
|
+
}, _callee, null, [[0, 10]]);
|
200
210
|
}));
|
201
211
|
return function (_x, _x2) {
|
202
212
|
return _ref4.apply(this, arguments);
|
@@ -413,7 +423,6 @@ var ProEditTable = function ProEditTable(_ref, ref) {
|
|
413
423
|
page: page,
|
414
424
|
formatMessage: formatMessage,
|
415
425
|
locale: locale,
|
416
|
-
pageErrorNum: pageErrorNum,
|
417
426
|
handlePageChange: handlePageChange
|
418
427
|
}
|
419
428
|
})), !isView && (value === null || value === void 0 ? void 0 : value.length) ? toolbarSticky ? _jsx(_Affix, _objectSpread(_objectSpread({
|
@@ -439,9 +448,9 @@ var ProEditTable = function ProEditTable(_ref, ref) {
|
|
439
448
|
columns: columns,
|
440
449
|
page: page,
|
441
450
|
pagination: pagination,
|
442
|
-
setState: setState,
|
443
451
|
isView: isView,
|
444
|
-
disabled: disabled
|
452
|
+
disabled: disabled,
|
453
|
+
setState: setState
|
445
454
|
});
|
446
455
|
}
|
447
456
|
}) : null]
|
@@ -38,14 +38,14 @@ export declare function cloneDeepFilterNode(value: any): any;
|
|
38
38
|
/**
|
39
39
|
* 分页校验
|
40
40
|
*/
|
41
|
-
export declare const onPageCheck: ({ form, name, value, columns, page, pagination,
|
41
|
+
export declare const onPageCheck: ({ form, name, value, columns, setState, page, pagination, isView, disabled }: {
|
42
42
|
form: any;
|
43
43
|
name: any;
|
44
44
|
value: any;
|
45
45
|
columns: any;
|
46
|
+
setState: any;
|
46
47
|
page: any;
|
47
48
|
pagination: any;
|
48
|
-
setState: any;
|
49
49
|
isView: any;
|
50
50
|
disabled: any;
|
51
51
|
}) => Promise<void>;
|
@@ -339,13 +339,13 @@ var handleCheckCellValue = /*#__PURE__*/function () {
|
|
339
339
|
*/
|
340
340
|
export var onPageCheck = /*#__PURE__*/function () {
|
341
341
|
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref7) {
|
342
|
-
var form, name, value, columns, page, pagination,
|
342
|
+
var form, name, value, columns, setState, page, pagination, isView, disabled, pageNum, pageSize, pageArr, flag, errorNum, errorPageNum, _i, _pageArr, item, start, end, nextValues, _iterator2, _step2, record, _iterator3, _step3, column, result, nextState;
|
343
343
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
344
344
|
while (1) switch (_context2.prev = _context2.next) {
|
345
345
|
case 0:
|
346
|
-
form = _ref7.form, name = _ref7.name, value = _ref7.value, columns = _ref7.columns,
|
346
|
+
form = _ref7.form, name = _ref7.name, value = _ref7.value, columns = _ref7.columns, setState = _ref7.setState, page = _ref7.page, pagination = _ref7.pagination, isView = _ref7.isView, disabled = _ref7.disabled;
|
347
347
|
if (!(pagination && !isView && !disabled)) {
|
348
|
-
_context2.next =
|
348
|
+
_context2.next = 72;
|
349
349
|
break;
|
350
350
|
}
|
351
351
|
pageNum = page.pageNum, pageSize = page.pageSize;
|
@@ -447,7 +447,7 @@ export var onPageCheck = /*#__PURE__*/function () {
|
|
447
447
|
break;
|
448
448
|
case 60:
|
449
449
|
if (!(flag && errorNum > 0)) {
|
450
|
-
_context2.next =
|
450
|
+
_context2.next = 72;
|
451
451
|
break;
|
452
452
|
}
|
453
453
|
nextState = {
|
@@ -473,13 +473,6 @@ export var onPageCheck = /*#__PURE__*/function () {
|
|
473
473
|
_context2.t3 = _context2["catch"](64);
|
474
474
|
handleScrollToError();
|
475
475
|
case 72:
|
476
|
-
_context2.next = 75;
|
477
|
-
break;
|
478
|
-
case 74:
|
479
|
-
setState({
|
480
|
-
pageErrorNum: 0
|
481
|
-
});
|
482
|
-
case 75:
|
483
476
|
case "end":
|
484
477
|
return _context2.stop();
|
485
478
|
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
interface UseEditTableErrorProps {
|
2
|
+
containerNode: HTMLElement | null;
|
3
|
+
className: string;
|
4
|
+
isEnabled: boolean;
|
5
|
+
}
|
6
|
+
declare const useEditTableError: ({ containerNode, className, isEnabled }: UseEditTableErrorProps) => [number];
|
7
|
+
export default useEditTableError;
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
2
|
+
import { useState, useEffect } from 'react';
|
3
|
+
import { debounce } from 'lodash';
|
4
|
+
var useEditTableError = function useEditTableError(_ref) {
|
5
|
+
var containerNode = _ref.containerNode,
|
6
|
+
className = _ref.className,
|
7
|
+
isEnabled = _ref.isEnabled;
|
8
|
+
var _useState = useState(0),
|
9
|
+
_useState2 = _slicedToArray(_useState, 2),
|
10
|
+
errorLength = _useState2[0],
|
11
|
+
setErrorLength = _useState2[1];
|
12
|
+
useEffect(function () {
|
13
|
+
// 如果 isEnabled 为 false 或容器节点不存在,直接跳过监听
|
14
|
+
if (!isEnabled || !containerNode) {
|
15
|
+
return; // 如果未启用监听或容器节点不存在,直接返回
|
16
|
+
}
|
17
|
+
// 防抖处理:将 setErrorLength 函数进行防抖
|
18
|
+
var debouncedSetErrorLength = debounce(function (errorCount) {
|
19
|
+
setErrorLength(errorCount); // 更新错误数量
|
20
|
+
}, 300); // 300ms 后更新状态
|
21
|
+
var observer = new MutationObserver(function (mutations) {
|
22
|
+
mutations.forEach(function (mutation) {
|
23
|
+
// 只处理节点的 class 属性变化
|
24
|
+
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
|
25
|
+
var target = mutation.target;
|
26
|
+
// 检查目标节点是否包含指定的类
|
27
|
+
if (target.classList.contains(className)) {
|
28
|
+
// 查找所有包含 className 的节点
|
29
|
+
var errorNodes = containerNode.querySelectorAll(".".concat(className));
|
30
|
+
// debugger;
|
31
|
+
// 过滤这些节点,只保留那些类名完全为 `ant-form-item-explain-error` 的节点
|
32
|
+
var validErrorNodes = Array.from(errorNodes).filter(function (node) {
|
33
|
+
return node.classList.length === 1 && node.classList.contains('ant-form-item-explain-error');
|
34
|
+
});
|
35
|
+
if (errorLength === 0) {
|
36
|
+
debouncedSetErrorLength(0);
|
37
|
+
}
|
38
|
+
if (errorLength === validErrorNodes.length) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
// 使用防抖后的方法更新错误数量
|
42
|
+
debouncedSetErrorLength(validErrorNodes.length);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
// 监听子节点的添加或删除
|
46
|
+
if (mutation.type === 'childList') {
|
47
|
+
// 检查删除的节点是否包含指定的类名
|
48
|
+
mutation.removedNodes.forEach(function (removedNode) {
|
49
|
+
if (removedNode instanceof HTMLElement && removedNode.classList.contains('ant-table-row')) {
|
50
|
+
// 更新错误数量
|
51
|
+
var _errorNodes = containerNode.querySelectorAll(".".concat(className));
|
52
|
+
if (errorLength === 0) {
|
53
|
+
debouncedSetErrorLength(0);
|
54
|
+
}
|
55
|
+
if (errorLength === _errorNodes.length) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
// 使用防抖后的方法更新错误数量
|
59
|
+
debouncedSetErrorLength(_errorNodes.length);
|
60
|
+
}
|
61
|
+
});
|
62
|
+
}
|
63
|
+
});
|
64
|
+
});
|
65
|
+
var config = {
|
66
|
+
attributes: true,
|
67
|
+
subtree: true,
|
68
|
+
attributeFilter: ['class'],
|
69
|
+
childList: true
|
70
|
+
};
|
71
|
+
// 启动 MutationObserver
|
72
|
+
observer.observe(containerNode.querySelector('tbody'), config);
|
73
|
+
// 清理 MutationObserver 和防抖定时器
|
74
|
+
return function () {
|
75
|
+
observer.disconnect();
|
76
|
+
debouncedSetErrorLength.cancel(); // 取消防抖定时器
|
77
|
+
};
|
78
|
+
}, [containerNode, className, isEnabled]); // 当 isEnabled 改变时会重新启动或取消监听
|
79
|
+
return [errorLength];
|
80
|
+
};
|
81
|
+
export default useEditTableError;
|
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
});
|
7
7
|
exports.default = void 0;
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
9
10
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
10
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
11
12
|
var _react = require("react");
|
12
13
|
var _antd = require("antd");
|
14
|
+
var _useEditTableError3 = _interopRequireDefault(require("../../utils/useEditTableError"));
|
13
15
|
var _excluded = ["tableProps"];
|
14
16
|
var BaseTable = function BaseTable(_ref) {
|
15
17
|
var _value$;
|
@@ -33,8 +35,14 @@ var BaseTable = function BaseTable(_ref) {
|
|
33
35
|
page = tableProps.page,
|
34
36
|
formatMessage = tableProps.formatMessage,
|
35
37
|
locale = tableProps.locale,
|
36
|
-
handlePageChange = tableProps.handlePageChange
|
37
|
-
|
38
|
+
handlePageChange = tableProps.handlePageChange;
|
39
|
+
var _useEditTableError = (0, _useEditTableError3.default)({
|
40
|
+
containerNode: tableRef.current,
|
41
|
+
className: 'ant-form-item-explain-error',
|
42
|
+
isEnabled: pagination // 分页时启用
|
43
|
+
}),
|
44
|
+
_useEditTableError2 = (0, _slicedToArray2.default)(_useEditTableError, 1),
|
45
|
+
errorLength = _useEditTableError2[0];
|
38
46
|
return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
39
47
|
children: [headerRender ? (0, _jsxRuntime.jsx)("div", {
|
40
48
|
className: "pro-edit-table-header",
|
@@ -55,10 +63,9 @@ var BaseTable = function BaseTable(_ref) {
|
|
55
63
|
};
|
56
64
|
}
|
57
65
|
}, resetProps), {}, {
|
58
|
-
pagination: pagination ? (0, _objectSpread2.default)({
|
59
|
-
|
60
|
-
|
61
|
-
showSizeChanger: false,
|
66
|
+
pagination: pagination ? (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
67
|
+
showSizeChanger: true,
|
68
|
+
pageSizeOptions: [5, 10, 20, 50],
|
62
69
|
showQuickJumper: true,
|
63
70
|
total: value === null || value === void 0 ? void 0 : value.length,
|
64
71
|
showTotal: function showTotal(total) {
|
@@ -69,15 +76,18 @@ var BaseTable = function BaseTable(_ref) {
|
|
69
76
|
});
|
70
77
|
},
|
71
78
|
itemRender: function itemRender(index, type, originalElement) {
|
72
|
-
return type === 'page' && page.pageNum === index &&
|
79
|
+
return type === 'page' && page.pageNum === index && errorLength ? (0, _jsxRuntime.jsxs)("div", {
|
73
80
|
className: "pro-edit-table-pagination-item-badge",
|
74
81
|
children: [(0, _jsxRuntime.jsx)(_antd.Badge, {
|
75
|
-
count:
|
82
|
+
count: errorLength
|
76
83
|
}), originalElement]
|
77
84
|
}) : originalElement;
|
78
85
|
},
|
79
86
|
onChange: handlePageChange
|
80
|
-
}, pagination)
|
87
|
+
}, pagination), {}, {
|
88
|
+
current: page.pageNum,
|
89
|
+
pageSize: page.pageSize
|
90
|
+
}) : false,
|
81
91
|
rowKey: "rowKey",
|
82
92
|
scroll: {
|
83
93
|
x: scroll === null || scroll === void 0 ? void 0 : scroll.x,
|
@@ -102,8 +102,7 @@ var ProEditTable = function ProEditTable(_ref, ref) {
|
|
102
102
|
page: {
|
103
103
|
pageNum: 1,
|
104
104
|
pageSize: (pagination === null || pagination === void 0 ? void 0 : pagination.pageSize) || 10
|
105
|
-
}
|
106
|
-
pageErrorNum: 0
|
105
|
+
}
|
107
106
|
}),
|
108
107
|
_useSetState2 = (0, _slicedToArray2.default)(_useSetState, 2),
|
109
108
|
state = _useSetState2[0],
|
@@ -114,8 +113,7 @@ var ProEditTable = function ProEditTable(_ref, ref) {
|
|
114
113
|
virtualKey = state.virtualKey,
|
115
114
|
selectedRowKeys = state.selectedRowKeys,
|
116
115
|
selectedRows = state.selectedRows,
|
117
|
-
page = state.page
|
118
|
-
pageErrorNum = state.pageErrorNum;
|
116
|
+
page = state.page;
|
119
117
|
var virtualRowName = (0, _tools.getNamePath)((0, _lodash.isArray)(name) ? name : [name], virtualKey);
|
120
118
|
// 样式处理
|
121
119
|
var _className = (0, _classnames.default)({
|
@@ -174,32 +172,44 @@ var ProEditTable = function ProEditTable(_ref, ref) {
|
|
174
172
|
case 0:
|
175
173
|
_context.prev = 0;
|
176
174
|
if (!pagination) {
|
175
|
+
_context.next = 8;
|
176
|
+
break;
|
177
|
+
}
|
178
|
+
if (!(pageSize !== page.pageSize)) {
|
177
179
|
_context.next = 5;
|
178
180
|
break;
|
179
181
|
}
|
180
|
-
|
182
|
+
setState({
|
183
|
+
page: {
|
184
|
+
pageNum: current,
|
185
|
+
pageSize: pageSize
|
186
|
+
}
|
187
|
+
});
|
188
|
+
return _context.abrupt("return");
|
189
|
+
case 5:
|
190
|
+
_context.next = 7;
|
181
191
|
return form.validateFields([name], {
|
182
192
|
recursive: true
|
183
193
|
});
|
184
|
-
case
|
194
|
+
case 7:
|
185
195
|
setState({
|
186
196
|
page: {
|
187
197
|
pageNum: current,
|
188
198
|
pageSize: pageSize !== null && pageSize !== void 0 ? pageSize : page.pageSize
|
189
199
|
}
|
190
200
|
});
|
191
|
-
case
|
192
|
-
_context.next =
|
201
|
+
case 8:
|
202
|
+
_context.next = 13;
|
193
203
|
break;
|
194
|
-
case
|
195
|
-
_context.prev =
|
204
|
+
case 10:
|
205
|
+
_context.prev = 10;
|
196
206
|
_context.t0 = _context["catch"](0);
|
197
207
|
(0, _tools.handleScrollToError)();
|
198
|
-
case
|
208
|
+
case 13:
|
199
209
|
case "end":
|
200
210
|
return _context.stop();
|
201
211
|
}
|
202
|
-
}, _callee, null, [[0,
|
212
|
+
}, _callee, null, [[0, 10]]);
|
203
213
|
}));
|
204
214
|
return function (_x, _x2) {
|
205
215
|
return _ref4.apply(this, arguments);
|
@@ -416,7 +426,6 @@ var ProEditTable = function ProEditTable(_ref, ref) {
|
|
416
426
|
page: page,
|
417
427
|
formatMessage: _locale.formatMessage,
|
418
428
|
locale: _locale.default,
|
419
|
-
pageErrorNum: pageErrorNum,
|
420
429
|
handlePageChange: handlePageChange
|
421
430
|
}
|
422
431
|
})), !isView && (value === null || value === void 0 ? void 0 : value.length) ? toolbarSticky ? (0, _jsxRuntime.jsx)(_antd.Affix, (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
@@ -442,9 +451,9 @@ var ProEditTable = function ProEditTable(_ref, ref) {
|
|
442
451
|
columns: columns,
|
443
452
|
page: page,
|
444
453
|
pagination: pagination,
|
445
|
-
setState: setState,
|
446
454
|
isView: isView,
|
447
|
-
disabled: disabled
|
455
|
+
disabled: disabled,
|
456
|
+
setState: setState
|
448
457
|
});
|
449
458
|
}
|
450
459
|
}) : null]
|
@@ -38,14 +38,14 @@ export declare function cloneDeepFilterNode(value: any): any;
|
|
38
38
|
/**
|
39
39
|
* 分页校验
|
40
40
|
*/
|
41
|
-
export declare const onPageCheck: ({ form, name, value, columns, page, pagination,
|
41
|
+
export declare const onPageCheck: ({ form, name, value, columns, setState, page, pagination, isView, disabled }: {
|
42
42
|
form: any;
|
43
43
|
name: any;
|
44
44
|
value: any;
|
45
45
|
columns: any;
|
46
|
+
setState: any;
|
46
47
|
page: any;
|
47
48
|
pagination: any;
|
48
|
-
setState: any;
|
49
49
|
isView: any;
|
50
50
|
disabled: any;
|
51
51
|
}) => Promise<void>;
|
@@ -348,13 +348,13 @@ var handleCheckCellValue = /*#__PURE__*/function () {
|
|
348
348
|
*/
|
349
349
|
var onPageCheck = exports.onPageCheck = /*#__PURE__*/function () {
|
350
350
|
var _ref8 = (0, _asyncToGenerator2.default)(/*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee2(_ref7) {
|
351
|
-
var form, name, value, columns, page, pagination,
|
351
|
+
var form, name, value, columns, setState, page, pagination, isView, disabled, pageNum, pageSize, pageArr, flag, errorNum, errorPageNum, _i, _pageArr, item, start, end, nextValues, _iterator2, _step2, record, _iterator3, _step3, column, result, nextState;
|
352
352
|
return (0, _regeneratorRuntime2.default)().wrap(function _callee2$(_context2) {
|
353
353
|
while (1) switch (_context2.prev = _context2.next) {
|
354
354
|
case 0:
|
355
|
-
form = _ref7.form, name = _ref7.name, value = _ref7.value, columns = _ref7.columns,
|
355
|
+
form = _ref7.form, name = _ref7.name, value = _ref7.value, columns = _ref7.columns, setState = _ref7.setState, page = _ref7.page, pagination = _ref7.pagination, isView = _ref7.isView, disabled = _ref7.disabled;
|
356
356
|
if (!(pagination && !isView && !disabled)) {
|
357
|
-
_context2.next =
|
357
|
+
_context2.next = 72;
|
358
358
|
break;
|
359
359
|
}
|
360
360
|
pageNum = page.pageNum, pageSize = page.pageSize;
|
@@ -456,7 +456,7 @@ var onPageCheck = exports.onPageCheck = /*#__PURE__*/function () {
|
|
456
456
|
break;
|
457
457
|
case 60:
|
458
458
|
if (!(flag && errorNum > 0)) {
|
459
|
-
_context2.next =
|
459
|
+
_context2.next = 72;
|
460
460
|
break;
|
461
461
|
}
|
462
462
|
nextState = {
|
@@ -482,13 +482,6 @@ var onPageCheck = exports.onPageCheck = /*#__PURE__*/function () {
|
|
482
482
|
_context2.t3 = _context2["catch"](64);
|
483
483
|
handleScrollToError();
|
484
484
|
case 72:
|
485
|
-
_context2.next = 75;
|
486
|
-
break;
|
487
|
-
case 74:
|
488
|
-
setState({
|
489
|
-
pageErrorNum: 0
|
490
|
-
});
|
491
|
-
case 75:
|
492
485
|
case "end":
|
493
486
|
return _context2.stop();
|
494
487
|
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
interface UseEditTableErrorProps {
|
2
|
+
containerNode: HTMLElement | null;
|
3
|
+
className: string;
|
4
|
+
isEnabled: boolean;
|
5
|
+
}
|
6
|
+
declare const useEditTableError: ({ containerNode, className, isEnabled }: UseEditTableErrorProps) => [number];
|
7
|
+
export default useEditTableError;
|
@@ -0,0 +1,88 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.default = void 0;
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
9
|
+
var _react = require("react");
|
10
|
+
var _lodash = require("lodash");
|
11
|
+
var useEditTableError = function useEditTableError(_ref) {
|
12
|
+
var containerNode = _ref.containerNode,
|
13
|
+
className = _ref.className,
|
14
|
+
isEnabled = _ref.isEnabled;
|
15
|
+
var _useState = (0, _react.useState)(0),
|
16
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
17
|
+
errorLength = _useState2[0],
|
18
|
+
setErrorLength = _useState2[1];
|
19
|
+
(0, _react.useEffect)(function () {
|
20
|
+
// 如果 isEnabled 为 false 或容器节点不存在,直接跳过监听
|
21
|
+
if (!isEnabled || !containerNode) {
|
22
|
+
return; // 如果未启用监听或容器节点不存在,直接返回
|
23
|
+
}
|
24
|
+
// 防抖处理:将 setErrorLength 函数进行防抖
|
25
|
+
var debouncedSetErrorLength = (0, _lodash.debounce)(function (errorCount) {
|
26
|
+
setErrorLength(errorCount); // 更新错误数量
|
27
|
+
}, 300); // 300ms 后更新状态
|
28
|
+
var observer = new MutationObserver(function (mutations) {
|
29
|
+
mutations.forEach(function (mutation) {
|
30
|
+
// 只处理节点的 class 属性变化
|
31
|
+
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
|
32
|
+
var target = mutation.target;
|
33
|
+
// 检查目标节点是否包含指定的类
|
34
|
+
if (target.classList.contains(className)) {
|
35
|
+
// 查找所有包含 className 的节点
|
36
|
+
var errorNodes = containerNode.querySelectorAll(".".concat(className));
|
37
|
+
// debugger;
|
38
|
+
// 过滤这些节点,只保留那些类名完全为 `ant-form-item-explain-error` 的节点
|
39
|
+
var validErrorNodes = Array.from(errorNodes).filter(function (node) {
|
40
|
+
return node.classList.length === 1 && node.classList.contains('ant-form-item-explain-error');
|
41
|
+
});
|
42
|
+
if (errorLength === 0) {
|
43
|
+
debouncedSetErrorLength(0);
|
44
|
+
}
|
45
|
+
if (errorLength === validErrorNodes.length) {
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
// 使用防抖后的方法更新错误数量
|
49
|
+
debouncedSetErrorLength(validErrorNodes.length);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
// 监听子节点的添加或删除
|
53
|
+
if (mutation.type === 'childList') {
|
54
|
+
// 检查删除的节点是否包含指定的类名
|
55
|
+
mutation.removedNodes.forEach(function (removedNode) {
|
56
|
+
if (removedNode instanceof HTMLElement && removedNode.classList.contains('ant-table-row')) {
|
57
|
+
// 更新错误数量
|
58
|
+
var _errorNodes = containerNode.querySelectorAll(".".concat(className));
|
59
|
+
if (errorLength === 0) {
|
60
|
+
debouncedSetErrorLength(0);
|
61
|
+
}
|
62
|
+
if (errorLength === _errorNodes.length) {
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
// 使用防抖后的方法更新错误数量
|
66
|
+
debouncedSetErrorLength(_errorNodes.length);
|
67
|
+
}
|
68
|
+
});
|
69
|
+
}
|
70
|
+
});
|
71
|
+
});
|
72
|
+
var config = {
|
73
|
+
attributes: true,
|
74
|
+
subtree: true,
|
75
|
+
attributeFilter: ['class'],
|
76
|
+
childList: true
|
77
|
+
};
|
78
|
+
// 启动 MutationObserver
|
79
|
+
observer.observe(containerNode.querySelector('tbody'), config);
|
80
|
+
// 清理 MutationObserver 和防抖定时器
|
81
|
+
return function () {
|
82
|
+
observer.disconnect();
|
83
|
+
debouncedSetErrorLength.cancel(); // 取消防抖定时器
|
84
|
+
};
|
85
|
+
}, [containerNode, className, isEnabled]); // 当 isEnabled 改变时会重新启动或取消监听
|
86
|
+
return [errorLength];
|
87
|
+
};
|
88
|
+
var _default = exports.default = useEditTableError;
|