@zat-design/sisyphus-react 4.3.3-beta.1 → 4.3.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.
@@ -1,4 +1,4 @@
1
- import { useEffect } from 'react';
1
+ import { useEffect, useMemo, useRef } from 'react';
2
2
  import { useDeepCompareEffect, useRequest as useRequestFunc } from 'ahooks';
3
3
  import { diffCode, getEnumData, setEnumData, removeEnumData, cacheFieldNames, baseCacheKey, baseStorage } from "../utils";
4
4
  import locale from "../../locale";
@@ -29,13 +29,58 @@ const useEnumRequest = (props, dispatch) => {
29
29
  console.warn('proEnum:', msg);
30
30
  }
31
31
  };
32
- const enumRes = useRequestFunc(useRequest?.service, {
32
+
33
+ // IndexedDB 缓存策略:包装 service,在 service 层面返回缓存数据,
34
+ // 而非跳过 run()。这样 enumRes.data/loading 正常变更,
35
+ // ProConfigProvider 的 onSuccess 回调能正常触发(修复白屏问题)。
36
+ const fromCacheRef = useRef(null);
37
+ const originalService = useRequest?.service;
38
+ const serviceForRequest = useMemo(() => {
39
+ if (!originalService || storage !== 'indexedDB') {
40
+ return originalService;
41
+ }
42
+ return async (...args) => {
43
+ if (!requestRefresh) {
44
+ const cached = await Promise.resolve(getEnumData(storage, cacheKey));
45
+ if (cached?.data && Object.keys(cached.data).length > 0 && cached?.time && Date.now() - cached.time <= 6e4 * 60) {
46
+ fromCacheRef.current = cached.data;
47
+ return {
48
+ status: 200,
49
+ data: cached.data
50
+ };
51
+ }
52
+ }
53
+ fromCacheRef.current = null;
54
+ return originalService(...args);
55
+ };
56
+ }, [originalService, storage, requestRefresh, cacheKey]);
57
+ const enumRes = useRequestFunc(serviceForRequest, {
33
58
  manual: true,
34
59
  cacheKey,
35
60
  cacheTime: -1,
36
61
  staleTime: 6e4 * 60,
37
62
  ...useRequest?.options,
38
63
  setCache: async res => {
64
+ // 缓存命中时跳过 transformResponse 和重复处理,直接 dispatch
65
+ if (fromCacheRef.current) {
66
+ const cachedData = fromCacheRef.current;
67
+ dispatch({
68
+ type: 'setProEnumDic',
69
+ payload: {
70
+ ...dics,
71
+ ...dataSource,
72
+ ...cachedData
73
+ }
74
+ });
75
+ if (main) {
76
+ setTimeout(() => {
77
+ window?.eventCenter?.publish('pro-enum-event', cachedData);
78
+ logDebug(locale?.ProEnum?.mainInitByCache);
79
+ }, 10000);
80
+ }
81
+ fromCacheRef.current = null;
82
+ return res;
83
+ }
39
84
  let response = res.data;
40
85
  if (transformResponse && typeof transformResponse === 'function') {
41
86
  response = await transformResponse(res.data);
@@ -97,40 +142,18 @@ const useEnumRequest = (props, dispatch) => {
97
142
  });
98
143
  if (main) {
99
144
  setTimeout(() => {
100
- window?.eventCenter?.publish('zat-design-pro-component-event', res.data);
145
+ window?.eventCenter?.publish('pro-enum-event', res.data);
101
146
  logDebug(locale?.ProEnum?.mainInitByRequest);
102
147
  }, 10000);
103
148
  }
104
149
  return res;
105
150
  },
106
- getCache: () => {
107
- // 支持异步读取
108
- const cachePromise = Promise.resolve(getEnumData(storage, cacheKey) || {
109
- data: {}
110
- });
111
-
112
- // 对于同步存储,直接返回;对于异步存储,返回 Promise
151
+ getCache: params => {
113
152
  if (storage === 'indexedDB') {
114
- return cachePromise.then(res => {
115
- dispatch({
116
- type: 'setProEnumDic',
117
- payload: {
118
- ...dics,
119
- ...dataSource,
120
- ...res?.data
121
- }
122
- });
123
- if (main) {
124
- setTimeout(() => {
125
- window?.eventCenter?.publish('zat-design-pro-component-event', res.data);
126
- logDebug(locale?.ProEnum?.mainInitByCache);
127
- }, 10000);
128
- }
129
- return res;
130
- });
153
+ return undefined;
131
154
  }
132
155
 
133
- // 同步存储的处理
156
+ // 同步存储的处理(原始逻辑)
134
157
  const res = getEnumData(storage, cacheKey) || {
135
158
  data: {}
136
159
  };
@@ -144,7 +167,7 @@ const useEnumRequest = (props, dispatch) => {
144
167
  });
145
168
  if (main) {
146
169
  setTimeout(() => {
147
- window?.eventCenter?.publish('zat-design-pro-component-event', res.data);
170
+ window?.eventCenter?.publish('pro-enum-event', res.data);
148
171
  logDebug(locale?.ProEnum?.mainInitByCache);
149
172
  }, 10000);
150
173
  }
@@ -210,7 +233,7 @@ const useEnumRequest = (props, dispatch) => {
210
233
  ...cacheData.data
211
234
  }
212
235
  });
213
- } else if (dataSource && Object.keys(dataSource)) {
236
+ } else if (dataSource && Object.keys(dataSource).length > 0) {
214
237
  // 子系统也可能会有 dataSource
215
238
  dispatch({
216
239
  type: 'setProEnumDic',
@@ -233,16 +256,13 @@ const useEnumRequest = (props, dispatch) => {
233
256
  if (requestRefresh) {
234
257
  window.localStorage.removeItem(cacheKey);
235
258
  window.sessionStorage.removeItem(cacheKey);
236
- // 清除 IndexedDB
237
259
  if (storage === 'indexedDB') {
238
260
  await removeEnumData('indexedDB', cacheKey);
239
261
  }
240
262
  }
241
263
  enumRes.run(params);
242
-
243
- // TODO 这段代码目前看起来是没啥用的、没起到作用
244
264
  mergeData();
245
- } else if (Object.keys(dataSource)) {
265
+ } else if (dataSource && Object.keys(dataSource).length > 0) {
246
266
  const res = await Promise.resolve(getEnumData(storage, cacheKey) || {
247
267
  data: {}
248
268
  });
@@ -283,15 +303,15 @@ const useEnumRequest = (props, dispatch) => {
283
303
  };
284
304
  useEffect(() => {
285
305
  if (main) {
286
- window?.eventCenter?.publish('zat-design-pro-component-event', {});
306
+ window?.eventCenter?.publish('pro-enum-event', {});
287
307
  logDebug(locale?.ProEnum?.mainInitOnce);
288
308
  }
289
309
  if (!main && share) {
290
- window?.eventCenter?.subscribe('zat-design-pro-component-event', shareProEnumDic);
310
+ window?.eventCenter?.subscribe('pro-enum-event', shareProEnumDic);
291
311
  logDebug(locale?.ProEnum?.sonInitEvent);
292
312
  }
293
313
  return () => {
294
- window?.eventCenter?.unsubscribe('zat-design-pro-component-event', shareProEnumDic);
314
+ window?.eventCenter?.unsubscribe('pro-enum-event', shareProEnumDic);
295
315
  };
296
316
  }, []);
297
317
  return enumRes;
@@ -75,33 +75,35 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
75
75
  confirm?: boolean | import("antd").ModalFuncProps | import("../../../render/propsType").FunctionArgs<any, boolean | import("antd").ModalFuncProps>;
76
76
  show?: boolean | ReactiveFunction<any, boolean>;
77
77
  component?: React.ReactNode | ReactiveFunction<any, React.ReactNode>;
78
- className?: string;
79
- style?: React.CSSProperties;
78
+ onReset?: () => void;
80
79
  trim?: boolean;
81
80
  normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
82
81
  children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
82
+ className?: string;
83
+ status?: "" | "warning" | "error" | "success" | "validating";
83
84
  hidden?: boolean;
84
85
  id?: string;
85
- onReset?: () => void;
86
- prefixCls?: string;
87
- rootClassName?: string;
88
- vertical?: boolean;
86
+ style?: React.CSSProperties;
89
87
  htmlFor?: string;
90
- layout?: import("antd/es/form/Form").FormItemLayout;
91
- help?: React.ReactNode;
92
- preserve?: boolean;
88
+ prefixCls?: string;
93
89
  trigger?: string;
94
90
  isView?: boolean;
95
- status?: "" | "warning" | "error" | "success" | "validating";
91
+ rootClassName?: string;
92
+ getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
93
+ vertical?: boolean;
94
+ desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
96
95
  validateTrigger?: string | false | string[];
97
- colon?: boolean;
96
+ preserve?: boolean;
97
+ clearNotShow?: boolean;
98
98
  labelAlign?: import("antd/es/form/interface").FormLabelAlign;
99
+ colon?: boolean;
100
+ layout?: import("antd/es/form/Form").FormItemLayout;
99
101
  labelCol?: import("antd").ColProps;
102
+ wrapperCol?: import("antd").ColProps;
100
103
  getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
101
104
  shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
102
105
  validateDebounce?: number;
103
106
  valuePropName?: string;
104
- getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
105
107
  messageVariables?: Record<string, string>;
106
108
  initialValue?: any;
107
109
  onMetaChange?: (meta: import("@rc-component/form/lib/Field").MetaEvent) => void;
@@ -112,7 +114,7 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
112
114
  icons: import("antd/es/form/FormItem").FeedbackIcons;
113
115
  };
114
116
  validateStatus?: "" | "warning" | "error" | "success" | "validating";
115
- wrapperCol?: import("antd").ColProps;
117
+ help?: React.ReactNode;
116
118
  fieldId?: string;
117
119
  valueType?: import("../../../render/propsType").ProFormValueType;
118
120
  switchValue?: [any, any];
@@ -125,8 +127,6 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
125
127
  upperCase?: boolean;
126
128
  toISOString?: boolean;
127
129
  toCSTString?: boolean;
128
- clearNotShow?: boolean;
129
- desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
130
130
  name: any;
131
131
  dependencies: any[];
132
132
  tooltip: string | {
@@ -141,7 +141,7 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
141
141
  * 创建组件属性
142
142
  */
143
143
  export declare const createComponentProps: (column: FlexibleGroupColumnType, formItemProps: any) => {
144
- componentProps: import("lodash").Omit<any, "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow" | "precision">;
144
+ componentProps: import("lodash").Omit<any, "format" | "clearNotShow" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "precision">;
145
145
  formItemTransform: {
146
146
  getValueProps: any;
147
147
  normalize: any;
@@ -227,6 +227,16 @@ const ProForm = (props, ref) => {
227
227
  labelAlign: labelAlign ?? config.labelAlign ?? 'left',
228
228
  onValuesChange: handleValuesChange,
229
229
  onFinish: handleFinish,
230
+ onFinishFailed: ({
231
+ errorFields
232
+ }) => {
233
+ if (scrollToError && errorFields?.length) {
234
+ form.scrollToField(errorFields[0]?.name, {
235
+ block: 'center',
236
+ behavior: 'smooth'
237
+ });
238
+ }
239
+ },
230
240
  initialValues: _initialValues,
231
241
  children: [/*#__PURE__*/_jsxs(Row, {
232
242
  gutter: 24,
@@ -25,7 +25,8 @@ const ProStepItem = ({
25
25
  const {
26
26
  register,
27
27
  collapse,
28
- lazyLoad: globalLazyLoad
28
+ lazyLoad: globalLazyLoad,
29
+ targetOffset
29
30
  } = useStep();
30
31
  const lazyLoad = stepLazyLoad ?? globalLazyLoad;
31
32
  useEffect(() => {
@@ -60,6 +61,9 @@ const ProStepItem = ({
60
61
  return /*#__PURE__*/_jsx("div", {
61
62
  className: "pro-step-item",
62
63
  id: id,
64
+ style: {
65
+ scrollMarginTop: targetOffset ? `${targetOffset}px` : undefined
66
+ },
63
67
  children: /*#__PURE__*/_jsx(ProCollapse, {
64
68
  title: title,
65
69
  icon: true,
@@ -83,6 +87,9 @@ const ProStepItem = ({
83
87
  return /*#__PURE__*/_jsx("div", {
84
88
  className: "pro-step-item",
85
89
  id: id,
90
+ style: {
91
+ scrollMarginTop: targetOffset ? `${targetOffset}px` : undefined
92
+ },
86
93
  children: renderChildren()
87
94
  });
88
95
  };
@@ -27,7 +27,8 @@ const ProStep = ({
27
27
  const ids = Object.keys(registerMap.current);
28
28
  const {
29
29
  collapse = false,
30
- lazyLoad = false
30
+ lazyLoad = false,
31
+ targetOffset
31
32
  } = resetProps;
32
33
  const dataSource = useMemo(() => {
33
34
  if (resetProps?.dataSource) {
@@ -150,6 +151,7 @@ const ProStep = ({
150
151
  triggerTo,
151
152
  handleScroll,
152
153
  lazyLoad,
154
+ targetOffset,
153
155
  unNotify,
154
156
  source: 'ProStep'
155
157
  },
@@ -102,6 +102,8 @@ export interface ProStepContextType {
102
102
  handleScroll: (id: string, options?: ScrollOptions) => void;
103
103
  /** 懒加载配置 */
104
104
  lazyLoad?: boolean | any;
105
+ /** 滚动偏移量 */
106
+ targetOffset?: number;
105
107
  /** 取消注册函数 */
106
108
  unNotify: (keys: string | string[]) => void;
107
109
  /** 来源 */
@@ -1,5 +1,6 @@
1
1
  import _pick from "lodash/pick";
2
2
  import _debounce from "lodash/debounce";
3
+ import scrollIntoView from 'scroll-into-view-if-needed';
3
4
  /**
4
5
  * 滚动到错误位置, 延迟200ms解决ProForm错误还未生成
5
6
  */
@@ -7,9 +8,10 @@ export const handleScrollError = dom => {
7
8
  setTimeout(() => {
8
9
  const errorDom = dom || document.querySelector('[class*="form-item-has-error"]');
9
10
  if (errorDom) {
10
- errorDom.scrollIntoView({
11
+ scrollIntoView(errorDom, {
11
12
  behavior: 'smooth',
12
- block: 'center'
13
+ block: 'center',
14
+ scrollMode: 'if-needed'
13
15
  });
14
16
  }
15
17
  }, 200);
@@ -25,7 +27,6 @@ export const handleScroll = (id, options) => {
25
27
  targetOffset = 0,
26
28
  scrollToError
27
29
  } = options || {};
28
- if (!scrollToError) return;
29
30
  const dom = document.querySelector(`#${id}`);
30
31
  if (dom) {
31
32
  // 查找指定id下的错误表单项
@@ -36,10 +37,10 @@ export const handleScroll = (id, options) => {
36
37
  } else {
37
38
  // 如果没有错误表单项,则滚动到指定元素位置
38
39
  setTimeout(_debounce(() => {
39
- const rect = dom.getBoundingClientRect();
40
- window.scrollTo({
41
- top: window.scrollY + rect.top - targetOffset,
42
- behavior: 'smooth'
40
+ scrollIntoView(dom, {
41
+ behavior: 'smooth',
42
+ block: 'start',
43
+ scrollMode: 'if-needed'
43
44
  });
44
45
  }, 100), 0);
45
46
  }
@@ -135,6 +135,9 @@ const ProTools = ({
135
135
  }, {
136
136
  color: '#A00F20',
137
137
  active: false
138
+ }, {
139
+ color: '#31AF96',
140
+ active: false
138
141
  }]);
139
142
  onReset();
140
143
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "4.3.3-beta.1",
3
+ "version": "4.3.3",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "es",