fix: 修改下拉框组件字段默认值 (#539)
Reviewed-on: daoyoucloud/tachycode#539 Co-authored-by: wjh <wwwjh0710@163.com> Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
parent
1675b39d0e
commit
48b045c4f9
@ -24,12 +24,12 @@ import {
|
||||
useAPIClient,
|
||||
useCompile,
|
||||
Select,
|
||||
useCollectionManager,
|
||||
} from '@nocobase/client';
|
||||
import { ConfigProvider, Radio, Space } from 'antd';
|
||||
import React, { memo, useCallback, useContext, useMemo, Profiler } from 'react';
|
||||
import { Schema, SchemaOptionsContext, observer, useField, useFieldSchema, useForm } from '@formily/react';
|
||||
import { ArrayItems, FormLayout } from '@formily/antd-v5';
|
||||
import { uid } from '@formily/shared';
|
||||
import { Field, onFieldValueChange } from '@formily/core';
|
||||
import {
|
||||
EditDefaultValue,
|
||||
@ -42,6 +42,7 @@ import {
|
||||
import _ from 'lodash';
|
||||
import { SchemaSettingsRemove } from '../../schema-settings/SchemaSettingsRemove';
|
||||
import { tval, useTranslation } from '../../locale';
|
||||
import { uid } from '@formily/shared';
|
||||
|
||||
const FieldComponentProps: React.FC = observer(
|
||||
(props) => {
|
||||
@ -160,6 +161,7 @@ export const FilterCustomItemInitializer: React.FC<{
|
||||
value: value.name,
|
||||
};
|
||||
});
|
||||
const cm = useCollectionManager();
|
||||
const { options: fieldComponents, values: fieldComponentValues } = useFieldComponents();
|
||||
const api = useAPIClient();
|
||||
const handleClick = useCallback(async () => {
|
||||
@ -278,6 +280,7 @@ export const FilterCustomItemInitializer: React.FC<{
|
||||
});
|
||||
const { title, component, collection, associationField } = values;
|
||||
const defaultSchema = getInterface(component)?.default?.uiSchema || {};
|
||||
const titleField = cm.getCollection(collection).titleField;
|
||||
const name = uid();
|
||||
insert(
|
||||
gridRowColWrap({
|
||||
@ -293,8 +296,8 @@ export const FilterCustomItemInitializer: React.FC<{
|
||||
'x-component-props': {
|
||||
...(defaultSchema['x-component-props'] || {}),
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'name',
|
||||
label: titleField,
|
||||
value: titleField,
|
||||
},
|
||||
associationField,
|
||||
collection,
|
||||
|
@ -24,7 +24,7 @@ import {
|
||||
VariableScopeProvider,
|
||||
} from '@nocobase/client';
|
||||
import _ from 'lodash';
|
||||
import React, { useCallback, useEffect, useMemo } from 'react';
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useTranslation } from '../locale';
|
||||
import { FormFilterScope } from '../components/filter-form/FormFilterScope';
|
||||
import { useFieldComponents } from '../schema-initializer';
|
||||
@ -522,6 +522,7 @@ export const SchemaSettingCollection = () => {
|
||||
value: value.name,
|
||||
};
|
||||
});
|
||||
const cm = useCollectionManager();
|
||||
const { dn } = useDesignable();
|
||||
return (
|
||||
<SchemaSettingsSelectItem
|
||||
@ -531,13 +532,14 @@ export const SchemaSettingCollection = () => {
|
||||
value={fieldSchema['collectionName']}
|
||||
onChange={(name) => {
|
||||
field.setValue('');
|
||||
const titleField = cm.getCollection(name).titleField;
|
||||
fieldSchema['collectionName'] = name;
|
||||
fieldSchema.default = '';
|
||||
fieldSchema['x-component-props'] = {
|
||||
...fieldSchema['x-component-props'],
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'name',
|
||||
label: titleField,
|
||||
value: titleField,
|
||||
},
|
||||
defaultValue: '',
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user