Skip to content

Commit 3a1d7c0

Browse files
YunaiVgitee-org
authored andcommitted
!149 代码生成器支持 MySQL、Oracle、PostgreSQL、SQLServer、DM 等数据库
Merge pull request !149 from 芋道源码/feature/1.6.2
2 parents 9433fec + 1309781 commit 3a1d7c0

File tree

5 files changed

+71
-138
lines changed

5 files changed

+71
-138
lines changed

src/api/infra/codegen.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,11 @@ export function getSchemaTableList(query) {
7373
}
7474

7575
// 基于数据库的表结构,创建代码生成器的表定义
76-
export function createCodegenListFromDB(tableNames) {
76+
export function createCodegenList(data) {
7777
return request({
78-
url: '/infra/codegen/create-list-from-db',
78+
url: '/infra/codegen/create-list',
7979
method: 'post',
80-
headers:{
81-
'Content-type': 'application/x-www-form-urlencoded'
82-
},
83-
data: 'tableNames=' + tableNames
84-
})
85-
}
86-
87-
// 基于 SQL 建表语句,创建代码生成器的表定义
88-
export function createCodegenListFromSQL(data) {
89-
return request({
90-
url: '/infra/codegen/create-list-from-sql',
91-
method: 'post',
92-
headers:{
93-
'Content-type': 'application/x-www-form-urlencoded'
94-
},
95-
data: 'sql=' + data.sql,
80+
data: data
9681
})
9782
}
9883

src/views/infra/codegen/editTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</el-table-column>
2020
<el-table-column
2121
label="物理类型"
22-
prop="columnType"
22+
prop="dataType"
2323
min-width="10%"
2424
:show-overflow-tooltip="true"
2525
/>

src/views/infra/codegen/importTable.vue

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,30 @@
11
<template>
22
<!-- 导入表 -->
33
<el-dialog title="导入表" :visible.sync="visible" width="800px" top="5vh" append-to-body>
4-
<el-form :model="queryParams" ref="queryForm" :inline="true">
5-
<el-form-item label="表名称" prop="tableName">
6-
<el-input
7-
v-model="queryParams.tableName"
8-
placeholder="请输入表名称"
9-
clearable
10-
size="small"
11-
@keyup.enter.native="handleQuery"
12-
/>
4+
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
5+
<el-form-item label="数据源" prop="dataSourceConfigId">
6+
<el-select v-model="queryParams.dataSourceConfigId" placeholder="请选择数据源" clearable>
7+
<el-option v-for="config in dataSourceConfigs"
8+
:key="config.id" :label="config.name" :value="config.id"/>
9+
</el-select>
1310
</el-form-item>
14-
<el-form-item label="表描述" prop="tableComment">
15-
<el-input
16-
v-model="queryParams.tableComment"
17-
placeholder="请输入表描述"
18-
clearable
19-
size="small"
20-
@keyup.enter.native="handleQuery"
21-
/>
11+
<el-form-item label="表名称" prop="name">
12+
<el-input v-model="queryParams.name" placeholder="请输入表名称" clearable @keyup.enter.native="handleQuery" />
13+
</el-form-item>
14+
<el-form-item label="表描述" prop="comment">
15+
<el-input v-model="queryParams.comment" placeholder="请输入表描述" clearable @keyup.enter.native="handleQuery"/>
2216
</el-form-item>
2317
<el-form-item>
2418
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
2519
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
2620
</el-form-item>
2721
</el-form>
2822
<el-row>
29-
<el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px">
30-
<el-table-column type="selection" width="55"></el-table-column>
31-
<el-table-column prop="tableSchema" label="数据库" :show-overflow-tooltip="true"></el-table-column>
32-
<el-table-column prop="tableName" label="表名称" :show-overflow-tooltip="true"></el-table-column>
33-
<el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true"></el-table-column>
34-
<el-table-column prop="createTime" label="创建时间">
35-
<template slot-scope="scope">
36-
<span>{{ parseTime(scope.row.createTime) }}</span>
37-
</template>
38-
</el-table-column>
23+
<el-table v-loading="loading" @row-click="clickRow" ref="table" :data="dbTableList"
24+
@selection-change="handleSelectionChange" height="260px">
25+
<el-table-column type="selection" width="55" />
26+
<el-table-column prop="name" label="表名称" :show-overflow-tooltip="true" />
27+
<el-table-column prop="comment" label="表描述" :show-overflow-tooltip="true" />
3928
</el-table>
4029
</el-row>
4130
<div slot="footer" class="dialog-footer">
@@ -46,10 +35,13 @@
4635
</template>
4736

4837
<script>
49-
import { getSchemaTableList, createCodegenListFromDB } from "@/api/infra/codegen";
38+
import { getSchemaTableList, createCodegenList } from "@/api/infra/codegen";
39+
import {getDataSourceConfigList} from "@/api/infra/dataSourceConfig";
5040
export default {
5141
data() {
5242
return {
43+
// 遮罩层
44+
loading: false,
5345
// 遮罩层
5446
visible: false,
5547
// 选中数组值
@@ -60,28 +52,40 @@ export default {
6052
dbTableList: [],
6153
// 查询参数
6254
queryParams: {
63-
tableName: undefined,
64-
tableComment: undefined
65-
}
55+
dataSourceConfigId: undefined,
56+
name: undefined,
57+
comment: undefined,
58+
},
59+
// 数据源列表
60+
dataSourceConfigs: [],
6661
};
6762
},
6863
methods: {
6964
// 显示弹框
7065
show() {
71-
this.getList();
7266
this.visible = true;
67+
// 加载数据源
68+
getDataSourceConfigList().then(response => {
69+
this.dataSourceConfigs = response.data;
70+
this.queryParams.dataSourceConfigId = this.dataSourceConfigs[0].id;
71+
// 加载表列表
72+
this.getList();
73+
});
7374
},
7475
clickRow(row) {
7576
this.$refs.table.toggleRowSelection(row);
7677
},
7778
// 多选框选中数据
7879
handleSelectionChange(selection) {
79-
this.tables = selection.map(item => item.tableName);
80+
this.tables = selection.map(item => item.name);
8081
},
8182
// 查询表数据
8283
getList() {
84+
this.loading = true;
8385
getSchemaTableList(this.queryParams).then(res => {
8486
this.dbTableList = res.data;
87+
}).finally(() => {
88+
this.loading = false;
8589
});
8690
},
8791
/** 搜索按钮操作 */
@@ -91,11 +95,15 @@ export default {
9195
/** 重置按钮操作 */
9296
resetQuery() {
9397
this.resetForm("queryForm");
98+
this.queryParams.dataSourceConfigId = this.dataSourceConfigs[0].id;
9499
this.handleQuery();
95100
},
96101
/** 导入按钮操作 */
97102
handleImportTable() {
98-
createCodegenListFromDB(this.tables.join(",")).then(res => {
103+
createCodegenList({
104+
dataSourceConfigId: this.queryParams.dataSourceConfigId,
105+
tableNames: this.tables
106+
}).then(res => {
99107
this.$modal.msgSuccess("导入成功");
100108
this.visible = false;
101109
this.$emit("ok");

src/views/infra/codegen/index.vue

Lines changed: 22 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,28 @@
2626
<el-row :gutter="10" class="mb8">
2727
<el-col :span="1.5">
2828
<el-button type="info" plain icon="el-icon-upload" size="mini" @click="openImportTable"
29-
v-hasPermi="['infra:codegen:create']">基于 DB 导入</el-button>
30-
<el-button type="info" plain icon="el-icon-upload" size="mini" @click="openImportSQL"
31-
v-hasPermi="['infra:codegen:create']">基于 SQL 导入</el-button>
29+
v-hasPermi="['infra:codegen:create']">导入</el-button>
3230
</el-col>
3331
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
3432
</el-row>
3533

3634
<!-- 列表 -->
3735
<el-table v-loading="loading" :data="tableList">
38-
<el-table-column label="表名称" align="center" prop="tableName" :show-overflow-tooltip="true" width="200"/>
36+
<el-table-column label="数据源" align="center" :formatter="dataSourceConfigNameFormat"/>
37+
<el-table-column label="表名称" align="center" prop="tableName" width="200"/>
3938
<el-table-column label="表描述" align="center" prop="tableComment" :show-overflow-tooltip="true" width="120"/>
40-
<el-table-column label="实体" align="center" prop="className" :show-overflow-tooltip="true" width="200"/>
41-
<el-table-column label="创建时间" align="center" prop="createTime" width="160">
39+
<el-table-column label="实体" align="center" prop="className" width="200"/>
40+
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
4241
<template slot-scope="scope">
4342
<span>{{ parseTime(scope.row.createTime) }}</span>
4443
</template>
4544
</el-table-column>
46-
<el-table-column label="更新时间" align="center" prop="createTime" width="160">
45+
<el-table-column label="更新时间" align="center" prop="createTime" width="180">
4746
<template slot-scope="scope">
4847
<span>{{ parseTime(scope.row.updateTime) }}</span>
4948
</template>
5049
</el-table-column>
51-
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
50+
<el-table-column label="操作" align="center" width="300px" class-name="small-padding fixed-width">
5251
<template slot-scope="scope">
5352
<el-button type="text" size="small" icon="el-icon-view" @click="handlePreview(scope.row)" v-hasPermi="['infra:codegen:preview']">预览</el-button>
5453
<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 @@
8180

8281
<!-- 基于 DB 导入 -->
8382
<import-table ref="import" @ok="handleQuery" />
84-
85-
<!-- 基于 SQL 导入 -->
86-
<el-dialog :title="importSQL.title" :visible.sync="importSQL.open" width="800px" append-to-body>
87-
<el-form ref="importSQLForm" :model="importSQL.form" :rules="importSQL.rules" label-width="120px">
88-
<el-row>
89-
<el-col :span="12">
90-
<el-form-item label="建表 SQL 语句" prop="sql">
91-
<el-input v-model="importSQL.form.sql" type="textarea" rows="30" style="width: 650px;" placeholder="请输入建 SQL 语句" />
92-
</el-form-item>
93-
</el-col>
94-
</el-row>
95-
</el-form>
96-
<div slot="footer" class="dialog-footer">
97-
<el-button type="primary" @click="submitImportSQLForm">确 定</el-button>
98-
<el-button @click="cancel">取 消</el-button>
99-
</div>
100-
</el-dialog>
10183
</div>
10284
</template>
10385

@@ -109,6 +91,7 @@ import importTable from "./importTable";
10991
// 代码高亮插件
11092
import hljs from "highlight.js/lib/highlight";
11193
import "highlight.js/styles/github-gist.css";
94+
import {getDataSourceConfigList} from "@/api/infra/dataSourceConfig";
11295
hljs.registerLanguage("java", require("highlight.js/lib/languages/java"));
11396
hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml"));
11497
hljs.registerLanguage("html", require("highlight.js/lib/languages/xml"));
@@ -150,21 +133,16 @@ export default {
150133
data: {},
151134
activeName: "",
152135
},
153-
// 基于 SQL 导入
154-
importSQL: {
155-
open: false,
156-
title: "",
157-
form: {
158-
159-
},
160-
rules: {
161-
sql: [{ required: true, message: "SQL 不能为空", trigger: "blur" }]
162-
}
163-
}
136+
// 数据源列表
137+
dataSourceConfigs: [],
164138
};
165139
},
166140
created() {
167141
this.getList();
142+
// 加载数据源
143+
getDataSourceConfigList().then(response => {
144+
this.dataSourceConfigs = response.data;
145+
});
168146
},
169147
activated() {
170148
const time = this.$route.query.t;
@@ -200,12 +178,6 @@ export default {
200178
},
201179
/** 同步数据库操作 */
202180
handleSynchDb(row) {
203-
// 基于 SQL 同步
204-
if (row.importType === 2) {
205-
this.importSQL.open = true;
206-
this.importSQL.form.tableId = row.id;
207-
return;
208-
}
209181
// 基于 DB 同步
210182
const tableName = row.tableName;
211183
this.$modal.confirm('确认要强制同步"' + tableName + '"表结构吗?').then(function() {
@@ -218,10 +190,6 @@ export default {
218190
openImportTable() {
219191
this.$refs.import.show();
220192
},
221-
/** 打开 SQL 导入的弹窗 **/
222-
openImportSQL() {
223-
this.importSQL.open = true;
224-
},
225193
/** 重置按钮操作 */
226194
resetQuery() {
227195
this.dateRange = [];
@@ -336,43 +304,15 @@ export default {
336304
this.$modal.msgSuccess("删除成功");
337305
}).catch(() => {});
338306
},
339-
// 取消按钮
340-
cancel() {
341-
this.importSQL.open = false;
342-
this.reset();
343-
},
344-
// 表单重置
345-
reset() {
346-
this.importSQL.form = {
347-
tableId: undefined,
348-
sql: undefined,
349-
};
350-
this.resetForm("importSQLForm");
351-
},
352-
// 提交 import SQL 表单
353-
submitImportSQLForm() {
354-
this.$refs["importSQLForm"].validate(valid => {
355-
if (!valid) {
356-
return;
357-
}
358-
// 修改的提交
359-
let form = this.importSQL.form;
360-
if (form.tableId != null) {
361-
syncCodegenFromSQL(form.tableId, form.sql).then(response => {
362-
this.$modal.msgSuccess("同步成功");
363-
this.importSQL.open = false;
364-
this.getList();
365-
});
366-
return;
307+
// 数据源配置的名字
308+
dataSourceConfigNameFormat(row, column) {
309+
for (const config of this.dataSourceConfigs) {
310+
if (row.dataSourceConfigId === config.id) {
311+
return config.name;
367312
}
368-
// 添加的提交
369-
createCodegenListFromSQL(form).then(response => {
370-
this.$modal.msgSuccess("导入成功");
371-
this.importSQL.open = false;
372-
this.getList();
373-
});
374-
});
375-
}
313+
}
314+
return '未知【' + row.leaderUserId + '';
315+
},
376316
}
377317
};
378318
</script>

src/views/infra/dataSourceConfig/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<!-- 列表 -->
1212
<el-table v-loading="loading" :data="list">
1313
<el-table-column label="主键编号" align="center" prop="id" />
14-
<el-table-column label="参数名称" align="center" prop="name" />
14+
<el-table-column label="数据源名称" align="center" prop="name" />
1515
<el-table-column label="数据源连接" align="center" prop="url" />
1616
<el-table-column label="用户名" align="center" prop="username" />
1717
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
@@ -32,7 +32,7 @@
3232
<!-- 对话框(添加 / 修改) -->
3333
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
3434
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
35-
<el-form-item label="参数名称" prop="name">
35+
<el-form-item label="数据源名称" prop="name">
3636
<el-input v-model="form.name" placeholder="请输入参数名称" />
3737
</el-form-item>
3838
<el-form-item label="数据源连接" prop="url">
@@ -76,7 +76,7 @@ export default {
7676
form: {},
7777
// 表单校验
7878
rules: {
79-
name: [{ required: true, message: "参数名称不能为空", trigger: "blur" }],
79+
name: [{ required: true, message: "数据源名称不能为空", trigger: "blur" }],
8080
url: [{ required: true, message: "数据源连接不能为空", trigger: "blur" }],
8181
username: [{ required: true, message: "用户名不能为空", trigger: "blur" }],
8282
password: [{ required: true, message: "密码不能为空", trigger: "blur" }],

0 commit comments

Comments
 (0)