importTable.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <!-- 导入表 -->
  3. <el-dialog title="导入表" v-model="visible" width="800px" top="5vh" append-to-body>
  4. <el-form :model="queryParams" ref="queryRef" :inline="true">
  5. <el-form-item label="表名称" prop="tableName">
  6. <el-input
  7. v-model="queryParams.tableName"
  8. placeholder="请输入表名称"
  9. clearable
  10. @keyup.enter="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="表描述" prop="tableComment">
  14. <el-input
  15. v-model="queryParams.tableComment"
  16. placeholder="请输入表描述"
  17. clearable
  18. @keyup.enter="handleQuery"
  19. />
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  23. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  24. </el-form-item>
  25. </el-form>
  26. <el-row>
  27. <el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px">
  28. <el-table-column type="selection" width="55"></el-table-column>
  29. <el-table-column prop="tableName" label="表名称" :show-overflow-tooltip="true"></el-table-column>
  30. <el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true"></el-table-column>
  31. <el-table-column prop="createTime" label="创建时间"></el-table-column>
  32. <el-table-column prop="updateTime" label="更新时间"></el-table-column>
  33. </el-table>
  34. <pagination
  35. v-show="total>0"
  36. :total="total"
  37. v-model:page="queryParams.pageNum"
  38. v-model:limit="queryParams.pageSize"
  39. @pagination="getList"
  40. />
  41. </el-row>
  42. <template #footer>
  43. <div class="dialog-footer">
  44. <el-button type="primary" @click="handleImportTable">确 定</el-button>
  45. <el-button @click="visible = false">取 消</el-button>
  46. </div>
  47. </template>
  48. </el-dialog>
  49. </template>
  50. <script setup>
  51. import { listDbTable, importTable } from "@/api/tool/gen";
  52. const total = ref(0);
  53. const visible = ref(false);
  54. const tables = ref([]);
  55. const dbTableList = ref([]);
  56. const { proxy } = getCurrentInstance();
  57. const queryParams = reactive({
  58. pageNum: 1,
  59. pageSize: 10,
  60. tableName: undefined,
  61. tableComment: undefined
  62. });
  63. const emit = defineEmits(["ok"]);
  64. /** 查询参数列表 */
  65. function show() {
  66. getList();
  67. visible.value = true;
  68. }
  69. /** 单击选择行 */
  70. function clickRow(row) {
  71. proxy.$refs.table.toggleRowSelection(row);
  72. }
  73. /** 多选框选中数据 */
  74. function handleSelectionChange(selection) {
  75. tables.value = selection.map(item => item.tableName);
  76. }
  77. /** 查询表数据 */
  78. function getList() {
  79. listDbTable(queryParams).then(res => {
  80. dbTableList.value = res.rows;
  81. total.value = res.total;
  82. });
  83. }
  84. /** 搜索按钮操作 */
  85. function handleQuery() {
  86. queryParams.pageNum = 1;
  87. getList();
  88. }
  89. /** 重置按钮操作 */
  90. function resetQuery() {
  91. proxy.resetForm("queryRef");
  92. handleQuery();
  93. }
  94. /** 导入按钮操作 */
  95. function handleImportTable() {
  96. const tableNames = tables.value.join(",");
  97. if (tableNames == "") {
  98. proxy.$modal.msgError("请选择要导入的表");
  99. return;
  100. }
  101. importTable({ tables: tableNames }).then(res => {
  102. proxy.$modal.msgSuccess(res.msg);
  103. if (res.code === 200) {
  104. visible.value = false;
  105. emit("ok");
  106. }
  107. });
  108. }
  109. defineExpose({
  110. show,
  111. });
  112. </script>