This commit is contained in:
2023-07-04 14:31:23 +08:00
parent b187d38894
commit 68fc55cf7f
2 changed files with 66 additions and 12 deletions

View File

@ -39,7 +39,7 @@ export function importTable(data) {
return request({
url: "/tool/gen/importTable",
method: "post",
params: data,
data: data,
});
}

View File

@ -26,16 +26,18 @@
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery"
>搜索</el-button
>
>搜索
</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row>
<el-table
class="db-table-list"
@row-click="clickRow"
ref="table"
:data="dbTableList"
@select="handleSelect"
@selection-change="handleSelectionChange"
height="260px"
>
@ -71,7 +73,7 @@
</template>
<script setup>
import { listDbTable, importTable } from "@/api/tool/gen";
import { importTable, listDbTable } from "@/api/tool/gen";
const total = ref(0);
const visible = ref(false);
@ -93,14 +95,40 @@ function show() {
getList();
visible.value = true;
}
/** 单击选择行 */
function clickRow(row) {
proxy.$refs.table.toggleRowSelection(row);
function clickRow(row, _, event) {
const rowIndex = dbTableList.value.findIndex(
(el) => el.tableName === row.tableName
);
document
.querySelector(
`.db-table-list .el-table__body tbody > .el-table__row:nth-child(${
rowIndex + 1
}) .el-table-column--selection .el-checkbox`
)
.click();
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
tables.value = selection.map((item) => item.tableName);
}
function handleSelectionChange(selection) {}
const handleSelect = (selection, row) => {
const isCheck =
selection.findIndex((el) => el.tableName === row.tableName) >
-1; /* 是否将行切换为选中状态 */
if (isCheck) {
selection.forEach((el) => {
if (el.tableName !== row.tableName) {
proxy.$refs.table.toggleRowSelection(el, false);
}
});
tables.value = [row];
} else {
tables.value = [];
}
};
/** 查询表数据 */
function getList() {
listDbTable(queryParams).then((res) => {
@ -108,24 +136,30 @@ function getList() {
total.value = res.total;
});
}
/** 搜索按钮操作 */
function handleQuery() {
queryParams.pageNum = 1;
getList();
}
/** 重置按钮操作 */
function resetQuery() {
proxy.resetForm("queryRef");
handleQuery();
}
/** 导入按钮操作 */
function handleImportTable() {
const tableNames = tables.value.join(",");
if (tableNames == "") {
if (tables.value.length === 0) {
proxy.$modal.msgError("请选择要导入的表");
return;
}
importTable({ tables: tableNames }).then((res) => {
const tableObj = tables.value[0];
importTable({
tableName: tableObj.tableName,
tableComment: tableObj.tableComment,
}).then((res) => {
proxy.$modal.msgSuccess(res.msg);
if (res.code === 200) {
visible.value = false;
@ -138,3 +172,23 @@ defineExpose({
show,
});
</script>
<style lang="scss" scoped>
:deep(.db-table-list) {
.el-table__header {
.el-checkbox {
visibility: hidden;
}
}
.el-table__body {
.el-table__row {
.el-table__cell:first-child {
.el-checkbox__inner {
border-radius: 50%;
}
}
}
}
}
</style>