From f807ab8e01c6fd0e0ddedcae2dc1941becc31b5c Mon Sep 17 00:00:00 2001 From: wjh Date: Tue, 11 Jun 2024 17:38:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E7=AB=AF=E5=BF=AB=E9=80=9F=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20(#1153)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1153 Reviewed-by: sealday Co-authored-by: wjh Co-committed-by: wjh --- .../antd/association-field/SubTabs/index.ts | 1 + .../antd/association-field/index.ts | 2 + .../antd-mobile/Select/AntdSelect.tsx | 49 +++++++++++++------ .../antd-mobile/Select/CreateRecordAction.tsx | 10 +++- .../components/antd-mobile/Select/Select.tsx | 8 +-- 5 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 packages/core/client/src/schema-component/antd/association-field/SubTabs/index.ts diff --git a/packages/core/client/src/schema-component/antd/association-field/SubTabs/index.ts b/packages/core/client/src/schema-component/antd/association-field/SubTabs/index.ts new file mode 100644 index 000000000..1146a6d5c --- /dev/null +++ b/packages/core/client/src/schema-component/antd/association-field/SubTabs/index.ts @@ -0,0 +1 @@ +export * from './hook'; diff --git a/packages/core/client/src/schema-component/antd/association-field/index.ts b/packages/core/client/src/schema-component/antd/association-field/index.ts index 37f657072..8a117644d 100644 --- a/packages/core/client/src/schema-component/antd/association-field/index.ts +++ b/packages/core/client/src/schema-component/antd/association-field/index.ts @@ -1,4 +1,5 @@ import { connect, mapReadPretty } from '@tachybase/schema'; + import { Action } from '../action'; import { Editable } from './Editable'; import { InternalPicker } from './InternalPicker'; @@ -7,6 +8,7 @@ import { ReadPretty } from './ReadPretty'; import { SubTable } from './SubTable'; export const AssociationField: any = connect(Editable, mapReadPretty(ReadPretty)); +export * from './SubTabs'; AssociationField.SubTable = SubTable; AssociationField.Nester = Nester; diff --git a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/AntdSelect.tsx b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/AntdSelect.tsx index f1a5aea0b..44ebfde15 100644 --- a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/AntdSelect.tsx +++ b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/AntdSelect.tsx @@ -14,6 +14,7 @@ import { useCollectionField, useCollectionManager, useDesignable, + useFieldServiceFilter, useRequest, } from '@tachybase/client'; import { isArray } from '@tachybase/utils/client'; @@ -33,7 +34,8 @@ export const AntdSelect = observer((props) => { const fieldSchema = useFieldSchema(); const cm = useCollectionManager(); const collection = useCollection(); - const [filter, setFilter] = useState(service?.params?.filter); + const [fieldServiceFilter] = useFieldServiceFilter(service?.params); + const [filter, setFilter] = useState(fieldServiceFilter); const api = useAPIClient(); const [selectValue, setSelectValue] = useState(value); const fieldNamesLabel = fieldNames?.label || 'label'; @@ -47,7 +49,7 @@ export const AntdSelect = observer((props) => { inputValue = value[fieldNamesLabel]; } - const { data, run } = useRequest( + const { run } = useRequest( { resource: collectionName, action: 'list', @@ -57,23 +59,23 @@ export const AntdSelect = observer((props) => { }, { manual: true, + onSuccess(data) { + if (data) { + const dataOption = data['data']?.map((value) => { + return { + ...value, + label: value[fieldNamesLabel], + value: value[fieldNamesValue], + }; + }); + setOptions(dataOption); + } + }, }, ); useEffect(() => { checkedPopup(); - }, [filter]); - useEffect(() => { - if (data) { - const dataOption = data['data']?.map((value) => { - return { - ...value, - label: value[fieldNamesLabel], - value: value[fieldNamesValue], - }; - }); - setOptions(dataOption); - } - }, [data]); + }, [filter, popupVisible]); const checkedPopup = () => { if (collectionName) { @@ -136,7 +138,13 @@ export const AntdSelect = observer((props) => { {fieldSchema['x-disabled'] ? '' : '请选择内容'} )} - + { + setPopupVisible(false); + }} + > { color="primary" onClick={() => { setPopupVisible(false); + const paramsFilter = { ...filter }; + if (paramsFilter[fieldNamesLabel]) delete paramsFilter[fieldNamesLabel]; + setSearchValue(''); + setFilter(paramsFilter); }} > 取消 @@ -210,6 +222,11 @@ export const AntdSelect = observer((props) => { onClick={() => { onChange(selectValue); setPopupVisible(false); + const paramsFilter = { ...filter }; + if (paramsFilter[fieldNamesLabel]) delete paramsFilter[fieldNamesLabel]; + setSearchValue(''); + setFilter(paramsFilter); + setSearchValue(''); }} > 确定 diff --git a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/CreateRecordAction.tsx b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/CreateRecordAction.tsx index b01e44837..880dc8d61 100644 --- a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/CreateRecordAction.tsx +++ b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/CreateRecordAction.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { css, SchemaComponentOptions, useApp, useCollection } from '@tachybase/client'; +import { ActionContextProvider, css, SchemaComponentOptions, useApp, useCollection } from '@tachybase/client'; import { observer, RecursionField, useField, useFieldSchema } from '@tachybase/schema'; import { Button, CenterPopup, Modal, Popup } from 'antd-mobile'; @@ -37,6 +37,10 @@ export const CreateRecordAction = observer( onMaskClick={() => { setVisible(false); }} + showCloseButton + onClose={() => { + setVisible(false); + }} className={css` .adm-popup-body { height: 80vh; @@ -45,7 +49,9 @@ export const CreateRecordAction = observer( `} > - + + + diff --git a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/Select.tsx b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/Select.tsx index 9545fc63e..fc18ea6bc 100644 --- a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/Select.tsx +++ b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/Select.tsx @@ -23,7 +23,7 @@ export const MSelect = connect( filterProps['collectionName'] = collection.name; } if (typeof filterProps['value'] !== 'object') { - filterProps['value'] = dataSource.filter((item) => item.value.toString() === filterProps['value']); + filterProps['value'] = dataSource.filter((item) => item.value.toString() === filterProps?.['value']); } return { ...filterProps }; }), @@ -32,7 +32,7 @@ export const MSelect = connect( const collectionField = useCollectionField(); const isSlectField = ['multipleSelect', 'select'].includes(collectionField?.interface); const field = useField(); - const dataSource = field.dataSource || collectionField?.uiSchema.enum || []; + const dataSource = field?.dataSource || collectionField?.uiSchema.enum || []; const fieldNamesLabel = fieldNames?.label || 'label'; if (isSlectField) { const option = []; @@ -58,10 +58,10 @@ export const MSelect = connect( let redValue = ''; if (isArray(value)) { redValue = value.reduce((prev, curr) => { - return prev + curr[fieldNamesLabel]; + return prev + curr?.[fieldNamesLabel]; }, ''); } else { - redValue = value[fieldNamesLabel]; + redValue = value?.[fieldNamesLabel] || ''; } return (