|
| 1 | +<template> |
| 2 | + <div class="p-4"> |
| 3 | + <BasicTable @register="registerTable"> |
| 4 | + <template #action="{ record }"> |
| 5 | + <TableAction |
| 6 | + :actions="[ |
| 7 | + { |
| 8 | + label: '编辑', |
| 9 | + onClick: handleEdit.bind(null, record), |
| 10 | + auth: 'other', // 根据权限控制是否显示: 无权限,不显示 |
| 11 | + }, |
| 12 | + { |
| 13 | + label: '删除', |
| 14 | + icon: 'ic:outline-delete-outline', |
| 15 | + onClick: handleDelete.bind(null, record), |
| 16 | + auth: 'super', // 根据权限控制是否显示: 有权限,会显示 |
| 17 | + }, |
| 18 | + ]" |
| 19 | + :dropDownActions="[ |
| 20 | + { |
| 21 | + label: '启用', |
| 22 | + popConfirm: { |
| 23 | + title: '是否启用?', |
| 24 | + confirm: handleOpen.bind(null, record), |
| 25 | + }, |
| 26 | + ifShow: (_action) => { |
| 27 | + return record.status !== 'enable'; // 根据业务控制是否显示: 非enable状态的不显示启用按钮 |
| 28 | + }, |
| 29 | + }, |
| 30 | + { |
| 31 | + label: '禁用', |
| 32 | + popConfirm: { |
| 33 | + title: '是否禁用?', |
| 34 | + confirm: handleOpen.bind(null, record), |
| 35 | + }, |
| 36 | + ifShow: () => { |
| 37 | + return record.status === 'enable'; // 根据业务控制是否显示: enable状态的显示禁用按钮 |
| 38 | + }, |
| 39 | + }, |
| 40 | + { |
| 41 | + label: '同时控制', |
| 42 | + popConfirm: { |
| 43 | + title: '是否动态显示?', |
| 44 | + confirm: handleOpen.bind(null, record), |
| 45 | + }, |
| 46 | + auth: 'super', // 同时根据权限和业务控制是否显示 |
| 47 | + ifShow: () => { |
| 48 | + return true; |
| 49 | + }, |
| 50 | + }, |
| 51 | + ]" |
| 52 | + /> |
| 53 | + </template> |
| 54 | + </BasicTable> |
| 55 | + </div> |
| 56 | +</template> |
| 57 | +<script lang="ts"> |
| 58 | + import { defineComponent } from 'vue'; |
| 59 | + import { BasicTable, useTable, BasicColumn, TableAction } from '/@/components/Table'; |
| 60 | +
|
| 61 | + import { demoListApi } from '/@/api/demo/table'; |
| 62 | + const columns: BasicColumn[] = [ |
| 63 | + { |
| 64 | + title: '编号', |
| 65 | + dataIndex: 'no', |
| 66 | + width: 100, |
| 67 | + }, |
| 68 | + { |
| 69 | + title: '姓名', |
| 70 | + dataIndex: 'name', |
| 71 | + auth: 'test', // 根据权限控制是否显示: 无权限,不显示 |
| 72 | + }, |
| 73 | + { |
| 74 | + title: '状态', |
| 75 | + dataIndex: 'status', |
| 76 | + }, |
| 77 | + { |
| 78 | + title: '地址', |
| 79 | + dataIndex: 'address', |
| 80 | + auth: 'super', // 同时根据权限和业务控制是否显示 |
| 81 | + ifShow: (_column) => { |
| 82 | + return true; |
| 83 | + }, |
| 84 | + }, |
| 85 | + { |
| 86 | + title: '开始时间', |
| 87 | + dataIndex: 'beginTime', |
| 88 | + }, |
| 89 | + { |
| 90 | + title: '结束时间', |
| 91 | + dataIndex: 'endTime', |
| 92 | + width: 200, |
| 93 | + }, |
| 94 | + ]; |
| 95 | + export default defineComponent({ |
| 96 | + components: { BasicTable, TableAction }, |
| 97 | + setup() { |
| 98 | + const [registerTable] = useTable({ |
| 99 | + title: 'TableAction组件及固定列示例', |
| 100 | + api: demoListApi, |
| 101 | + columns: columns, |
| 102 | + bordered: true, |
| 103 | + actionColumn: { |
| 104 | + width: 250, |
| 105 | + title: 'Action', |
| 106 | + dataIndex: 'action', |
| 107 | + slots: { customRender: 'action' }, |
| 108 | + }, |
| 109 | + }); |
| 110 | + function handleEdit(record: Recordable) { |
| 111 | + console.log('点击了编辑', record); |
| 112 | + } |
| 113 | + function handleDelete(record: Recordable) { |
| 114 | + console.log('点击了删除', record); |
| 115 | + } |
| 116 | + function handleOpen(record: Recordable) { |
| 117 | + console.log('点击了启用', record); |
| 118 | + } |
| 119 | + return { |
| 120 | + registerTable, |
| 121 | + handleEdit, |
| 122 | + handleDelete, |
| 123 | + handleOpen, |
| 124 | + }; |
| 125 | + }, |
| 126 | + }); |
| 127 | +</script> |
0 commit comments