@zat-design/sisyphus-react 4.3.4 → 4.3.5-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.
@@ -198,9 +198,7 @@ function useEnum(codes, value, compose) {
198
198
  const options = {};
199
199
  codes.forEach(code => {
200
200
  const values = catchData?.data?.[code];
201
- if (Array.isArray(values) && values.length) {
202
- options[code] = values;
203
- }
201
+ options[code] = Array.isArray(values) ? values : [];
204
202
  });
205
203
  return options;
206
204
  }
@@ -64,13 +64,14 @@ const useEnumRequest = (props, dispatch) => {
64
64
  // 缓存命中时跳过 transformResponse 和重复处理,直接 dispatch
65
65
  if (fromCacheRef.current) {
66
66
  const cachedData = fromCacheRef.current;
67
+ const mergedPayload = {
68
+ ...dics,
69
+ ...cachedData,
70
+ ...dataSource
71
+ };
67
72
  dispatch({
68
73
  type: 'setProEnumDic',
69
- payload: {
70
- ...dics,
71
- ...dataSource,
72
- ...cachedData
73
- }
74
+ payload: mergedPayload
74
75
  });
75
76
  if (main) {
76
77
  setTimeout(() => {
@@ -132,13 +133,14 @@ const useEnumRequest = (props, dispatch) => {
132
133
  await Promise.resolve(setEnumData(storage, cacheKey, res));
133
134
 
134
135
  // 同步数据到全局
136
+ const mergedPayload = {
137
+ ...dics,
138
+ ...res.data,
139
+ ...dataSource
140
+ };
135
141
  dispatch({
136
142
  type: 'setProEnumDic',
137
- payload: {
138
- ...dics,
139
- ...dataSource,
140
- ...res.data
141
- }
143
+ payload: mergedPayload
142
144
  });
143
145
  if (main) {
144
146
  setTimeout(() => {
@@ -157,13 +159,14 @@ const useEnumRequest = (props, dispatch) => {
157
159
  const res = getEnumData(storage, cacheKey) || {
158
160
  data: {}
159
161
  };
162
+ const mergedPayload = {
163
+ ...dics,
164
+ ...res?.data,
165
+ ...dataSource
166
+ };
160
167
  dispatch({
161
168
  type: 'setProEnumDic',
162
- payload: {
163
- ...dics,
164
- ...dataSource,
165
- ...res?.data
166
- }
169
+ payload: mergedPayload
167
170
  });
168
171
  if (main) {
169
172
  setTimeout(() => {
@@ -229,18 +232,25 @@ const useEnumRequest = (props, dispatch) => {
229
232
  type: 'setProEnumDic',
230
233
  payload: {
231
234
  ...dics,
232
- ...dataSource,
233
- ...cacheData.data
235
+ ...cacheData.data,
236
+ ...dataSource
234
237
  }
235
238
  });
236
239
  } else if (dataSource && Object.keys(dataSource).length > 0) {
237
- // 子系统也可能会有 dataSource
240
+ // 子系统也可能会有 dataSource,并需要同步写入缓存
241
+ const mergedPayload = {
242
+ ...dics,
243
+ ...cacheData.data,
244
+ ...dataSource
245
+ };
246
+ await Promise.resolve(setEnumData(storage, cacheKey, {
247
+ ...cacheData,
248
+ data: mergedPayload,
249
+ time: Date.now()
250
+ }));
238
251
  dispatch({
239
252
  type: 'setProEnumDic',
240
- payload: {
241
- ...dics,
242
- ...dataSource
243
- }
253
+ payload: mergedPayload
244
254
  });
245
255
  }
246
256
  }
@@ -266,12 +276,18 @@ const useEnumRequest = (props, dispatch) => {
266
276
  const res = await Promise.resolve(getEnumData(storage, cacheKey) || {
267
277
  data: {}
268
278
  });
279
+ const mergedData = {
280
+ ...res?.data,
281
+ ...dataSource
282
+ };
283
+ await Promise.resolve(setEnumData(storage, cacheKey, {
284
+ ...res,
285
+ data: mergedData,
286
+ time: Date.now()
287
+ }));
269
288
  dispatch({
270
289
  type: 'setProEnumDic',
271
- payload: {
272
- ...dataSource,
273
- ...res?.data
274
- }
290
+ payload: mergedData
275
291
  });
276
292
  } else {
277
293
  const res = await Promise.resolve(getEnumData(storage, cacheKey) || {
@@ -1,4 +1,3 @@
1
- import _isNumber from "lodash/isNumber";
2
1
  import _omit from "lodash/omit";
3
2
  import _isArray from "lodash/isArray";
4
3
  import _isString from "lodash/isString";
@@ -36,7 +35,7 @@ const ProEnum = props => {
36
35
  const {
37
36
  viewEmpty
38
37
  } = otherProps || {};
39
- const _defalutValue = props?.defaultValue;
38
+ const _defaultValue = props?.defaultValue;
40
39
  const {
41
40
  isView: configIsView
42
41
  } = useFieldProps() || {};
@@ -68,8 +67,8 @@ const ProEnum = props => {
68
67
  fieldValue = 'value';
69
68
  }
70
69
 
71
- // 这种时候优先级最高、完全走自定义
72
- if (useRequest?.service && props.fieldNames) {
70
+ // 组件显式传入 fieldNames 时优先级最高,必须覆盖 clear 默认映射
71
+ if (props.fieldNames && Object.keys(props.fieldNames).length) {
73
72
  if (props.fieldNames?.label) label = props.fieldNames.label;
74
73
  if (props.fieldNames?.value) fieldValue = props.fieldNames.value;
75
74
  }
@@ -264,7 +263,7 @@ const ProEnum = props => {
264
263
  return _isFunction(props.optionRender) && record.length ? _optionRender() : labelList?.join(',');
265
264
  };
266
265
  if (_isView) {
267
- const __value = value || _defalutValue;
266
+ const __value = value ?? _defaultValue;
268
267
  if (Array.isArray(__value)) {
269
268
  return /*#__PURE__*/_jsx(Container, {
270
269
  tooltip: true,
@@ -274,7 +273,7 @@ const ProEnum = props => {
274
273
  }
275
274
  return /*#__PURE__*/_jsx(Container, {
276
275
  viewEmpty: viewEmpty,
277
- children: __value || _isNumber(__value) ? transToLabel([__value]) : null
276
+ children: __value != null ? transToLabel([__value]) : null
278
277
  });
279
278
  }
280
279
  return /*#__PURE__*/_jsx(_Fragment, {
@@ -1,4 +1,4 @@
1
- import { getEnumData, setEnumData, cacheFieldNames, baseCacheKey } from "./index";
1
+ import { getEnumData, setEnumData, cacheFieldNames, baseCacheKey, normalizeEnumCacheData } from "./index";
2
2
 
3
3
  /**
4
4
  * 替换频繁枚举缓存数据的参数接口
@@ -16,9 +16,9 @@ async function replaceFrequentEnumCacheAsync(params) {
16
16
  fieldNames,
17
17
  clear
18
18
  } = params;
19
- const cacheData = await Promise.resolve(getEnumData(storage, cacheKey) || {
19
+ const cacheData = normalizeEnumCacheData(await Promise.resolve(getEnumData(storage, cacheKey) || {
20
20
  data: {}
21
- });
21
+ }));
22
22
 
23
23
  // 确保cacheData.data存在
24
24
  if (!cacheData.data) {
@@ -40,8 +40,9 @@ async function replaceFrequentEnumCacheAsync(params) {
40
40
  cacheData.time = Date.now();
41
41
  }
42
42
  });
43
- await Promise.resolve(setEnumData(storage, cacheKey, cacheData));
44
- return cacheData;
43
+ const normalizedCacheData = normalizeEnumCacheData(cacheData);
44
+ await Promise.resolve(setEnumData(storage, cacheKey, normalizedCacheData));
45
+ return normalizedCacheData;
45
46
  }
46
47
 
47
48
  /**
@@ -86,9 +87,9 @@ export function replaceFrequentEnumCache(params) {
86
87
  const cacheDataResult = getEnumData(storage, cacheKey);
87
88
  // getEnumData 对于非 indexedDB 返回同步值,对于 indexedDB 返回 Promise
88
89
  // 这里 storage 不是 indexedDB,所以是同步值
89
- const cacheData = cacheDataResult || {
90
+ const cacheData = normalizeEnumCacheData(cacheDataResult || {
90
91
  data: {}
91
- };
92
+ });
92
93
 
93
94
  // 确保cacheData.data存在
94
95
  if (!cacheData.data) {
@@ -110,8 +111,9 @@ export function replaceFrequentEnumCache(params) {
110
111
  cacheData.time = Date.now();
111
112
  }
112
113
  });
113
- setEnumData(storage, cacheKey, cacheData);
114
- return cacheData;
114
+ const normalizedCacheData = normalizeEnumCacheData(cacheData);
115
+ setEnumData(storage, cacheKey, normalizedCacheData);
116
+ return normalizedCacheData;
115
117
  }
116
118
 
117
119
  /**
@@ -43,7 +43,7 @@ function resolveEnumResult(allData, params) {
43
43
  if (codes) {
44
44
  return codes.reduce((acc, c) => {
45
45
  const opts = allData[c];
46
- if (Array.isArray(opts) && opts.length) acc[c] = opts;
46
+ acc[c] = Array.isArray(opts) ? opts : [];
47
47
  return acc;
48
48
  }, {});
49
49
  }
@@ -5,10 +5,15 @@ export declare const baseCacheKey = "zat-design-pro-component-cacheKey";
5
5
  export declare const baseStorage: StorageType;
6
6
  /** 模块级内存缓存,key 为 cacheKey,替代原单例 baseEnumStorage 变量 */
7
7
  export declare const enumMemoryCache: Map<string, any>;
8
+ /**
9
+ * 从 IndexedDB 读取数据
10
+ */
8
11
  interface EnumRes {
9
12
  data: Record<string, DataOptionType[]>;
13
+ dataLength?: number;
10
14
  [key: string]: any;
11
15
  }
16
+ export declare function normalizeEnumCacheData(cacheData: any): EnumRes;
12
17
  /**
13
18
  * 获取枚举数据
14
19
  * @param storage
@@ -43,7 +48,7 @@ export declare function getEnumDataSync(storage: StorageType, cacheKey: string):
43
48
  * @param code
44
49
  * @returns
45
50
  */
46
- export declare function hasEnumList(storage: StorageType, cacheKey: any, code: string): false | DataOptionType[];
51
+ export declare function hasEnumList(storage: StorageType, cacheKey: string, code: string): false | DataOptionType[];
47
52
  /**
48
53
  * 判断是否是对象
49
54
  * @param obj
@@ -57,7 +62,7 @@ export declare function isObject(obj: any): boolean;
57
62
  * @param cacheKey
58
63
  * @param responseData
59
64
  */
60
- export declare function mergeCacheData(storage: string, code: string, cacheKey: string, responseData: any): Promise<void>;
65
+ export declare function mergeCacheData(storage: StorageType, code: string, cacheKey: string, responseData: any): Promise<void>;
61
66
  /**
62
67
  * diff code 差异
63
68
  * @param cacheCodes
@@ -33,6 +33,24 @@ async function checkIndexedDBSupport() {
33
33
  /**
34
34
  * 从 IndexedDB 读取数据
35
35
  */
36
+
37
+ function getEnumCodeLength(data) {
38
+ if (!data || typeof data !== 'object' || Array.isArray(data)) {
39
+ return 0;
40
+ }
41
+ return Object.keys(data).length;
42
+ }
43
+ export function normalizeEnumCacheData(cacheData) {
44
+ const rawData = cacheData?.data && typeof cacheData.data === 'object' && !Array.isArray(cacheData.data) ? cacheData.data : {};
45
+ const data = {
46
+ ...rawData
47
+ };
48
+ return {
49
+ ...(cacheData || {}),
50
+ data,
51
+ dataLength: getEnumCodeLength(data)
52
+ };
53
+ }
36
54
  async function getFromIndexedDB(key) {
37
55
  const available = await checkIndexedDBSupport();
38
56
  if (!available) {
@@ -61,7 +79,8 @@ async function setToIndexedDB(key, value) {
61
79
  if (!available) {
62
80
  return;
63
81
  }
64
- if (!Object.keys(value?.data || {}).length) {
82
+ const normalizedValue = normalizeEnumCacheData(value);
83
+ if (!Object.keys(normalizedValue.data || {}).length) {
65
84
  return;
66
85
  }
67
86
  try {
@@ -69,12 +88,13 @@ async function setToIndexedDB(key, value) {
69
88
  const {
70
89
  params,
71
90
  ...cleanValue
72
- } = value;
91
+ } = normalizedValue;
73
92
  await set(key, cleanValue);
74
93
  } catch (error) {
75
94
  console.warn('ProEnum: IndexedDB write failed:', error);
76
95
  }
77
96
  }
97
+
78
98
  /**
79
99
  * 获取枚举数据
80
100
  * @param storage
@@ -124,21 +144,22 @@ export function getEnumData(storage, cacheKey) {
124
144
  * @param data
125
145
  */
126
146
  export function setEnumData(storage, cacheKey, data) {
127
- if (!Object.keys(data?.data || {}).length) {
147
+ const normalizedData = normalizeEnumCacheData(data);
148
+ if (!Object.keys(normalizedData.data || {}).length) {
128
149
  return;
129
150
  }
130
151
 
131
152
  // IndexedDB:同步写内存缓存,异步持久化到 IndexedDB
132
153
  if (storage === 'indexedDB') {
133
- enumMemoryCache.set(cacheKey, data);
134
- return setToIndexedDB(cacheKey, data);
154
+ enumMemoryCache.set(cacheKey, normalizedData);
155
+ return setToIndexedDB(cacheKey, normalizedData);
135
156
  }
136
157
 
137
158
  // localStorage/sessionStorage 保持同步
138
159
  if (storage === 'localStorage') {
139
- window.localStorage.setItem(cacheKey, JSON.stringify(data));
160
+ window.localStorage.setItem(cacheKey, JSON.stringify(normalizedData));
140
161
  } else if (storage === 'sessionStorage') {
141
- window.sessionStorage.setItem(cacheKey, JSON.stringify(data));
162
+ window.sessionStorage.setItem(cacheKey, JSON.stringify(normalizedData));
142
163
  }
143
164
  }
144
165
 
@@ -148,6 +169,7 @@ export function setEnumData(storage, cacheKey, data) {
148
169
  * @param cacheKey
149
170
  */
150
171
  export async function removeEnumData(storage, cacheKey) {
172
+ enumMemoryCache.delete(cacheKey);
151
173
  if (storage === 'indexedDB') {
152
174
  const available = await checkIndexedDBSupport();
153
175
  if (!available) {
@@ -228,20 +250,18 @@ export function isObject(obj) {
228
250
  * @param responseData
229
251
  */
230
252
  export async function mergeCacheData(storage, code, cacheKey, responseData) {
253
+ const buildNextCacheData = cacheData => {
254
+ const normalizedCacheData = normalizeEnumCacheData(cacheData);
255
+ normalizedCacheData.data[code] = responseData;
256
+ return normalizeEnumCacheData(normalizedCacheData);
257
+ };
231
258
  if (storage === 'indexedDB') {
232
- const cacheData = await getFromIndexedDB(cacheKey);
233
- if (cacheData && cacheData.data) {
234
- cacheData.data[code] = responseData;
235
- }
236
- await setToIndexedDB(cacheKey, cacheData);
259
+ const cacheData = enumMemoryCache.has(cacheKey) ? enumMemoryCache.get(cacheKey) : await getFromIndexedDB(cacheKey);
260
+ await Promise.resolve(setEnumData('indexedDB', cacheKey, buildNextCacheData(cacheData)));
237
261
  } else {
238
262
  const cacheStorage = storage === 'localStorage' ? 'localStorage' : 'sessionStorage';
239
263
  const cacheData = JSON.parse(window?.[cacheStorage]?.getItem(cacheKey) || '{}');
240
- // 合并枚举到总数据源上
241
- if (cacheData && cacheData.data) {
242
- cacheData.data[code] = responseData;
243
- }
244
- window?.[cacheStorage]?.setItem(cacheKey, JSON.stringify(cacheData));
264
+ await Promise.resolve(setEnumData(cacheStorage, cacheKey, buildNextCacheData(cacheData)));
245
265
  }
246
266
  }
247
267
 
@@ -148,7 +148,7 @@ const InputNumber = props => {
148
148
  }
149
149
  }
150
150
  }
151
- return [_min ?? min ?? valueProps?.min, _max ?? max ?? valueProps?.max];
151
+ return [_min ?? min ?? valueProps?.min ?? initialConfig?.min, _max ?? max ?? valueProps?.max ?? initialConfig?.max];
152
152
  }, [range, min, max, rest.precision]);
153
153
  const _className = classNames({
154
154
  'full-form-item': true,
@@ -75,39 +75,33 @@ 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
- trigger?: string;
79
- style?: React.CSSProperties;
78
+ id?: string;
79
+ className?: string;
80
80
  hidden?: boolean;
81
- layout?: import("antd/es/form/Form").FormItemLayout;
82
- help?: React.ReactNode;
83
- vertical?: boolean;
84
- preserve?: boolean;
81
+ style?: React.CSSProperties;
85
82
  children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
86
- isView?: boolean;
87
- trim?: boolean;
88
- normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
89
- className?: string;
90
- status?: "" | "warning" | "error" | "success" | "validating";
83
+ onReset?: () => void;
91
84
  prefixCls?: string;
92
85
  rootClassName?: string;
93
- id?: string;
94
- onReset?: () => void;
95
- getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
96
- desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
97
- validateTrigger?: string | false | string[];
98
- clearNotShow?: boolean;
99
- labelAlign?: import("antd/es/form/interface").FormLabelAlign;
86
+ status?: "" | "warning" | "error" | "success" | "validating";
87
+ vertical?: boolean;
88
+ isView?: boolean;
100
89
  colon?: boolean;
101
- labelCol?: import("antd").ColProps;
102
- wrapperCol?: import("antd").ColProps;
103
90
  htmlFor?: string;
91
+ labelAlign?: import("antd/es/form/interface").FormLabelAlign;
92
+ labelCol?: import("antd").ColProps;
104
93
  getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
94
+ normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
105
95
  shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
96
+ trigger?: string;
97
+ validateTrigger?: string | false | string[];
106
98
  validateDebounce?: number;
107
99
  valuePropName?: string;
100
+ getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
108
101
  messageVariables?: Record<string, string>;
109
102
  initialValue?: any;
110
103
  onMetaChange?: (meta: import("@rc-component/form/lib/Field").MetaEvent) => void;
104
+ preserve?: boolean;
111
105
  isListField?: boolean;
112
106
  isList?: boolean;
113
107
  noStyle?: boolean;
@@ -115,6 +109,9 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
115
109
  icons: import("antd/es/form/FormItem").FeedbackIcons;
116
110
  };
117
111
  validateStatus?: "" | "warning" | "error" | "success" | "validating";
112
+ layout?: import("antd/es/form/Form").FormItemLayout;
113
+ wrapperCol?: import("antd").ColProps;
114
+ help?: React.ReactNode;
118
115
  fieldId?: string;
119
116
  valueType?: import("../../../render/propsType").ProFormValueType;
120
117
  switchValue?: [any, any];
@@ -124,9 +121,12 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
124
121
  index?: number;
125
122
  }) => string | React.ReactElement<any, any>;
126
123
  viewType?: import("../../../render/propsType").ViewType;
124
+ trim?: boolean;
127
125
  upperCase?: boolean;
128
126
  toISOString?: boolean;
129
127
  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" | "clearNotShow" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "precision">;
144
+ componentProps: import("lodash").Omit<any, "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow" | "precision">;
145
145
  formItemTransform: {
146
146
  getValueProps: any;
147
147
  normalize: any;
@@ -22,7 +22,7 @@ const ConfirmWrapper = props => {
22
22
  name,
23
23
  index,
24
24
  listName
25
- } = ProForm.useFieldProps();
25
+ } = ProForm.useFieldProps() || {};
26
26
  const handleChange = async (value, ...other) => {
27
27
  const _value = value?.target ? value.target.value : value;
28
28
  const confirmProps = _isFunction(confirm) ? await confirm(value, form.getFieldsValue(), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "4.3.4",
3
+ "version": "4.3.5-beta.3",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "es",