diff --git a/packages/core/client/src/block-provider/SubFormProvider.tsx b/packages/core/client/src/block-provider/SubFormProvider.tsx index b99e153317..f115637094 100644 --- a/packages/core/client/src/block-provider/SubFormProvider.tsx +++ b/packages/core/client/src/block-provider/SubFormProvider.tsx @@ -1,10 +1,12 @@ import { createForm, onFormValuesChange } from '@formily/core'; -import { useField, useForm } from '@formily/react'; +import { useField, useForm, useFieldSchema } from '@formily/react'; import { Spin } from 'antd'; import React, { createContext, useContext, useEffect, useMemo } from 'react'; import { RecordProvider } from '../record-provider'; import { BlockProvider, useBlockRequestContext } from './BlockProvider'; import { useFormBlockContext } from './FormBlockProvider'; +import { useCollectionManager, useCollection } from '../collection-manager'; +import { isArray } from 'lodash'; export const SubFormContext = createContext({}); @@ -15,16 +17,27 @@ const InternalSubFormProvider = (props) => { if (!formBlockCtx?.updateAssociationValues?.includes(fieldName)) { formBlockCtx?.updateAssociationValues?.push(fieldName); } - const field = useField(); const parentForm = useForm(); + const { getCollectionField } = useCollectionManager(); + const collectionField = getCollectionField(props.association); const form = useMemo( () => createForm({ effects() { onFormValuesChange((form) => { - parentForm.setValuesIn(fieldName, form.values); - formBlockCtx?.form?.setValuesIn(fieldName, form.values); + if (['oho', 'obo'].includes(collectionField.interface)) { + parentForm.setValuesIn(fieldName, form.values); + formBlockCtx?.form?.setValuesIn(fieldName, form.values); + } else { + console.log(parentForm.values) + console.log(form.values) + // const fieldValue = parentForm.values[fieldName]; + // const values = isArray(fieldValue) ? fieldValue : [fieldValue]; + // values.push(form.values); + // console.log(values); + // parentForm.setValuesIn(fieldName, values); + } }); }, readPretty, diff --git a/packages/core/client/src/collection-manager/interfaces/o2m.tsx b/packages/core/client/src/collection-manager/interfaces/o2m.tsx index b16349d049..695727d7f1 100644 --- a/packages/core/client/src/collection-manager/interfaces/o2m.tsx +++ b/packages/core/client/src/collection-manager/interfaces/o2m.tsx @@ -107,12 +107,15 @@ export const o2m: IField = { array: { type: 'array', 'x-component': 'ArrayCards', - default:[{}], + 'x-component-props': { + headStyle: { display: 'none' }, + }, + default: [{}], items: { type: 'object', properties: { block: { - type: 'object', + type: 'void', 'x-decorator': 'SubFormProvider', 'x-decorator-props': { collection: field.target, @@ -122,7 +125,7 @@ export const o2m: IField = { fieldName: field.name, readPretty, }, - 'x-component': 'CardItem', + 'x-component': 'div', 'x-component-props': { bordered: true, }, @@ -135,7 +138,7 @@ export const o2m: IField = { }, properties: { __form_grid: { - type: 'void', + type: 'object', 'x-component': 'Grid', 'x-initializer': 'FormItemInitializers', properties: {}, 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 1a67491bfe..37c506224b 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 @@ -1,5 +1,5 @@ import { LoadingOutlined } from '@ant-design/icons'; -import { connect, mapProps, mapReadPretty } from '@formily/react'; +import { connect, mapProps, mapReadPretty, useFieldSchema } from '@formily/react'; import _ from 'lodash'; import React, { useCallback, useMemo } from 'react'; import { useFieldTitle } from '../../hooks'; @@ -9,7 +9,7 @@ import useServiceOptions from './useServiceOptions'; export const defaultFieldNames = { label: 'id', - value: 'value', + value: 'id', color: 'color', options: 'children', }; @@ -21,6 +21,7 @@ export type AssociationSelectProps

= RemoteSelectProps

& { const InternalAssociationSelect = connect( (props: AssociationSelectProps) => { const { fieldNames, objectValue = true } = props; + const fieldSchema = useFieldSchema(); const service = useServiceOptions(props); useFieldTitle(); @@ -46,7 +47,15 @@ const InternalAssociationSelect = connect( } }, [props.value, normalizeValues]); - return ; + return ( + + ); }, mapProps( { diff --git a/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx b/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx index 8df1332832..7e0da5b1f7 100644 --- a/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx +++ b/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx @@ -20,6 +20,7 @@ export type RemoteSelectProps

= SelectProps & { target: string; wait?: number; manual?: boolean; + multiple?:boolean; mapOptions?: (data: any) => RemoteSelectProps['fieldNames']; targetField?: any; service: ResourceActionOptions

; @@ -211,14 +212,25 @@ const InternalRemoteSelect = connect( async onClick() { await onClick(); const { data } = actionField.data.data?.data; - form.setValuesIn(field.props.name, { - [fieldNames.label]: data[fieldNames.label], - id: data.id, - value: data.id, - }); + if (['oho', 'obo'].includes(collectionField.interface)) { + form.setValuesIn(field.props.name, { + [fieldNames.label]: data[fieldNames.label], + id: data.id, + value: data.id, + }); + } else { + const values = form.values[fieldSchema.name] || []; + values.push({ + [fieldNames.label]: data[fieldNames.label], + id: data.id, + value: data.id, + }); + form.setValuesIn(field.props.name, values); + } }, }; }; + console.log(others); return (