From dcf3cf63e3d14cee0483b2847753eb06f80b8a31 Mon Sep 17 00:00:00 2001 From: wjh Date: Wed, 13 Mar 2024 12:04:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E7=BA=A7=E8=81=94?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cascaderComponentFieldSettings.tsx | 71 +++++++------------ .../association-field/InternalCascader.tsx | 7 +- 2 files changed, 31 insertions(+), 47 deletions(-) diff --git a/packages/core/client/src/modules/fields/component/Cascader/cascaderComponentFieldSettings.tsx b/packages/core/client/src/modules/fields/component/Cascader/cascaderComponentFieldSettings.tsx index cde650901..3aaf801bd 100644 --- a/packages/core/client/src/modules/fields/component/Cascader/cascaderComponentFieldSettings.tsx +++ b/packages/core/client/src/modules/fields/component/Cascader/cascaderComponentFieldSettings.tsx @@ -132,8 +132,21 @@ export const SchemaSettingsSortingRule = function SortRuleConfigure(props) { }); _.set(field.componentProps, 'service.params.sort', sortArr); props?.onSubmitCallBack?.(sortArr); - fieldSchema['x-component-props']['service']['params']['sort'] = field.componentProps?.service.params?.sort; + const service = fieldSchema['x-component-props']?.service; + if (service) { + service.params['sort'] = field.componentProps?.service.params?.sort; + } else { + fieldSchema['x-component-props']['service'] = { + params: { + sort: field.componentProps?.service.params?.sort, + }, + }; + } const componentProps = fieldSchema['x-component-props']; + const path = field.path?.splice(field.path?.length - 1, 1); + field.form.query(`${path.concat(`*.` + fieldSchema.name)}`).forEach((f) => { + f.componentProps = componentProps; + }); dn.emit('patch', { schema: { ['x-uid']: fieldSchema['x-uid'], @@ -206,45 +219,6 @@ const titleField: any = { }, }; -export const allowMultiple: any = { - name: 'allowMultiple', - type: 'switch', - useVisible() { - const isFieldReadPretty = useIsFieldReadPretty(); - const collectionField = useCollectionField(); - return !isFieldReadPretty && ['hasMany', 'belongsToMany'].includes(collectionField?.type); - }, - useComponentProps() { - const { t } = useTranslation(); - const field = useField(); - const { fieldSchema: tableColumnSchema } = useColumnSchema(); - const schema = useFieldSchema(); - const fieldSchema = tableColumnSchema || schema; - const { dn, refresh } = useDesignable(); - return { - title: t('Allow multiple'), - checked: - fieldSchema['x-component-props']?.multiple === undefined ? true : fieldSchema['x-component-props'].multiple, - onChange(value) { - const schema = { - ['x-uid']: fieldSchema['x-uid'], - }; - fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {}; - field.componentProps = field.componentProps || {}; - - fieldSchema['x-component-props'].multiple = value; - field.componentProps.multiple = value; - - schema['x-component-props'] = fieldSchema['x-component-props']; - dn.emit('patch', { - schema, - }); - refresh(); - }, - }; - }, -}; - const setDefaultSortingRules = { name: 'setDefaultSortingRules', Component: SchemaSettingsSortingRule, @@ -290,7 +264,16 @@ const setTheDataScope: any = { onSubmit: ({ filter }) => { filter = removeNullCondition(filter); _.set(field.componentProps, 'service.params.filter', filter); - fieldSchema['x-component-props']['service']['params']['filter'] = filter; + const service = fieldSchema['x-component-props']?.service; + if (service) { + service.params['filter'] = filter; + } else { + fieldSchema['x-component-props']['service'] = { + params: { + filter: { ...filter }, + }, + }; + } const componentProps = fieldSchema['x-component-props']; const path = field.path?.splice(field.path?.length - 1, 1); field.form.query(`${path.concat(`*.` + fieldSchema.name)}`).forEach((f) => { @@ -363,9 +346,8 @@ export const cascaderComponentFieldSettings = new SchemaSettings({ { ...setTheDataScope, useVisible() { - const isSelectFieldMode = useIsSelectFieldMode(); const isFieldReadPretty = useIsFieldReadPretty(); - return isSelectFieldMode && !isFieldReadPretty; + return !isFieldReadPretty; }, }, { @@ -377,9 +359,8 @@ export const cascaderComponentFieldSettings = new SchemaSettings({ }; }, useVisible() { - const isSelectFieldMode = useIsSelectFieldMode(); const isFieldReadPretty = useIsFieldReadPretty(); - return isSelectFieldMode && !isFieldReadPretty; + return !isFieldReadPretty; }, }, { diff --git a/packages/core/client/src/schema-component/antd/association-field/InternalCascader.tsx b/packages/core/client/src/schema-component/antd/association-field/InternalCascader.tsx index 4c106227a..4bb1ab11b 100644 --- a/packages/core/client/src/schema-component/antd/association-field/InternalCascader.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/InternalCascader.tsx @@ -31,7 +31,8 @@ const Cascade = connect((props) => { const { options: collectionField, field: associationField } = useAssociationFieldContext(); const resource = api.resource(collectionField.target); const fieldNames = associationField?.componentProps?.fieldNames; - const fieldFilter = fieldSchema['x-component-props']['service']['params']['filter']; + const fieldFilter = fieldSchema['x-component-props']?.service?.params?.filter; + const sort = fieldSchema['x-component-props']?.service?.params?.sort; const field: any = useField(); useEffect(() => { if (props.value) { @@ -52,6 +53,7 @@ const Cascade = connect((props) => { const response = await resource.list({ pageSize: 9999, filter: mergeFilter([fieldFilter, filter]), + sort, tree: true, }); return response?.data?.data; @@ -210,7 +212,7 @@ export const InternalCascader = observer( ...props, style: { width: '100%' }, }, - 'x-read-pretty': 'false', + 'x-read-pretty': false, }, remove: { type: 'void', @@ -243,6 +245,7 @@ export const InternalCascader = observer( ...props, style: { width: '100%' }, }, + 'x-read-pretty': false, }} /> ) : (