index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <script lang="ts" setup>
  2. import type { VxeGridProps } from '#/adapter/vxe-table';
  3. import { Button } from 'antdv-next';
  4. import { useVbenVxeGrid } from '#/adapter/vxe-table';
  5. import { MOCK_TREE_TABLE_DATA } from '../table-data';
  6. interface RowType {
  7. date: string;
  8. id: number;
  9. name: string;
  10. parentId: null | number;
  11. size: number;
  12. type: string;
  13. }
  14. // 数据实例
  15. // const MOCK_TREE_TABLE_DATA = [
  16. // {
  17. // date: '2020-08-01',
  18. // id: 10_000,
  19. // name: 'Test1',
  20. // parentId: null,
  21. // size: 1024,
  22. // type: 'mp3',
  23. // },
  24. // {
  25. // date: '2021-04-01',
  26. // id: 10_050,
  27. // name: 'Test2',
  28. // parentId: 10_000,
  29. // size: 0,
  30. // type: 'mp4',
  31. // },
  32. // ];
  33. const gridOptions: VxeGridProps<RowType> = {
  34. columns: [
  35. { type: 'seq', width: 70 },
  36. { field: 'name', minWidth: 300, title: 'Name', treeNode: true },
  37. { field: 'size', title: 'Size' },
  38. { field: 'type', title: 'Type' },
  39. { field: 'date', title: 'Date' },
  40. ],
  41. data: MOCK_TREE_TABLE_DATA,
  42. pagerConfig: {
  43. enabled: false,
  44. },
  45. treeConfig: {
  46. parentField: 'parentId',
  47. rowField: 'id',
  48. transform: true,
  49. },
  50. };
  51. const [Grid, gridApi] = useVbenVxeGrid({ gridOptions });
  52. const expandAll = () => {
  53. gridApi.grid?.setAllTreeExpand(true);
  54. };
  55. const collapseAll = () => {
  56. gridApi.grid?.setAllTreeExpand(false);
  57. };
  58. </script>
  59. <template>
  60. <div class="vp-raw h-75 w-full">
  61. <Grid>
  62. <template #toolbar-tools>
  63. <Button class="mr-2" type="primary" @click="expandAll">
  64. 展开全部
  65. </Button>
  66. <Button type="primary" @click="collapseAll"> 折叠全部 </Button>
  67. </template>
  68. </Grid>
  69. </div>
  70. </template>