importTable.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <!-- 导入表 -->
  3. <el-dialog title="导入表" :visible.sync="visible" width="800px" top="5vh" append-to-body>
  4. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
  5. <el-form-item label="数据源" prop="dataSourceConfigId">
  6. <el-select v-model="queryParams.dataSourceConfigId" placeholder="请选择数据源" clearable>
  7. <el-option v-for="config in dataSourceConfigs"
  8. :key="config.id" :label="config.name" :value="config.id"/>
  9. </el-select>
  10. </el-form-item>
  11. <el-form-item label="表名称" prop="name">
  12. <el-input v-model="queryParams.name" placeholder="请输入表名称" clearable @keyup.enter.native="handleQuery" />
  13. </el-form-item>
  14. <el-form-item label="表描述" prop="comment">
  15. <el-input v-model="queryParams.comment" placeholder="请输入表描述" clearable @keyup.enter.native="handleQuery"/>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  19. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  20. </el-form-item>
  21. </el-form>
  22. <el-row>
  23. <el-table v-loading="loading" @row-click="clickRow" ref="table" :data="dbTableList"
  24. @selection-change="handleSelectionChange" height="260px">
  25. <el-table-column type="selection" width="55" />
  26. <el-table-column prop="name" label="表名称" :show-overflow-tooltip="true" />
  27. <el-table-column prop="comment" label="表描述" :show-overflow-tooltip="true" />
  28. </el-table>
  29. </el-row>
  30. <div slot="footer" class="dialog-footer">
  31. <el-button type="primary" @click="handleImportTable">确 定</el-button>
  32. <el-button @click="visible = false">取 消</el-button>
  33. </div>
  34. </el-dialog>
  35. </template>
  36. <script>
  37. import { getSchemaTableList, createCodegenList } from "@/api/infra/codegen";
  38. import {getDataSourceConfigList} from "@/api/infra/dataSourceConfig";
  39. export default {
  40. data() {
  41. return {
  42. // 遮罩层
  43. loading: false,
  44. // 遮罩层
  45. visible: false,
  46. // 选中数组值
  47. tables: [],
  48. // 总条数
  49. total: 0,
  50. // 表数据
  51. dbTableList: [],
  52. // 查询参数
  53. queryParams: {
  54. dataSourceConfigId: undefined,
  55. name: undefined,
  56. comment: undefined,
  57. },
  58. // 数据源列表
  59. dataSourceConfigs: [],
  60. };
  61. },
  62. methods: {
  63. // 显示弹框
  64. show() {
  65. this.visible = true;
  66. // 加载数据源
  67. getDataSourceConfigList().then(response => {
  68. this.dataSourceConfigs = response.data;
  69. this.queryParams.dataSourceConfigId = this.dataSourceConfigs[0].id;
  70. // 加载表列表
  71. this.getList();
  72. });
  73. },
  74. clickRow(row) {
  75. this.$refs.table.toggleRowSelection(row);
  76. },
  77. // 多选框选中数据
  78. handleSelectionChange(selection) {
  79. this.tables = selection.map(item => item.name);
  80. },
  81. // 查询表数据
  82. getList() {
  83. this.loading = true;
  84. getSchemaTableList(this.queryParams).then(res => {
  85. this.dbTableList = res.data;
  86. }).finally(() => {
  87. this.loading = false;
  88. });
  89. },
  90. /** 搜索按钮操作 */
  91. handleQuery() {
  92. this.getList();
  93. },
  94. /** 重置按钮操作 */
  95. resetQuery() {
  96. this.resetForm("queryForm");
  97. this.queryParams.dataSourceConfigId = this.dataSourceConfigs[0].id;
  98. this.handleQuery();
  99. },
  100. /** 导入按钮操作 */
  101. handleImportTable() {
  102. createCodegenList({
  103. dataSourceConfigId: this.queryParams.dataSourceConfigId,
  104. tableNames: this.tables
  105. }).then(res => {
  106. this.$modal.msgSuccess("导入成功");
  107. this.visible = false;
  108. this.$emit("ok");
  109. });
  110. }
  111. }
  112. };
  113. </script>