ruoyi-plus-vben5/apps/web-antd/src/views/system/menu/helper.ts

26 lines
775 B
TypeScript
Raw Normal View History

2025-05-26 09:28:54 +08:00
import type { MaybePromise } from '@vben/types';
import type { useVbenVxeGrid } from '#/adapter/vxe-table';
/**
* / // ()
*
* @param tableApi api
* @param callback
*/
export async function preserveTreeTableState(
tableApi: ReturnType<typeof useVbenVxeGrid>[1],
callback: () => MaybePromise<void>,
) {
// 保存当前状态
const scrollState = tableApi.grid.getScroll();
const expandRecords = tableApi.grid.getTreeExpandRecords();
// 执行回调
await callback();
// 恢复状态
tableApi.grid.setTreeExpand(expandRecords, true);
tableApi.grid.scrollTo(scrollState.scrollLeft, scrollState.scrollTop);
}