@zat-design/sisyphus-react 4.3.4-beta.2 → 4.3.5-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/es/ProEnum/hooks/useEnum.js +1 -3
- package/es/ProEnum/utils/frequentEnum.js +11 -9
- package/es/ProEnum/utils/getEnum.js +1 -1
- package/es/ProEnum/utils/index.d.ts +7 -2
- package/es/ProEnum/utils/index.js +37 -17
- package/es/ProForm/components/combination/Group/utils/index.d.ts +13 -13
- package/package.json +1 -1
|
@@ -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
|
-
|
|
202
|
-
options[code] = values;
|
|
203
|
-
}
|
|
201
|
+
options[code] = Array.isArray(values) ? values : [];
|
|
204
202
|
});
|
|
205
203
|
return options;
|
|
206
204
|
}
|
|
@@ -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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
114
|
-
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
-
} =
|
|
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
|
-
|
|
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,
|
|
134
|
-
return setToIndexedDB(cacheKey,
|
|
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(
|
|
160
|
+
window.localStorage.setItem(cacheKey, JSON.stringify(normalizedData));
|
|
140
161
|
} else if (storage === 'sessionStorage') {
|
|
141
|
-
window.sessionStorage.setItem(cacheKey, JSON.stringify(
|
|
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
|
-
|
|
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
|
|
|
@@ -75,29 +75,28 @@ 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;
|
|
80
|
-
hidden?: boolean;
|
|
81
|
-
layout?: import("antd/es/form/Form").FormItemLayout;
|
|
82
|
-
help?: React.ReactNode;
|
|
83
|
-
vertical?: boolean;
|
|
84
|
-
preserve?: boolean;
|
|
85
78
|
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
79
|
status?: "" | "warning" | "error" | "success" | "validating";
|
|
80
|
+
isView?: boolean;
|
|
81
|
+
id?: string;
|
|
91
82
|
prefixCls?: string;
|
|
83
|
+
className?: string;
|
|
84
|
+
style?: React.CSSProperties;
|
|
92
85
|
rootClassName?: string;
|
|
93
|
-
id?: string;
|
|
94
|
-
onReset?: () => void;
|
|
95
86
|
getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
|
|
87
|
+
trim?: boolean;
|
|
88
|
+
normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
|
|
89
|
+
vertical?: boolean;
|
|
90
|
+
trigger?: string;
|
|
91
|
+
hidden?: boolean;
|
|
92
|
+
onReset?: () => void;
|
|
96
93
|
desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
|
|
97
94
|
validateTrigger?: string | false | string[];
|
|
95
|
+
preserve?: boolean;
|
|
98
96
|
clearNotShow?: boolean;
|
|
99
97
|
labelAlign?: import("antd/es/form/interface").FormLabelAlign;
|
|
100
98
|
colon?: boolean;
|
|
99
|
+
layout?: import("antd/es/form/Form").FormItemLayout;
|
|
101
100
|
labelCol?: import("antd").ColProps;
|
|
102
101
|
wrapperCol?: import("antd").ColProps;
|
|
103
102
|
htmlFor?: string;
|
|
@@ -115,6 +114,7 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
|
|
|
115
114
|
icons: import("antd/es/form/FormItem").FeedbackIcons;
|
|
116
115
|
};
|
|
117
116
|
validateStatus?: "" | "warning" | "error" | "success" | "validating";
|
|
117
|
+
help?: React.ReactNode;
|
|
118
118
|
fieldId?: string;
|
|
119
119
|
valueType?: import("../../../render/propsType").ProFormValueType;
|
|
120
120
|
switchValue?: [any, any];
|