2019-10-08 09:14:38 +08:00
|
|
|
<template>
|
|
|
|
<div class="app-container">
|
2020-08-01 15:45:38 +08:00
|
|
|
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
|
2019-12-02 09:28:11 +08:00
|
|
|
<el-form-item label="表名称" prop="tableName">
|
|
|
|
<el-input
|
|
|
|
v-model="queryParams.tableName"
|
|
|
|
placeholder="请输入表名称"
|
|
|
|
clearable
|
|
|
|
size="small"
|
|
|
|
@keyup.enter.native="handleQuery"
|
|
|
|
/>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="表描述" prop="tableComment">
|
|
|
|
<el-input
|
|
|
|
v-model="queryParams.tableComment"
|
|
|
|
placeholder="请输入表描述"
|
|
|
|
clearable
|
|
|
|
size="small"
|
|
|
|
@keyup.enter.native="handleQuery"
|
|
|
|
/>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="创建时间">
|
|
|
|
<el-date-picker
|
|
|
|
v-model="dateRange"
|
|
|
|
size="small"
|
|
|
|
style="width: 240px"
|
|
|
|
value-format="yyyy-MM-dd"
|
|
|
|
type="daterange"
|
|
|
|
range-separator="-"
|
|
|
|
start-placeholder="开始日期"
|
|
|
|
end-placeholder="结束日期"
|
|
|
|
></el-date-picker>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item>
|
2021-02-09 15:55:54 +08:00
|
|
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
2019-12-02 09:28:11 +08:00
|
|
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
<el-row :gutter="10" class="mb8">
|
|
|
|
<el-col :span="1.5">
|
2021-02-10 17:45:04 +08:00
|
|
|
<el-button type="info" plain icon="el-icon-upload" size="mini" @click="openImportTable" v-hasPermi="['tool:gen:import']">导入</el-button>
|
2019-12-02 09:28:11 +08:00
|
|
|
</el-col>
|
2020-08-10 10:12:39 +08:00
|
|
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
2019-12-02 09:28:11 +08:00
|
|
|
</el-row>
|
|
|
|
|
2021-02-09 22:14:01 +08:00
|
|
|
<el-table v-loading="loading" :data="tableList">
|
2021-02-10 17:45:04 +08:00
|
|
|
<el-table-column label="表名称" align="center" prop="tableName" :show-overflow-tooltip="true" 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"/>
|
2021-02-09 22:14:01 +08:00
|
|
|
<el-table-column label="创建时间" align="center" prop="createTime" width="160">
|
|
|
|
<template slot-scope="scope">
|
|
|
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
<el-table-column label="创建时间" align="center" prop="createTime" width="160">
|
|
|
|
<template slot-scope="scope">
|
|
|
|
<span>{{ parseTime(scope.row.updateTime) }}</span>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
2019-12-02 09:28:11 +08:00
|
|
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
|
|
|
<template slot-scope="scope">
|
2021-02-10 17:45:04 +08:00
|
|
|
<el-button type="text" size="small" icon="el-icon-view" @click="handlePreview(scope.row)" v-hasPermi="['tool:gen:preview']">预览</el-button>
|
|
|
|
<el-button type="text" size="small" icon="el-icon-edit" @click="handleEditTable(scope.row)" v-hasPermi="['tool:gen:edit']">编辑</el-button>
|
|
|
|
<el-button type="text" size="small" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['tool:gen:remove']">删除</el-button>
|
|
|
|
<el-button type="text" size="small" icon="el-icon-refresh" @click="handleSynchDb(scope.row)" v-hasPermi="['tool:gen:edit']">同步</el-button>
|
|
|
|
<el-button type="text" size="small" icon="el-icon-download" @click="handleGenTable(scope.row)" v-hasPermi="['tool:gen:code']">生成代码</el-button>
|
2019-12-02 09:28:11 +08:00
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
</el-table>
|
2021-02-10 17:45:04 +08:00
|
|
|
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" @pagination="getList"/>
|
2019-12-02 09:28:11 +08:00
|
|
|
<!-- 预览界面 -->
|
2020-04-17 14:14:54 +08:00
|
|
|
<el-dialog :title="preview.title" :visible.sync="preview.open" width="80%" top="5vh" append-to-body>
|
2021-02-10 17:45:04 +08:00
|
|
|
<el-tabs tab-position="left" v-model="preview.activeName">
|
|
|
|
<el-tab-pane v-for="item in preview.data" :label="item.filePath.substring(item.filePath.lastIndexOf('/') + 1)" :name="item.filePath" :key="item.filePath">
|
|
|
|
<pre><code class="hljs" v-html="highlightedCode(item)"></code></pre>
|
2019-12-02 09:28:11 +08:00
|
|
|
</el-tab-pane>
|
|
|
|
</el-tabs>
|
|
|
|
</el-dialog>
|
|
|
|
<import-table ref="import" @ok="handleQuery" />
|
2019-10-08 09:14:38 +08:00
|
|
|
</div>
|
2019-12-02 09:28:11 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-02-11 01:05:21 +08:00
|
|
|
import { getCodegenTablePage, previewCodegen, downloadCodegen, deleteCodegen, syncCodegen } from "@/api/tool/codegen";
|
2021-02-09 22:14:01 +08:00
|
|
|
|
2019-12-02 09:28:11 +08:00
|
|
|
import importTable from "./importTable";
|
2021-02-09 15:55:54 +08:00
|
|
|
// 代码高亮插件
|
|
|
|
import hljs from "highlight.js/lib/highlight";
|
|
|
|
import "highlight.js/styles/github-gist.css";
|
|
|
|
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"));
|
|
|
|
hljs.registerLanguage("vue", require("highlight.js/lib/languages/xml"));
|
|
|
|
hljs.registerLanguage("javascript", require("highlight.js/lib/languages/javascript"));
|
|
|
|
hljs.registerLanguage("sql", require("highlight.js/lib/languages/sql"));
|
2020-12-11 17:04:54 +08:00
|
|
|
|
2019-12-02 09:28:11 +08:00
|
|
|
export default {
|
|
|
|
name: "Gen",
|
|
|
|
components: { importTable },
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
// 遮罩层
|
|
|
|
loading: true,
|
|
|
|
// 唯一标识符
|
|
|
|
uniqueId: "",
|
|
|
|
// 选中表数组
|
|
|
|
tableNames: [],
|
2020-08-01 15:45:38 +08:00
|
|
|
// 显示搜索条件
|
|
|
|
showSearch: true,
|
2019-12-02 09:28:11 +08:00
|
|
|
// 总条数
|
|
|
|
total: 0,
|
|
|
|
// 表数据
|
|
|
|
tableList: [],
|
|
|
|
// 日期范围
|
|
|
|
dateRange: "",
|
|
|
|
// 查询参数
|
|
|
|
queryParams: {
|
2021-02-09 22:14:01 +08:00
|
|
|
pageNo: 1,
|
2019-12-02 09:28:11 +08:00
|
|
|
pageSize: 10,
|
|
|
|
tableName: undefined,
|
|
|
|
tableComment: undefined
|
|
|
|
},
|
|
|
|
// 预览参数
|
|
|
|
preview: {
|
|
|
|
open: false,
|
|
|
|
title: "代码预览",
|
|
|
|
data: {},
|
|
|
|
activeName: "domain.java"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.getList();
|
|
|
|
},
|
|
|
|
activated() {
|
|
|
|
const time = this.$route.query.t;
|
2021-02-09 22:14:01 +08:00
|
|
|
if (time != null && time !== this.uniqueId) {
|
2019-12-02 09:28:11 +08:00
|
|
|
this.uniqueId = time;
|
|
|
|
this.resetQuery();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
/** 查询表集合 */
|
|
|
|
getList() {
|
|
|
|
this.loading = true;
|
2021-02-11 01:05:21 +08:00
|
|
|
getCodegenTablePage(this.addDateRange(this.queryParams, [
|
2021-02-09 22:14:01 +08:00
|
|
|
this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined,
|
|
|
|
this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined,
|
|
|
|
], 'CreateTime')).then(response => {
|
|
|
|
this.tableList = response.data.list;
|
|
|
|
this.total = response.data.total;
|
|
|
|
this.loading = false;
|
|
|
|
}
|
2019-12-02 09:28:11 +08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
/** 搜索按钮操作 */
|
|
|
|
handleQuery() {
|
2021-02-09 22:14:01 +08:00
|
|
|
this.queryParams.pageNo = 1;
|
2019-12-02 09:28:11 +08:00
|
|
|
this.getList();
|
|
|
|
},
|
|
|
|
/** 生成代码操作 */
|
|
|
|
handleGenTable(row) {
|
2021-02-10 19:05:22 +08:00
|
|
|
downloadCodegen(row.id).then(response => {
|
|
|
|
this.downloadZip(response, 'codegen-' + row.tableName + '.zip');
|
|
|
|
})
|
2019-12-02 09:28:11 +08:00
|
|
|
},
|
2020-09-18 10:24:21 +08:00
|
|
|
/** 同步数据库操作 */
|
|
|
|
handleSynchDb(row) {
|
|
|
|
const tableName = row.tableName;
|
|
|
|
this.$confirm('确认要强制同步"' + tableName + '"表结构吗?', "警告", {
|
|
|
|
confirmButtonText: "确定",
|
|
|
|
cancelButtonText: "取消",
|
|
|
|
type: "warning"
|
|
|
|
}).then(function() {
|
2021-02-11 01:05:21 +08:00
|
|
|
return syncCodegen(row.id);
|
2020-09-18 10:24:21 +08:00
|
|
|
}).then(() => {
|
|
|
|
this.msgSuccess("同步成功");
|
2020-10-10 17:54:30 +08:00
|
|
|
})
|
2020-09-18 10:24:21 +08:00
|
|
|
},
|
2019-12-02 09:28:11 +08:00
|
|
|
/** 打开导入表弹窗 */
|
|
|
|
openImportTable() {
|
|
|
|
this.$refs.import.show();
|
|
|
|
},
|
|
|
|
/** 重置按钮操作 */
|
|
|
|
resetQuery() {
|
|
|
|
this.dateRange = [];
|
|
|
|
this.resetForm("queryForm");
|
|
|
|
this.handleQuery();
|
|
|
|
},
|
|
|
|
/** 预览按钮 */
|
|
|
|
handlePreview(row) {
|
2021-02-10 17:45:04 +08:00
|
|
|
previewCodegen(row.id).then(response => {
|
2019-12-02 09:28:11 +08:00
|
|
|
this.preview.data = response.data;
|
2021-02-10 17:45:04 +08:00
|
|
|
this.preview.activeName = response.data[0].filePath;
|
2019-12-02 09:28:11 +08:00
|
|
|
this.preview.open = true;
|
|
|
|
});
|
|
|
|
},
|
2021-02-09 15:55:54 +08:00
|
|
|
/** 高亮显示 */
|
2021-02-10 17:45:04 +08:00
|
|
|
highlightedCode(item) {
|
|
|
|
// const vmName = key.substring(key.lastIndexOf("/") + 1, key.indexOf(".vm"));
|
|
|
|
// var language = vmName.substring(vmName.indexOf(".") + 1, vmName.length);
|
|
|
|
var language = item.filePath.substring(item.filePath.lastIndexOf(".") + 1);
|
|
|
|
const result = hljs.highlight(language, item.code || "", true);
|
2021-02-09 15:55:54 +08:00
|
|
|
return result.value || ' ';
|
|
|
|
},
|
2019-12-02 09:28:11 +08:00
|
|
|
/** 修改按钮操作 */
|
|
|
|
handleEditTable(row) {
|
2021-02-09 22:14:01 +08:00
|
|
|
const tableId = row.id;
|
2020-06-24 17:17:22 +08:00
|
|
|
this.$router.push("/gen/edit/" + tableId);
|
2019-12-02 09:28:11 +08:00
|
|
|
},
|
|
|
|
/** 删除按钮操作 */
|
|
|
|
handleDelete(row) {
|
2021-02-11 01:05:21 +08:00
|
|
|
const tableIds = row.id;
|
|
|
|
this.$confirm('是否确认删除表名称为"' + row.tableName + '"的数据项?', "警告", {
|
2019-12-02 09:28:11 +08:00
|
|
|
confirmButtonText: "确定",
|
|
|
|
cancelButtonText: "取消",
|
|
|
|
type: "warning"
|
|
|
|
}).then(function() {
|
2021-02-11 01:05:21 +08:00
|
|
|
return deleteCodegen(tableIds);
|
2019-12-02 09:28:11 +08:00
|
|
|
}).then(() => {
|
|
|
|
this.getList();
|
|
|
|
this.msgSuccess("删除成功");
|
2020-10-10 17:54:30 +08:00
|
|
|
})
|
2019-12-02 09:28:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2021-02-09 15:55:54 +08:00
|
|
|
</script>
|