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