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,
|
useAPIClient,
|
||||||
useCompile,
|
useCompile,
|
||||||
Select,
|
Select,
|
||||||
|
useCollectionManager,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import { ConfigProvider, Radio, Space } from 'antd';
|
import { ConfigProvider, Radio, Space } from 'antd';
|
||||||
import React, { memo, useCallback, useContext, useMemo, Profiler } from 'react';
|
import React, { memo, useCallback, useContext, useMemo, Profiler } from 'react';
|
||||||
import { Schema, SchemaOptionsContext, observer, useField, useFieldSchema, useForm } from '@formily/react';
|
import { Schema, SchemaOptionsContext, observer, useField, useFieldSchema, useForm } from '@formily/react';
|
||||||
import { ArrayItems, FormLayout } from '@formily/antd-v5';
|
import { ArrayItems, FormLayout } from '@formily/antd-v5';
|
||||||
import { uid } from '@formily/shared';
|
|
||||||
import { Field, onFieldValueChange } from '@formily/core';
|
import { Field, onFieldValueChange } from '@formily/core';
|
||||||
import {
|
import {
|
||||||
EditDefaultValue,
|
EditDefaultValue,
|
||||||
@ -42,6 +42,7 @@ import {
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { SchemaSettingsRemove } from '../../schema-settings/SchemaSettingsRemove';
|
import { SchemaSettingsRemove } from '../../schema-settings/SchemaSettingsRemove';
|
||||||
import { tval, useTranslation } from '../../locale';
|
import { tval, useTranslation } from '../../locale';
|
||||||
|
import { uid } from '@formily/shared';
|
||||||
|
|
||||||
const FieldComponentProps: React.FC = observer(
|
const FieldComponentProps: React.FC = observer(
|
||||||
(props) => {
|
(props) => {
|
||||||
@ -160,6 +161,7 @@ export const FilterCustomItemInitializer: React.FC<{
|
|||||||
value: value.name,
|
value: value.name,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
const cm = useCollectionManager();
|
||||||
const { options: fieldComponents, values: fieldComponentValues } = useFieldComponents();
|
const { options: fieldComponents, values: fieldComponentValues } = useFieldComponents();
|
||||||
const api = useAPIClient();
|
const api = useAPIClient();
|
||||||
const handleClick = useCallback(async () => {
|
const handleClick = useCallback(async () => {
|
||||||
@ -278,6 +280,7 @@ export const FilterCustomItemInitializer: React.FC<{
|
|||||||
});
|
});
|
||||||
const { title, component, collection, associationField } = values;
|
const { title, component, collection, associationField } = values;
|
||||||
const defaultSchema = getInterface(component)?.default?.uiSchema || {};
|
const defaultSchema = getInterface(component)?.default?.uiSchema || {};
|
||||||
|
const titleField = cm.getCollection(collection).titleField;
|
||||||
const name = uid();
|
const name = uid();
|
||||||
insert(
|
insert(
|
||||||
gridRowColWrap({
|
gridRowColWrap({
|
||||||
@ -293,8 +296,8 @@ export const FilterCustomItemInitializer: React.FC<{
|
|||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
...(defaultSchema['x-component-props'] || {}),
|
...(defaultSchema['x-component-props'] || {}),
|
||||||
fieldNames: {
|
fieldNames: {
|
||||||
label: 'name',
|
label: titleField,
|
||||||
value: 'name',
|
value: titleField,
|
||||||
},
|
},
|
||||||
associationField,
|
associationField,
|
||||||
collection,
|
collection,
|
||||||
|
@ -24,7 +24,7 @@ import {
|
|||||||
VariableScopeProvider,
|
VariableScopeProvider,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React, { useCallback, useEffect, useMemo } from 'react';
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { useTranslation } from '../locale';
|
import { useTranslation } from '../locale';
|
||||||
import { FormFilterScope } from '../components/filter-form/FormFilterScope';
|
import { FormFilterScope } from '../components/filter-form/FormFilterScope';
|
||||||
import { useFieldComponents } from '../schema-initializer';
|
import { useFieldComponents } from '../schema-initializer';
|
||||||
@ -522,6 +522,7 @@ export const SchemaSettingCollection = () => {
|
|||||||
value: value.name,
|
value: value.name,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
const cm = useCollectionManager();
|
||||||
const { dn } = useDesignable();
|
const { dn } = useDesignable();
|
||||||
return (
|
return (
|
||||||
<SchemaSettingsSelectItem
|
<SchemaSettingsSelectItem
|
||||||
@ -531,13 +532,14 @@ export const SchemaSettingCollection = () => {
|
|||||||
value={fieldSchema['collectionName']}
|
value={fieldSchema['collectionName']}
|
||||||
onChange={(name) => {
|
onChange={(name) => {
|
||||||
field.setValue('');
|
field.setValue('');
|
||||||
|
const titleField = cm.getCollection(name).titleField;
|
||||||
fieldSchema['collectionName'] = name;
|
fieldSchema['collectionName'] = name;
|
||||||
fieldSchema.default = '';
|
fieldSchema.default = '';
|
||||||
fieldSchema['x-component-props'] = {
|
fieldSchema['x-component-props'] = {
|
||||||
...fieldSchema['x-component-props'],
|
...fieldSchema['x-component-props'],
|
||||||
fieldNames: {
|
fieldNames: {
|
||||||
label: 'name',
|
label: titleField,
|
||||||
value: 'name',
|
value: titleField,
|
||||||
},
|
},
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user