From 0d36caf1c0b2cda1c60e3eb8d987798e63305237 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Tue, 21 Mar 2023 16:56:05 +0800 Subject: [PATCH] fix: collectionFieldsOptions cannot get all fields (#1588) --- .../hooks/useCollectionManager.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts b/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts index 06b0b502c..3fd8b557e 100644 --- a/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts +++ b/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts @@ -83,12 +83,11 @@ export const useCollectionManager = () => { }; // 缓存下面已经获取的 options,防止无限循环 - const cachedOptions = {}; - const getCollectionFieldsOptions = ( collectionName: string, type: string | string[] = 'string', opts?: { + cached?: Record; /** * 为 true 时允许查询所有关联字段 * 为 Array 时仅允许查询指定的关联字段 @@ -96,12 +95,13 @@ export const useCollectionManager = () => { association?: boolean | string[]; }, ) => { + const { association = false, cached = {} } = opts || {}; + // 防止无限循环 - if (cachedOptions[collectionName]) { - return _.cloneDeep(cachedOptions[collectionName]); + if (cached[collectionName]) { + return _.cloneDeep(cached[collectionName]); } - const { association = false } = opts || {}; if (typeof type === 'string') { type = [type]; } @@ -122,7 +122,7 @@ export const useCollectionManager = () => { ...field, }; if (association && field.target) { - result.children = getCollectionFieldsOptions(field.target, type, opts); + result.children = getCollectionFieldsOptions(field.target, type, { ...opts, cached }); if (!result.children?.length) { return null; } @@ -132,7 +132,7 @@ export const useCollectionManager = () => { // 过滤 map 产生为 null 的数据 .filter(Boolean); - cachedOptions[collectionName] = options; + cached[collectionName] = options; return options; };