@zat-design/sisyphus-react 4.0.12 → 4.0.13

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.
@@ -15,6 +15,9 @@ import { useProConfig } from "../../ProConfigProvider";
15
15
  import { getEnumData } from "../utils";
16
16
  var baseEnumStorage = (_ref = window.localStorage.getItem('zat-design-pro-component-cacheKey') && JSON.parse(window.localStorage.getItem('zat-design-pro-component-cacheKey'))) !== null && _ref !== void 0 ? _ref : null;
17
17
 
18
+ // 模块级缓存,用于存储正在进行的 IndexedDB 读取 Promise,避免重复读取
19
+ var indexedDBLoadingCache = new Map();
20
+
18
21
  /**
19
22
  * input code output [DataOption[],getEnumLabel]
20
23
  * @param code
@@ -59,7 +62,9 @@ function useEnum(codes, value, compose) {
59
62
  _ref2$fieldNames = _ref2.fieldNames,
60
63
  fieldNames = _ref2$fieldNames === void 0 ? {} : _ref2$fieldNames,
61
64
  _ref2$clear = _ref2.clear,
62
- clear = _ref2$clear === void 0 ? true : _ref2$clear;
65
+ clear = _ref2$clear === void 0 ? true : _ref2$clear,
66
+ _ref2$dics = _ref2.dics,
67
+ dics = _ref2$dics === void 0 ? {} : _ref2$dics;
63
68
 
64
69
  // 存在子应用自管理枚举时,需要根据其指定的cacheKey进行缓存
65
70
  if (cacheKey !== 'zat-design-pro-component-cacheKey') {
@@ -68,6 +73,12 @@ function useEnum(codes, value, compose) {
68
73
 
69
74
  // 使用 state 来存储异步加载的数据
70
75
  var _useState = useState(() => {
76
+ // 优先使用全局状态中的 dics 数据(如果存在)
77
+ if (storage === 'indexedDB' && dics && Object.keys(dics).length > 0) {
78
+ return {
79
+ data: dics
80
+ };
81
+ }
71
82
  // 初始化:对于同步存储,直接返回数据;对于 IndexedDB,返回空数据
72
83
  if (storage === 'indexedDB') {
73
84
  return {
@@ -82,27 +93,76 @@ function useEnum(codes, value, compose) {
82
93
  enumData = _useState2[0],
83
94
  setEnumData = _useState2[1];
84
95
 
96
+ // 监听全局状态中的 dics 变化,优先使用 dics 数据
97
+ useEffect(() => {
98
+ if (storage === 'indexedDB' && dics && Object.keys(dics).length > 0) {
99
+ setEnumData(prevData => {
100
+ // 只有当 dics 有数据且与当前数据不同时才更新
101
+ if (JSON.stringify(dics) !== JSON.stringify(prevData === null || prevData === void 0 ? void 0 : prevData.data)) {
102
+ return {
103
+ data: dics
104
+ };
105
+ }
106
+ return prevData;
107
+ });
108
+ }
109
+ }, [storage, cacheKey, dics]);
110
+
85
111
  // 异步加载 IndexedDB 数据
86
112
  useEffect(() => {
87
113
  if (storage === 'indexedDB') {
88
- Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage)).then(data => {
89
- setEnumData(prevData => {
90
- if (data && JSON.stringify(data) !== JSON.stringify(prevData)) {
91
- baseEnumStorage = data;
92
- return data || {
93
- data: {}
94
- };
95
- }
96
- return prevData;
97
- });
98
- }).catch(() => {
99
- // 错误已在 getEnumData 中处理,这里只设置空数据
100
- setEnumData({
101
- data: {}
114
+ // 使用模块级缓存避免重复读取
115
+ var loadPromise = indexedDBLoadingCache.get(cacheKey);
116
+ if (!loadPromise) {
117
+ loadPromise = Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage)).then(data => {
118
+ // 读取完成后,从缓存中移除
119
+ indexedDBLoadingCache.delete(cacheKey);
120
+ return data;
121
+ }).catch(error => {
122
+ // 读取失败后,从缓存中移除
123
+ indexedDBLoadingCache.delete(cacheKey);
124
+ // 错误已在 getEnumData 中处理,这里返回空数据
125
+ return {
126
+ data: {}
127
+ };
102
128
  });
129
+ indexedDBLoadingCache.set(cacheKey, loadPromise);
130
+ }
131
+ loadPromise.then(data => {
132
+ // 如果数据为空或无效,且当前 enumData 也是空的,尝试重新读取
133
+ if ((!data || !data.data || Object.keys(data.data).length === 0) && (!enumData || !enumData.data || Object.keys(enumData.data).length === 0)) {
134
+ // 延迟重试,给 IndexedDB 一些时间
135
+ setTimeout(() => {
136
+ // 清除缓存,允许重新读取
137
+ indexedDBLoadingCache.delete(cacheKey);
138
+ Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage)).then(retryData => {
139
+ if (retryData && retryData.data && Object.keys(retryData.data).length > 0) {
140
+ setEnumData(prevData => {
141
+ if (retryData && JSON.stringify(retryData) !== JSON.stringify(prevData)) {
142
+ baseEnumStorage = retryData;
143
+ return retryData;
144
+ }
145
+ return prevData;
146
+ });
147
+ }
148
+ }).catch(() => {
149
+ // 重试失败,保持空数据
150
+ });
151
+ }, 100);
152
+ } else {
153
+ setEnumData(prevData => {
154
+ if (data && JSON.stringify(data) !== JSON.stringify(prevData)) {
155
+ baseEnumStorage = data;
156
+ return data || {
157
+ data: {}
158
+ };
159
+ }
160
+ return prevData;
161
+ });
162
+ }
103
163
  });
104
164
  }
105
- }, [storage, cacheKey]);
165
+ }, [storage, cacheKey, enumData]);
106
166
  var catchData = storage === 'indexedDB' ? enumData : getEnumData(storage, cacheKey, baseEnumStorage);
107
167
 
108
168
  // 默认枚举缓存数据(仅同步存储)
@@ -79,7 +79,12 @@ export interface ProEnumConfigType {
79
79
  * @description 字段别名
80
80
  * @default { label: 'label', value: 'value', children: 'children' }
81
81
  */
82
- fieldNames?: Record<'label' | 'value' | 'children', string>;
82
+ fieldNames?: {
83
+ label?: string;
84
+ value?: string;
85
+ children?: string;
86
+ [key: string]: string | undefined;
87
+ };
83
88
  /**
84
89
  * @description 缓存的key、默认 zat-design-pro-component-cacheKey
85
90
  * @default "zat-design-pro-component-cacheKey"
@@ -376,10 +376,12 @@ export function cacheFieldNames(fieldNames, dataSource) {
376
376
  restFieldNames = _objectWithoutProperties(fieldNames, _excluded);
377
377
  var result = {};
378
378
  Object.keys(restFieldNames).forEach(key => {
379
- if (![undefined, null].includes(dataSource[restFieldNames[key]])) {
380
- result[key] = dataSource[restFieldNames[key]];
381
- } else {
382
- result[key] = dataSource[key];
379
+ var sourceKey = restFieldNames[key];
380
+ var sourceVal = dataSource[sourceKey];
381
+ var fallbackVal = dataSource[key];
382
+ var val = ![undefined, null, ''].includes(sourceVal) ? sourceVal : fallbackVal;
383
+ if (![undefined, null, ''].includes(val)) {
384
+ result[key] = val;
383
385
  }
384
386
  });
385
387
  // 递归去对数据进行清洗
@@ -76,28 +76,28 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
76
76
  show?: boolean | ReactiveFunction<any, boolean>;
77
77
  component?: React.ReactNode | ReactiveFunction<any, React.ReactNode>;
78
78
  children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
79
+ isView?: boolean;
79
80
  id?: string;
80
81
  prefixCls?: string;
81
82
  className?: string;
82
83
  style?: React.CSSProperties;
83
84
  rootClassName?: string;
84
- status?: "" | "warning" | "error" | "success" | "validating";
85
- isView?: boolean;
86
- getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
87
85
  hidden?: boolean;
88
86
  onReset?: () => void;
87
+ status?: "" | "warning" | "error" | "success" | "validating";
89
88
  vertical?: boolean;
89
+ validateTrigger?: string | false | string[];
90
+ getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
90
91
  desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
91
- trim?: boolean;
92
- normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
92
+ valueType?: import("../../../render/propsType").ProFormValueType;
93
93
  colon?: boolean;
94
94
  htmlFor?: string;
95
95
  labelAlign?: import("antd/es/form/interface").FormLabelAlign;
96
96
  labelCol?: import("antd").ColProps;
97
97
  getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
98
+ normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
98
99
  shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
99
100
  trigger?: string;
100
- validateTrigger?: string | false | string[];
101
101
  validateDebounce?: number;
102
102
  valuePropName?: string;
103
103
  messageVariables?: Record<string, string>;
@@ -115,8 +115,6 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
115
115
  wrapperCol?: import("antd").ColProps;
116
116
  help?: React.ReactNode;
117
117
  fieldId?: string;
118
- toCSTString?: boolean;
119
- valueType?: import("../../../render/propsType").ProFormValueType;
120
118
  switchValue?: [any, any];
121
119
  viewRender?: (value: any, record: any, { form, index, namePath, }: {
122
120
  [key: string]: any;
@@ -124,8 +122,10 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
124
122
  index?: number;
125
123
  }) => string | React.ReactElement<any, any>;
126
124
  viewType?: import("../../../render/propsType").ViewType;
125
+ trim?: boolean;
127
126
  upperCase?: boolean;
128
127
  toISOString?: boolean;
128
+ toCSTString?: boolean;
129
129
  clearNotShow?: boolean;
130
130
  name: any;
131
131
  dependencies: any[];
@@ -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, "toCSTString" | "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "clearNotShow" | "precision">;
144
+ componentProps: import("lodash").Omit<any, "precision" | "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow">;
145
145
  formItemTransform: {
146
146
  getValueProps: any;
147
147
  normalize: any;
@@ -21,6 +21,9 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
21
21
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
22
  var baseEnumStorage = (_ref = window.localStorage.getItem('zat-design-pro-component-cacheKey') && JSON.parse(window.localStorage.getItem('zat-design-pro-component-cacheKey'))) !== null && _ref !== void 0 ? _ref : null;
23
23
 
24
+ // 模块级缓存,用于存储正在进行的 IndexedDB 读取 Promise,避免重复读取
25
+ var indexedDBLoadingCache = new Map();
26
+
24
27
  /**
25
28
  * input code output [DataOption[],getEnumLabel]
26
29
  * @param code
@@ -65,7 +68,9 @@ function useEnum(codes, value, compose) {
65
68
  _ref2$fieldNames = _ref2.fieldNames,
66
69
  fieldNames = _ref2$fieldNames === void 0 ? {} : _ref2$fieldNames,
67
70
  _ref2$clear = _ref2.clear,
68
- clear = _ref2$clear === void 0 ? true : _ref2$clear;
71
+ clear = _ref2$clear === void 0 ? true : _ref2$clear,
72
+ _ref2$dics = _ref2.dics,
73
+ dics = _ref2$dics === void 0 ? {} : _ref2$dics;
69
74
 
70
75
  // 存在子应用自管理枚举时,需要根据其指定的cacheKey进行缓存
71
76
  if (cacheKey !== 'zat-design-pro-component-cacheKey') {
@@ -74,6 +79,12 @@ function useEnum(codes, value, compose) {
74
79
 
75
80
  // 使用 state 来存储异步加载的数据
76
81
  var _useState = (0, _react.useState)(() => {
82
+ // 优先使用全局状态中的 dics 数据(如果存在)
83
+ if (storage === 'indexedDB' && dics && Object.keys(dics).length > 0) {
84
+ return {
85
+ data: dics
86
+ };
87
+ }
77
88
  // 初始化:对于同步存储,直接返回数据;对于 IndexedDB,返回空数据
78
89
  if (storage === 'indexedDB') {
79
90
  return {
@@ -88,27 +99,76 @@ function useEnum(codes, value, compose) {
88
99
  enumData = _useState2[0],
89
100
  setEnumData = _useState2[1];
90
101
 
102
+ // 监听全局状态中的 dics 变化,优先使用 dics 数据
103
+ (0, _react.useEffect)(() => {
104
+ if (storage === 'indexedDB' && dics && Object.keys(dics).length > 0) {
105
+ setEnumData(prevData => {
106
+ // 只有当 dics 有数据且与当前数据不同时才更新
107
+ if (JSON.stringify(dics) !== JSON.stringify(prevData === null || prevData === void 0 ? void 0 : prevData.data)) {
108
+ return {
109
+ data: dics
110
+ };
111
+ }
112
+ return prevData;
113
+ });
114
+ }
115
+ }, [storage, cacheKey, dics]);
116
+
91
117
  // 异步加载 IndexedDB 数据
92
118
  (0, _react.useEffect)(() => {
93
119
  if (storage === 'indexedDB') {
94
- Promise.resolve((0, _utils.getEnumData)(storage, cacheKey, baseEnumStorage)).then(data => {
95
- setEnumData(prevData => {
96
- if (data && JSON.stringify(data) !== JSON.stringify(prevData)) {
97
- baseEnumStorage = data;
98
- return data || {
99
- data: {}
100
- };
101
- }
102
- return prevData;
103
- });
104
- }).catch(() => {
105
- // 错误已在 getEnumData 中处理,这里只设置空数据
106
- setEnumData({
107
- data: {}
120
+ // 使用模块级缓存避免重复读取
121
+ var loadPromise = indexedDBLoadingCache.get(cacheKey);
122
+ if (!loadPromise) {
123
+ loadPromise = Promise.resolve((0, _utils.getEnumData)(storage, cacheKey, baseEnumStorage)).then(data => {
124
+ // 读取完成后,从缓存中移除
125
+ indexedDBLoadingCache.delete(cacheKey);
126
+ return data;
127
+ }).catch(error => {
128
+ // 读取失败后,从缓存中移除
129
+ indexedDBLoadingCache.delete(cacheKey);
130
+ // 错误已在 getEnumData 中处理,这里返回空数据
131
+ return {
132
+ data: {}
133
+ };
108
134
  });
135
+ indexedDBLoadingCache.set(cacheKey, loadPromise);
136
+ }
137
+ loadPromise.then(data => {
138
+ // 如果数据为空或无效,且当前 enumData 也是空的,尝试重新读取
139
+ if ((!data || !data.data || Object.keys(data.data).length === 0) && (!enumData || !enumData.data || Object.keys(enumData.data).length === 0)) {
140
+ // 延迟重试,给 IndexedDB 一些时间
141
+ setTimeout(() => {
142
+ // 清除缓存,允许重新读取
143
+ indexedDBLoadingCache.delete(cacheKey);
144
+ Promise.resolve((0, _utils.getEnumData)(storage, cacheKey, baseEnumStorage)).then(retryData => {
145
+ if (retryData && retryData.data && Object.keys(retryData.data).length > 0) {
146
+ setEnumData(prevData => {
147
+ if (retryData && JSON.stringify(retryData) !== JSON.stringify(prevData)) {
148
+ baseEnumStorage = retryData;
149
+ return retryData;
150
+ }
151
+ return prevData;
152
+ });
153
+ }
154
+ }).catch(() => {
155
+ // 重试失败,保持空数据
156
+ });
157
+ }, 100);
158
+ } else {
159
+ setEnumData(prevData => {
160
+ if (data && JSON.stringify(data) !== JSON.stringify(prevData)) {
161
+ baseEnumStorage = data;
162
+ return data || {
163
+ data: {}
164
+ };
165
+ }
166
+ return prevData;
167
+ });
168
+ }
109
169
  });
110
170
  }
111
- }, [storage, cacheKey]);
171
+ }, [storage, cacheKey, enumData]);
112
172
  var catchData = storage === 'indexedDB' ? enumData : (0, _utils.getEnumData)(storage, cacheKey, baseEnumStorage);
113
173
 
114
174
  // 默认枚举缓存数据(仅同步存储)
@@ -79,7 +79,12 @@ export interface ProEnumConfigType {
79
79
  * @description 字段别名
80
80
  * @default { label: 'label', value: 'value', children: 'children' }
81
81
  */
82
- fieldNames?: Record<'label' | 'value' | 'children', string>;
82
+ fieldNames?: {
83
+ label?: string;
84
+ value?: string;
85
+ children?: string;
86
+ [key: string]: string | undefined;
87
+ };
83
88
  /**
84
89
  * @description 缓存的key、默认 zat-design-pro-component-cacheKey
85
90
  * @default "zat-design-pro-component-cacheKey"
@@ -388,10 +388,12 @@ function cacheFieldNames(fieldNames, dataSource) {
388
388
  restFieldNames = _objectWithoutProperties(fieldNames, _excluded);
389
389
  var result = {};
390
390
  Object.keys(restFieldNames).forEach(key => {
391
- if (![undefined, null].includes(dataSource[restFieldNames[key]])) {
392
- result[key] = dataSource[restFieldNames[key]];
393
- } else {
394
- result[key] = dataSource[key];
391
+ var sourceKey = restFieldNames[key];
392
+ var sourceVal = dataSource[sourceKey];
393
+ var fallbackVal = dataSource[key];
394
+ var val = ![undefined, null, ''].includes(sourceVal) ? sourceVal : fallbackVal;
395
+ if (![undefined, null, ''].includes(val)) {
396
+ result[key] = val;
395
397
  }
396
398
  });
397
399
  // 递归去对数据进行清洗
@@ -76,28 +76,28 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
76
76
  show?: boolean | ReactiveFunction<any, boolean>;
77
77
  component?: React.ReactNode | ReactiveFunction<any, React.ReactNode>;
78
78
  children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
79
+ isView?: boolean;
79
80
  id?: string;
80
81
  prefixCls?: string;
81
82
  className?: string;
82
83
  style?: React.CSSProperties;
83
84
  rootClassName?: string;
84
- status?: "" | "warning" | "error" | "success" | "validating";
85
- isView?: boolean;
86
- getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
87
85
  hidden?: boolean;
88
86
  onReset?: () => void;
87
+ status?: "" | "warning" | "error" | "success" | "validating";
89
88
  vertical?: boolean;
89
+ validateTrigger?: string | false | string[];
90
+ getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
90
91
  desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
91
- trim?: boolean;
92
- normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
92
+ valueType?: import("../../../render/propsType").ProFormValueType;
93
93
  colon?: boolean;
94
94
  htmlFor?: string;
95
95
  labelAlign?: import("antd/es/form/interface").FormLabelAlign;
96
96
  labelCol?: import("antd").ColProps;
97
97
  getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
98
+ normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
98
99
  shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
99
100
  trigger?: string;
100
- validateTrigger?: string | false | string[];
101
101
  validateDebounce?: number;
102
102
  valuePropName?: string;
103
103
  messageVariables?: Record<string, string>;
@@ -115,8 +115,6 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
115
115
  wrapperCol?: import("antd").ColProps;
116
116
  help?: React.ReactNode;
117
117
  fieldId?: string;
118
- toCSTString?: boolean;
119
- valueType?: import("../../../render/propsType").ProFormValueType;
120
118
  switchValue?: [any, any];
121
119
  viewRender?: (value: any, record: any, { form, index, namePath, }: {
122
120
  [key: string]: any;
@@ -124,8 +122,10 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
124
122
  index?: number;
125
123
  }) => string | React.ReactElement<any, any>;
126
124
  viewType?: import("../../../render/propsType").ViewType;
125
+ trim?: boolean;
127
126
  upperCase?: boolean;
128
127
  toISOString?: boolean;
128
+ toCSTString?: boolean;
129
129
  clearNotShow?: boolean;
130
130
  name: any;
131
131
  dependencies: any[];
@@ -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, "toCSTString" | "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "clearNotShow" | "precision">;
144
+ componentProps: import("lodash").Omit<any, "precision" | "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow">;
145
145
  formItemTransform: {
146
146
  getValueProps: any;
147
147
  normalize: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "4.0.12",
3
+ "version": "4.0.13",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",