Blame view

Yi.Vben5.Vue3/docs/src/demos/vben-vxe-table/basic/index.vue 2.07 KB
515fceeb   “wangming”   框架初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  <script lang="ts" setup>
  import type { VxeGridListeners, VxeGridProps } from '#/adapter/vxe-table';
  
  import { Button, message } from 'ant-design-vue';
  
  import { useVbenVxeGrid } from '#/adapter/vxe-table';
  
  import { MOCK_TABLE_DATA } from '../table-data';
  
  interface RowType {
    address: string;
    age: number;
    id: number;
    name: string;
    nick: string;
    role: string;
  }
  
  const gridOptions: VxeGridProps<RowType> = {
    columns: [
      { title: '序号', type: 'seq', width: 50 },
      { field: 'name', title: 'Name' },
      { field: 'age', sortable: true, title: 'Age' },
      { field: 'nick', title: 'nick' },
      { field: 'role', title: 'Role' },
      { field: 'address', showOverflow: true, title: 'Address' },
    ],
    data: MOCK_TABLE_DATA,
    pagerConfig: {
      enabled: false,
    },
    sortConfig: {
      multiple: true,
    },
  };
  
  const gridEvents: VxeGridListeners<RowType> = {
    cellClick: ({ row }) => {
      message.info(`cell-click: ${row.name}`);
    },
  };
  
  const [Grid, gridApi] = useVbenVxeGrid({ gridEvents, gridOptions });
  
  const showBorder = gridApi.useStore((state) => state.gridOptions?.border);
  const showStripe = gridApi.useStore((state) => state.gridOptions?.stripe);
  
  function changeBorder() {
    gridApi.setGridOptions({
      border: !showBorder.value,
    });
  }
  
  function changeStripe() {
    gridApi.setGridOptions({
      stripe: !showStripe.value,
    });
  }
  
  function changeLoading() {
    gridApi.setLoading(true);
    setTimeout(() => {
      gridApi.setLoading(false);
    }, 2000);
  }
  </script>
  
  <template>
    <!-- 此处的`vp-raw` 是为了适配文档的展示效果,实际使用时不需要 -->
    <div class="vp-raw w-full">
      <Grid>
        <template #toolbar-tools>
          <Button class="mr-2" type="primary" @click="changeBorder">
            {{ showBorder ? '隐藏' : '显示' }}边框
          </Button>
          <Button class="mr-2" type="primary" @click="changeLoading">
            显示loading
          </Button>
          <Button class="mr-2" type="primary" @click="changeStripe">
            {{ showStripe ? '隐藏' : '显示' }}斑马纹
          </Button>
        </template>
      </Grid>
    </div>
  </template>