vben
2020-11-17 0b6110a8fc92a11df6501346e093246a5abe2b0e
提交 | 用户 | age
faf3f4 1 <template>
2   <div class="p-4">
3     <BasicTable @register="registerTable">
0b6110 4       <template #action="{ record }">
faf3f4 5         <TableAction
6           :actions="[
7             {
8               label: '删除',
0b6110 9               onClick: handleDelete.bind(null, record),
faf3f4 10             },
11           ]"
12           :dropDownActions="[
13             {
14               label: '启用',
0b6110 15               onClick: handleOpen.bind(null, record),
faf3f4 16             },
17           ]"
18         />
19       </template>
20     </BasicTable>
21   </div>
22 </template>
23 <script lang="ts">
24   import { defineComponent } from 'vue';
25   import { BasicTable, useTable, BasicColumn, TableAction } from '/@/components/Table';
26
27   import { demoListApi } from '/@/api/demo/table';
28   const columns: BasicColumn[] = [
29     {
30       title: 'ID',
31       dataIndex: 'id',
32       fixed: 'left',
33       width: 280,
34     },
35     {
36       title: '姓名',
37       dataIndex: 'name',
38       width: 260,
39     },
40     {
41       title: '地址',
42       dataIndex: 'address',
43       width: 260,
44     },
45     {
46       title: '编号',
47       dataIndex: 'no',
48       width: 300,
49     },
50     {
51       title: '开始时间',
52       width: 200,
53       dataIndex: 'beginTime',
54     },
55     {
56       title: '结束时间',
57       dataIndex: 'endTime',
58       width: 200,
59     },
60   ];
61   export default defineComponent({
62     components: { BasicTable, TableAction },
63     setup() {
64       const [registerTable] = useTable({
65         title: 'TableAction组件及固定列示例',
66         api: demoListApi,
67         columns: columns,
68         rowSelection: { type: 'radio' },
69         actionColumn: {
70           width: 160,
71           title: 'Action',
72           dataIndex: 'action',
73           slots: { customRender: 'action' },
74         },
75       });
0b6110 76       function handleDelete(record: any) {
V 77         console.log('点击了删除', record);
faf3f4 78       }
0b6110 79       function handleOpen(record: any) {
V 80         console.log('点击了启用', record);
faf3f4 81       }
82       return {
83         registerTable,
84         handleDelete,
85         handleOpen,
86       };
87     },
88   });
89 </script>