AuthColumn.vue 4.1 KB

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