mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-13 10:35:07 +08:00
支持主流数据库的代码生成
This commit is contained in:
@ -73,26 +73,11 @@ export function getSchemaTableList(query) {
|
||||
}
|
||||
|
||||
// 基于数据库的表结构,创建代码生成器的表定义
|
||||
export function createCodegenListFromDB(tableNames) {
|
||||
export function createCodegenList(data) {
|
||||
return request({
|
||||
url: '/infra/codegen/create-list-from-db',
|
||||
url: '/infra/codegen/create-list',
|
||||
method: 'post',
|
||||
headers:{
|
||||
'Content-type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
data: 'tableNames=' + tableNames
|
||||
})
|
||||
}
|
||||
|
||||
// 基于 SQL 建表语句,创建代码生成器的表定义
|
||||
export function createCodegenListFromSQL(data) {
|
||||
return request({
|
||||
url: '/infra/codegen/create-list-from-sql',
|
||||
method: 'post',
|
||||
headers:{
|
||||
'Content-type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
data: 'sql=' + data.sql,
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
label="物理类型"
|
||||
prop="dateType"
|
||||
prop="dataType"
|
||||
min-width="10%"
|
||||
:show-overflow-tooltip="true"
|
||||
/>
|
||||
|
@ -8,11 +8,11 @@
|
||||
:key="config.id" :label="config.name" :value="config.id"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="表名称" prop="tableName">
|
||||
<el-input v-model="queryParams.tableName" placeholder="请输入表名称" clearable @keyup.enter.native="handleQuery" />
|
||||
<el-form-item label="表名称" prop="name">
|
||||
<el-input v-model="queryParams.name" placeholder="请输入表名称" clearable @keyup.enter.native="handleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item label="表描述" prop="tableComment">
|
||||
<el-input v-model="queryParams.tableComment" placeholder="请输入表描述" clearable @keyup.enter.native="handleQuery"/>
|
||||
<el-form-item label="表描述" prop="comment">
|
||||
<el-input v-model="queryParams.comment" placeholder="请输入表描述" clearable @keyup.enter.native="handleQuery"/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
@ -20,15 +20,11 @@
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-row>
|
||||
<el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px">
|
||||
<el-table v-loading="loading" @row-click="clickRow" ref="table" :data="dbTableList"
|
||||
@selection-change="handleSelectionChange" height="260px">
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="tableName" label="表名称" :show-overflow-tooltip="true" />
|
||||
<el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true" />
|
||||
<el-table-column prop="createTime" label="创建时间">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="name" label="表名称" :show-overflow-tooltip="true" />
|
||||
<el-table-column prop="comment" label="表描述" :show-overflow-tooltip="true" />
|
||||
</el-table>
|
||||
</el-row>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
@ -39,11 +35,13 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getSchemaTableList, createCodegenListFromDB } from "@/api/infra/codegen";
|
||||
import { getSchemaTableList, createCodegenList } from "@/api/infra/codegen";
|
||||
import {getDataSourceConfigList} from "@/api/infra/dataSourceConfig";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
loading: false,
|
||||
// 遮罩层
|
||||
visible: false,
|
||||
// 选中数组值
|
||||
@ -55,8 +53,8 @@ export default {
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
dataSourceConfigId: undefined,
|
||||
tableName: undefined,
|
||||
tableComment: undefined,
|
||||
name: undefined,
|
||||
comment: undefined,
|
||||
},
|
||||
// 数据源列表
|
||||
dataSourceConfigs: [],
|
||||
@ -79,12 +77,15 @@ export default {
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.tables = selection.map(item => item.tableName);
|
||||
this.tables = selection.map(item => item.name);
|
||||
},
|
||||
// 查询表数据
|
||||
getList() {
|
||||
this.loading = true;
|
||||
getSchemaTableList(this.queryParams).then(res => {
|
||||
this.dbTableList = res.data;
|
||||
}).finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
@ -99,7 +100,10 @@ export default {
|
||||
},
|
||||
/** 导入按钮操作 */
|
||||
handleImportTable() {
|
||||
createCodegenListFromDB(this.tables.join(",")).then(res => {
|
||||
createCodegenList({
|
||||
dataSourceConfigId: this.queryParams.dataSourceConfigId,
|
||||
tableNames: this.tables
|
||||
}).then(res => {
|
||||
this.$modal.msgSuccess("导入成功");
|
||||
this.visible = false;
|
||||
this.$emit("ok");
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user