From 1c0415cd46cc41150955bd69e57e2ed1918db495 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Tue, 7 Nov 2023 14:50:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=88=97=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E9=80=89=E6=8B=A9=E4=B8=8E=E5=AE=9E=E9=99=85=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E4=B8=80=E8=87=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-ui/scss/components/_table.scss | 10 ++ .../src/renderers/Table/AutoFilterForm.tsx | 98 +++++++++---------- 2 files changed, 59 insertions(+), 49 deletions(-) diff --git a/packages/amis-ui/scss/components/_table.scss b/packages/amis-ui/scss/components/_table.scss index d93fd7ab9f7..8ec35a3195b 100644 --- a/packages/amis-ui/scss/components/_table.scss +++ b/packages/amis-ui/scss/components/_table.scss @@ -1108,3 +1108,13 @@ } } } + +.#{$ns}AutoFilterToolbar { + display: block; + text-align: right; + white-space: nowrap; + + > .#{$ns}Button { + margin-top: 0; + } +} diff --git a/packages/amis/src/renderers/Table/AutoFilterForm.tsx b/packages/amis/src/renderers/Table/AutoFilterForm.tsx index d3d14f70921..54aee11dd4a 100644 --- a/packages/amis/src/renderers/Table/AutoFilterForm.tsx +++ b/packages/amis/src/renderers/Table/AutoFilterForm.tsx @@ -71,7 +71,7 @@ export function AutoFilterForm({ }) ); - let showExpander = searchableColumns.length >= columnsNum; + let showExpander = activedSearchableColumns.length >= columnsNum; // todo 以后做动画 if (!searchFormExpanded && body.length) { @@ -100,7 +100,7 @@ export function AutoFilterForm({ } lastGroup.body.push({ type: 'container', - className: 'ButtonToolbar text-right block', + className: 'AutoFilterToolbar', wrapperBody: false, body: [ { @@ -114,32 +114,31 @@ export function AutoFilterForm({ visible: showBtnToolbar, buttons: searchableColumns.map(column => { return { - type: 'checkbox', - label: false, - className: cx('Table-searchableForm-checkbox'), - inputClassName: cx('Table-searchableForm-checkbox-inner'), - name: `${ - column.searchable.strategy === 'jsonql' ? '' : '__search_' - }${column.searchable?.name ?? column.name}`, - option: column.searchable?.label ?? column.label, - /** - * syncLocation开启后,参数值会从地址栏Query中二次同步到数据域中,其中布尔(boolean)类型的值被转化为字符串 - * eg: - * true ==> "true" - * false ==> "false" - * 所以这里将真值和假值转化成字符串格式规避 - */ - trueValue: '1', - falseValue: '0', - value: !!column.enableSearch ? '1' : '0', - badge: { - offset: [-10, 5], - visibleOn: `${ - column.toggable && !column.toggled && column.enableSearch - }` - }, - onChange: (value: '1' | '0') => - onItemToggleExpanded?.(column, value === '1' ? true : false) + children: ({render}: any) => + render( + `column-search-toggler-${column.id}`, + { + type: 'checkbox', + label: false, + className: cx('Table-searchableForm-checkbox'), + inputClassName: cx('Table-searchableForm-checkbox-inner'), + name: `__whatever_name`, + option: column.searchable?.label ?? column.label, + badge: { + offset: [-10, 5], + visibleOn: `${ + column.toggable && + !column.toggled && + column.enableSearch + }` + } + }, + { + value: activedSearchableColumns.includes(column), + onChange: (value: any) => + onItemToggleExpanded?.(column, value) + } + ) }; }) }, @@ -147,34 +146,35 @@ export function AutoFilterForm({ { type: 'submit', label: __('search'), + size: 'sm', level: 'primary', - className: 'w-18' + className: 'w-18 mr-2' }, { type: 'reset', label: __('reset'), + size: 'sm', className: 'w-18' }, - showExpander - ? { - children: () => ( - - {__(searchFormExpanded ? 'collapse' : 'expand')} - - - - - ) - } - : null - ].filter(item => item) + { + children: () => + showExpander ? ( + + {__(searchFormExpanded ? 'collapse' : 'expand')} + + + + + ) : null + } + ] }); return { @@ -227,7 +227,7 @@ export default observer( const onItemToggleExpanded = React.useCallback( (column: IColumn, value: boolean) => { column.setEnableSearch(value); - store.setSearchFormExpanded(true); + value && store.setSearchFormExpanded(true); }, [] );