Skip to content

Commit 2fa344d

Browse files
committed
支持主流数据库的代码生成
1 parent 51e4869 commit 2fa344d

File tree

4 files changed

+47
-118
lines changed

4 files changed

+47
-118
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="dateType"
22+
prop="dataType"
2323
min-width="10%"
2424
:show-overflow-tooltip="true"
2525
/>

src/views/infra/codegen/importTable.vue

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,23 @@
88
:key="config.id" :label="config.name" :value="config.id"/>
99
</el-select>
1010
</el-form-item>
11-
<el-form-item label="表名称" prop="tableName">
12-
<el-input v-model="queryParams.tableName" placeholder="请输入表名称" clearable @keyup.enter.native="handleQuery" />
11+
<el-form-item label="表名称" prop="name">
12+
<el-input v-model="queryParams.name" placeholder="请输入表名称" clearable @keyup.enter.native="handleQuery" />
1313
</el-form-item>
14-
<el-form-item label="表描述" prop="tableComment">
15-
<el-input v-model="queryParams.tableComment" placeholder="请输入表描述" clearable @keyup.enter.native="handleQuery"/>
14+
<el-form-item label="表描述" prop="comment">
15+
<el-input v-model="queryParams.comment" placeholder="请输入表描述" clearable @keyup.enter.native="handleQuery"/>
1616
</el-form-item>
1717
<el-form-item>
1818
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
1919
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
2020
</el-form-item>
2121
</el-form>
2222
<el-row>
23-
<el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px">
23+
<el-table v-loading="loading" @row-click="clickRow" ref="table" :data="dbTableList"
24+
@selection-change="handleSelectionChange" height="260px">
2425
<el-table-column type="selection" width="55" />
25-
<el-table-column prop="tableName" label="表名称" :show-overflow-tooltip="true" />
26-
<el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true" />
27-
<el-table-column prop="createTime" label="创建时间">
28-
<template slot-scope="scope">
29-
<span>{{ parseTime(scope.row.createTime) }}</span>
30-
</template>
31-
</el-table-column>
26+
<el-table-column prop="name" label="表名称" :show-overflow-tooltip="true" />
27+
<el-table-column prop="comment" label="表描述" :show-overflow-tooltip="true" />
3228
</el-table>
3329
</el-row>
3430
<div slot="footer" class="dialog-footer">
@@ -39,11 +35,13 @@
3935
</template>
4036

4137
<script>
42-
import { getSchemaTableList, createCodegenListFromDB } from "@/api/infra/codegen";
38+
import { getSchemaTableList, createCodegenList } from "@/api/infra/codegen";
4339
import {getDataSourceConfigList} from "@/api/infra/dataSourceConfig";
4440
export default {
4541
data() {
4642
return {
43+
// 遮罩层
44+
loading: false,
4745
// 遮罩层
4846
visible: false,
4947
// 选中数组值
@@ -55,8 +53,8 @@ export default {
5553
// 查询参数
5654
queryParams: {
5755
dataSourceConfigId: undefined,
58-
tableName: undefined,
59-
tableComment: undefined,
56+
name: undefined,
57+
comment: undefined,
6058
},
6159
// 数据源列表
6260
dataSourceConfigs: [],
@@ -79,12 +77,15 @@ export default {
7977
},
8078
// 多选框选中数据
8179
handleSelectionChange(selection) {
82-
this.tables = selection.map(item => item.tableName);
80+
this.tables = selection.map(item => item.name);
8381
},
8482
// 查询表数据
8583
getList() {
84+
this.loading = true;
8685
getSchemaTableList(this.queryParams).then(res => {
8786
this.dbTableList = res.data;
87+
}).finally(() => {
88+
this.loading = false;
8889
});
8990
},
9091
/** 搜索按钮操作 */
@@ -99,7 +100,10 @@ export default {
99100
},
100101
/** 导入按钮操作 */
101102
handleImportTable() {
102-
createCodegenListFromDB(this.tables.join(",")).then(res => {
103+
createCodegenList({
104+
dataSourceConfigId: this.queryParams.dataSourceConfigId,
105+
tableNames: this.tables
106+
}).then(res => {
103107
this.$modal.msgSuccess("导入成功");
104108
this.visible = false;
105109
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>

0 commit comments

Comments
 (0)