代码生成

This commit is contained in:
wind
2019-11-13 18:40:40 +08:00
parent bcee37b84b
commit 035d23078b
39 changed files with 5696 additions and 103 deletions

View File

@ -0,0 +1,66 @@
import request from '@/utils/request'
// 查询
export function listTable(query) {
return request({
url: '/tool/gen/list',
method: 'post',
params: query
})
}
// 查询db数据库列表
export function listdbTable(query) {
return request({
url: '/tool/gen/db/list',
method: 'post',
params: query
})
}
// 导出table
export function exportTable(data) {
return request({
url: '/tool/gen/list/'+data,
method: 'get',
})
}
// 查询更改表信息
export function editTableInfo(data) {
return request({
url: '/tool/gen/edit',
method: 'get',
params:data
})
}
// 更改表请求
export function editGenInfo(data) {
return request({
url: '/tool/gen/edit',
method: 'post',
data:data
})
}
// 导入表
export function importTable(data) {
return request({
url: '/tool/gen/importTable',
method: 'post',
params:data
})
}
// 预览
export function previewTable(data) {
return request({
url: '/tool/gen/preview/'+data,
method: 'get'
})
}
// 移除tableid
export function removeTable(data) {
return request({
url: '/tool/gen/remove',
method: 'post',
params:data
})
}

View File

@ -1,95 +1,96 @@
/**
* 通用js方法封装处理
* Copyright (c) 2019 ruoyi
*/
const baseURL = process.env.VUE_APP_BASE_API
// 日期格式化
export function parseTime(time, pattern) {
if (arguments.length === 0) {
return null
}
const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
let date
if (typeof time === 'object') {
date = time
} else {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
}
if ((typeof time === 'number') && (time.toString().length === 10)) {
time = time * 1000
}
date = new Date(time)
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
}
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key]
// Note: getDay() returns 0 on Sunday
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
if (result.length > 0 && value < 10) {
value = '0' + value
}
return value || 0
})
return time_str
}
// 表单重置
export function resetForm(refName) {
if (this.$refs[refName] !== undefined) {
this.$refs[refName].resetFields();
}
}
// 添加日期范围
export function addDateRange(params, dateRange) {
var search = params;
if (null != dateRange) {
search.params = {
beginTime: this.dateRange[0],
endTime: this.dateRange[1]
};
}
return search;
}
// 回显数据字典
export function selectDictLabel(datas, value) {
var actions = [];
Object.keys(datas).map((key) => {
if (datas[key].dictValue == ('' + value)) {
actions.push(datas[key].dictLabel);
return false;
}
})
return actions.join('');
}
// 通用下载方法
export function download(fileName) {
window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
}
// 字符串格式化(%s )
export function sprintf(str) {
var args = arguments, flag = true, i = 1;
str = str.replace(/%s/g, function () {
var arg = args[i++];
if (typeof arg === 'undefined') {
flag = false;
return '';
}
return arg;
});
return flag ? str : '';
}
/**
* 通用js方法封装处理
* Copyright (c) 2019 ruoyi
*/
const baseURL = process.env.VUE_APP_BASE_API
// 日期格式化
export function parseTime(time, pattern) {
if (arguments.length === 0) {
return null
}
const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
let date
if (typeof time === 'object') {
date = time
} else {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
}
if ((typeof time === 'number') && (time.toString().length === 10)) {
time = time * 1000
}
date = new Date(time)
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
}
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key]
// Note: getDay() returns 0 on Sunday
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
if (result.length > 0 && value < 10) {
value = '0' + value
}
return value || 0
})
return time_str
}
// 表单重置
export function resetForm(refName) {
if (this.$refs[refName] !== undefined) {
this.$refs[refName].resetFields();
}
}
// 添加日期范围
export function addDateRange(params, dateRange) {
var search = params;
search.params=[]
if (null != dateRange) {
search.params = {
beginTime: this.dateRange[0],
endTime: this.dateRange[1]
};
}
return search;
}
// 回显数据字典
export function selectDictLabel(datas, value) {
var actions = [];
Object.keys(datas).map((key) => {
if (datas[key].dictValue == ('' + value)) {
actions.push(datas[key].dictLabel);
return false;
}
})
return actions.join('');
}
// 通用下载方法
export function download(fileName) {
window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
}
// 字符串格式化(%s )
export function sprintf(str) {
var args = arguments, flag = true, i = 1;
str = str.replace(/%s/g, function () {
var arg = args[i++];
if (typeof arg === 'undefined') {
flag = false;
return '';
}
return arg;
});
return flag ? str : '';
}

View File

@ -0,0 +1,40 @@
import axios from 'axios'
import { getToken } from '@/utils/auth'
const mimeMap = {
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
zip: 'application/zip'
}
const baseUrl = process.env.VUE_APP_BASE_API
export function downLoadZip(str, filename) {
var url = baseUrl + str
axios({
method: 'get',
url: url,
responseType: 'blob',
headers: {'Authorization':'Bearer ' + getToken()}
}).then(res => {
resolveBlob(res, mimeMap.zip)
})
}
/**
* 解析blob响应内容并下载
* @param {*} res blob响应内容
* @param {String} mimeType MIME类型
*/
export function resolveBlob (res, mimeType) {
const aLink = document.createElement('a')
var blob = new Blob([res.data], { type: mimeType })
// //从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名;
var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
var contentDisposition = decodeURI(res.headers['content-disposition'])
var result = patt.exec(contentDisposition)
var fileName = result[1]
fileName=fileName.replace(/\"/g,'')
aLink.href = URL.createObjectURL(blob)
aLink.setAttribute('download', fileName) // 设置下载文件名称
document.body.appendChild(aLink)
aLink.click()
document.body.appendChild(aLink)
}

View File

@ -0,0 +1,141 @@
<template>
<!-- 导入表 -->
<el-dialog title="导入表" :visible.sync="visible" width="800px">
<el-form :model="queryParams" ref="importQueryForm" :inline="true" label-width="68px">
<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-button type="text" style="margin-left: 20px" @click="handleImportSearch">搜索</el-button>
<el-button type="text" style="margin-left: 20px" @click="handleImportReset">重置</el-button>
</el-form>
<el-row>
<el-table
:data="dbTableList"
@selection-change="handleSelectionChange"
style="width: 100%;">
<el-table-column
type="selection"
width="55"></el-table-column>
<el-table-column
prop="tableName"
label="表名称"
>
</el-table-column>
<el-table-column
prop="tableComment"
label="表描述"
>
</el-table-column>
<el-table-column
prop="createTime"
label="创建时间"
>
</el-table-column>
<el-table-column
prop="updateTime"
label="更新时间"
>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="handleDbList"
/>
</el-row>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="handleImportTable"> </el-button>
<el-button @click="handleImportCancel"> </el-button>
</div>
</el-dialog>
</template>
<script>
import { listdbTable,importTable } from '@/api/tool/gen'
export default {
data() {
return {
visible: false,
center: true,
// 选中数组
ids: [],
tables: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
queryParams:
{
tableName:'',
tableComment:'',
pageNum: 1,
pageSize: 10
},
dbTableList:[],
total:0
};
},
created() {
this.handleImportSearch()
},
methods: {
show(){
this.visible=true
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.tableId)
this.tables = selection.map(item => item.tableName)
this.single = selection.length!=1
this.multiple = !selection.length
},
handleImportSearch()
{
this.queryParams.pageNum=1
this.handleDbList()
},
handleDbList()
{
listdbTable(this.queryParams).then(res => {
if(res.code===200){
this.dbTableList = res.rows
this.total=res.total
}
})
},
handleImportReset(){
this.resetForm("importQueryForm");
},
handleImportTable()//导入table
{
importTable({tables:this.tables.join(",")}).then(res => {
this.msgSuccess(res.msg);
if (res.code === 200) {
this.visible=false
this.$emit('ok');
}
})
},
handleImportCancel(){
this.visible=false
},
}
};
</script>

View File

@ -1,5 +1,244 @@
<template>
<div class="app-container">
代码生成
</div>
</template>
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
<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>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<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">
<el-button
type="primary"
icon="el-icon-download"
size="mini"
@click="handleBatchGenTable"
v-hasPermi="['system:post:add']"
>生成</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
icon="el-icon-upload"
size="mini"
@click="handleImport"
v-hasPermi="['system:post:add']"
>导入</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleEditTable"
v-hasPermi="['system:post:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['system:post:remove']"
>删除</el-button>
</el-col>
</el-row>
<el-table
:data="tableList"
style="width: 100% ;margin-top: 10px"
@selection-change="handleSelectionChange"
>
<el-table-column
type="selection"
width="30"></el-table-column>
<el-table-column label="序号" align="center" prop="tableId" width="50px"/>
<el-table-column label="表名称" align="center" prop="tableName" />
<el-table-column label="表描述" align="center" prop="tableComment" />
<el-table-column label="实体" align="center" prop="className" />
<el-table-column label="创建时间" align="center" prop="createTime" />
<el-table-column label="更新时间" align="center" prop="updateTime" />
<el-table-column
label="操作"
align="center"
min-width="180px"
>
<template slot-scope="scope">
<el-button type="text" size="small" icon="el-icon-view" @click="handlepreView(scope.row)">预览</el-button>
<el-button type="text" size="small" icon="el-icon-edit" @click="handleEditTable(scope.row)">编辑</el-button>
<el-button type="text" size="small" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
<el-button type="text" size="small" icon="el-icon-download"@click="handleGenTable(scope.row.tableName)">生成代码</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 预览界面 -->
<el-dialog :title="title" :visible.sync="preDialog.open" width="900px" lock-scroll>
<el-tabs v-model="vm.activeName" type="card">
<el-tab-pane :label="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))" v-for="(value, key) in preDialog.preData" :key="key">
<pre>{{ value }}</pre>
</el-tab-pane>
</el-tabs>
</el-dialog>
<import-dailog ref="import" @ok="handleQuery"/>
</div>
</template>
<script>
import { listTable,listdbTable,importTable,previewTable,removeTable } from '@/api/tool/gen'
import importDailog from './dailog/importDailog';
import { downLoadZip } from '@/utils/zipdownload'
export default {
components: { importDailog },
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
tableNames: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 总条数
total: 0,
// 岗位表格数据
tableList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 状态数据字典
statusOptions: [],
// 日期范围
dateRange: '',
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
tableName: undefined,
tableComment: undefined
},
// 表单参数
form: {},
vm:{
activeName:"0"
},
preDialog:{
open: false,
preData:{}
},
};
},
created() {
this.getList()
},
methods: {
/** 查询岗位列表 */
getList() {
this.loading = true;
listTable(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.tableList = response.rows;
this.total = response.total;
this.loading = false;
});
},
/** 搜索按钮操作 */
handleQuery() {
console.log("handleQuery")
this.queryParams.pageNum = 1;
this.getList();
},
handleGenTable(tabelname){
downLoadZip('tool/gen/genCode/'+tabelname, 'ruoyi')
},
handleBatchGenTable(tabelname){
downLoadZip('tool/gen/batchGenCode?tables='+this.tableNames.join(','), 'ruoyi')
},
handleImport(){
this.$refs.import.show()
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm("queryForm");
this.handleQuery();
},
handlepreView(row){
previewTable(row.tableId).then(response => {
this.title="代码预览"
this.preDialog.preData = response.data
this.preDialog.open=true
})
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.tableId)
this.tableNames = selection.map(item => item.tableName)
this.single = selection.length!=1
this.multiple = !selection.length
},
/** 修改按钮操作 */
handleEditTable(row) {
const tableId = row.tableId || this.ids[0]
console.log(tableId)
this.$router.push({ path: '/gen/edit',query: { tableId: tableId } });
},
/** 删除按钮操作 */
handleDelete(row) {
const tableIds = row.tableId || this.ids.join(',');
this.$confirm('是否确认删除表编号为"' + tableIds + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return removeTable({ids:tableIds});
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(function() {});
}
}
};
</script>