From 07d1c7ccc0a8e9226b639de8580600b4bc2fe826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rairn?= <958414905@qq.com> Date: Wed, 26 Apr 2023 13:54:15 +0800 Subject: [PATCH] fix(AssociationSelect): fix x-read-pretty not working (#1766) * fix: the default value input should not be disabled * fix(AssociationSelect): fix x-read-pretty not working --- .../antd/association-select/AssociationSelect.tsx | 12 +++++++++++- .../src/schema-component/antd/form-item/FormItem.tsx | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx b/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx index 1319e459f..57cf10bd7 100644 --- a/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx +++ b/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx @@ -4,7 +4,7 @@ import { Field } from '@formily/core'; import { ISchema, connect, mapProps, mapReadPretty, useField, useFieldSchema } from '@formily/react'; import { uid } from '@formily/shared'; import _ from 'lodash'; -import React, { useCallback, useMemo } from 'react'; +import React, { useCallback, useEffect, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { useFilterByTk, useFormBlockContext } from '../../../block-provider'; import { @@ -118,6 +118,14 @@ AssociationSelect.Designer = function Designer() { const defaultFilter = field.componentProps?.service?.params?.filter || {}; const dataSource = useCollectionFilterOptions(collectionField?.target); + // TODO: 这里 fieldSchema['x-read-pretty'] 的值为 true,但是 field.readPretty 的值却为 false,不知道什么原因 + useEffect(() => { + // 没有这一步判断会出现禁用状态失效的情况 + if (field.readPretty !== fieldSchema['x-read-pretty']) { + field.readPretty = !!fieldSchema['x-read-pretty']; + } + }, [fieldSchema['x-read-pretty']]); + const sort = defaultSort?.map((item: string) => { return item.startsWith('-') ? { @@ -416,6 +424,8 @@ AssociationSelect.Designer = function Designer() { name: 'default', title: t('Default value'), default: fieldSchema.default || collectionField.defaultValue, + 'x-read-pretty': false, + 'x-disabled': false, }, }, } as ISchema diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx index 136a51335..f0cd8d602 100644 --- a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx +++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx @@ -450,6 +450,8 @@ FormItem.Designer = function Designer() { name: 'default', title: t('Default value'), default: getFieldDefaultValue(fieldSchema, collectionField), + 'x-read-pretty': false, + 'x-disabled': false, } : { ...(fieldSchema || {}),