index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable" :rowSelection="rowSelection">
  4. <template #tableTitle>
  5. <a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleAdd" style="margin-right: 5px">新增</a-button>
  6. <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
  7. <j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
  8. <a-dropdown v-if="selectedRowKeys.length > 0">
  9. <template #overlay>
  10. <a-menu>
  11. <a-menu-item key="1" @click="batchHandleDelete">
  12. <Icon icon="ant-design:delete-outlined"></Icon>
  13. 删除
  14. </a-menu-item>
  15. </a-menu>
  16. </template>
  17. <a-button
  18. >批量操作
  19. <Icon icon="mdi:chevron-down"></Icon>
  20. </a-button>
  21. </a-dropdown>
  22. </template>
  23. <template #action="{ record }">
  24. <TableAction :actions="getActions(record)" />
  25. </template>
  26. </BasicTable>
  27. <DataSourceModal @register="registerModal" @success="reload" />
  28. </div>
  29. </template>
  30. <script lang="ts" name="monitor-datasource" setup>
  31. import { ref } from 'vue';
  32. import { BasicTable, TableAction } from '/@/components/Table';
  33. import { useModal } from '/@/components/Modal';
  34. import { getDataSourceList, deleteDataSource, batchDeleteDataSource, getExportUrl, getImportUrl } from './datasource.api';
  35. import { columns, searchFormSchema } from './datasource.data';
  36. import DataSourceModal from './DataSourceModal.vue';
  37. import { useMessage } from '/@/hooks/web/useMessage';
  38. import { useListPage } from '/@/hooks/system/useListPage';
  39. const { createMessage } = useMessage();
  40. const [registerModal, { openModal }] = useModal();
  41. // 列表页面公共参数、方法
  42. const { prefixCls, tableContext, onImportXls, onExportXls } = useListPage({
  43. designScope: 'quartz-template',
  44. tableProps: {
  45. title: '任务列表',
  46. api: getDataSourceList,
  47. columns: columns,
  48. formConfig: {
  49. labelWidth: 120,
  50. schemas: searchFormSchema,
  51. fieldMapToTime: [['fieldTime', ['beginDate', 'endDate'], 'YYYY-MM-DD HH:mm:ss']],
  52. },
  53. },
  54. exportConfig: {
  55. name: '数据源列表',
  56. url: getExportUrl,
  57. },
  58. importConifg: {
  59. url: getImportUrl,
  60. },
  61. });
  62. const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  63. /**
  64. * 操作列定义
  65. * @param record
  66. */
  67. function getActions(record) {
  68. return [
  69. {
  70. label: '编辑',
  71. onClick: handleEdit.bind(null, record),
  72. },
  73. {
  74. label: '删除',
  75. popConfirm: {
  76. title: '是否确认删除',
  77. confirm: handleDelete.bind(null, record),
  78. },
  79. },
  80. ];
  81. }
  82. /**
  83. * 新增事件
  84. */
  85. function handleAdd() {
  86. openModal(true, {
  87. isUpdate: false,
  88. });
  89. }
  90. /**
  91. * 编辑事件
  92. */
  93. function handleEdit(record) {
  94. openModal(true, {
  95. record,
  96. isUpdate: true,
  97. });
  98. }
  99. /**
  100. * 删除事件
  101. */
  102. async function handleDelete(record) {
  103. await deleteDataSource({ id: record.id }, reload);
  104. }
  105. /**
  106. * 批量删除事件
  107. */
  108. async function batchHandleDelete() {
  109. await batchDeleteDataSource({ ids: selectedRowKeys.value }, reload);
  110. }
  111. </script>