index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable" :rowSelection="rowSelection">
  4. <template #tableTitle>
  5. <a-button preIcon="ant-design:plus-outlined" type="primary" @click="handleAdd" style="margin-right: 5px">新增</a-button>
  6. <a-dropdown v-if="selectedRowKeys.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>
  14. </template>
  15. <a-button>批量操作
  16. <Icon icon="mdi:chevron-down"></Icon>
  17. </a-button>
  18. </a-dropdown>
  19. </template>
  20. <template #action="{ record }">
  21. <TableAction :actions="getActions(record)"/>
  22. </template>
  23. </BasicTable>
  24. <TenantModal @register="registerModal" @success="reload"/>
  25. </div>
  26. </template>
  27. <script lang="ts" name="system-tenant" setup>
  28. import {ref} from 'vue';
  29. import {BasicTable, TableAction} from '/@/components/Table';
  30. import {useModal} from '/@/components/Modal';
  31. import {getTenantList, deleteTenant, batchDeleteTenant} from './tenant.api';
  32. import {columns, searchFormSchema} from './tenant.data';
  33. import TenantModal from './TenantModal.vue';
  34. import {useMessage} from "/@/hooks/web/useMessage";
  35. import { useListPage } from '/@/hooks/system/useListPage'
  36. const {createMessage} = useMessage();
  37. const [registerModal, {openModal}] = useModal();
  38. // 列表页面公共参数、方法
  39. const { prefixCls, tableContext } = useListPage({
  40. designScope: 'tenant-template',
  41. tableProps: {
  42. title: '租户列表',
  43. api: getTenantList,
  44. columns: columns,
  45. formConfig: {
  46. schemas: searchFormSchema,
  47. fieldMapToTime: [['fieldTime', ['beginDate', 'endDate'], 'YYYY-MM-DD HH:mm:ss']]
  48. }
  49. }
  50. })
  51. const [registerTable, {reload},{ rowSelection, selectedRowKeys }] =tableContext;
  52. /**
  53. * 操作列定义
  54. * @param record
  55. */
  56. function getActions(record) {
  57. return [
  58. {
  59. label: '编辑',
  60. onClick: handleEdit.bind(null, record),
  61. },
  62. {
  63. label: '删除',
  64. popConfirm: {
  65. title: '是否确认删除',
  66. placement: 'left',
  67. confirm: handleDelete.bind(null, record),
  68. },
  69. },
  70. ]
  71. }
  72. /**
  73. * 新增事件
  74. */
  75. function handleAdd() {
  76. openModal(true, {
  77. isUpdate: false,
  78. });
  79. }
  80. /**
  81. * 编辑事件
  82. */
  83. function handleEdit(record) {
  84. openModal(true, {
  85. record,
  86. isUpdate: true,
  87. });
  88. }
  89. /**
  90. * 删除事件
  91. */
  92. async function handleDelete(record) {
  93. await deleteTenant({id: record.id}, reload);
  94. }
  95. /**
  96. * 批量删除事件
  97. */
  98. async function batchHandleDelete() {
  99. await batchDeleteTenant({ids: selectedRowKeys.value}, reload);
  100. }
  101. </script>