Skip to content

Commit 9379093

Browse files
authored
feat: customizable table separator (vbenjs#5898)
* 表格的分隔条支持定制背景色或完全移除
1 parent c9014d0 commit 9379093

File tree

3 files changed

+79
-12
lines changed

3 files changed

+79
-12
lines changed

docs/src/components/common-ui/vben-vxe-table.md

+27-9
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ vxeUI.renderer.add('CellLink', {
167167

168168
当启用了表单搜索时,可以在toolbarConfig中配置`search``true`来让表格在工具栏区域显示一个搜索表单控制按钮。表格的所有以`form-`开头的命名插槽都会被传递给搜索表单。
169169

170+
### 定制分隔条
171+
172+
当你启用表单搜索时,在表单和表格之间会显示一个分隔条。这个分隔条使用了默认的组件背景色,并且横向贯穿整个Vben Vxe Table在视觉上融入了页面的默认背景中。如果你在Vben Vxe Table的外层包裹了一个不同背景色的容器(如将其放在一个Card内),默认的表单和表格之间的分隔条可能就显得格格不入了,下面的代码演示了如何定制这个分隔条。
173+
174+
```ts
175+
const [Grid] = useVbenVxeGrid({
176+
formOptions: {},
177+
gridOptions: {},
178+
// 完全移除分隔条
179+
separator: false,
180+
// 你也可以使用下面的代码来移除分隔条
181+
// separator: { show: false },
182+
// 或者使用下面的代码来改变分隔条的颜色
183+
// separator: { backgroundColor: 'rgba(100,100,0,0.5)' },
184+
});
185+
```
186+
170187
<DemoPreview dir="demos/vben-vxe-table/form" />
171188

172189
## 单元格编辑
@@ -231,15 +248,16 @@ useVbenVxeGrid 返回的第二个参数,是一个对象,包含了一些表
231248

232249
所有属性都可以传入 `useVbenVxeGrid` 的第一个参数中。
233250

234-
| 属性名 | 描述 | 类型 |
235-
| -------------- | -------------------- | ------------------- |
236-
| tableTitle | 表格标题 | `string` |
237-
| tableTitleHelp | 表格标题帮助信息 | `string` |
238-
| gridClass | grid组件的class | `string` |
239-
| gridOptions | grid组件的参数 | `VxeTableGridProps` |
240-
| gridEvents | grid组件的触发的事件 | `VxeGridListeners` |
241-
| formOptions | 表单参数 | `VbenFormProps` |
242-
| showSearchForm | 是否显示搜索表单 | `boolean` |
251+
| 属性名 | 描述 | 类型 | 版本要求 |
252+
| --- | --- | --- | --- |
253+
| tableTitle | 表格标题 | `string` | - |
254+
| tableTitleHelp | 表格标题帮助信息 | `string` | - |
255+
| gridClass | grid组件的class | `string` | - |
256+
| gridOptions | grid组件的参数 | `VxeTableGridProps` | - |
257+
| gridEvents | grid组件的触发的事件 | `VxeGridListeners` | - |
258+
| formOptions | 表单参数 | `VbenFormProps` | - |
259+
| showSearchForm | 是否显示搜索表单 | `boolean` | - |
260+
| separator | 搜索表单与表格主体之间的分隔条 | `boolean\|SeparatorOptions` | >5.5.4 |
243261

244262
## Slots
245263

packages/effects/plugins/src/vxe-table/types.ts

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export interface VxeTableGridOptions<T = any> extends VxeTableGridProps<T> {
3131
toolbarConfig?: ToolbarConfigOptions;
3232
}
3333

34+
export interface SeparatorOptions {
35+
show?: boolean;
36+
backgroundColor?: string;
37+
}
3438
export interface VxeGridProps {
3539
/**
3640
* 标题
@@ -64,6 +68,10 @@ export interface VxeGridProps {
6468
* 显示搜索表单
6569
*/
6670
showSearchForm?: boolean;
71+
/**
72+
* 搜索表单与表格主体之间的分隔条
73+
*/
74+
separator?: boolean | SeparatorOptions;
6775
}
6876

6977
export type ExtendedVxeGridApi = VxeGridApi & {

packages/effects/plugins/src/vxe-table/use-vxe-grid.vue

+44-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ import { usePriorityValues } from '@vben/hooks';
2929
import { EmptyIcon } from '@vben/icons';
3030
import { $t } from '@vben/locales';
3131
import { usePreferences } from '@vben/preferences';
32-
import { cloneDeep, cn, isEqual, mergeWithArrayOverride } from '@vben/utils';
32+
import {
33+
cloneDeep,
34+
cn,
35+
isBoolean,
36+
isEqual,
37+
mergeWithArrayOverride,
38+
} from '@vben/utils';
3339
3440
import { VbenHelpTooltip, VbenLoading } from '@vben-core/shadcn-ui';
3541
@@ -67,10 +73,30 @@ const {
6773
tableTitle,
6874
tableTitleHelp,
6975
showSearchForm,
76+
separator,
7077
} = usePriorityValues(props, state);
7178
7279
const { isMobile } = usePreferences();
73-
80+
const isSeparator = computed(() => {
81+
if (
82+
!formOptions.value ||
83+
showSearchForm.value === false ||
84+
separator.value === false
85+
) {
86+
return false;
87+
}
88+
if (separator.value === true || separator.value === undefined) {
89+
return true;
90+
}
91+
return separator.value.show !== false;
92+
});
93+
const separatorBg = computed(() => {
94+
return !separator.value ||
95+
isBoolean(separator.value) ||
96+
!separator.value.backgroundColor
97+
? undefined
98+
: separator.value.backgroundColor;
99+
});
74100
const slots: SetupContext['slots'] = useSlots();
75101
76102
const [Form, formApi] = useTableForm({
@@ -375,7 +401,18 @@ onUnmounted(() => {
375401
<div
376402
v-if="formOptions"
377403
v-show="showSearchForm !== false"
378-
:class="cn('relative rounded py-3', isCompactForm ? 'pb-8' : 'pb-4')"
404+
:class="
405+
cn(
406+
'relative rounded py-3',
407+
isCompactForm
408+
? isSeparator
409+
? 'pb-8'
410+
: 'pb-4'
411+
: isSeparator
412+
? 'pb-4'
413+
: 'pb-0',
414+
)
415+
"
379416
>
380417
<slot name="form">
381418
<Form>
@@ -404,6 +441,10 @@ onUnmounted(() => {
404441
</Form>
405442
</slot>
406443
<div
444+
v-if="isSeparator"
445+
:style="{
446+
...(separatorBg ? { backgroundColor: separatorBg } : undefined),
447+
}"
407448
class="bg-background-deep z-100 absolute -left-2 bottom-1 h-2 w-[calc(100%+1rem)] overflow-hidden md:bottom-2 md:h-3"
408449
></div>
409450
</div>

0 commit comments

Comments
 (0)