useTableConfigHook.ts 994 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import type { TableColumnProps, PaginationProps, BasicTableProps } from '@/types/basic-table';
  2. import { DEFAULT_PAGE_SIZE } from '@/constant/pagination';
  3. import { reactive } from 'vue';
  4. /**
  5. * 表格配置hook
  6. * @param columns 表格列配置
  7. * @param options 表格选项配置 element-plus表格配置
  8. * @example
  9. * const { tableConfig, pagination } = useTableConfig(columns, options);
  10. * @returns 表格配置项和分页处理方法
  11. * @description 用于BasicTable组件的配置
  12. * @author Chauncey
  13. */
  14. const useTableConfig = (columns: TableColumnProps[], options: any = {}, isPagination = true) => {
  15. // 分页配置
  16. const pagination = reactive<PaginationProps>({
  17. total: 0,
  18. pageSize: DEFAULT_PAGE_SIZE,
  19. pageNumber: 1,
  20. });
  21. // 表格配置
  22. const tableConfig = reactive<BasicTableProps>({
  23. columns,
  24. pagination: isPagination ? pagination : undefined,
  25. ...options,
  26. });
  27. return {
  28. tableConfig,
  29. pagination,
  30. };
  31. };
  32. export default useTableConfig;