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
This commit is contained in:
被雨水过滤的空气-Rairn 2023-04-26 13:54:15 +08:00 committed by GitHub
parent de5260bc2c
commit 07d1c7ccc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import { Field } from '@formily/core';
import { ISchema, connect, mapProps, mapReadPretty, useField, useFieldSchema } from '@formily/react'; import { ISchema, connect, mapProps, mapReadPretty, useField, useFieldSchema } from '@formily/react';
import { uid } from '@formily/shared'; import { uid } from '@formily/shared';
import _ from 'lodash'; import _ from 'lodash';
import React, { useCallback, useMemo } from 'react'; import React, { useCallback, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useFilterByTk, useFormBlockContext } from '../../../block-provider'; import { useFilterByTk, useFormBlockContext } from '../../../block-provider';
import { import {
@ -118,6 +118,14 @@ AssociationSelect.Designer = function Designer() {
const defaultFilter = field.componentProps?.service?.params?.filter || {}; const defaultFilter = field.componentProps?.service?.params?.filter || {};
const dataSource = useCollectionFilterOptions(collectionField?.target); 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) => { const sort = defaultSort?.map((item: string) => {
return item.startsWith('-') return item.startsWith('-')
? { ? {
@ -416,6 +424,8 @@ AssociationSelect.Designer = function Designer() {
name: 'default', name: 'default',
title: t('Default value'), title: t('Default value'),
default: fieldSchema.default || collectionField.defaultValue, default: fieldSchema.default || collectionField.defaultValue,
'x-read-pretty': false,
'x-disabled': false,
}, },
}, },
} as ISchema } as ISchema

View File

@ -450,6 +450,8 @@ FormItem.Designer = function Designer() {
name: 'default', name: 'default',
title: t('Default value'), title: t('Default value'),
default: getFieldDefaultValue(fieldSchema, collectionField), default: getFieldDefaultValue(fieldSchema, collectionField),
'x-read-pretty': false,
'x-disabled': false,
} }
: { : {
...(fieldSchema || {}), ...(fieldSchema || {}),