Blame view

src/views/demo/table/VxeTable.vue 2.9 KB
1
2
3
4
5
6
7
8
9
<template>
  <PageWrapper
    title="VxeTable表格"
    content="只展示部分操作,详细功能请查看VxeTable官网事例"
    contentFullHeight
    fixedHeight
  >
    <VxeBasicTable ref="tableRef" v-bind="gridOptions">
      <template #action="{ row }">
10
        <TableAction outside :actions="createActions(row)" />
11
12
13
14
15
16
      </template>
    </VxeBasicTable>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { reactive, ref } from 'vue';
17
  import { ActionItem, TableAction } from '/@/components/Table';
18
19
20
  import { PageWrapper } from '/@/components/Page';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { vxeTableColumns, vxeTableFormSchema } from './tableData';
21
  import { BasicTableProps, VxeBasicTable, VxeGridInstance } from '/@/components/VxeTable';
22
23
24
25
26
27
28
29
  import { demoListApi } from '/@/api/demo/table';

  const { createMessage } = useMessage();

  const tableRef = ref<VxeGridInstance>();

  const gridOptions = reactive<BasicTableProps>({
    id: 'VxeTable',
30
    keepSource: true,
31
32
33
34
35
    editConfig: { trigger: 'click', mode: 'cell', showStatus: true },
    columns: vxeTableColumns,
    toolbarConfig: {
      buttons: [
        {
36
          content: '在第一行新增',
37
38
39
40
          buttonRender: {
            name: 'AButton',
            props: {
              type: 'primary',
41
              preIcon: 'mdi:page-next-outline',
42
43
44
            },
            events: {
              click: () => {
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
                tableRef.value?.insert({ name: '新增的' });
                createMessage.success('新增成功');
              },
            },
          },
        },
        {
          content: '在最后一行新增',
          buttonRender: {
            name: 'AButton',
            props: {
              type: 'warning',
            },
            events: {
              click: () => {
                tableRef.value?.insertAt({ name: '新增的' }, -1);
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
              },
            },
          },
        },
      ],
    },
    formConfig: {
      enabled: true,
      items: vxeTableFormSchema,
    },
    height: 'auto',
    proxyConfig: {
      ajax: {
        query: async ({ page, form }) => {
          return demoListApi({
            pageNum: page.currentPage,
            pageSize: page.pageSize,
            ...form,
          });
        },
        queryAll: async ({ form }) => {
82
          return await demoListApi(form);
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
        },
      },
    },
  });

  // 操作按钮(权限控制)
  const createActions = (record) => {
    const actions: ActionItem[] = [
      {
        label: '详情',
        onClick: () => {
          console.log(record);
        },
      },
      {
        label: '编辑',
        onClick: () => {},
      },
      {
        label: '删除',
        color: 'error',
        popConfirm: {
          title: '是否确认删除',
106
107
108
          confirm: () => {
            tableRef.value?.remove(record);
          },
109
110
111
112
113
114
115
        },
      },
    ];

    return actions;
  };
</script>