index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!-- eslint-disable vue/multi-word-component-names -->
  2. <template>
  3. <BasicTable @register="registerMapTable" :rowSelection="rowSelection">
  4. <template #resetBefore>
  5. <!-- <a-button type="default" class="ml-8px" preIcon="mdi:download" @click="onExportXls"> 下载 </a-button> -->
  6. <a-button type="default" class="ml-8px" preIcon="mdi:plus" @click="handleOpenModal({})"> 新增 </a-button>
  7. </template>
  8. <template #action="{ record }">
  9. <button @click="handleGoToPageQuery(record, `/manage/mapView`)" class="action-btn" title=""> 布点 </button>
  10. <button @click="handleOpenModal(record)" class="action-btn" title="修改">
  11. <SvgIcon name="edit" />
  12. </button>
  13. <!-- 删除按钮 -->
  14. <Popconfirm
  15. title="删除确认"
  16. description="是否确认删除?"
  17. okText="确认"
  18. cancelText="取消"
  19. @confirm="handleDeleteRecord(record)"
  20. @cancel="handleCancel"
  21. placement="top"
  22. >
  23. <button class="action-btn" title="删除">
  24. <SvgIcon name="delete" />
  25. </button>
  26. </Popconfirm>
  27. </template>
  28. </BasicTable>
  29. <!-- 注册编辑弹框组件 -->
  30. <MapEditModal @register="registerModal" @success="handleModalSuccess" />
  31. </template>
  32. <script setup lang="ts">
  33. import { computed, onMounted } from 'vue';
  34. import { useRouter } from 'vue-router';
  35. import { BasicTable } from '/@/components/Table';
  36. import { SvgIcon } from '/@/components/Icon';
  37. import { Popconfirm } from 'ant-design-vue';
  38. // 引入动态列/表单配置函数 + 类型
  39. import { getColumns, getSearchFormSchema } from './cad.data';
  40. import { getMineFileList, deleteMineFile } from './cad.api';
  41. import { useListPage } from '/@/hooks/system/useListPage';
  42. // import { useIntervalFn } from '@vueuse/core';
  43. import { useModal } from '/@/components/Modal';
  44. import MapEditModal from './components/MapEditModal.vue';
  45. // 路由实例
  46. const router = useRouter();
  47. // 弹框注册
  48. const [registerModal, { openModal }] = useModal();
  49. // 生成动态列和搜索表单(computed响应式更新)
  50. const columns = computed(() => getColumns());
  51. const searchFormSchema = computed(() => getSearchFormSchema());
  52. // ========== 表格注册 ==========
  53. const { tableContext: mapManageTable } = useListPage({
  54. tableProps: {
  55. api: getMineFileList, // 数据统计接口
  56. // dataSource: mockData,
  57. columns, // 绑定动态列
  58. rowKey: 'mineCode',
  59. rowSelection: {
  60. type: 'checkbox',
  61. onChange: (selectedRowKeys, selectedRows) => {
  62. console.log('选中了:', selectedRowKeys, selectedRows);
  63. },
  64. },
  65. formConfig: {
  66. labelWidth: 120,
  67. schemas: searchFormSchema.value, // 绑定动态搜索表单
  68. showAdvancedButton: false,
  69. schemaGroupNames: ['常规查询'],
  70. },
  71. showIndexColumn: false,
  72. scroll: { x: 'max-content' },
  73. },
  74. exportConfig: {
  75. url: '/ventanaly-province/province/mineData/exportMineData', //后端接口未知
  76. name: '矿山信息',
  77. params: {},
  78. },
  79. });
  80. const [registerMapTable, mapTable, { rowSelection }] = mapManageTable;
  81. // const { pause, resume } = useIntervalFn(() => mapTable.reload({ silence: true }), 60000);
  82. /**
  83. * 打开弹框函数
  84. * @param result 弹框数据
  85. */
  86. function handleOpenModal(record: any) {
  87. openModal(true, { ...record });
  88. }
  89. /**
  90. * 弹框结果处理函数
  91. * @param result 弹框数据
  92. */
  93. async function handleModalSuccess() {
  94. await mapTable.reload();
  95. }
  96. /**
  97. * 删除记录方法
  98. * @param record 当前行数据
  99. */
  100. async function handleDeleteRecord(record: any) {
  101. try {
  102. await deleteMineFile({ id: record.id });
  103. await mapTable.reload();
  104. } catch (error) {
  105. console.error('删除失败:', error);
  106. }
  107. }
  108. function handleGoToPageQuery(record: any, path: string) {
  109. const mineCode = record.mineCode;
  110. router.push({
  111. path,
  112. state: { mineCode },
  113. });
  114. }
  115. /**
  116. * 气泡取消按钮通用回调
  117. */
  118. function handleCancel() {
  119. // 取消操作,无逻辑(仅关闭气泡)
  120. }
  121. // ========== 初始化 ==========
  122. onMounted(async () => {});
  123. </script>
  124. <style lang="less" scoped>
  125. .action-btn {
  126. height: 30px;
  127. cursor: pointer;
  128. margin-right: 10px;
  129. background: none;
  130. &:last-child {
  131. margin-right: 0;
  132. }
  133. }
  134. </style>