UserRecycleBinModal.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <BasicModal v-bind="$attrs" @register="registerModal" title="用户回收站" :showOkBtn="false" width="1000px" destroyOnClose>
  3. <BasicTable @register="registerTable" :rowSelection="rowSelection">
  4. <!--插槽:table标题-->
  5. <template #tableTitle>
  6. <a-dropdown v-if="checkedKeys.length > 0">
  7. <template #overlay>
  8. <a-menu>
  9. <a-menu-item key="1" @click="batchHandleDelete">
  10. <Icon icon="ant-design:delete-outlined"></Icon>
  11. 批量删除
  12. </a-menu-item>
  13. <a-menu-item key="1" @click="batchHandleRevert">
  14. <Icon icon="ant-design:redo-outlined"></Icon>
  15. 批量还原
  16. </a-menu-item>
  17. </a-menu>
  18. </template>
  19. <a-button
  20. >批量操作
  21. <Icon icon="ant-design:down-outlined"></Icon>
  22. </a-button>
  23. </a-dropdown>
  24. </template>
  25. <!--操作栏-->
  26. <template #bodyCell="{ column, record }">
  27. <template v-if="column.key === 'action'">
  28. <TableAction :actions="getTableAction(record)" />
  29. </template>
  30. </template>
  31. </BasicTable>
  32. </BasicModal>
  33. </template>
  34. <script lang="ts" setup>
  35. import { ref, toRaw, unref } from 'vue';
  36. import { BasicModal, useModalInner } from '/@/components/Modal';
  37. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  38. import { recycleColumns } from './user.data';
  39. import { getRecycleBinList, putRecycleBin, deleteRecycleBin } from './user.api';
  40. import { useMessage } from '/@/hooks/web/useMessage';
  41. const { createConfirm } = useMessage();
  42. // 声明Emits
  43. const emit = defineEmits(['success', 'register']);
  44. const checkedKeys = ref<Array<string | number>>([]);
  45. const [registerModal] = useModalInner(() => {
  46. checkedKeys.value = [];
  47. });
  48. //注册table数据
  49. const [registerTable, { reload }] = useTable({
  50. api: getRecycleBinList,
  51. columns: recycleColumns,
  52. rowKey: 'id',
  53. striped: true,
  54. useSearchForm: false,
  55. showTableSetting: false,
  56. clickToRowSelect: false,
  57. bordered: true,
  58. showIndexColumn: false,
  59. pagination: true,
  60. tableSetting: { fullScreen: true },
  61. canResize: false,
  62. actionColumn: {
  63. width: 150,
  64. title: '操作',
  65. dataIndex: 'action',
  66. // slots: { customRender: 'action' },
  67. fixed: undefined,
  68. },
  69. });
  70. /**
  71. * 选择列配置
  72. */
  73. const rowSelection = {
  74. type: 'checkbox',
  75. columnWidth: 50,
  76. selectedRowKeys: checkedKeys,
  77. onChange: onSelectChange,
  78. };
  79. /**
  80. * 选择事件
  81. */
  82. function onSelectChange(selectedRowKeys: (string | number)[]) {
  83. checkedKeys.value = selectedRowKeys;
  84. }
  85. /**
  86. * 还原事件
  87. */
  88. async function handleRevert(record) {
  89. await putRecycleBin({ userIds: record.id }, reload);
  90. emit('success');
  91. }
  92. /**
  93. * 批量还原事件
  94. */
  95. function batchHandleRevert() {
  96. handleRevert({ id: toRaw(unref(checkedKeys)).join(',') });
  97. }
  98. /**
  99. * 删除事件
  100. */
  101. async function handleDelete(record) {
  102. await deleteRecycleBin({ userIds: record.id }, reload);
  103. }
  104. /**
  105. * 批量删除事件
  106. */
  107. function batchHandleDelete() {
  108. createConfirm({
  109. iconType: 'warning',
  110. title: '删除',
  111. content: '确定要永久删除吗?删除后将不可恢复!',
  112. onOk: () => handleDelete({ id: toRaw(unref(checkedKeys)).join(',') }),
  113. onCancel() {},
  114. });
  115. }
  116. //获取操作栏事件
  117. function getTableAction(record) {
  118. return [
  119. {
  120. label: '取回',
  121. icon: 'ant-design:redo-outlined',
  122. popConfirm: {
  123. title: '是否确认还原',
  124. confirm: handleRevert.bind(null, record),
  125. },
  126. },
  127. {
  128. label: '彻底删除',
  129. icon: 'ant-design:scissor-outlined',
  130. popConfirm: {
  131. title: '是否确认删除',
  132. confirm: handleDelete.bind(null, record),
  133. },
  134. },
  135. ];
  136. }
  137. </script>