AuthColumn.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. import { demoListApi } from '/@/api/demo/table';
  61. const columns: BasicColumn[] = [
  62. {
  63. title: '编号',
  64. dataIndex: 'no',
  65. width: 100,
  66. },
  67. {
  68. title: '姓名',
  69. dataIndex: 'name',
  70. auth: 'test', // 根据权限控制是否显示: 无权限,不显示
  71. },
  72. {
  73. title: '状态',
  74. dataIndex: 'status',
  75. },
  76. {
  77. title: '地址',
  78. dataIndex: 'address',
  79. auth: 'super', // 同时根据权限和业务控制是否显示
  80. ifShow: (_column) => {
  81. return true;
  82. },
  83. },
  84. {
  85. title: '开始时间',
  86. dataIndex: 'beginTime',
  87. },
  88. {
  89. title: '结束时间',
  90. dataIndex: 'endTime',
  91. width: 200,
  92. },
  93. ];
  94. export default defineComponent({
  95. components: { BasicTable, TableAction },
  96. setup() {
  97. const [registerTable] = useTable({
  98. title: 'TableAction组件及固定列示例',
  99. api: demoListApi,
  100. columns: columns,
  101. bordered: true,
  102. actionColumn: {
  103. width: 250,
  104. title: 'Action',
  105. dataIndex: 'action',
  106. slots: { customRender: 'action' },
  107. },
  108. });
  109. function handleEdit(record: Recordable) {
  110. console.log('点击了编辑', record);
  111. }
  112. function handleDelete(record: Recordable) {
  113. console.log('点击了删除', record);
  114. }
  115. function handleOpen(record: Recordable) {
  116. console.log('点击了启用', record);
  117. }
  118. return {
  119. registerTable,
  120. handleEdit,
  121. handleDelete,
  122. handleOpen,
  123. };
  124. },
  125. });
  126. </script>