工具栏与业务扩展
VTableToolbar 提供标题、业务操作区和常用工具。布局参考 React ProTable,支持 Ant Design Vue 和 Element Plus 预设。将它放进 VTable 的 title 插槽即可使用。
默认提供刷新、密度和列设置;全屏按需启用。导出、新增、批量操作等业务能力通过插槽加入,可以使用项目已安装的 UI 库按钮。
加入导出按钮
下面的“导出 CSV”来自 #actions,与内置工具并排显示。示例读取 title 插槽的 data 和工具栏的受控列配置,只导出当前展示数据中的可见字段;列设置、分页或筛选变化后,业务可以选择导出当前页、全部数据或已选择的记录。
<script setup lang="ts">
import { onBeforeUnmount, ref, shallowRef } from 'vue'
import { Button, VTable, VTableToolbar } from '@vtable-guild/vtable-guild'
import type { TableColumnsType, TableColumnSettingsSize } from '@vtable-guild/vtable-guild'
interface Member {
key: number
name: string
city: string
status: string
}
const columns = shallowRef<TableColumnsType<Member>>([
{ key: 'name', title: '姓名', dataIndex: 'name' },
{ key: 'city', title: '城市', dataIndex: 'city' },
{ key: 'status', title: '状态', dataIndex: 'status', visible: false },
])
const rows: Member[] = [
{ key: 1, name: '陈嘉', city: '杭州', status: '在职' },
{ key: 2, name: '苏晚', city: '上海', status: '在职' },
{ key: 3, name: '周野', city: '深圳', status: '休假' },
]
const size = ref<TableColumnSettingsSize>('middle')
const loading = ref(false)
const refreshes = ref(0)
const csv = ref('')
let refreshTimer: ReturnType<typeof setTimeout> | undefined
onBeforeUnmount(() => clearTimeout(refreshTimer))
function reload() {
loading.value = true
// Replace this sample with your data-loading function and clear loading in finally.
refreshTimer = setTimeout(() => {
refreshes.value++
loading.value = false
}, 500)
}
function exportCsv(data: Member[], currentColumns: TableColumnsType<Member>) {
const visible = currentColumns.flatMap<{ key: 'name' | 'city' | 'status'; title: unknown }>(
(column) =>
typeof column !== 'symbol' &&
column.visible !== false &&
(column.key === 'name' || column.key === 'city' || column.key === 'status')
? [{ key: column.key, title: column.title }]
: [],
)
if (!visible.length) return
const cell = (value: unknown) => `"${String(value ?? '').replace(/"/g, '""')}"`
csv.value = [
visible.map((column) => cell(column.title)).join(','),
...data.map((row) => visible.map((column) => cell(row[column.key])).join(',')),
].join('\r\n')
const url = URL.createObjectURL(
new Blob(['\uFEFF', csv.value], { type: 'text/csv;charset=utf-8;' }),
)
const link = document.createElement('a')
link.href = url
link.download = 'members.csv'
link.click()
setTimeout(() => URL.revokeObjectURL(url), 0)
}
</script>
<template>
<div class="toolbar-demo">
<VTable :columns="columns" :size="size" :data-source="rows" :loading="loading" bordered>
<template #title="{ data }">
<VTableToolbar
v-model:columns="columns"
v-model:size="size"
title="团队成员"
:loading="loading"
:options="{ fullScreen: true }"
@reload="reload"
>
<template #actions="{ columns: currentColumns, disabled }">
<Button :disabled="disabled" @click="exportCsv(data, currentColumns)">导出 CSV</Button>
</template>
</VTableToolbar>
</template>
</VTable>
<p aria-live="polite">已刷新 {{ refreshes }} 次</p>
<pre v-if="csv" class="toolbar-demo-csv" aria-label="导出内容">{{ csv }}</pre>
</div>
</template>
<style scoped>
.toolbar-demo-csv {
max-width: 100%;
overflow: auto;
}
</style>组件不会执行数据请求或转换导出文件。你可以将示例中的导出函数换成 Excel、PDF 或服务端导出任务,按钮的权限、确认和进度由业务决定。
搜索、筛选与视图切换
search 开启一体式关键词输入与右侧搜索图标按钮,默认高度 32px。只关心提交结果时监听 search 即可:按 Enter、点击搜索按钮或清空图标都会触发,参数是提交的关键词,清空时为空字符串。
<VTableToolbar search @search="keyword = $event" />输入草稿默认由组件持有,输入变化不会自动提交或刷新。需要在外部读取或修改草稿时(例如“重置”按钮同时清空输入框),用 v-model:search-value 接管;此时输入框显示的始终是传入的值。
清空图标依次触发 update:searchValue('')、clearSearch 和 search('')。空关键词的请求放在 search 中处理;clearSearch 只用于区分“清空”这一操作,不要在两个事件里重复请求。
#filter 放入业务已有的筛选控件;默认与操作按钮同排,multipleLine 将它放进第二行。#extra 始终使用独立整行,可组合 Tabs、批量提示条或其他业务内容。状态、页码与选择是否随视图切换而重置由业务决定。
<script setup lang="ts">
import { computed, ref } from 'vue'
import { Button, VTable, VTableToolbar } from '@vtable-guild/vtable-guild'
import type { TableColumnsType } from '@vtable-guild/vtable-guild'
interface Order {
key: number
name: string
status: 'pending' | 'done'
city: string
}
const columns: TableColumnsType<Order> = [
{ key: 'name', title: '姓名', dataIndex: 'name' },
{ key: 'city', title: '城市', dataIndex: 'city' },
{ key: 'status', title: '状态', dataIndex: 'status' },
]
const rows: Order[] = [
{ key: 1, name: '陈嘉', city: '杭州', status: 'pending' },
{ key: 2, name: '苏晚', city: '上海', status: 'done' },
{ key: 3, name: '周野', city: '杭州', status: 'pending' },
]
const submittedKeyword = ref('')
const view = ref<'all' | Order['status']>('all')
const city = ref('')
const refreshes = ref(0)
const filteredRows = computed(() =>
rows.filter(
(row) =>
(!submittedKeyword.value || row.name.includes(submittedKeyword.value)) &&
(view.value === 'all' || row.status === view.value) &&
(!city.value || row.city === city.value),
),
)
const views = [
{ key: 'all', label: '全部' },
{ key: 'pending', label: '待处理' },
{ key: 'done', label: '已完成' },
] as const
</script>
<template>
<VTable :columns="columns" :data-source="filteredRows">
<template #title>
<VTableToolbar
title="订单列表"
:search="{ placeholder: '按姓名查询' }"
:options="{ density: false, setting: false }"
multiple-line
@search="submittedKeyword = $event"
@reload="refreshes++"
>
<template #filter>
<label
>城市
<select v-model="city" aria-label="城市">
<option value="">全部城市</option>
<option value="杭州">杭州</option>
<option value="上海">上海</option>
</select></label
>
<span>刷新 {{ refreshes }} 次</span>
</template>
<template #extra>
<nav aria-label="订单视图" class="toolbar-search-views">
<Button
v-for="item in views"
:key="item.key"
:type="view === item.key ? 'primary' : 'default'"
:aria-pressed="view === item.key"
@click="view = item.key"
>{{ item.label }}</Button
>
</nav>
</template>
</VTableToolbar>
</template>
</VTable>
</template>
<style scoped>
.toolbar-search-views {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
</style>#search 可以完全替换内置搜索控件。它与其他工具栏插槽共用 searchValue、updateSearchValue(value)、submitSearch(value?)、clearSearch(),草稿同样可以不绑定。loading 期间可以修改搜索草稿,提交和清空暂时禁用;disabled 同时禁用输入和操作。按 Enter 提交时会避开输入法组合状态。
<VTableToolbar @search="submitQuery">
<template #search="{ searchValue, updateSearchValue, submitSearch, disabled }">
<a-input-search
:value="searchValue"
:disabled="disabled"
@update:value="updateSearchValue"
@search="submitSearch"
/>
</template>
</VTableToolbar>开关与替换
通过 options 隐藏某个内置工具,false 关闭所有内置工具。#actions 和 #settings 保留,业务按钮可独立使用。
<VTableToolbar
v-model:columns="columns"
v-model:size="size"
title="订单列表"
:options="{ reload: false, density: false }"
>
<template #actions="{ disabled }">
<a-button :disabled="disabled" @click="exportOrders">导出 Excel</a-button>
<a-button type="primary" :disabled="disabled" @click="createOrder">新建订单</a-button>
</template>
</VTableToolbar>#title 自定义标题区。#settings 完全替换内置工具区,适合自定义图标、操作顺序或菜单;插槽参数提供 reload、toggleFullscreen 方法及当前状态。
<VTableToolbar title="订单列表" :loading="loading" @reload="loadOrders">
<template #title><strong>订单列表</strong><a-tag>本月</a-tag></template>
<template #settings="{ reload, loading, disabled }">
<a-button :loading="loading" :disabled="disabled" @click="reload">重新加载</a-button>
</template>
</VTableToolbar>状态
columns、size与表格共用,使用v-model接受更新。未传columns时隐藏列设置;未传size时读取表格主题的默认密度。- 刷新只触发
reload。请求期间由业务设置loading,刷新按钮显示加载状态并防止重复点击,密度和列设置仍可使用。 disabled禁用内置操作。自定义按钮通过插槽参数读取disabled、loading并决定禁用规则。
全屏
工具栏放在 VTable 的 title 或 footer 插槽里时,开启 options.fullScreen 即可,整张表格(含标题、分页)进入浏览器全屏:
<VTable :columns="columns" :data-source="rows">
<template #title>
<VTableToolbar :options="{ fullScreen: true }" />
</template>
</VTable>需要把查询表单等表格以外的内容一起全屏,或工具栏不在表格插槽内时,用 fullscreenTarget 指定元素,它优先于所在表格:
<div ref="page">
<QueryForm />
<VTableToolbar :options="{ fullScreen: true }" :fullscreen-target="() => page" />
<VTable :columns="columns" :data-source="rows" />
</div>- 全屏的表格使用
--vtg-table-bg作为背景,内容超出屏幕时可滚动。自定义目标的背景、内边距和滚动由业务通过:fullscreen设置。 - 没有可用目标或浏览器不支持全屏时按钮禁用;工具栏既不在表格内又没有传
fullscreenTarget时,开发环境会给出告警。 - 浏览器确认变化后触发
fullscreenChange,按 Escape 退出也会同步;请求被拒绝时触发fullscreenError。 - 全屏时筛选菜单、列设置、页大小菜单和提示文字默认挂载到全屏元素内。通过
getPopupContainer自定义容器时,应返回全屏元素的后代。
API
TRecord 表示业务行类型。
Props
| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
title | VNodeChild | - | 标题,也可使用 #title。 |
columns | TableColumnsType<TRecord> | - | 与表格共用的受控列配置,配合 v-model:columns 使用。未传时隐藏列设置。 |
size | 'large' | 'middle' | 'small' | 跟随表格主题 | 与表格共用的密度,配合 v-model:size 使用。 |
options | false | TableToolbarOptions | - | 内置工具开关,配置项。false 关闭全部内置工具。 |
loading | boolean | false | 刷新按钮的加载状态,期间禁用刷新、搜索提交和清空。 |
search | boolean | TableToolbarSearchConfig | false | 开启内置搜索,配置项。 |
searchValue | string | - | 搜索输入草稿。传入后受控,配合 v-model:search-value 使用;不传时由组件持有。 |
multipleLine | boolean | false | 将 filter 插槽移到独立一行。 |
disabled | boolean | false | 禁用内置操作,并向插槽传递禁用状态。 |
fullscreenTarget | () => HTMLElement | null | undefined | 所在表格 | 进入全屏的元素,默认是所在表格的根元素。工具栏在表格的 title / footer 插槽外,或需要带上表格以外的内容时传入。 |
columnSettings | object | - | 内嵌列设置面板的配置,配置项。 |
locale | object | - | 实例文案覆盖,字段见主题与语言。 |
ui | object | - | 实例 slot class 覆盖,可用的 slot 见 ui slots。 |
class | string | - | 根元素 class。 |
options
内置工具的开关。fixed、draggable 传递给列设置面板。
| 字段 | 类型 | 默认值 | 说明 |
|---|---|---|---|
reload | boolean | true | 显示刷新按钮。 |
density | boolean | true | 显示密度切换。 |
setting | boolean | true | 显示列设置入口;未传 columns 时不显示。 |
fixed | boolean | true | 列设置面板中的固定按钮。 |
draggable | boolean | true | 列设置面板中的拖拽排序。 |
fullScreen | boolean | false | 显示全屏按钮。全屏目标见 fullscreenTarget。 |
search
search 传对象时的配置项;传 true 使用默认值。
| 字段 | 类型 | 默认值 | 说明 |
|---|---|---|---|
placeholder | string | 跟随语言包 | 输入框占位文本与无障碍名称,默认取语言包的 searchPlaceholder。 |
clearable | boolean | true | 有输入内容时显示清空图标。 |
columnSettings
传给内嵌列设置面板的配置,字段含义与 VTableColumnSettings 的同名属性一致。
| 字段 | 类型 | 默认值 | 说明 |
|---|---|---|---|
locale | object | - | 列设置面板的文案覆盖。 |
ui | object | - | 列设置面板的 slot class 覆盖,可用的 slot 见 ui slots。 |
class | string | - | 列设置触发器容器的 class。 |
getPopupContainer | (trigger: HTMLElement) => HTMLElement | - | 密度菜单与列设置面板的挂载容器,默认 document.body。浏览器全屏时默认挂到全屏元素内,自定义时应返回它的后代。 |
Events
| 事件 | 参数 | 说明 |
|---|---|---|
update:columns | (columns: TableColumnsType<TRecord>) => void | 列显隐、固定或顺序变化。 |
update:size | (size: 'large' | 'middle' | 'small') => void | 密度变化。 |
reset | () => void | 点击列设置面板的“重置”,只恢复初始列显隐。 |
reload | () => void | 点击刷新。组件不发起请求。 |
update:searchValue | (value: string) => void | 搜索输入草稿变化,不代表提交。 |
search | (value: string) => void | 提交搜索:按 Enter、点击搜索按钮或清空图标。清空时 value 为空字符串。 |
clearSearch | () => void | 点击清空图标,随后触发 search 并传入空字符串。 |
fullscreenChange | (active: boolean) => void | 浏览器确认进入或退出全屏后触发,包括按 Escape 退出。 |
fullscreenError | (error: unknown) => void | 全屏请求被浏览器拒绝。 |
Slots
| Slot | 参数类型 | 说明 |
|---|---|---|
title | TableToolbarSlotProps<TRecord> | 自定义标题区。 |
actions | TableToolbarSlotProps<TRecord> | 业务操作按钮,与内置工具并排。 |
settings | TableToolbarSlotProps<TRecord> | 完全替换内置工具区。 |
search | TableToolbarSlotProps<TRecord> | 替换内置搜索控件。 |
filter | TableToolbarSlotProps<TRecord> | 筛选控件;默认与操作同排,multipleLine 时独立一行。 |
extra | TableToolbarSlotProps<TRecord> | 独立整行的扩展内容。 |
columnLabel | { column: ColumnType<TRecord> | ColumnGroupType<TRecord> } | 自定义列设置面板中的列标签。 |
Slot Props
除 columnLabel 外,所有插槽都接收 TableToolbarSlotProps<TRecord>。
| 字段 | 类型 | 说明 |
|---|---|---|
columns | TableColumnsType<TRecord> | 当前列配置;未传 columns 时为空数组。 |
size | 'large' | 'middle' | 'small' | 当前密度。 |
loading | boolean | 当前加载状态。 |
disabled | boolean | 当前禁用状态。 |
fullscreen | boolean | 全屏目标是否处于全屏。 |
fullscreenAvailable | boolean | 存在全屏目标且浏览器支持全屏。 |
reload | () => void | 触发 reload 事件;disabled 或 loading 时不触发。 |
toggleFullscreen | () => Promise<void> | 进入或退出全屏。 |
searchValue | string | 当前搜索草稿。 |
updateSearchValue | (value: string) => void | 更新搜索草稿。 |
submitSearch | (value?: string) => void | 提交搜索;未传参数时使用当前草稿。 |
clearSearch | () => void | 清空草稿并提交空关键词。 |
主题与语言
工具栏使用全局 theme.toolbar.slots 或实例 ui,内嵌列设置通过 theme.columnSettings.slots 或 columnSettings.ui 覆盖。
工具栏文案跟随全局语言,支持 localeOverrides.toolbar 和实例 locale。列设置文案仍由 columnSettings.locale 或 localeOverrides.columnSettings 控制。
主题代码分别列出工具栏和列设置面板的默认 class。
ui slots
| 主题配置 | Slot | 说明 |
|---|---|---|
theme.toolbar | root | 工具栏根容器与响应式布局。 |
theme.toolbar | title | 标题区。 |
theme.toolbar | right | 业务操作和内置工具的包裹层。 |
theme.toolbar | actions | #actions 业务按钮容器。 |
theme.toolbar | settings | 内置工具或 #settings 的容器。 |
theme.toolbar | search | 工具栏轻搜索容器。 |
theme.toolbar | searchGroup | 搜索输入区和提交按钮的组合容器。 |
theme.toolbar | searchField | 搜索文本框的外层。 |
theme.toolbar | searchInput | 搜索文本输入框。 |
theme.toolbar | searchSubmit | 搜索提交按钮。 |
theme.toolbar | searchClear | 清除搜索文本按钮。 |
theme.toolbar | searchIcon | 搜索与清除图标。 |
theme.toolbar | filter | 单行布局中的 #filter 内容容器。 |
theme.toolbar | extra | #extra 与多行布局中的 #filter 内容容器。 |
theme.toolbar | action | 刷新、全屏等内置按钮。 |
theme.toolbar | icon | 内置工具图标。 |
theme.toolbar | loadingIcon | 刷新加载动画。 |
theme.columnSettings | root | 密度与列设置触发器容器。 |
theme.columnSettings | trigger | 列设置按钮。 |
theme.columnSettings | densityTrigger | 密度按钮。 |
theme.columnSettings | popup | 列设置浮层。 |
theme.columnSettings | densityPopup | 密度浮层。 |
theme.columnSettings | density | 密度菜单选项。 |
theme.columnSettings | header | 列设置面板头部。 |
theme.columnSettings | heading | 全选标题。 |
theme.columnSettings | reset | 重置按钮。 |
theme.columnSettings | columns | 列列表。 |
theme.columnSettings | children | 嵌套子列列表。 |
theme.columnSettings | item | 列列表项。 |
theme.columnSettings | row | 列选项行,作为拖拽载体。 |
theme.columnSettings | rowDragging | 拖拽中的源行描边。 |
theme.columnSettings | rowDropAbove | 目标行的上插入线。 |
theme.columnSettings | rowDropBelow | 目标行的下插入线。 |
theme.columnSettings | rowDropDot | 插入线左端的圆点。 |
theme.columnSettings | dragHandle | 拖拽手柄。 |
theme.columnSettings | pinActions | 固定位置按钮组。 |
theme.columnSettings | pinAction | 固定位置按钮。 |
theme.columnSettings | pinIcon | 固定位置图标。 |
theme.columnSettings | group | 按固定位置划分的列组容器。 |
theme.columnSettings | groupTitle | 固定位置分组标题。 |
theme.columnSettings | groupColumns | 组内列列表。 |
theme.columnSettings | label | 列选项标签。 |
theme.columnSettings | checkboxControl | 复选框容器。 |
theme.columnSettings | checkbox | 复选框输入元素。 |
theme.columnSettings | checkMark | 选中标记。 |
theme.columnSettings | indeterminateMark | 半选标记。 |
theme.columnSettings | labelText | 列选项标签文字。 |
theme.columnSettings | empty | 无可配置列时的提示。 |
预设默认值
createVTableGuild({
theme: {
toolbar: {
slots: {
root: 'flex min-h-8 flex-wrap items-center justify-between gap-x-4 gap-y-3 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-on-surface)] font-[family-name:var(--font-family-base)] leading-[var(--vtg-table-line-height)]',
title: 'min-w-0 flex-1 text-[length:var(--vtg-toolbar-title-font-size)] font-[number:var(--vtg-toolbar-title-font-weight)]',
right: 'ml-auto flex max-w-full flex-wrap items-center justify-end gap-4',
actions: 'flex max-w-full flex-wrap items-center gap-2',
settings: 'inline-flex shrink-0 items-center gap-4',
search: 'flex w-[var(--vtg-toolbar-search-width,240px)] max-w-full items-center',
searchGroup: 'inline-flex h-[var(--vtg-toolbar-search-height,32px)] w-full min-w-0 items-stretch text-[length:var(--vtg-toolbar-search-font-size,14px)]',
searchField: 'relative z-0 -mr-px flex min-w-0 flex-1 items-center gap-1 rounded-l-[var(--vtg-input-border-radius)] border border-[color:var(--color-border)] bg-[color:var(--color-surface)] px-[var(--vtg-input-padding-inline)] transition-all duration-200 hover:z-10 hover:border-[color:var(--color-primary-hover)] focus-within:z-10 focus-within:border-[color:var(--color-primary)] focus-within:shadow-[0_0_0_2px_rgba(5,145,255,0.1)] data-[disabled]:cursor-not-allowed data-[disabled]:bg-[color:var(--color-bg-disabled)] data-[disabled]:hover:border-[color:var(--color-border)]',
searchInput: 'h-full min-w-0 flex-1 rounded-none border-0 bg-transparent p-0 text-[length:var(--vtg-toolbar-search-font-size,14px)] outline-none shadow-none focus:shadow-none',
searchSubmit: 'relative z-0 inline-flex w-[var(--vtg-toolbar-search-height,32px)] shrink-0 items-center justify-center rounded-r-[var(--vtg-input-border-radius)] border border-[color:var(--color-border)] bg-[color:var(--color-surface)] p-0 text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:z-10 hover:text-[color:var(--color-primary-hover)] hover:border-[color:var(--color-primary-hover)] focus-visible:z-10 focus-visible:outline-none focus-visible:border-[color:var(--color-primary)] focus-visible:shadow-[0_0_0_2px_rgba(5,145,255,0.1)] disabled:cursor-not-allowed disabled:bg-[color:var(--color-bg-disabled)] disabled:text-[color:var(--color-text-disabled)] disabled:hover:border-[color:var(--color-border)]',
searchClear: 'inline-flex shrink-0 items-center justify-center border-0 bg-transparent p-0 text-[color:var(--color-text-placeholder)] cursor-pointer hover:text-[color:var(--color-muted)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)]',
searchIcon: 'block h-[1em] w-[1em] shrink-0',
filter: 'flex min-w-0 max-w-full flex-wrap items-center gap-2',
extra: 'flex w-full min-w-0 flex-wrap items-center gap-3',
action: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
icon: 'block',
loadingIcon: 'animate-spin motion-reduce:animate-none',
},
},
columnSettings: {
slots: {
root: 'inline-flex items-center gap-4',
trigger: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
densityTrigger: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
popup: '[--vtg-table-popup-panel-radius:var(--vtg-column-settings-radius)] [--vtg-table-popup-panel-shadow:var(--vtg-column-settings-shadow)] flex flex-col [--vtg-table-popup-width:var(--vtg-column-settings-width)] max-w-[calc(100vw-16px)]',
densityPopup: '[--vtg-table-popup-panel-radius:var(--vtg-column-settings-radius)] [--vtg-table-popup-panel-shadow:var(--vtg-column-settings-shadow)] min-w-[80px]',
density: 'block w-full border-0 rounded-[var(--vtg-btn-border-radius-sm)] px-3 py-[5px] text-left text-[length:var(--vtg-table-font-size)] font-normal leading-[var(--vtg-table-line-height)] bg-transparent cursor-pointer hover:bg-[color:var(--color-control-item-hover-bg)] aria-checked:bg-[color:var(--color-control-item-active-bg)] aria-checked:text-[color:var(--color-primary)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
header: 'flex items-center justify-between gap-3 h-8 mb-2 px-2',
heading: 'group inline-flex items-center gap-2 cursor-pointer font-normal',
reset: 'shrink-0 border-0 bg-transparent p-0 text-[color:var(--color-primary)] text-[length:var(--vtg-table-font-size)] font-semibold cursor-pointer hover:text-[color:var(--color-primary-hover)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
columns: 'm-0 max-h-[280px] overflow-auto list-none px-2 py-2',
children: 'm-0 list-none pl-6',
item: 'm-0 p-0 pb-1',
row: 'relative flex min-w-0 items-center gap-1 select-none [&[draggable=true]]:cursor-grab [&[draggable=true]]:active:cursor-grabbing [&[draggable=false]]:cursor-not-allowed',
rowDragging: 'rounded-[var(--vtg-btn-border-radius-sm)] bg-[color:var(--color-control-item-active-bg)] ring-1 ring-inset ring-[color:var(--color-primary)]',
rowDropAbove: 'pointer-events-none absolute right-0 top-0 z-[1] h-[2px] rounded-[1px] left-[calc(var(--vtg-column-settings-icon-size)+var(--vtg-checkbox-size)+16px)] bg-[color:var(--vtg-table-row-drop-indicator-color)]',
rowDropBelow: 'pointer-events-none absolute right-0 bottom-0 z-[1] h-[2px] rounded-[1px] left-[calc(var(--vtg-column-settings-icon-size)+var(--vtg-checkbox-size)+16px)] bg-[color:var(--vtg-table-row-drop-indicator-color)]',
rowDropDot: 'pointer-events-none absolute start-[-6px] top-[-3px] h-2 w-2 rounded-full border-2 border-[color:var(--vtg-table-row-drop-indicator-color)] bg-transparent',
dragHandle: 'inline-flex w-[var(--vtg-column-settings-icon-size)] shrink-0 items-center justify-center mr-2 select-none text-[color:var(--color-muted)]',
pinActions: 'inline-flex shrink-0 items-center gap-0.5',
pinAction: 'inline-flex items-center justify-center h-5 w-5 p-0 border-0 rounded-[var(--vtg-btn-border-radius-sm)] bg-transparent text-[color:var(--color-muted)] cursor-pointer hover:text-[color:var(--color-primary)] hover:bg-[color:var(--color-control-item-hover-bg)] aria-pressed:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
pinIcon: 'h-[var(--vtg-column-settings-pin-icon-size,14px)] w-[var(--vtg-column-settings-pin-icon-size,14px)]',
group: 'm-0 list-none p-0',
groupTitle: 'py-1 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-muted)]',
groupColumns: 'm-0 list-none p-0',
label: 'group flex min-w-0 flex-1 min-h-6 items-center gap-1 cursor-pointer has-[:disabled]:cursor-not-allowed has-[:disabled]:text-[color:var(--color-text-disabled)]',
checkboxControl: 'relative inline-flex shrink-0 h-[var(--vtg-checkbox-size)] w-[var(--vtg-checkbox-size)]',
checkbox: 'peer m-0 h-full w-full appearance-none border border-[color:var(--color-border)] rounded-[var(--vtg-checkbox-border-radius)] bg-[color:var(--color-surface)] cursor-inherit transition-colors duration-300 checked:bg-[color:var(--color-primary)] checked:border-[color:var(--color-primary)] group-hover:enabled:border-[color:var(--color-primary)] group-hover:enabled:checked:bg-[color:var(--color-primary-hover)] group-hover:enabled:checked:border-transparent disabled:bg-[color:var(--color-bg-disabled)] disabled:border-[color:var(--color-border)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
checkMark: 'pointer-events-none absolute box-border top-1/2 left-[22%] w-[5.71px] h-[9.14px] border-b-2 border-r-2 border-[color:var(--vtg-checkbox-check-color,#fff)] [transform:rotate(45deg)_translate(-50%,_-50%)] peer-disabled:border-[color:var(--color-text-disabled)]',
indeterminateMark: 'pointer-events-none absolute top-1/2 left-1/2 w-2 h-2 rounded-[1px] bg-[color:var(--vtg-checkbox-indeterminate-color,var(--color-primary))] -translate-x-1/2 -translate-y-1/2',
labelText: 'min-w-0 flex-1 truncate px-1',
empty: 'px-2 py-2 text-[color:var(--color-muted)]',
},
},
},
})createVTableGuild({
themePreset: 'element-plus',
theme: {
toolbar: {
slots: {
root: 'flex min-h-8 flex-wrap items-center justify-between gap-x-4 gap-y-3 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-on-surface)] font-[family-name:var(--font-family-base)] leading-[var(--vtg-table-line-height)]',
title: 'min-w-0 flex-1 text-[length:var(--vtg-toolbar-title-font-size)] font-[number:var(--vtg-toolbar-title-font-weight)]',
right: 'ml-auto flex max-w-full flex-wrap items-center justify-end gap-4',
actions: 'flex max-w-full flex-wrap items-center gap-2 [&>.el-button+.el-button]:!ml-0',
settings: 'inline-flex shrink-0 items-center gap-4',
search: 'flex w-[var(--vtg-toolbar-search-width,240px)] max-w-full items-center',
searchGroup: 'inline-flex h-[var(--vtg-toolbar-search-height,32px)] w-full min-w-0 items-stretch text-[length:var(--vtg-toolbar-search-font-size,14px)]',
searchField: 'relative z-0 -mr-px flex min-w-0 flex-1 items-center gap-1 rounded-l-[var(--vtg-input-border-radius)] border border-[color:var(--color-border)] bg-[color:var(--color-surface)] px-[var(--vtg-input-padding-inline)] transition-all duration-200 hover:z-10 hover:border-[color:var(--color-primary-hover)] focus-within:z-10 focus-within:border-[color:var(--color-primary)] focus-within:shadow-[0_0_0_2px_rgba(5,145,255,0.1)] data-[disabled]:cursor-not-allowed data-[disabled]:bg-[color:var(--color-bg-disabled)] data-[disabled]:hover:border-[color:var(--color-border)] hover:border-[color:var(--color-border-hover)] focus-within:shadow-none focus-within:hover:border-[color:var(--color-primary)]',
searchInput: 'h-full min-w-0 flex-1 rounded-none border-0 bg-transparent p-0 text-[length:var(--vtg-toolbar-search-font-size,14px)] outline-none shadow-none focus:shadow-none',
searchSubmit: 'relative z-0 inline-flex w-[var(--vtg-toolbar-search-height,32px)] shrink-0 items-center justify-center rounded-r-[var(--vtg-input-border-radius)] border border-[color:var(--color-border)] bg-[color:var(--color-surface)] p-0 text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:z-10 hover:text-[color:var(--color-primary-hover)] hover:border-[color:var(--color-primary-hover)] focus-visible:z-10 focus-visible:outline-none focus-visible:border-[color:var(--color-primary)] focus-visible:shadow-[0_0_0_2px_rgba(5,145,255,0.1)] disabled:cursor-not-allowed disabled:bg-[color:var(--color-bg-disabled)] disabled:text-[color:var(--color-text-disabled)] disabled:hover:border-[color:var(--color-border)] bg-[color:var(--color-bg-disabled)] text-[color:var(--color-muted)] focus-visible:shadow-none',
searchClear: 'inline-flex shrink-0 items-center justify-center border-0 bg-transparent p-0 text-[color:var(--color-text-placeholder)] cursor-pointer hover:text-[color:var(--color-muted)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)]',
searchIcon: 'block h-[1em] w-[1em] shrink-0',
filter: 'flex min-w-0 max-w-full flex-wrap items-center gap-2',
extra: 'flex w-full min-w-0 flex-wrap items-center gap-3',
action: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
icon: 'block',
loadingIcon: 'animate-spin motion-reduce:animate-none',
},
},
columnSettings: {
slots: {
root: 'inline-flex items-center gap-4',
trigger: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
densityTrigger: 'inline-flex items-center justify-center h-6 w-6 p-0 border-0 bg-transparent text-[length:var(--vtg-column-settings-icon-size)] text-[color:var(--color-on-surface)] cursor-pointer transition-colors duration-200 hover:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
popup: '[--vtg-table-popup-panel-radius:var(--vtg-column-settings-radius)] [--vtg-table-popup-panel-shadow:var(--vtg-column-settings-shadow)] flex flex-col [--vtg-table-popup-width:var(--vtg-column-settings-width)] max-w-[calc(100vw-16px)]',
densityPopup: '[--vtg-table-popup-panel-radius:var(--vtg-column-settings-radius)] [--vtg-table-popup-panel-shadow:var(--vtg-column-settings-shadow)] min-w-[80px]',
density: 'block w-full border-0 rounded-[var(--vtg-btn-border-radius-sm)] px-3 py-[5px] text-left text-[length:var(--vtg-table-font-size)] font-normal leading-[var(--vtg-table-line-height)] bg-transparent cursor-pointer hover:bg-[color:var(--color-control-item-hover-bg)] aria-checked:bg-[color:var(--color-control-item-active-bg)] aria-checked:text-[color:var(--color-primary)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
header: 'flex items-center justify-between gap-3 h-8 mb-2 px-2',
heading: 'group inline-flex items-center gap-2 cursor-pointer font-normal',
reset: 'shrink-0 border-0 bg-transparent p-0 text-[color:var(--color-primary)] text-[length:var(--vtg-table-font-size)] font-semibold cursor-pointer hover:text-[color:var(--color-primary-hover)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
columns: 'm-0 max-h-[280px] overflow-auto list-none px-2 py-2',
children: 'm-0 list-none pl-6',
item: 'm-0 p-0 pb-1',
row: 'relative flex min-w-0 items-center gap-1 select-none [&[draggable=true]]:cursor-grab [&[draggable=true]]:active:cursor-grabbing [&[draggable=false]]:cursor-not-allowed',
rowDragging: 'rounded-[var(--vtg-btn-border-radius-sm)] bg-[color:var(--color-control-item-active-bg)] ring-1 ring-inset ring-[color:var(--color-primary)]',
rowDropAbove: 'pointer-events-none absolute right-0 top-0 z-[1] h-[2px] rounded-[1px] left-[calc(var(--vtg-column-settings-icon-size)+var(--vtg-checkbox-size)+16px)] bg-[color:var(--vtg-table-row-drop-indicator-color)]',
rowDropBelow: 'pointer-events-none absolute right-0 bottom-0 z-[1] h-[2px] rounded-[1px] left-[calc(var(--vtg-column-settings-icon-size)+var(--vtg-checkbox-size)+16px)] bg-[color:var(--vtg-table-row-drop-indicator-color)]',
rowDropDot: 'pointer-events-none absolute start-[-6px] top-[-3px] h-2 w-2 rounded-full border-2 border-[color:var(--vtg-table-row-drop-indicator-color)] bg-transparent',
dragHandle: 'inline-flex w-[var(--vtg-column-settings-icon-size)] shrink-0 items-center justify-center mr-2 select-none text-[color:var(--color-muted)]',
pinActions: 'inline-flex shrink-0 items-center gap-0.5',
pinAction: 'inline-flex items-center justify-center h-5 w-5 p-0 border-0 rounded-[var(--vtg-btn-border-radius-sm)] bg-transparent text-[color:var(--color-muted)] cursor-pointer hover:text-[color:var(--color-primary)] hover:bg-[color:var(--color-control-item-hover-bg)] aria-pressed:text-[color:var(--color-primary)] disabled:cursor-not-allowed disabled:text-[color:var(--color-text-disabled)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)]',
pinIcon: 'h-[var(--vtg-column-settings-pin-icon-size,14px)] w-[var(--vtg-column-settings-pin-icon-size,14px)]',
group: 'm-0 list-none p-0',
groupTitle: 'py-1 text-[length:var(--vtg-table-font-size)] text-[color:var(--color-muted)]',
groupColumns: 'm-0 list-none p-0',
label: 'group flex min-w-0 flex-1 min-h-6 items-center gap-1 cursor-pointer has-[:disabled]:cursor-not-allowed has-[:disabled]:text-[color:var(--color-text-disabled)]',
checkboxControl: 'relative inline-flex shrink-0 h-[var(--vtg-checkbox-size)] w-[var(--vtg-checkbox-size)]',
checkbox: 'peer m-0 h-full w-full appearance-none border border-[color:var(--color-border)] rounded-[var(--vtg-checkbox-border-radius)] bg-[color:var(--color-surface)] cursor-inherit transition-colors duration-300 checked:bg-[color:var(--color-primary)] checked:border-[color:var(--color-primary)] group-hover:enabled:border-[color:var(--color-primary)] group-hover:enabled:checked:bg-[color:var(--color-primary-hover)] group-hover:enabled:checked:border-transparent disabled:bg-[color:var(--color-bg-disabled)] disabled:border-[color:var(--color-border)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--color-primary)] indeterminate:bg-[color:var(--color-primary)] indeterminate:border-[color:var(--color-primary)]',
checkMark: 'pointer-events-none absolute box-content top-1/2 left-1/2 w-[3px] h-[7px] border border-transparent border-l-0 border-t-0 border-[color:var(--vtg-checkbox-check-color,#fff)] [transform:translate(-45%,_-60%)_rotate(45deg)] [transform-origin:center] peer-disabled:border-[color:var(--color-text-placeholder)]',
indeterminateMark: 'pointer-events-none absolute left-0 right-0 top-[5px] w-[12px] rounded-none translate-x-0 translate-y-0 h-[2px] bg-[color:var(--vtg-checkbox-indeterminate-color,#fff)] [transform:scale(.5)]',
labelText: 'min-w-0 flex-1 truncate px-1',
empty: 'px-2 py-2 text-[color:var(--color-muted)]',
},
},
},
})CSS 变量
| 变量 | 作用 | antdv | element-plus |
|---|---|---|---|
--vtg-table-popup-radius | 筛选、批量选择等表格弹层的圆角 | 6px | 2px |
--vtg-table-popup-border | 表格弹层边框 | 0 | 1px solid var(--vtg-border-color-lighter, var(--color-default)) |
--vtg-table-popup-padding-block | 表格弹层垂直内边距 | 4px | 5px |
--vtg-table-popup-padding-inline | 表格弹层水平内边距 | 4px | 0px |
--vtg-table-popup-shadow | 表格弹层阴影 | 0 6px 16px rgb(0 0 0 / 8%), 0 3px 6px -4px rgb(0 0 0 / 12%), 0 9px 28px 8px rgb(0 0 0 / 5%) | 0 0 12px rgb(0 0 0 / 12%) |
--vtg-toolbar-title-font-size | 工具栏标题字号 | 16px | 16px |
--vtg-toolbar-title-font-weight | 工具栏标题字重 | 500 | 500 |
--vtg-toolbar-search-width | 工具栏轻搜索宽度 | 240px | 240px |
--vtg-toolbar-search-height | 工具栏轻搜索高度 | 32px | 32px |
--vtg-toolbar-search-font-size | 工具栏轻搜索字号 | 14px | 14px |
--vtg-column-settings-width | 列设置面板宽度 | 224px | 280px |
--vtg-column-settings-radius | 列设置与密度浮层圆角 | var(--vtg-table-popup-radius) | var(--vtg-table-popup-radius) |
--vtg-column-settings-icon-size | 工具栏与列设置图标大小 | 16px | 16px |
--vtg-column-settings-z | 列设置与密度浮层层级 | 1050 | 2000 |
--vtg-column-settings-shadow | 浮层阴影 | var(--vtg-table-popup-shadow) | var(--vtg-table-popup-shadow) |
--vtg-column-settings-pin-icon-size | 固定位置按钮图标大小 | 未声明,回退 14px | 未声明,回退 14px |
Type Declarations
工具栏类型
import type { VNodeChild } from 'vue'
import type {
TableColumnsType,
TableColumnSettingsProps,
TableColumnSettingsOptions,
TableColumnSettingsSize,
TableColumnSettingsSlots,
SlotProps,
ToolbarThemeConfig,
VTableGuildToolbarLocale,
} from '@vtable-guild/vtable-guild'
export interface TableToolbarOptions extends TableColumnSettingsOptions {
reload?: boolean
fullScreen?: boolean
}
export interface TableToolbarSearchConfig {
placeholder?: string
clearable?: boolean
}
export interface TableToolbarProps<TRecord extends object = Record<string, unknown>> {
title?: VNodeChild
columns?: TableColumnsType<TRecord>
size?: TableColumnSettingsSize
options?: false | TableToolbarOptions
loading?: boolean
search?: boolean | TableToolbarSearchConfig
searchValue?: string
multipleLine?: boolean
disabled?: boolean
fullscreenTarget?: () => HTMLElement | null | undefined
columnSettings?: Pick<
TableColumnSettingsProps<TRecord>,
'locale' | 'ui' | 'class' | 'getPopupContainer'
>
locale?: Partial<VTableGuildToolbarLocale>
ui?: SlotProps<ToolbarThemeConfig>
class?: string
}
export interface TableToolbarSlotProps<TRecord extends object = Record<string, unknown>> {
columns: TableColumnsType<TRecord>
size: TableColumnSettingsSize
loading: boolean
disabled: boolean
fullscreen: boolean
fullscreenAvailable: boolean
reload: () => void
toggleFullscreen: () => Promise<void>
searchValue: string
updateSearchValue: (value: string) => void
submitSearch: (value?: string) => void
clearSearch: () => void
}
export interface TableToolbarSlots<TRecord extends object = Record<string, unknown>> {
title?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
actions?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
settings?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
search?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
filter?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
extra?: (props: TableToolbarSlotProps<TRecord>) => VNodeChild
columnLabel?: TableColumnSettingsSlots<TRecord>['columnLabel']
}export interface TableColumnSettingsOptions {
density?: boolean
setting?: boolean
fixed?: boolean
draggable?: boolean
}export interface VTableGuildToolbarLocale {
searchPlaceholder?: string
search?: string
clearSearch?: string
label: string
reload: string
fullScreen: string
exitFullScreen: string
}export type ToolbarThemeConfig = typeof toolbarTheme
export type ToolbarSlots = keyof ToolbarThemeConfig['slots']