1
0

basic.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <script lang="ts" setup>
  2. import type { VxeGridListeners, VxeGridProps } from '#/adapter/vxe-table';
  3. import { Page } from '@vben/common-ui';
  4. import { Button, message } from 'ant-design-vue';
  5. import { useVbenVxeGrid } from '#/adapter/vxe-table';
  6. import DocButton from '../doc-button.vue';
  7. import { MOCK_TABLE_DATA } from './table-data';
  8. interface RowType {
  9. address: string;
  10. age: number;
  11. id: number;
  12. name: string;
  13. nickname: string;
  14. role: string;
  15. }
  16. const gridOptions: VxeGridProps<RowType> = {
  17. columns: [
  18. { title: '序号', type: 'seq', width: 50 },
  19. { field: 'name', title: 'Name' },
  20. { field: 'age', sortable: true, title: 'Age' },
  21. { field: 'nickname', title: 'Nickname' },
  22. { field: 'role', title: 'Role' },
  23. { field: 'address', showOverflow: true, title: 'Address' },
  24. ],
  25. data: MOCK_TABLE_DATA,
  26. pagerConfig: {
  27. enabled: false,
  28. },
  29. sortConfig: {
  30. multiple: true,
  31. },
  32. };
  33. const gridEvents: VxeGridListeners<RowType> = {
  34. cellClick: ({ row }) => {
  35. message.info(`cell-click: ${row.name}`);
  36. },
  37. };
  38. const [Grid, gridApi] = useVbenVxeGrid({ gridEvents, gridOptions });
  39. const showBorder = gridApi.useStore((state) => state.gridOptions?.border);
  40. const showStripe = gridApi.useStore((state) => state.gridOptions?.stripe);
  41. function changeBorder() {
  42. gridApi.setGridOptions({
  43. border: !showBorder.value,
  44. });
  45. }
  46. function changeStripe() {
  47. gridApi.setGridOptions({
  48. stripe: !showStripe.value,
  49. });
  50. }
  51. function changeLoading() {
  52. gridApi.setLoading(true);
  53. setTimeout(() => {
  54. gridApi.setLoading(false);
  55. }, 2000);
  56. }
  57. </script>
  58. <template>
  59. <Page
  60. description="表格组件常用于快速开发数据展示与交互界面,示例数据为静态数据。该组件是对vxe-table进行简单的二次封装,大部分属性与方法与vxe-table保持一致。"
  61. title="表格基础示例"
  62. >
  63. <template #extra>
  64. <DocButton path="/components/common-ui/vben-vxe-table" />
  65. </template>
  66. <Grid table-title="基础列表" table-title-help="提示">
  67. <!-- <template #toolbar-actions>
  68. <Button class="mr-2" type="primary">左侧插槽</Button>
  69. </template> -->
  70. <template #toolbar-tools>
  71. <Button class="mr-2" type="primary" @click="changeBorder">
  72. {{ showBorder ? '隐藏' : '显示' }}边框
  73. </Button>
  74. <Button class="mr-2" type="primary" @click="changeLoading">
  75. 显示loading
  76. </Button>
  77. <Button class="mr-2" type="primary" @click="changeStripe">
  78. {{ showStripe ? '隐藏' : '显示' }}斑马纹
  79. </Button>
  80. </template>
  81. </Grid>
  82. </Page>
  83. </template>