feat: 新增 useTableToolbar hooks 简化 toolbar 工具栏挂载

This commit is contained in:
puhui999
2025-05-09 16:42:44 +08:00
parent 2cbf17398b
commit 8859ee5f29
14 changed files with 823 additions and 864 deletions

View File

@@ -0,0 +1 @@
export * from './use-table-toolbar';

View File

@@ -0,0 +1,36 @@
import type { VxeTableInstance } from '#/adapter/vxe-table';
import type { TableToolbar } from '#/components/table-toolbar';
import { ref, watch } from 'vue';
export function useTableToolbar() {
const hiddenSearchBar = ref(false); // 隐藏搜索栏
const tableToolbarRef = ref<InstanceType<typeof TableToolbar>>();
const tableRef = ref<VxeTableInstance>();
const isBound = ref<boolean>(false);
/** 挂载 toolbar 工具栏 */
async function bindTableToolbar() {
const table = tableRef.value;
const tableToolbar = tableToolbarRef.value;
if (table && tableToolbar) {
await table.connect(tableToolbar.getToolbarRef()!);
isBound.value = true;
}
}
watch(
() => tableRef.value,
(val) => {
if (!val || isBound.value) return;
bindTableToolbar();
},
{ immediate: true },
);
return {
hiddenSearchBar,
tableToolbarRef,
tableRef,
};
}