@zat-design/sisyphus-react 3.12.1-beta.2 → 3.12.1-beta.3

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.
@@ -27,8 +27,9 @@ import { useFieldProps } from './utils/useFieldProps';
27
27
  import locale from '../locale';
28
28
  import useWatch from './utils/useWatch';
29
29
  import FormsProvider, { useContextForms, useForms } from '../FormsProvider';
30
+ import { useStep } from '../ProStep';
30
31
  var ProForm = function ProForm(props, ref) {
31
- var _localStorage, _ref2;
32
+ var _localStorage, _ref3;
32
33
  var _props$mode = props.mode,
33
34
  mode = _props$mode === void 0 ? 'search' : _props$mode,
34
35
  span = props.span,
@@ -78,11 +79,15 @@ var ProForm = function ProForm(props, ref) {
78
79
  var _ref = useProDrawerFormContext() || {},
79
80
  _ref$source = _ref.source,
80
81
  source = _ref$source === void 0 ? '' : _ref$source;
82
+ // stepSource: 用于区分是哪个组件调用,用于错误提示
83
+ var _ref2 = useStep() || {},
84
+ _ref2$source = _ref2.source,
85
+ stepSource = _ref2$source === void 0 ? '' : _ref2$source;
81
86
  var _useForm = useForm(originForm, {
82
87
  scrollToError: scrollToError,
83
88
  optimize: optimize,
84
89
  formKey: formKey,
85
- source: source || 'ProForm'
90
+ source: source || stepSource || 'ProForm'
86
91
  }),
87
92
  _useForm2 = _slicedToArray(_useForm, 1),
88
93
  form = _useForm2[0];
@@ -220,7 +225,7 @@ var ProForm = function ProForm(props, ref) {
220
225
  className: cls,
221
226
  form: form
222
227
  }, formProps), omit(config, ['isDiffAll'])), otherProps), {}, {
223
- labelAlign: (_ref2 = labelAlign !== null && labelAlign !== void 0 ? labelAlign : config.labelAlign) !== null && _ref2 !== void 0 ? _ref2 : 'left',
228
+ labelAlign: (_ref3 = labelAlign !== null && labelAlign !== void 0 ? labelAlign : config.labelAlign) !== null && _ref3 !== void 0 ? _ref3 : 'left',
224
229
  onValuesChange: handleValuesChange,
225
230
  onFinish: handleFinish,
226
231
  initialValues: _initialValues,
@@ -7,7 +7,7 @@ import _Form from "antd/es/form";
7
7
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
8
8
  import { useContext } from 'react';
9
9
  import { filterInternalFields } from './index';
10
- import { handleScrollToError } from '../../ProEditTable/utils/tools';
10
+ import { handleScrollToError as handleScrollToErrorProEditTable } from '../../ProEditTable/utils/tools';
11
11
  import { FormsContext } from '../../FormsProvider';
12
12
  export var useForm = function useForm(originForm, options) {
13
13
  // 如果没有form实例可以直接把options放在第一个参数位置
@@ -121,7 +121,7 @@ export var useForm = function useForm(originForm, options) {
121
121
  behavior: 'smooth'
122
122
  });
123
123
  }
124
- handleScrollToError();
124
+ handleScrollToErrorProEditTable();
125
125
  throw _context.t0;
126
126
  case 23:
127
127
  case "end":
@@ -8,35 +8,6 @@ import React from 'react';
8
8
  import { forceVisible } from 'react-lazyload';
9
9
  import { useStep } from '../../index';
10
10
  import { getLoadedMap } from '../../utils';
11
- /**
12
- * 检查错误列表并返回第一个错误项
13
- * @param arr DOM元素数组
14
- * @returns 错误元素信息
15
- */
16
- var checkErrorList = function checkErrorList(arr) {
17
- for (var i = 0; i < arr.length; i++) {
18
- if (arr[i].className.includes('errored')) {
19
- return {
20
- errorDom: arr[i],
21
- index: i
22
- };
23
- }
24
- }
25
- return null;
26
- };
27
- /**
28
- * 查找第一个错误的DOM元素
29
- * @returns 错误元素信息
30
- */
31
- var findFirstErrorDom = function findFirstErrorDom() {
32
- var errorList = document.querySelectorAll('.pro-step-com-menu-item');
33
- var hasErrorItem = document.querySelectorAll('.pro-step-com-menu-item .errored');
34
- var hasFormError = document.querySelector('.ant-form-item-explain-error');
35
- if ((hasErrorItem === null || hasErrorItem === void 0 ? void 0 : hasErrorItem.length) && !hasFormError) {
36
- return checkErrorList(errorList);
37
- }
38
- return null;
39
- };
40
11
  /**
41
12
  * 检查所有模块是否已加载完成
42
13
  * @param data 模块加载数据
@@ -83,11 +54,6 @@ var Listener = function Listener(_ref) {
83
54
  values = _context.sent;
84
55
  setTimeout(function () {
85
56
  var localData = localStorage.getItem('cache-pro-step');
86
- var _ref3 = findFirstErrorDom() || {},
87
- errorDom = _ref3.errorDom;
88
- if (errorDom) {
89
- errorDom.click();
90
- }
91
57
  if (localData !== 'false') {
92
58
  var _children$props, _children$props$onCli;
93
59
  children === null || children === void 0 ? void 0 : (_children$props = children.props) === null || _children$props === void 0 ? void 0 : (_children$props$onCli = _children$props.onClick) === null || _children$props$onCli === void 0 ? void 0 : _children$props$onCli.call(_children$props, values);
@@ -99,7 +65,7 @@ var Listener = function Listener(_ref) {
99
65
  return _context.stop();
100
66
  }
101
67
  }, _callee);
102
- })), 3000)
68
+ })), 1000)
103
69
  }));
104
70
  };
105
71
  export default Listener;
@@ -9,7 +9,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
9
  import { createContext, useCallback, useContext, useMemo, useRef, useState } from 'react';
10
10
  import { debounce } from 'lodash';
11
11
  import { useSetState, useLocalStorageState } from 'ahooks';
12
- import { handleScroll } from './utils';
12
+ import { handleScroll, handleScrollError } from './utils';
13
13
  import Step from './components/Step';
14
14
  import Item from './components/Item';
15
15
  import Listener from './components/Listener';
@@ -37,11 +37,8 @@ var ProStep = function ProStep(_ref) {
37
37
  _useLocalStorageState2 = _slicedToArray(_useLocalStorageState, 2),
38
38
  setLocalData = _useLocalStorageState2[1];
39
39
  var ids = Object.keys(registerMap.current);
40
- var targetOffset = resetProps.targetOffset,
41
- _resetProps$collapse = resetProps.collapse,
40
+ var _resetProps$collapse = resetProps.collapse,
42
41
  collapse = _resetProps$collapse === void 0 ? false : _resetProps$collapse,
43
- _resetProps$scrollToE = resetProps.scrollToError,
44
- scrollToError = _resetProps$scrollToE === void 0 ? true : _resetProps$scrollToE,
45
42
  _resetProps$lazyLoad = resetProps.lazyLoad,
46
43
  lazyLoad = _resetProps$lazyLoad === void 0 ? false : _resetProps$lazyLoad;
47
44
  var dataSource = useMemo(function () {
@@ -147,28 +144,6 @@ var ProStep = function ProStep(_ref) {
147
144
  });
148
145
  }
149
146
  };
150
- var handleScrollError = function handleScrollError(data) {
151
- var errorDom = document.querySelector('.ant-form-item-explain-error');
152
- if (errorDom) {
153
- errorDom.scrollIntoView({
154
- behavior: 'smooth',
155
- block: 'center'
156
- });
157
- }
158
- // const errorModuleKeys = Object.keys(data).reverse();
159
- // if (errorModuleKeys?.length) {
160
- // const firstErrorModuleKey = dataSource.find((item) => {
161
- // const moduleKey = errorModuleKeys.find((child) => child === item.code);
162
- // return data[moduleKey];
163
- // })?.code;
164
- // console.log('firstErrorModuleKey', firstErrorModuleKey)·;
165
- // firstErrorModuleKey &&
166
- // handleScroll(firstErrorModuleKey, {
167
- // targetOffset,
168
- // scrollToError,
169
- // });
170
- // }
171
- };
172
147
  var notify = /*#__PURE__*/function () {
173
148
  var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
174
149
  var _ref7, excludes, triggerIds, events, res, nextErrorCollection;
@@ -199,7 +174,7 @@ var ProStep = function ProStep(_ref) {
199
174
  setState({
200
175
  errorCollection: nextErrorCollection
201
176
  });
202
- handleScrollError(nextErrorCollection);
177
+ handleScrollError();
203
178
  return _context2.abrupt("return", res);
204
179
  case 12:
205
180
  case "end":
@@ -237,7 +212,7 @@ var ProStep = function ProStep(_ref) {
237
212
  setState({
238
213
  errorCollection: nextErrorCollection
239
214
  });
240
- handleScrollError(nextErrorCollection);
215
+ handleScrollError();
241
216
  return _context3.abrupt("return", result);
242
217
  case 10:
243
218
  case "end":
@@ -258,7 +233,8 @@ var ProStep = function ProStep(_ref) {
258
233
  triggerTo: triggerTo,
259
234
  handleScroll: handleScroll,
260
235
  lazyLoad: lazyLoad,
261
- unNotify: unNotify
236
+ unNotify: unNotify,
237
+ source: 'ProStep'
262
238
  },
263
239
  children: _jsxs("div", {
264
240
  className: "pro-step-wrapper",
@@ -104,6 +104,8 @@ export interface ProStepContextType {
104
104
  lazyLoad?: boolean | any;
105
105
  /** 取消注册函数 */
106
106
  unNotify: (keys: string | string[]) => void;
107
+ /** 来源 */
108
+ source?: string;
107
109
  }
108
110
  /**
109
111
  * 注册参数类型
@@ -175,16 +177,6 @@ export interface ListenerProps {
175
177
  /** 允许其他任意属性 */
176
178
  [key: string]: any;
177
179
  }
178
- /**
179
- * 错误结果类型
180
- * @interface ErrorResult
181
- */
182
- export interface ErrorResult {
183
- /** 错误DOM元素 */
184
- errorDom: HTMLElement | null;
185
- /** 索引 */
186
- index: number;
187
- }
188
180
  /**
189
181
  * 锚点SVG属性类型
190
182
  * @interface AnchorSvgProps
@@ -1,7 +1,11 @@
1
1
  import React from 'react';
2
2
  import type { LoadedMapType } from '../propsType';
3
3
  /**
4
- * 处理滚动到指定元素位置
4
+ * 滚动到错误位置, 延迟200ms解决ProForm错误还未生成
5
+ */
6
+ export declare const handleScrollError: (dom?: HTMLElement) => void;
7
+ /**
8
+ * 处理滚动到指定元素位置, 如发现有错误, 则优先滚动到错误位置
5
9
  * @param id 目标元素的ID
6
10
  * @param options 滚动选项
7
11
  */
@@ -1,7 +1,21 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import { debounce, pick } from 'lodash';
3
3
  /**
4
- * 处理滚动到指定元素位置
4
+ * 滚动到错误位置, 延迟200ms解决ProForm错误还未生成
5
+ */
6
+ export var handleScrollError = function handleScrollError(dom) {
7
+ setTimeout(function () {
8
+ var errorDom = dom || document.querySelector('[class*="form-item-has-error"]');
9
+ if (errorDom) {
10
+ errorDom.scrollIntoView({
11
+ behavior: 'smooth',
12
+ block: 'center'
13
+ });
14
+ }
15
+ }, 200);
16
+ };
17
+ /**
18
+ * 处理滚动到指定元素位置, 如发现有错误, 则优先滚动到错误位置
5
19
  * @param id 目标元素的ID
6
20
  * @param options 滚动选项
7
21
  */
@@ -13,12 +27,20 @@ export var handleScroll = function handleScroll(id, options) {
13
27
  if (!scrollToError) return;
14
28
  var dom = document.querySelector("#".concat(id));
15
29
  if (dom) {
16
- setTimeout(debounce(function () {
17
- window.scrollTo({
18
- top: dom.offsetTop - targetOffset,
19
- behavior: 'smooth'
20
- });
21
- }, 100), 0);
30
+ // 查找指定id下的错误表单项
31
+ var errorDom = dom.querySelector('[class*="form-item-has-error"]');
32
+ if (errorDom && scrollToError) {
33
+ // 如果发现错误表单项,执行handleScrollError函数
34
+ handleScrollError(errorDom);
35
+ } else {
36
+ // 如果没有错误表单项,则滚动到指定元素位置
37
+ setTimeout(debounce(function () {
38
+ window.scrollTo({
39
+ top: dom.offsetTop - targetOffset,
40
+ behavior: 'smooth'
41
+ });
42
+ }, 100), 0);
43
+ }
22
44
  }
23
45
  };
24
46
  /**
@@ -27,9 +27,10 @@ var _useFieldProps = require("./utils/useFieldProps");
27
27
  var _locale = _interopRequireDefault(require("../locale"));
28
28
  var _useWatch = _interopRequireDefault(require("./utils/useWatch"));
29
29
  var _FormsProvider = _interopRequireWildcard(require("../FormsProvider"));
30
+ var _ProStep = require("../ProStep");
30
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
32
  var ProForm = function ProForm(props, ref) {
32
- var _localStorage, _ref2;
33
+ var _localStorage, _ref3;
33
34
  var _props$mode = props.mode,
34
35
  mode = _props$mode === void 0 ? 'search' : _props$mode,
35
36
  span = props.span,
@@ -79,11 +80,15 @@ var ProForm = function ProForm(props, ref) {
79
80
  var _ref = (0, _ProDrawerForm.useProDrawerFormContext)() || {},
80
81
  _ref$source = _ref.source,
81
82
  source = _ref$source === void 0 ? '' : _ref$source;
83
+ // stepSource: 用于区分是哪个组件调用,用于错误提示
84
+ var _ref2 = (0, _ProStep.useStep)() || {},
85
+ _ref2$source = _ref2.source,
86
+ stepSource = _ref2$source === void 0 ? '' : _ref2$source;
82
87
  var _useForm = (0, _useForm3.useForm)(originForm, {
83
88
  scrollToError: scrollToError,
84
89
  optimize: optimize,
85
90
  formKey: formKey,
86
- source: source || 'ProForm'
91
+ source: source || stepSource || 'ProForm'
87
92
  }),
88
93
  _useForm2 = (0, _slicedToArray2.default)(_useForm, 1),
89
94
  form = _useForm2[0];
@@ -221,7 +226,7 @@ var ProForm = function ProForm(props, ref) {
221
226
  className: cls,
222
227
  form: form
223
228
  }, formProps), (0, _lodash.omit)(config, ['isDiffAll'])), otherProps), {}, {
224
- labelAlign: (_ref2 = labelAlign !== null && labelAlign !== void 0 ? labelAlign : config.labelAlign) !== null && _ref2 !== void 0 ? _ref2 : 'left',
229
+ labelAlign: (_ref3 = labelAlign !== null && labelAlign !== void 0 ? labelAlign : config.labelAlign) !== null && _ref3 !== void 0 ? _ref3 : 'left',
225
230
  onValuesChange: handleValuesChange,
226
231
  onFinish: handleFinish,
227
232
  initialValues: _initialValues,
@@ -15,35 +15,6 @@ var _reactLazyload = require("react-lazyload");
15
15
  var _index = require("../../index");
16
16
  var _utils = require("../../utils");
17
17
  var _excluded = ["children", "delayTime", "excludes"];
18
- /**
19
- * 检查错误列表并返回第一个错误项
20
- * @param arr DOM元素数组
21
- * @returns 错误元素信息
22
- */
23
- var checkErrorList = function checkErrorList(arr) {
24
- for (var i = 0; i < arr.length; i++) {
25
- if (arr[i].className.includes('errored')) {
26
- return {
27
- errorDom: arr[i],
28
- index: i
29
- };
30
- }
31
- }
32
- return null;
33
- };
34
- /**
35
- * 查找第一个错误的DOM元素
36
- * @returns 错误元素信息
37
- */
38
- var findFirstErrorDom = function findFirstErrorDom() {
39
- var errorList = document.querySelectorAll('.pro-step-com-menu-item');
40
- var hasErrorItem = document.querySelectorAll('.pro-step-com-menu-item .errored');
41
- var hasFormError = document.querySelector('.ant-form-item-explain-error');
42
- if ((hasErrorItem === null || hasErrorItem === void 0 ? void 0 : hasErrorItem.length) && !hasFormError) {
43
- return checkErrorList(errorList);
44
- }
45
- return null;
46
- };
47
18
  /**
48
19
  * 检查所有模块是否已加载完成
49
20
  * @param data 模块加载数据
@@ -90,11 +61,6 @@ var Listener = function Listener(_ref) {
90
61
  values = _context.sent;
91
62
  setTimeout(function () {
92
63
  var localData = localStorage.getItem('cache-pro-step');
93
- var _ref3 = findFirstErrorDom() || {},
94
- errorDom = _ref3.errorDom;
95
- if (errorDom) {
96
- errorDom.click();
97
- }
98
64
  if (localData !== 'false') {
99
65
  var _children$props, _children$props$onCli;
100
66
  children === null || children === void 0 ? void 0 : (_children$props = children.props) === null || _children$props === void 0 ? void 0 : (_children$props$onCli = _children$props.onClick) === null || _children$props$onCli === void 0 ? void 0 : _children$props$onCli.call(_children$props, values);
@@ -106,7 +72,7 @@ var Listener = function Listener(_ref) {
106
72
  return _context.stop();
107
73
  }
108
74
  }, _callee);
109
- })), 3000)
75
+ })), 1000)
110
76
  }));
111
77
  };
112
78
  var _default = exports.default = Listener;
@@ -44,11 +44,8 @@ var ProStep = function ProStep(_ref) {
44
44
  _useLocalStorageState2 = (0, _slicedToArray2.default)(_useLocalStorageState, 2),
45
45
  setLocalData = _useLocalStorageState2[1];
46
46
  var ids = Object.keys(registerMap.current);
47
- var targetOffset = resetProps.targetOffset,
48
- _resetProps$collapse = resetProps.collapse,
47
+ var _resetProps$collapse = resetProps.collapse,
49
48
  collapse = _resetProps$collapse === void 0 ? false : _resetProps$collapse,
50
- _resetProps$scrollToE = resetProps.scrollToError,
51
- scrollToError = _resetProps$scrollToE === void 0 ? true : _resetProps$scrollToE,
52
49
  _resetProps$lazyLoad = resetProps.lazyLoad,
53
50
  lazyLoad = _resetProps$lazyLoad === void 0 ? false : _resetProps$lazyLoad;
54
51
  var dataSource = (0, _react.useMemo)(function () {
@@ -154,28 +151,6 @@ var ProStep = function ProStep(_ref) {
154
151
  });
155
152
  }
156
153
  };
157
- var handleScrollError = function handleScrollError(data) {
158
- var errorDom = document.querySelector('.ant-form-item-explain-error');
159
- if (errorDom) {
160
- errorDom.scrollIntoView({
161
- behavior: 'smooth',
162
- block: 'center'
163
- });
164
- }
165
- // const errorModuleKeys = Object.keys(data).reverse();
166
- // if (errorModuleKeys?.length) {
167
- // const firstErrorModuleKey = dataSource.find((item) => {
168
- // const moduleKey = errorModuleKeys.find((child) => child === item.code);
169
- // return data[moduleKey];
170
- // })?.code;
171
- // console.log('firstErrorModuleKey', firstErrorModuleKey)·;
172
- // firstErrorModuleKey &&
173
- // handleScroll(firstErrorModuleKey, {
174
- // targetOffset,
175
- // scrollToError,
176
- // });
177
- // }
178
- };
179
154
  var notify = /*#__PURE__*/function () {
180
155
  var _ref6 = (0, _asyncToGenerator2.default)(/*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee2(params) {
181
156
  var _ref7, excludes, triggerIds, events, res, nextErrorCollection;
@@ -206,7 +181,7 @@ var ProStep = function ProStep(_ref) {
206
181
  setState({
207
182
  errorCollection: nextErrorCollection
208
183
  });
209
- handleScrollError(nextErrorCollection);
184
+ (0, _utils.handleScrollError)();
210
185
  return _context2.abrupt("return", res);
211
186
  case 12:
212
187
  case "end":
@@ -244,7 +219,7 @@ var ProStep = function ProStep(_ref) {
244
219
  setState({
245
220
  errorCollection: nextErrorCollection
246
221
  });
247
- handleScrollError(nextErrorCollection);
222
+ (0, _utils.handleScrollError)();
248
223
  return _context3.abrupt("return", result);
249
224
  case 10:
250
225
  case "end":
@@ -265,7 +240,8 @@ var ProStep = function ProStep(_ref) {
265
240
  triggerTo: triggerTo,
266
241
  handleScroll: _utils.handleScroll,
267
242
  lazyLoad: lazyLoad,
268
- unNotify: unNotify
243
+ unNotify: unNotify,
244
+ source: 'ProStep'
269
245
  },
270
246
  children: (0, _jsxRuntime.jsxs)("div", {
271
247
  className: "pro-step-wrapper",
@@ -104,6 +104,8 @@ export interface ProStepContextType {
104
104
  lazyLoad?: boolean | any;
105
105
  /** 取消注册函数 */
106
106
  unNotify: (keys: string | string[]) => void;
107
+ /** 来源 */
108
+ source?: string;
107
109
  }
108
110
  /**
109
111
  * 注册参数类型
@@ -175,16 +177,6 @@ export interface ListenerProps {
175
177
  /** 允许其他任意属性 */
176
178
  [key: string]: any;
177
179
  }
178
- /**
179
- * 错误结果类型
180
- * @interface ErrorResult
181
- */
182
- export interface ErrorResult {
183
- /** 错误DOM元素 */
184
- errorDom: HTMLElement | null;
185
- /** 索引 */
186
- index: number;
187
- }
188
180
  /**
189
181
  * 锚点SVG属性类型
190
182
  * @interface AnchorSvgProps
@@ -1,7 +1,11 @@
1
1
  import React from 'react';
2
2
  import type { LoadedMapType } from '../propsType';
3
3
  /**
4
- * 处理滚动到指定元素位置
4
+ * 滚动到错误位置, 延迟200ms解决ProForm错误还未生成
5
+ */
6
+ export declare const handleScrollError: (dom?: HTMLElement) => void;
7
+ /**
8
+ * 处理滚动到指定元素位置, 如发现有错误, 则优先滚动到错误位置
5
9
  * @param id 目标元素的ID
6
10
  * @param options 滚动选项
7
11
  */
@@ -4,11 +4,25 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.handleScroll = exports.getLoadedMap = exports.default = void 0;
7
+ exports.handleScrollError = exports.handleScroll = exports.getLoadedMap = exports.default = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
9
  var _lodash = require("lodash");
10
10
  /**
11
- * 处理滚动到指定元素位置
11
+ * 滚动到错误位置, 延迟200ms解决ProForm错误还未生成
12
+ */
13
+ var handleScrollError = exports.handleScrollError = function handleScrollError(dom) {
14
+ setTimeout(function () {
15
+ var errorDom = dom || document.querySelector('[class*="form-item-has-error"]');
16
+ if (errorDom) {
17
+ errorDom.scrollIntoView({
18
+ behavior: 'smooth',
19
+ block: 'center'
20
+ });
21
+ }
22
+ }, 200);
23
+ };
24
+ /**
25
+ * 处理滚动到指定元素位置, 如发现有错误, 则优先滚动到错误位置
12
26
  * @param id 目标元素的ID
13
27
  * @param options 滚动选项
14
28
  */
@@ -20,12 +34,20 @@ var handleScroll = exports.handleScroll = function handleScroll(id, options) {
20
34
  if (!scrollToError) return;
21
35
  var dom = document.querySelector("#".concat(id));
22
36
  if (dom) {
23
- setTimeout((0, _lodash.debounce)(function () {
24
- window.scrollTo({
25
- top: dom.offsetTop - targetOffset,
26
- behavior: 'smooth'
27
- });
28
- }, 100), 0);
37
+ // 查找指定id下的错误表单项
38
+ var errorDom = dom.querySelector('[class*="form-item-has-error"]');
39
+ if (errorDom && scrollToError) {
40
+ // 如果发现错误表单项,执行handleScrollError函数
41
+ handleScrollError(errorDom);
42
+ } else {
43
+ // 如果没有错误表单项,则滚动到指定元素位置
44
+ setTimeout((0, _lodash.debounce)(function () {
45
+ window.scrollTo({
46
+ top: dom.offsetTop - targetOffset,
47
+ behavior: 'smooth'
48
+ });
49
+ }, 100), 0);
50
+ }
29
51
  }
30
52
  };
31
53
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "3.12.1-beta.2",
3
+ "version": "3.12.1-beta.3",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",