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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
| <template>
| <PageWrapper
| title="VxeTable表格"
| content="只展示部分操作,详细功能请查看VxeTable官网事例"
| contentFullHeight
| fixedHeight
| >
| <VxeBasicTable ref="tableRef" v-bind="gridOptions">
| <template #action="{ row }">
| <TableAction outside :actions="createActions(row)" />
| </template>
| </VxeBasicTable>
| </PageWrapper>
| </template>
| <script lang="ts" setup>
| import { reactive, ref } from 'vue';
| import { ActionItem, TableAction } from '/@/components/Table';
| import { PageWrapper } from '/@/components/Page';
| import { useMessage } from '/@/hooks/web/useMessage';
| import { vxeTableColumns, vxeTableFormSchema } from './tableData';
| import { BasicTableProps, VxeBasicTable, VxeGridInstance } from '/@/components/VxeTable';
| import { demoListApi } from '/@/api/demo/table';
|
| const { createMessage } = useMessage();
|
| const tableRef = ref<VxeGridInstance>();
|
| const gridOptions = reactive<BasicTableProps>({
| id: 'VxeTable',
| keepSource: true,
| editConfig: { trigger: 'click', mode: 'cell', showStatus: true },
| columns: vxeTableColumns,
| toolbarConfig: {
| buttons: [
| {
| content: '在第一行新增',
| buttonRender: {
| name: 'AButton',
| props: {
| type: 'primary',
| preIcon: 'mdi:page-next-outline',
| },
| events: {
| click: () => {
| tableRef.value?.insert({ name: '新增的' });
| createMessage.success('新增成功');
| },
| },
| },
| },
| {
| content: '在最后一行新增',
| buttonRender: {
| name: 'AButton',
| props: {
| type: 'warning',
| },
| events: {
| click: () => {
| tableRef.value?.insertAt({ name: '新增的' }, -1);
| },
| },
| },
| },
| ],
| },
| 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 }) => {
| return await demoListApi(form);
| },
| },
| },
| });
|
| // 操作按钮(权限控制)
| const createActions = (record) => {
| const actions: ActionItem[] = [
| {
| label: '详情',
| onClick: () => {
| console.log(record);
| },
| },
| {
| label: '编辑',
| onClick: () => {},
| },
| {
| label: '删除',
| color: 'error',
| popConfirm: {
| title: '是否确认删除?',
| placement: 'left',
| confirm: () => {
| tableRef.value?.remove(record);
| },
| },
| },
| ];
|
| return actions;
| };
| </script>
|
|