From 2f0c3c4c05d8d45f1551766682d09c3b684bb9ac Mon Sep 17 00:00:00 2001 From: Netfan Date: Thu, 12 Dec 2024 21:37:30 +0800 Subject: [PATCH 1/3] feat: table search form visible control --- .../components/common-ui/vben-vxe-table.md | 18 ++++--- packages/effects/plugins/src/vxe-table/api.ts | 18 +++++++ .../effects/plugins/src/vxe-table/index.ts | 3 +- .../effects/plugins/src/vxe-table/types.ts | 16 +++++- .../plugins/src/vxe-table/use-vxe-grid.vue | 53 +++++++++++++++---- packages/locales/src/langs/en-US/common.json | 3 +- packages/locales/src/langs/zh-CN/common.json | 3 +- .../src/views/examples/vxe-table/form.vue | 17 ++++-- 8 files changed, 105 insertions(+), 26 deletions(-) diff --git a/docs/src/components/common-ui/vben-vxe-table.md b/docs/src/components/common-ui/vben-vxe-table.md index 29f679f6aaf..75af4bdff5b 100644 --- a/docs/src/components/common-ui/vben-vxe-table.md +++ b/docs/src/components/common-ui/vben-vxe-table.md @@ -215,14 +215,15 @@ const [Grid, gridApi] = useVbenVxeGrid({ useVbenVxeGrid 返回的第二个参数,是一个对象,包含了一些表单的方法。 -| 方法名 | 描述 | 类型 | -| --- | --- | --- | -| setLoading | 设置loading状态 | `(loading)=>void` | -| setGridOptions | 设置vxe-table grid组件参数 | `(options: Partialvoid` | -| reload | 重载表格,会进行初始化 | `(params:any)=>void` | -| query | 重载表格,会保留当前分页 | `(params:any)=>void` | -| grid | vxe-table grid实例 | `VxeGridInstance` | -| formApi | vbenForm api实例 | `FormApi` | +| 方法名 | 描述 | 类型 | 说明 | +| --- | --- | --- | --- | +| setLoading | 设置loading状态 | `(loading)=>void` | - | +| setGridOptions | 设置vxe-table grid组件参数 | `(options: Partialvoid` | - | +| reload | 重载表格,会进行初始化 | `(params:any)=>void` | - | +| query | 重载表格,会保留当前分页 | `(params:any)=>void` | - | +| grid | vxe-table grid实例 | `VxeGridInstance` | - | +| formApi | vbenForm api实例 | `FormApi` | - | +| toggleSearchForm | 设置搜索表单显示状态 | `(show?: boolean)=>boolean` | 当省略参数时,则将表单在显示和隐藏两种状态之间切换 | ## Props @@ -236,3 +237,4 @@ useVbenVxeGrid 返回的第二个参数,是一个对象,包含了一些表 | gridOptions | grid组件的参数 | `VxeTableGridProps` | | gridEvents | grid组件的触发的⌚️ | `VxeGridListeners` | | formOptions | 表单参数 | `VbenFormProps` | +| isFormShow | 是否显示搜索表单 | `boolean` | diff --git a/packages/effects/plugins/src/vxe-table/api.ts b/packages/effects/plugins/src/vxe-table/api.ts index 365c90b7eb8..0f3ea65d9db 100644 --- a/packages/effects/plugins/src/vxe-table/api.ts +++ b/packages/effects/plugins/src/vxe-table/api.ts @@ -8,6 +8,7 @@ import { toRaw } from 'vue'; import { Store } from '@vben-core/shared/store'; import { bindMethods, + isBoolean, isFunction, mergeWithArrayOverride, StateHandler, @@ -20,6 +21,7 @@ function getDefaultState(): VxeGridProps { gridOptions: {}, gridEvents: {}, formOptions: undefined, + isFormShow: true, }; } @@ -80,6 +82,12 @@ export class VxeGridApi { } } + setFormVisible(isVisible: boolean) { + this.setState({ + isFormShow: isVisible, + }); + } + setGridOptions(options: Partial) { this.setState({ gridOptions: options, @@ -108,6 +116,16 @@ export class VxeGridApi { } } + toggleSearchForm(show?: boolean) { + this.setState({ + isFormShow: isBoolean(show) ? show : !this.state?.isFormShow, + }); + // nextTick(() => { + // this.grid.recalculate(); + // }); + return this.state?.isFormShow; + } + unmount() { this.isMounted = false; this.stateHandler.reset(); diff --git a/packages/effects/plugins/src/vxe-table/index.ts b/packages/effects/plugins/src/vxe-table/index.ts index 4ae1c2ef5fd..38fe5880666 100644 --- a/packages/effects/plugins/src/vxe-table/index.ts +++ b/packages/effects/plugins/src/vxe-table/index.ts @@ -1,5 +1,6 @@ export { setupVbenVxeTable } from './init'; +export type { VxeTableGridOptions } from './types'; export * from './use-vxe-grid'; -export { default as VbenVxeGrid } from './use-vxe-grid.vue'; +export { default as VbenVxeGrid } from './use-vxe-grid.vue'; export type { VxeGridListeners, VxeGridProps } from 'vxe-table'; diff --git a/packages/effects/plugins/src/vxe-table/types.ts b/packages/effects/plugins/src/vxe-table/types.ts index e6559a283b6..aac88a70544 100644 --- a/packages/effects/plugins/src/vxe-table/types.ts +++ b/packages/effects/plugins/src/vxe-table/types.ts @@ -2,6 +2,7 @@ import type { ClassType, DeepPartial } from '@vben/types'; import type { VbenFormProps } from '@vben-core/form-ui'; import type { VxeGridListeners, + VxeGridPropTypes, VxeGridProps as VxeTableGridProps, VxeUIExport, } from 'vxe-table'; @@ -18,6 +19,15 @@ export interface VxePaginationInfo { total: number; } +interface ToolbarConfigOptions extends VxeGridPropTypes.ToolbarConfig { + /** 是否显示切换搜索表单的按钮 */ + search?: boolean; +} + +export interface VxeTableGridOptions extends VxeTableGridProps { + toolbarConfig: ToolbarConfigOptions; +} + export interface VxeGridProps { /** * 标题 @@ -38,7 +48,7 @@ export interface VxeGridProps { /** * vxe-grid 配置 */ - gridOptions?: DeepPartial; + gridOptions?: DeepPartial; /** * vxe-grid 事件 */ @@ -47,6 +57,10 @@ export interface VxeGridProps { * 表单配置 */ formOptions?: VbenFormProps; + /** + * 显示搜索表单 + */ + isFormShow?: boolean; } export type ExtendedVxeGridApi = { diff --git a/packages/effects/plugins/src/vxe-table/use-vxe-grid.vue b/packages/effects/plugins/src/vxe-table/use-vxe-grid.vue index feca4cb2b92..be7bf34d955 100644 --- a/packages/effects/plugins/src/vxe-table/use-vxe-grid.vue +++ b/packages/effects/plugins/src/vxe-table/use-vxe-grid.vue @@ -1,7 +1,9 @@