懒羊羊
2024-03-13 b64ed2c784bde6dea9d18149ca706ebe532c857d
提交 | 用户 | 时间
e57a89 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="tableName">
6         <el-input
7           v-model="queryParams.tableName"
8           placeholder="请输入表名称"
9           clearable
10           @keyup.enter.native="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.native="handleQuery"
19         />
20       </el-form-item>
21       <el-form-item>
22         <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
23         <el-button icon="el-icon-refresh" size="mini" @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         :page.sync="queryParams.pageNum"
38         :limit.sync="queryParams.pageSize"
39         @pagination="getList"
40       />
41     </el-row>
42     <div slot="footer" class="dialog-footer">
43       <el-button type="primary" @click="handleImportTable">确 定</el-button>
44       <el-button @click="visible = false">取 消</el-button>
45     </div>
46   </el-dialog>
47 </template>
48
49 <script>
50 import { listDbTable, importTable } from "@/api/tool/gen";
51 export default {
52   data() {
53     return {
54       // 遮罩层
55       visible: false,
56       // 选中数组值
57       tables: [],
58       // 总条数
59       total: 0,
60       // 表数据
61       dbTableList: [],
62       // 查询参数
63       queryParams: {
64         pageNum: 1,
65         pageSize: 10,
66         tableName: undefined,
67         tableComment: undefined
68       }
69     };
70   },
71   methods: {
72     // 显示弹框
73     show() {
74       this.getList();
75       this.visible = true;
76     },
77     clickRow(row) {
78       this.$refs.table.toggleRowSelection(row);
79     },
80     // 多选框选中数据
81     handleSelectionChange(selection) {
82       this.tables = selection.map(item => item.tableName);
83     },
84     // 查询表数据
85     getList() {
86       listDbTable(this.queryParams).then(res => {
87         if (res.code === 200) {
88           this.dbTableList = res.rows;
89           this.total = res.total;
90         }
91       });
92     },
93     /** 搜索按钮操作 */
94     handleQuery() {
95       this.queryParams.pageNum = 1;
96       this.getList();
97     },
98     /** 重置按钮操作 */
99     resetQuery() {
100       this.resetForm("queryForm");
101       this.handleQuery();
102     },
103     /** 导入按钮操作 */
104     handleImportTable() {
105       const tableNames = this.tables.join(",");
106       if (tableNames == "") {
107         this.$modal.msgError("请选择要导入的表");
108         return;
109       }
110       importTable({ tables: tableNames }).then(res => {
111         this.$modal.msgSuccess(res.msg);
112         if (res.code === 200) {
113           this.visible = false;
114           this.$emit("ok");
115         }
116       });
117     }
118   }
119 };
120 </script>