支持主流数据库的代码生成

This commit is contained in:
YunaiV
2022-04-29 23:14:34 +08:00
parent f1069aa306
commit b34e2691f8
31 changed files with 283 additions and 1031 deletions

View File

@ -26,29 +26,28 @@
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="info" plain icon="el-icon-upload" size="mini" @click="openImportTable"
v-hasPermi="['infra:codegen:create']">基于 DB 导入</el-button>
<el-button type="info" plain icon="el-icon-upload" size="mini" @click="openImportSQL"
v-hasPermi="['infra:codegen:create']">基于 SQL 导入</el-button>
v-hasPermi="['infra:codegen:create']">导入</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<!-- 列表 -->
<el-table v-loading="loading" :data="tableList">
<el-table-column label="表名称" align="center" prop="tableName" :show-overflow-tooltip="true" width="200"/>
<el-table-column label="数据源" align="center" :formatter="dataSourceConfigNameFormat"/>
<el-table-column label="表名称" align="center" prop="tableName" width="200"/>
<el-table-column label="表描述" align="center" prop="tableComment" :show-overflow-tooltip="true" width="120"/>
<el-table-column label="实体" align="center" prop="className" :show-overflow-tooltip="true" width="200"/>
<el-table-column label="创建时间" align="center" prop="createTime" width="160">
<el-table-column label="实体" align="center" prop="className" width="200"/>
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="更新时间" align="center" prop="createTime" width="160">
<el-table-column label="更新时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.updateTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<el-table-column label="操作" align="center" width="300px" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button type="text" size="small" icon="el-icon-view" @click="handlePreview(scope.row)" v-hasPermi="['infra:codegen:preview']">预览</el-button>
<el-button type="text" size="small" icon="el-icon-edit" @click="handleEditTable(scope.row)" v-hasPermi="['infra:codegen:update']">编辑</el-button>
@ -81,23 +80,6 @@
<!-- 基于 DB 导入 -->
<import-table ref="import" @ok="handleQuery" />
<!-- 基于 SQL 导入 -->
<el-dialog :title="importSQL.title" :visible.sync="importSQL.open" width="800px" append-to-body>
<el-form ref="importSQLForm" :model="importSQL.form" :rules="importSQL.rules" label-width="120px">
<el-row>
<el-col :span="12">
<el-form-item label="建表 SQL 语句" prop="sql">
<el-input v-model="importSQL.form.sql" type="textarea" rows="30" style="width: 650px;" placeholder="请输入建 SQL 语句" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitImportSQLForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
@ -109,6 +91,7 @@ import importTable from "./importTable";
// 代码高亮插件
import hljs from "highlight.js/lib/highlight";
import "highlight.js/styles/github-gist.css";
import {getDataSourceConfigList} from "@/api/infra/dataSourceConfig";
hljs.registerLanguage("java", require("highlight.js/lib/languages/java"));
hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml"));
hljs.registerLanguage("html", require("highlight.js/lib/languages/xml"));
@ -150,21 +133,16 @@ export default {
data: {},
activeName: "",
},
// 基于 SQL 导入
importSQL: {
open: false,
title: "",
form: {
},
rules: {
sql: [{ required: true, message: "SQL 不能为空", trigger: "blur" }]
}
}
// 数据源列表
dataSourceConfigs: [],
};
},
created() {
this.getList();
// 加载数据源
getDataSourceConfigList().then(response => {
this.dataSourceConfigs = response.data;
});
},
activated() {
const time = this.$route.query.t;
@ -200,12 +178,6 @@ export default {
},
/** 同步数据库操作 */
handleSynchDb(row) {
// 基于 SQL 同步
if (row.importType === 2) {
this.importSQL.open = true;
this.importSQL.form.tableId = row.id;
return;
}
// 基于 DB 同步
const tableName = row.tableName;
this.$modal.confirm('确认要强制同步"' + tableName + '"表结构吗?').then(function() {
@ -218,10 +190,6 @@ export default {
openImportTable() {
this.$refs.import.show();
},
/** 打开 SQL 导入的弹窗 **/
openImportSQL() {
this.importSQL.open = true;
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
@ -336,43 +304,15 @@ export default {
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
// 取消按钮
cancel() {
this.importSQL.open = false;
this.reset();
},
// 表单重置
reset() {
this.importSQL.form = {
tableId: undefined,
sql: undefined,
};
this.resetForm("importSQLForm");
},
// 提交 import SQL 表单
submitImportSQLForm() {
this.$refs["importSQLForm"].validate(valid => {
if (!valid) {
return;
// 数据源配置的名字
dataSourceConfigNameFormat(row, column) {
for (const config of this.dataSourceConfigs) {
if (row.dataSourceConfigId === config.id) {
return config.name;
}
// 修改的提交
let form = this.importSQL.form;
if (form.tableId != null) {
syncCodegenFromSQL(form.tableId, form.sql).then(response => {
this.$modal.msgSuccess("同步成功");
this.importSQL.open = false;
this.getList();
});
return;
}
// 添加的提交
createCodegenListFromSQL(form).then(response => {
this.$modal.msgSuccess("导入成功");
this.importSQL.open = false;
this.getList();
});
});
}
}
return '未知【' + row.leaderUserId + '】';
},
}
};
</script>