ImportTable.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <Dialog v-model="dialogVisible" title="导入表" width="800px">
  3. <!-- 搜索栏 -->
  4. <el-form ref="queryFormRef" :inline="true" :model="queryParams" label-width="68px">
  5. <el-form-item label="数据源" prop="dataSourceConfigId">
  6. <el-select
  7. v-model="queryParams.dataSourceConfigId"
  8. class="!w-240px"
  9. placeholder="请选择数据源"
  10. >
  11. <el-option
  12. v-for="config in dataSourceConfigList"
  13. :key="config.id"
  14. :label="config.name"
  15. :value="config.id"
  16. />
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item label="表名称" prop="name">
  20. <el-input
  21. v-model="queryParams.name"
  22. class="!w-240px"
  23. clearable
  24. placeholder="请输入表名称"
  25. @keyup.enter="getList"
  26. />
  27. </el-form-item>
  28. <el-form-item label="表描述" prop="comment">
  29. <el-input
  30. v-model="queryParams.comment"
  31. class="!w-240px"
  32. clearable
  33. placeholder="请输入表描述"
  34. @keyup.enter="getList"
  35. />
  36. </el-form-item>
  37. <el-form-item>
  38. <el-button @click="getList">
  39. <Icon class="mr-5px" icon="ep:search" />
  40. 搜索
  41. </el-button>
  42. <el-button @click="resetQuery">
  43. <Icon class="mr-5px" icon="ep:refresh" />
  44. 重置
  45. </el-button>
  46. </el-form-item>
  47. </el-form>
  48. <!-- 列表 -->
  49. <el-row>
  50. <el-table
  51. ref="tableRef"
  52. v-loading="dbTableLoading"
  53. :data="dbTableList"
  54. height="260px"
  55. @row-click="handleRowClick"
  56. @selection-change="handleSelectionChange"
  57. >
  58. <el-table-column type="selection" width="55" />
  59. <el-table-column :show-overflow-tooltip="true" label="表名称" prop="name" />
  60. <el-table-column :show-overflow-tooltip="true" label="表描述" prop="comment" />
  61. </el-table>
  62. </el-row>
  63. <!-- 操作 -->
  64. <template #footer>
  65. <el-button :disabled="tableList.length === 0" type="primary" @click="handleImportTable">
  66. 导入
  67. </el-button>
  68. <el-button @click="close">关闭</el-button>
  69. </template>
  70. </Dialog>
  71. </template>
  72. <script lang="ts" name="InfraCodegenImportTable" setup>
  73. import * as CodegenApi from '@/api/infra/codegen'
  74. import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig'
  75. import { ElTable } from 'element-plus'
  76. const message = useMessage() // 消息弹窗
  77. const dialogVisible = ref(false) // 弹窗的是否展示
  78. const dbTableLoading = ref(true) // 数据源的加载中
  79. const dbTableList = ref<CodegenApi.DatabaseTableVO[]>([]) // 表的列表
  80. const queryParams = reactive({
  81. name: undefined,
  82. comment: undefined,
  83. dataSourceConfigId: 0
  84. })
  85. const queryFormRef = ref() // 搜索的表单
  86. const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) // 数据源列表
  87. /** 查询表数据 */
  88. const getList = async () => {
  89. dbTableLoading.value = true
  90. try {
  91. dbTableList.value = await CodegenApi.getSchemaTableList(queryParams)
  92. } finally {
  93. dbTableLoading.value = false
  94. }
  95. }
  96. /** 重置操作 */
  97. const resetQuery = async () => {
  98. queryParams.name = undefined
  99. queryParams.comment = undefined
  100. queryParams.dataSourceConfigId = dataSourceConfigList.value[0].id as number
  101. await getList()
  102. }
  103. /** 打开弹窗 */
  104. const open = async () => {
  105. // 加载数据源的列表
  106. dataSourceConfigList.value = await DataSourceConfigApi.getDataSourceConfigList()
  107. queryParams.dataSourceConfigId = dataSourceConfigList.value[0].id as number
  108. dialogVisible.value = true
  109. // 加载表的列表
  110. await getList()
  111. }
  112. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  113. /** 关闭弹窗 */
  114. const close = () => {
  115. dialogVisible.value = false
  116. tableList.value = []
  117. }
  118. const tableRef = ref<typeof ElTable>() // 表格的 Ref
  119. const tableList = ref<string[]>([]) // 选中的表名
  120. /** 处理某一行的点击 */
  121. const handleRowClick = (row) => {
  122. unref(tableRef)?.toggleRowSelection(row)
  123. }
  124. /** 多选框选中数据 */
  125. const handleSelectionChange = (selection) => {
  126. tableList.value = selection.map((item) => item.name)
  127. }
  128. /** 导入按钮操作 */
  129. const handleImportTable = async () => {
  130. await CodegenApi.createCodegenList({
  131. dataSourceConfigId: queryParams.dataSourceConfigId,
  132. tableNames: tableList.value
  133. })
  134. message.success('导入成功')
  135. emit('success')
  136. close()
  137. }
  138. const emit = defineEmits(['success'])
  139. </script>