@zat-design/sisyphus-react 3.13.2 → 3.13.3-beta.1
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/README.md +1 -1
- package/dist/index.esm.css +3 -0
- package/es/FormsProvider/index.d.ts +2 -2
- package/es/ProForm/components/FormFooter/index.js +14 -1
- package/es/ProForm/components/FormFooter/propsType.d.ts +2 -1
- package/es/ProForm/components/base/DatePicker/index.js +0 -9
- package/es/ProForm/components/base/RangePicker/index.js +0 -8
- package/es/ProForm/components/render/Render.js +4 -2
- package/es/ProForm/index.js +13 -3
- package/es/ProForm/propsType.d.ts +2 -0
- package/es/ProForm/utils/index.d.ts +7 -2
- package/es/ProForm/utils/index.js +19 -1
- package/es/ProForm/utils/useForm.d.ts +7 -2
- package/es/ProForm/utils/useForm.js +87 -20
- package/es/ProForm/utils/useWatch.d.ts +8 -3
- package/es/ProForm/utils/useWatch.js +136 -54
- package/es/ProTable/components/RcTable/components/DraggableTable/index.js +0 -9
- package/es/ProTable/components/RenderTabs/index.js +7 -2
- package/es/ProTable/hooks/useAntdTable.js +8 -13
- package/es/ProTable/propsType.d.ts +6 -6
- package/es/ProTable/utils/index.d.ts +0 -1
- package/es/ProTable/utils/index.js +0 -1
- package/es/ProTooltip/index.js +9 -2
- package/es/ProTooltip/propsType.d.ts +2 -3
- package/es/ProTree/components/AdaptiveTooltip.js +0 -9
- package/es/ProTree/components/List.js +0 -8
- package/es/ProTree/components/SearchTitle.js +0 -8
- package/es/ProTreeModal/index.js +0 -8
- package/es/ProUpload/components/ImageRender.js +0 -9
- package/es/ProUpload/index.js +0 -7
- package/es/style/theme/antd.less +5 -0
- package/lib/FormsProvider/index.d.ts +2 -2
- package/lib/ProForm/components/FormFooter/index.js +14 -1
- package/lib/ProForm/components/FormFooter/propsType.d.ts +2 -1
- package/lib/ProForm/components/base/DatePicker/index.js +0 -8
- package/lib/ProForm/components/base/RangePicker/index.js +1 -10
- package/lib/ProForm/components/render/Render.js +4 -2
- package/lib/ProForm/index.js +11 -1
- package/lib/ProForm/propsType.d.ts +2 -0
- package/lib/ProForm/utils/index.d.ts +7 -2
- package/lib/ProForm/utils/index.js +20 -2
- package/lib/ProForm/utils/useForm.d.ts +7 -2
- package/lib/ProForm/utils/useForm.js +86 -19
- package/lib/ProForm/utils/useWatch.d.ts +8 -3
- package/lib/ProForm/utils/useWatch.js +136 -56
- package/lib/ProTable/components/RcTable/components/DraggableTable/index.js +0 -8
- package/lib/ProTable/components/RenderTabs/index.js +7 -2
- package/lib/ProTable/hooks/useAntdTable.js +6 -13
- package/lib/ProTable/propsType.d.ts +6 -6
- package/lib/ProTable/utils/index.d.ts +0 -1
- package/lib/ProTable/utils/index.js +0 -1
- package/lib/ProTooltip/index.js +9 -2
- package/lib/ProTooltip/propsType.d.ts +2 -3
- package/lib/ProTree/components/AdaptiveTooltip.js +0 -9
- package/lib/ProTree/components/List.js +0 -8
- package/lib/ProTree/components/SearchTitle.js +0 -9
- package/lib/ProTreeModal/index.js +0 -9
- package/lib/ProUpload/components/ImageRender.js +0 -9
- package/lib/ProUpload/index.js +0 -7
- package/lib/style/theme/antd.less +5 -0
- package/package.json +2 -2
package/lib/ProForm/index.js
CHANGED
@@ -28,7 +28,7 @@ var _locale = _interopRequireDefault(require("../locale"));
|
|
28
28
|
var _useWatch = _interopRequireDefault(require("./utils/useWatch"));
|
29
29
|
var _FormsProvider = _interopRequireWildcard(require("../FormsProvider"));
|
30
30
|
var _ProStep = require("../ProStep");
|
31
|
-
var _excluded = ["mode", "span", "disabled", "isView", "columns", "footer", "onOk", "okText", "onCancel", "confirmLoading", "cancelText", "form", "children", "rowProps", "className", "expand", "expandOpen", "expandOpenChange", "viewEmpty", "labelAlign", "labelWidth", "onValuesChange", "onFinish", "diffConfig", "submitOnEnter", "clearNotShow", "initialValues", "requiredOnView", "formId", "required", "formKey", "globalControl", "scrollToError", "optimize", "desensitizationKey"];
|
31
|
+
var _excluded = ["mode", "span", "disabled", "isView", "columns", "footer", "onOk", "okText", "onCancel", "confirmLoading", "cancelText", "form", "children", "rowProps", "className", "expand", "expandOpen", "expandOpenChange", "viewEmpty", "labelAlign", "labelWidth", "onValuesChange", "onFinish", "diffConfig", "submitOnEnter", "clearNotShow", "initialValues", "requiredOnView", "formId", "required", "formKey", "globalControl", "scrollToError", "optimize", "desensitizationKey", "stopOnFirstError"];
|
32
32
|
var ProForm = function ProForm(props, ref) {
|
33
33
|
var _localStorage, _ref3;
|
34
34
|
var _props$mode = props.mode,
|
@@ -74,6 +74,8 @@ var ProForm = function ProForm(props, ref) {
|
|
74
74
|
optimize = _props$optimize === void 0 ? false : _props$optimize,
|
75
75
|
_props$desensitizatio = props.desensitizationKey,
|
76
76
|
desensitizationKey = _props$desensitizatio === void 0 ? 'zat-design-pro-component-desensitization' : _props$desensitizatio,
|
77
|
+
_props$stopOnFirstErr = props.stopOnFirstError,
|
78
|
+
stopOnFirstError = _props$stopOnFirstErr === void 0 ? false : _props$stopOnFirstErr,
|
77
79
|
otherProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
78
80
|
var config = (0, _ProConfigProvider.useProConfig)('ProForm');
|
79
81
|
// source: 用于区分是哪个组件调用,用于错误提示
|
@@ -92,6 +94,14 @@ var ProForm = function ProForm(props, ref) {
|
|
92
94
|
}),
|
93
95
|
_useForm2 = (0, _slicedToArray2.default)(_useForm, 1),
|
94
96
|
form = _useForm2[0];
|
97
|
+
// 保存内部配置
|
98
|
+
(0, _react.useEffect)(function () {
|
99
|
+
if (!form.__INTERNAL_CONFIG__) {
|
100
|
+
form.__INTERNAL_CONFIG__ = {};
|
101
|
+
}
|
102
|
+
form.__INTERNAL_CONFIG__.fields = (0, _index.getFormFieldPaths)(form);
|
103
|
+
form.__INTERNAL_CONFIG__.stopOnFirstError = stopOnFirstError;
|
104
|
+
}, [stopOnFirstError, form]);
|
95
105
|
var _useControlled = (0, _index.useControlled)({
|
96
106
|
value: expandOpen,
|
97
107
|
onChange: expandOpenChange
|
@@ -101,6 +101,8 @@ export interface ProFormType<Values = any> extends FormProps<Values> {
|
|
101
101
|
optimize?: boolean;
|
102
102
|
/** 全局脱敏开关的key、默认 zat-design-pro-component-desensitization */
|
103
103
|
desensitizationKey?: string;
|
104
|
+
/** 是否在遇到第一个错误时停止验证 */
|
105
|
+
stopOnFirstError?: boolean;
|
104
106
|
}
|
105
107
|
export interface TransformType<T = any> {
|
106
108
|
normalize?: (value: StoreValue, prevValue: StoreValue, allValues: Store) => StoreValue;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ColProps, FormProps } from 'antd';
|
1
|
+
import { ColProps, FormProps, FormInstance } from 'antd';
|
2
2
|
import { InternalNamePath, NamePath } from 'antd/es/form/interface';
|
3
3
|
interface transProps {
|
4
4
|
formProps: FormProps;
|
@@ -95,6 +95,11 @@ export declare const findOptionByValue: (treeData: any[], value: string | number
|
|
95
95
|
export declare const equalDependencies: (dependencies: any, prevValues: any, currentValues: any) => any;
|
96
96
|
/** 解析namePath */
|
97
97
|
export declare const parseNamePath: (input: string) => any;
|
98
|
-
/**
|
98
|
+
/**
|
99
|
+
* 获取表单所有字段路径的简化函数
|
100
|
+
* @param form 表单实例
|
101
|
+
* @returns 所有字段路径数组
|
102
|
+
*/
|
103
|
+
export declare const getFormFieldPaths: (form: FormInstance) => any[];
|
99
104
|
export declare function findNamesKeyInArray(arr: string[], key: string): string | null;
|
100
105
|
export {};
|
@@ -9,7 +9,7 @@ exports.filterInternalFields = exports.equalDependencies = exports.diffField = e
|
|
9
9
|
exports.findNamesKeyInArray = findNamesKeyInArray;
|
10
10
|
exports.getAllNamePath = exports.findOptionByValue = void 0;
|
11
11
|
exports.getArrayBeforeNumber = getArrayBeforeNumber;
|
12
|
-
exports.hasRowKey = exports.getLayout = exports.getDecimalDigits = void 0;
|
12
|
+
exports.hasRowKey = exports.getLayout = exports.getFormFieldPaths = exports.getDecimalDigits = void 0;
|
13
13
|
exports.initialValuesToNames = initialValuesToNames;
|
14
14
|
exports.splitNameStr = exports.parseNamePath = exports.isUpperCase = exports.isTrim = exports.isSelect = exports.isNullValue = exports.isNullArray = exports.isNotFullArray = exports.isEmptyArray = void 0;
|
15
15
|
exports.toArray = toArray;
|
@@ -425,7 +425,25 @@ var parseNamePath = exports.parseNamePath = function parseNamePath(input) {
|
|
425
425
|
});
|
426
426
|
return [result];
|
427
427
|
};
|
428
|
-
/**
|
428
|
+
/**
|
429
|
+
* 获取表单所有字段路径的简化函数
|
430
|
+
* @param form 表单实例
|
431
|
+
* @returns 所有字段路径数组
|
432
|
+
*/
|
433
|
+
var getFormFieldPaths = exports.getFormFieldPaths = function getFormFieldPaths(form) {
|
434
|
+
try {
|
435
|
+
// @ts-ignore
|
436
|
+
var _form$getInternalHook = form.getInternalHooks('RC_FORM_INTERNAL_HOOKS'),
|
437
|
+
getFields = _form$getInternalHook.getFields;
|
438
|
+
var allFields = getFields();
|
439
|
+
return allFields.map(function (field) {
|
440
|
+
return field.name;
|
441
|
+
});
|
442
|
+
} catch (error) {
|
443
|
+
console.error('获取表单字段失败:', error);
|
444
|
+
return [];
|
445
|
+
}
|
446
|
+
};
|
429
447
|
function findNamesKeyInArray(arr, key) {
|
430
448
|
var _iterator = (0, _createForOfIteratorHelper2.default)(arr),
|
431
449
|
_step;
|
@@ -1,12 +1,17 @@
|
|
1
1
|
import { FormInstance } from 'antd';
|
2
2
|
import { NamePath } from 'antd/es/form/interface';
|
3
3
|
import { ValuedNotifyInfo } from 'rc-field-form/es/interface';
|
4
|
-
export type
|
4
|
+
export type ModifiedFormInstanceType<T> = FormInstance<T> & {
|
5
5
|
isModified?: boolean;
|
6
6
|
/** 默认清空设置值的报错状态 */
|
7
7
|
setFieldValue: (name: NamePath, value: any, info?: ValuedNotifyInfo) => void;
|
8
8
|
formKey?: string;
|
9
9
|
_init?: boolean;
|
10
|
+
__INTERNAL_CONFIG__?: {
|
11
|
+
fields?: any[];
|
12
|
+
stopOnFirstError?: boolean;
|
13
|
+
[key: string]: any;
|
14
|
+
};
|
10
15
|
};
|
11
16
|
export interface FormInstanceOption {
|
12
17
|
scrollToError?: boolean;
|
@@ -14,4 +19,4 @@ export interface FormInstanceOption {
|
|
14
19
|
formKey?: string;
|
15
20
|
source?: string;
|
16
21
|
}
|
17
|
-
export declare const useForm: <T>(originForm?:
|
22
|
+
export declare const useForm: <T>(originForm?: ModifiedFormInstanceType<T> | FormInstanceOption, options?: FormInstanceOption) => [ModifiedFormInstanceType<T>];
|
@@ -5,9 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
6
6
|
});
|
7
7
|
exports.useForm = void 0;
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
9
8
|
var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
|
10
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11
|
+
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
11
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
12
13
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
13
14
|
var _antd = require("antd");
|
@@ -56,10 +57,19 @@ var useForm = exports.useForm = function useForm(originForm, options) {
|
|
56
57
|
var _validateFields = /*#__PURE__*/function () {
|
57
58
|
var _ref2 = (0, _asyncToGenerator2.default)(/*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee(nameList) {
|
58
59
|
var _rest$,
|
60
|
+
_form$__INTERNAL_CONF,
|
59
61
|
_len,
|
60
62
|
rest,
|
61
63
|
_key,
|
62
64
|
isRecursive,
|
65
|
+
stopOnFirstError,
|
66
|
+
allFields,
|
67
|
+
_iterator,
|
68
|
+
_step,
|
69
|
+
field,
|
70
|
+
_options2,
|
71
|
+
_error$errorFields,
|
72
|
+
_error$errorFields$,
|
63
73
|
validateNames,
|
64
74
|
_form$getInternalHook,
|
65
75
|
getFields,
|
@@ -67,8 +77,8 @@ var useForm = exports.useForm = function useForm(originForm, options) {
|
|
67
77
|
_document,
|
68
78
|
tablePagination,
|
69
79
|
_tablePagination$clic,
|
70
|
-
_error$
|
71
|
-
_error$errorFields
|
80
|
+
_error$errorFields2,
|
81
|
+
_error$errorFields$2,
|
72
82
|
_args = arguments;
|
73
83
|
return (0, _regeneratorRuntime2.default)().wrap(function _callee$(_context) {
|
74
84
|
while (1) switch (_context.prev = _context.next) {
|
@@ -77,11 +87,68 @@ var useForm = exports.useForm = function useForm(originForm, options) {
|
|
77
87
|
for (_len = _args.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
78
88
|
rest[_key - 1] = _args[_key];
|
79
89
|
}
|
80
|
-
// @ts-ignore
|
81
90
|
isRecursive = rest === null || rest === void 0 ? void 0 : (_rest$ = rest[0]) === null || _rest$ === void 0 ? void 0 : _rest$.recursive;
|
91
|
+
stopOnFirstError = form === null || form === void 0 ? void 0 : (_form$__INTERNAL_CONF = form.__INTERNAL_CONFIG__) === null || _form$__INTERNAL_CONF === void 0 ? void 0 : _form$__INTERNAL_CONF.stopOnFirstError; // 如果启用了 stopOnFirstError 且没有指定字段列表
|
92
|
+
if (!(stopOnFirstError && !nameList)) {
|
93
|
+
_context.next = 33;
|
94
|
+
break;
|
95
|
+
}
|
96
|
+
// 获取所有表单字段
|
97
|
+
allFields = (0, _index.getFormFieldPaths)(form); // 单独验证每个字段
|
98
|
+
// eslint-disable-next-line no-restricted-syntax
|
99
|
+
_iterator = (0, _createForOfIteratorHelper2.default)(allFields);
|
100
|
+
_context.prev = 7;
|
101
|
+
_iterator.s();
|
102
|
+
case 9:
|
103
|
+
if ((_step = _iterator.n()).done) {
|
104
|
+
_context.next = 24;
|
105
|
+
break;
|
106
|
+
}
|
107
|
+
field = _step.value;
|
108
|
+
_context.prev = 11;
|
109
|
+
// 创建不包含 stopOnFirstError 的选项
|
110
|
+
// @ts-ignore
|
111
|
+
_options2 = (rest === null || rest === void 0 ? void 0 : rest[0]) ? (0, _objectSpread2.default)({}, rest[0]) : {};
|
112
|
+
delete _options2.stopOnFirstError;
|
113
|
+
// 验证单个字段
|
114
|
+
// eslint-disable-next-line no-await-in-loop
|
115
|
+
_context.next = 16;
|
116
|
+
return validateFields([field], _options2);
|
117
|
+
case 16:
|
118
|
+
_context.next = 22;
|
119
|
+
break;
|
120
|
+
case 18:
|
121
|
+
_context.prev = 18;
|
122
|
+
_context.t0 = _context["catch"](11);
|
123
|
+
// 遇到错误,滚动到错误位置
|
124
|
+
if (scrollToError && (_context.t0 === null || _context.t0 === void 0 ? void 0 : (_error$errorFields = _context.t0.errorFields) === null || _error$errorFields === void 0 ? void 0 : _error$errorFields.length)) {
|
125
|
+
form.scrollToField((_error$errorFields$ = _context.t0.errorFields[0]) === null || _error$errorFields$ === void 0 ? void 0 : _error$errorFields$.name, {
|
126
|
+
block: 'center',
|
127
|
+
behavior: 'smooth'
|
128
|
+
});
|
129
|
+
}
|
130
|
+
// 中止验证,抛出错误
|
131
|
+
throw _context.t0;
|
132
|
+
case 22:
|
133
|
+
_context.next = 9;
|
134
|
+
break;
|
135
|
+
case 24:
|
136
|
+
_context.next = 29;
|
137
|
+
break;
|
138
|
+
case 26:
|
139
|
+
_context.prev = 26;
|
140
|
+
_context.t1 = _context["catch"](7);
|
141
|
+
_iterator.e(_context.t1);
|
142
|
+
case 29:
|
143
|
+
_context.prev = 29;
|
144
|
+
_iterator.f();
|
145
|
+
return _context.finish(29);
|
146
|
+
case 32:
|
147
|
+
return _context.abrupt("return", form.getFieldsValue());
|
148
|
+
case 33:
|
82
149
|
validateNames = []; // 前缀校验模式
|
83
150
|
if (!isRecursive) {
|
84
|
-
_context.next =
|
151
|
+
_context.next = 42;
|
85
152
|
break;
|
86
153
|
}
|
87
154
|
// @ts-ignore
|
@@ -98,13 +165,13 @@ var useForm = exports.useForm = function useForm(originForm, options) {
|
|
98
165
|
}
|
99
166
|
// @ts-ignore
|
100
167
|
// delete rest[0].recursive;
|
101
|
-
_context.next =
|
168
|
+
_context.next = 41;
|
102
169
|
return validateFields.apply(void 0, [validateNames].concat(rest)).then(function (values) {
|
103
170
|
return (0, _index.filterInternalFields)(values, optimize);
|
104
171
|
});
|
105
|
-
case
|
172
|
+
case 41:
|
106
173
|
return _context.abrupt("return", _context.sent);
|
107
|
-
case
|
174
|
+
case 42:
|
108
175
|
// 解决,单个pro-edit-table的表单校验
|
109
176
|
if ((nameList === null || nameList === void 0 ? void 0 : nameList.length) && !nameList.join('-').includes(',')) {
|
110
177
|
tablePagination = document && ((_document = document) === null || _document === void 0 ? void 0 : _document.querySelector("#pro-edit-table-pagination-".concat(nameList.join('-'))));
|
@@ -112,28 +179,28 @@ var useForm = exports.useForm = function useForm(originForm, options) {
|
|
112
179
|
tablePagination === null || tablePagination === void 0 ? void 0 : (_tablePagination$clic = tablePagination.click) === null || _tablePagination$clic === void 0 ? void 0 : _tablePagination$clic.call(tablePagination);
|
113
180
|
}
|
114
181
|
}
|
115
|
-
_context.next =
|
182
|
+
_context.next = 45;
|
116
183
|
return validateFields.apply(void 0, [nameList].concat(rest)).then(function (values) {
|
117
184
|
return nameList ? values : _getFieldsValue();
|
118
185
|
});
|
119
|
-
case
|
186
|
+
case 45:
|
120
187
|
return _context.abrupt("return", _context.sent);
|
121
|
-
case
|
122
|
-
_context.prev =
|
123
|
-
_context.
|
124
|
-
if (scrollToError && (_context.
|
125
|
-
form.scrollToField((_error$errorFields$ = _context.
|
188
|
+
case 48:
|
189
|
+
_context.prev = 48;
|
190
|
+
_context.t2 = _context["catch"](0);
|
191
|
+
if (scrollToError && (_context.t2 === null || _context.t2 === void 0 ? void 0 : (_error$errorFields2 = _context.t2.errorFields) === null || _error$errorFields2 === void 0 ? void 0 : _error$errorFields2.length) && source === 'ProForm') {
|
192
|
+
form.scrollToField((_error$errorFields$2 = _context.t2.errorFields[0]) === null || _error$errorFields$2 === void 0 ? void 0 : _error$errorFields$2.name, {
|
126
193
|
block: 'center',
|
127
194
|
behavior: 'smooth'
|
128
195
|
});
|
129
196
|
}
|
130
197
|
(0, _tools.handleScrollToError)();
|
131
|
-
throw _context.
|
132
|
-
case
|
198
|
+
throw _context.t2;
|
199
|
+
case 53:
|
133
200
|
case "end":
|
134
201
|
return _context.stop();
|
135
202
|
}
|
136
|
-
}, _callee, null, [[0, 18]]);
|
203
|
+
}, _callee, null, [[0, 48], [7, 26, 29, 32], [11, 18]]);
|
137
204
|
}));
|
138
205
|
return function _validateFields(_x) {
|
139
206
|
return _ref2.apply(this, arguments);
|
@@ -181,8 +248,8 @@ var useForm = exports.useForm = function useForm(originForm, options) {
|
|
181
248
|
form.getFieldsValue = _getFieldsValue;
|
182
249
|
form.setFieldValue = _setFieldValue;
|
183
250
|
form.setFieldsValue = _setFieldsValue;
|
184
|
-
form.getFieldsValue = _getFieldsValue;
|
185
251
|
form.validateFields = _validateFields;
|
186
252
|
form.isModified = true;
|
253
|
+
form.__INTERNAL_CONFIG__ = {};
|
187
254
|
return [form];
|
188
255
|
};
|
@@ -1,6 +1,11 @@
|
|
1
|
-
import {
|
1
|
+
import { FormInstance, NamePath } from 'rc-field-form/es/interface';
|
2
2
|
export declare function toArray<T>(value?: T | T[] | null): T[];
|
3
|
-
|
4
|
-
|
3
|
+
/**
|
4
|
+
* ProForm的useWatch hook,用于监听表单字段变化
|
5
|
+
* @param dependencies 监听的字段路径
|
6
|
+
* @param form 表单实例
|
7
|
+
* @param wait 防抖等待时间
|
8
|
+
* @returns 表单值
|
9
|
+
*/
|
5
10
|
declare function useWatch(dependencies: string | NamePath[], form?: FormInstance, wait?: number): any;
|
6
11
|
export default useWatch;
|
@@ -5,83 +5,163 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
6
6
|
});
|
7
7
|
exports.default = void 0;
|
8
|
-
exports.getNamePath = getNamePath;
|
9
|
-
exports.stringify = stringify;
|
10
8
|
exports.toArray = toArray;
|
9
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
12
11
|
var _lodash = require("lodash");
|
13
|
-
var _FieldContext = require("rc-field-form/es/FieldContext");
|
14
12
|
var _warning = _interopRequireDefault(require("rc-util/lib/warning"));
|
15
13
|
var _react = require("react");
|
14
|
+
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
16
15
|
function toArray(value) {
|
17
16
|
if (value === undefined || value === null) {
|
18
17
|
return [];
|
19
18
|
}
|
20
19
|
return Array.isArray(value) ? value : [value];
|
21
20
|
}
|
22
|
-
|
23
|
-
|
21
|
+
// 从一个对象或Form值中获取特定路径的值
|
22
|
+
function get(source, path) {
|
23
|
+
if (!source || path.length === 0) {
|
24
|
+
return source;
|
25
|
+
}
|
26
|
+
var current = source;
|
27
|
+
for (var i = 0; i < path.length; i++) {
|
28
|
+
if (current === undefined || current === null) {
|
29
|
+
return undefined;
|
30
|
+
}
|
31
|
+
current = current[path[i]];
|
32
|
+
}
|
33
|
+
return current;
|
24
34
|
}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
35
|
+
/**
|
36
|
+
* 将值设置到指定路径的嵌套对象中
|
37
|
+
* @param obj 目标对象
|
38
|
+
* @param path 路径数组
|
39
|
+
* @param value 要设置的值
|
40
|
+
*/
|
41
|
+
function setValueByPath(obj, path, value) {
|
42
|
+
if (path.length === 0) return;
|
43
|
+
// 处理单层路径
|
44
|
+
if (path.length === 1) {
|
45
|
+
obj[path[0]] = value;
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
// 处理多层嵌套路径
|
49
|
+
var current = obj;
|
50
|
+
for (var i = 0; i < path.length - 1; i++) {
|
51
|
+
var key = path[i];
|
52
|
+
if (!current[key]) {
|
53
|
+
current[key] = {};
|
54
|
+
}
|
55
|
+
current = current[key];
|
30
56
|
}
|
57
|
+
current[path[path.length - 1]] = value;
|
31
58
|
}
|
32
|
-
// 创建之后namepath
|
33
|
-
var useWatchWarning = process.env.NODE_ENV !== 'production' ? function (
|
34
|
-
var
|
35
|
-
var
|
36
|
-
(0, _warning.default)(
|
59
|
+
// 创建之后namepath就不可变的警告
|
60
|
+
var useWatchWarning = process.env.NODE_ENV !== 'production' ? function (dependencies) {
|
61
|
+
var depsStr = JSON.stringify(dependencies);
|
62
|
+
var depsStrRef = (0, _react.useRef)(depsStr);
|
63
|
+
(0, _warning.default)(depsStrRef.current === depsStr, '`useWatch` is not support dynamic `namePath`. Please provide static instead.');
|
37
64
|
} : function () {};
|
65
|
+
/**
|
66
|
+
* ProForm的useWatch hook,用于监听表单字段变化
|
67
|
+
* @param dependencies 监听的字段路径
|
68
|
+
* @param form 表单实例
|
69
|
+
* @param wait 防抖等待时间
|
70
|
+
* @returns 表单值
|
71
|
+
*/
|
38
72
|
function useWatch(dependencies, form, wait) {
|
39
|
-
|
73
|
+
// 处理开发环境警告
|
74
|
+
useWatchWarning(dependencies);
|
75
|
+
// 获取表单实例
|
76
|
+
var formInstance = form;
|
77
|
+
// 用于存储最终结果
|
40
78
|
var _useState = (0, _react.useState)({}),
|
41
79
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
80
|
+
state = _useState2[0],
|
81
|
+
setState = _useState2[1];
|
82
|
+
// 使用ref存储中间状态,避免不必要的渲染
|
83
|
+
var valueRef = (0, _react.useRef)({});
|
84
|
+
var prevStateRef = (0, _react.useRef)({});
|
85
|
+
// 标准化依赖为路径数组的数组
|
86
|
+
var namePaths = (0, _react.useMemo)(function () {
|
87
|
+
// 将依赖标准化为数组的数组形式
|
88
|
+
var paths = [];
|
89
|
+
// 字符串形式: 'fieldName'
|
90
|
+
if (typeof dependencies === 'string') {
|
91
|
+
paths.push(dependencies);
|
92
|
+
// 数组形式
|
93
|
+
} else if (Array.isArray(dependencies)) {
|
94
|
+
// 检查是否是路径数组的集合,例如:[['a', 'number'], 'fieldName']
|
95
|
+
var isPathsCollection = dependencies.length > 0 && (typeof dependencies[0] === 'string' || Array.isArray(dependencies[0]));
|
96
|
+
if (isPathsCollection) {
|
97
|
+
// 每个元素都是一个路径
|
98
|
+
dependencies.forEach(function (path) {
|
99
|
+
paths.push(path);
|
100
|
+
});
|
101
|
+
} else {
|
102
|
+
// 整个数组是一个单一路径
|
103
|
+
paths.push(dependencies);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
return paths;
|
107
|
+
}, [/* dependencies 故意忽略,与原实现一致 */]);
|
108
|
+
// 保存防抖函数引用,避免重复创建
|
109
|
+
var debouncedFn = (0, _react.useMemo)(function () {
|
110
|
+
if (wait) {
|
111
|
+
return (0, _lodash.debounce)(function (value) {
|
112
|
+
// 只在值真正变化时才更新状态
|
113
|
+
if (!(0, _isEqual.default)(prevStateRef.current, value)) {
|
114
|
+
prevStateRef.current = (0, _objectSpread2.default)({}, value);
|
115
|
+
setState(value);
|
116
|
+
}
|
117
|
+
}, wait);
|
118
|
+
}
|
119
|
+
// 非防抖版本
|
120
|
+
return function (value) {
|
121
|
+
if (!(0, _isEqual.default)(prevStateRef.current, value)) {
|
122
|
+
prevStateRef.current = (0, _objectSpread2.default)({}, value);
|
123
|
+
setState(value);
|
124
|
+
}
|
125
|
+
};
|
126
|
+
}, [wait]);
|
58
127
|
(0, _react.useEffect)(function () {
|
59
|
-
if (!
|
60
|
-
|
61
|
-
|
62
|
-
|
128
|
+
if (!formInstance) return undefined;
|
129
|
+
// 创建更新状态的函数
|
130
|
+
var updateState = function updateState() {
|
131
|
+
var values = formInstance.getFieldsValue(true);
|
132
|
+
var newState = {};
|
133
|
+
// 处理每个监听路径
|
134
|
+
namePaths.forEach(function (path) {
|
135
|
+
// 将路径转换为数组形式
|
136
|
+
var namePath = toArray(path);
|
137
|
+
// 获取路径对应的值
|
138
|
+
var value = get(values, namePath);
|
139
|
+
// 将值设置到正确的嵌套结构中
|
140
|
+
setValueByPath(newState, namePath, value);
|
141
|
+
});
|
142
|
+
// 存储并更新状态
|
143
|
+
valueRef.current = newState;
|
144
|
+
debouncedFn(newState);
|
145
|
+
};
|
146
|
+
// 初始调用一次
|
147
|
+
updateState();
|
148
|
+
// 注册表单变化监听
|
149
|
+
var getInternalHooks = formInstance.getInternalHooks;
|
150
|
+
var _getInternalHooks = getInternalHooks('RC_FORM_INTERNAL_HOOKS'),
|
63
151
|
registerWatch = _getInternalHooks.registerWatch;
|
64
|
-
var
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
152
|
+
var cancelWatch = registerWatch(function (values) {
|
153
|
+
if (values) {
|
154
|
+
updateState();
|
155
|
+
}
|
156
|
+
});
|
157
|
+
// 清理订阅
|
158
|
+
return function () {
|
159
|
+
if (wait) {
|
160
|
+
debouncedFn.cancel();
|
71
161
|
}
|
162
|
+
cancelWatch();
|
72
163
|
};
|
73
|
-
|
74
|
-
|
75
|
-
callback = (0, _lodash.debounce)(callback, wait);
|
76
|
-
}
|
77
|
-
var cancelRegister = registerWatch(callback);
|
78
|
-
var initialValue = getFieldsValue(_dependencies);
|
79
|
-
setValue(initialValue);
|
80
|
-
return cancelRegister;
|
81
|
-
},
|
82
|
-
// We do not need re-register since namePath content is the same
|
83
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
84
|
-
[isValidForm]);
|
85
|
-
return value;
|
164
|
+
}, [formInstance, namePaths, debouncedFn, wait]);
|
165
|
+
return state;
|
86
166
|
}
|
87
167
|
var _default = exports.default = useWatch;
|
@@ -15,14 +15,6 @@ var _DndWrapper = _interopRequireWildcard(require("./components/DndWrapper"));
|
|
15
15
|
var _index = require("../../../index");
|
16
16
|
require("../../../../style/index.less");
|
17
17
|
var _excluded = ["dataSource", "tableProps", "draggableProps", "summaryProps", "emptyTextProps"];
|
18
|
-
/*
|
19
|
-
* @Author: ''
|
20
|
-
* @Date: 2024-08-09 13:48:59
|
21
|
-
* @LastEditors: ''
|
22
|
-
* @LastEditTime: 2024-08-27 15:27:44
|
23
|
-
* @FilePath: /za-material-warehouse/src/ProTable/components/RcTable/components/DraggableTable/index.tsx
|
24
|
-
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
25
|
-
*/
|
26
18
|
var DraggableTable = function DraggableTable(_ref) {
|
27
19
|
var dataSource = _ref.dataSource,
|
28
20
|
tableProps = _ref.tableProps,
|
@@ -20,7 +20,8 @@ var RenderTabs = function RenderTabs(props) {
|
|
20
20
|
transformResponse = props.transformResponse,
|
21
21
|
tabsProps = props.tabsProps,
|
22
22
|
name = props.name,
|
23
|
-
formTableProps = props.formTableProps
|
23
|
+
formTableProps = props.formTableProps,
|
24
|
+
transformParams = props.transformParams;
|
24
25
|
var _ref = formTableProps || {},
|
25
26
|
form = _ref.form,
|
26
27
|
onSearch = _ref.onSearch;
|
@@ -71,7 +72,11 @@ var RenderTabs = function RenderTabs(props) {
|
|
71
72
|
var fieldsValues = (form === null || form === void 0 ? void 0 : form.getFieldsValue()) || {};
|
72
73
|
setActiveKey(key);
|
73
74
|
form.setFieldValue(name, key);
|
74
|
-
|
75
|
+
var params = (0, _objectSpread3.default)((0, _objectSpread3.default)({}, fieldsValues), {}, (0, _defineProperty2.default)({}, name, key));
|
76
|
+
if (transformParams && typeof transformParams === 'function') {
|
77
|
+
params = transformParams(params);
|
78
|
+
}
|
79
|
+
onSearch === null || onSearch === void 0 ? void 0 : onSearch(params);
|
75
80
|
},
|
76
81
|
type: "card"
|
77
82
|
}, tabsProps), {}, {
|
@@ -33,13 +33,12 @@ var useDefaultOptions = function useDefaultOptions(options) {
|
|
33
33
|
};
|
34
34
|
var previousSearchValues = null;
|
35
35
|
function useAntdTable(service, options, useRequestOptions) {
|
36
|
-
var _locale$ProTable2, _locale$ProTable3, _locale$ProTable4, _locale$ProTable5;
|
36
|
+
var _locale$ProTable2, _locale$ProTable3, _locale$ProTable4, _locale$ProTable5, _result$params;
|
37
37
|
var _useSetState = (0, _ahooks.useSetState)({
|
38
38
|
data: [],
|
39
39
|
total: 0,
|
40
40
|
selectedRecords: [],
|
41
41
|
selectedRowKeys: [],
|
42
|
-
searchValues: undefined,
|
43
42
|
extraFilter: {
|
44
43
|
filters: undefined,
|
45
44
|
sorter: undefined
|
@@ -52,7 +51,6 @@ function useAntdTable(service, options, useRequestOptions) {
|
|
52
51
|
total = _useSetState2$.total,
|
53
52
|
selectedRecords = _useSetState2$.selectedRecords,
|
54
53
|
selectedRowKeys = _useSetState2$.selectedRowKeys,
|
55
|
-
searchValues = _useSetState2$.searchValues,
|
56
54
|
extraFilter = _useSetState2$.extraFilter,
|
57
55
|
allSelected = _useSetState2$.allSelected,
|
58
56
|
setState = _useSetState2[1];
|
@@ -73,6 +71,9 @@ function useAntdTable(service, options, useRequestOptions) {
|
|
73
71
|
transformParams = _useDefaultOptions.transformParams,
|
74
72
|
transformResponse = _useDefaultOptions.transformResponse,
|
75
73
|
disabled = _useDefaultOptions.disabled;
|
74
|
+
// 搜索表单里的值
|
75
|
+
var _searchValues = _antd.Form.useWatch([], form);
|
76
|
+
var searchValues = (0, _utils.removeEmptyKeys)(_searchValues);
|
76
77
|
var _ref = useRequestOptions || {},
|
77
78
|
defaultParams = _ref.defaultParams;
|
78
79
|
var defaultParam = Array.isArray(defaultParams) ? defaultParams === null || defaultParams === void 0 ? void 0 : defaultParams[0] : defaultParams || {};
|
@@ -110,12 +111,6 @@ function useAntdTable(service, options, useRequestOptions) {
|
|
110
111
|
allSelected: false
|
111
112
|
}, values));
|
112
113
|
};
|
113
|
-
var params = (0, _react.useMemo)(function () {
|
114
|
-
var newQueryBean = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, searchValues), extraFilter);
|
115
|
-
return getTransformParams((0, _objectSpread2.default)({
|
116
|
-
page: page
|
117
|
-
}, newQueryBean));
|
118
|
-
}, [page, searchValues, extraFilter]);
|
119
114
|
var curService = (0, _react.useMemo)(function () {
|
120
115
|
return service.toString();
|
121
116
|
}, [service]);
|
@@ -254,10 +249,9 @@ function useAntdTable(service, options, useRequestOptions) {
|
|
254
249
|
onPageChange(newPage);
|
255
250
|
}
|
256
251
|
// 减少查询按钮的渲染,只有需要重置值时才需要调用
|
257
|
-
if ((selectedRecords === null || selectedRecords === void 0 ? void 0 : selectedRecords.length) || (0, _utils.isNonEmptyObject)(_values)
|
252
|
+
if ((selectedRecords === null || selectedRecords === void 0 ? void 0 : selectedRecords.length) || (0, _utils.isNonEmptyObject)(_values) || !(0, _lodash.isEqual)(previousSearchValues, _values)) {
|
258
253
|
previousSearchValues = _values;
|
259
254
|
setState({
|
260
|
-
searchValues: _values,
|
261
255
|
allSelected: false,
|
262
256
|
selectedRecords: [],
|
263
257
|
selectedRowKeys: []
|
@@ -269,7 +263,6 @@ function useAntdTable(service, options, useRequestOptions) {
|
|
269
263
|
}, [extraFilter, page.pageSize, previousPage, getTransformParams]);
|
270
264
|
var resetParams = (0, _react.useCallback)(function (page) {
|
271
265
|
setState({
|
272
|
-
searchValues: undefined,
|
273
266
|
allSelected: false,
|
274
267
|
selectedRecords: [],
|
275
268
|
selectedRowKeys: [],
|
@@ -484,7 +477,7 @@ function useAntdTable(service, options, useRequestOptions) {
|
|
484
477
|
};
|
485
478
|
var useAntdTableProps = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, result), {}, {
|
486
479
|
data: data,
|
487
|
-
params: params,
|
480
|
+
params: (result === null || result === void 0 ? void 0 : (_result$params = result.params) === null || _result$params === void 0 ? void 0 : _result$params[0]) || {},
|
488
481
|
rowSelection: rowSelection,
|
489
482
|
searchValues: searchValues,
|
490
483
|
allSelected: allSelected,
|