修复代码生成页面数据编辑保存之后总是跳转第一页的问题

This commit is contained in:
稚屿 2021-09-08 11:18:35 +08:00
parent a5e38f6f99
commit d2b61762b7
3 changed files with 735 additions and 732 deletions

View File

@ -1,160 +1,160 @@
import Vue from 'vue' import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
Vue.use(Router) Vue.use(Router)
/* Layout */ /* Layout */
import Layout from '@/layout' import Layout from '@/layout'
/** /**
* Note: 路由配置项 * Note: 路由配置项
* *
* hidden: true // 当设置 true 的时候该路由不会再侧边栏出现 如401login等页面或者如一些编辑页面/edit/1 * hidden: true // 当设置 true 的时候该路由不会再侧边栏出现 如401login等页面或者如一些编辑页面/edit/1
* alwaysShow: true // 当你一个路由下面的 children 声明的路由大于1个时自动会变成嵌套的模式--如组件页面 * alwaysShow: true // 当你一个路由下面的 children 声明的路由大于1个时自动会变成嵌套的模式--如组件页面
* // 只有一个时,会将那个子路由当做根路由显示在侧边栏--如引导页面 * // 只有一个时,会将那个子路由当做根路由显示在侧边栏--如引导页面
* // 若你想不管路由下面的 children 声明的个数都显示你的根路由 * // 若你想不管路由下面的 children 声明的个数都显示你的根路由
* // 你可以设置 alwaysShow: true这样它就会忽略之前定义的规则一直显示根路由 * // 你可以设置 alwaysShow: true这样它就会忽略之前定义的规则一直显示根路由
* redirect: noRedirect // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击 * redirect: noRedirect // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
* name:'router-name' // 设定路由的名字,一定要填写不然使用<keep-alive>时会出现各种问题 * name:'router-name' // 设定路由的名字,一定要填写不然使用<keep-alive>时会出现各种问题
* query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
* meta : { * meta : {
noCache: true // 如果设置为true则不会被 <keep-alive> 缓存(默认 false) noCache: true // 如果设置为true则不会被 <keep-alive> 缓存(默认 false)
title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字 title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字
icon: 'svg-name' // 设置该路由的图标对应路径src/assets/icons/svg icon: 'svg-name' // 设置该路由的图标对应路径src/assets/icons/svg
breadcrumb: false // 如果设置为false则不会在breadcrumb面包屑中显示 breadcrumb: false // 如果设置为false则不会在breadcrumb面包屑中显示
activeMenu: '/system/user' // 当路由设置了该属性,则会高亮相对应的侧边栏。 activeMenu: '/system/user' // 当路由设置了该属性,则会高亮相对应的侧边栏。
} }
*/ */
// 公共路由 // 公共路由
export const constantRoutes = [ export const constantRoutes = [
{ {
path: '/redirect', path: '/redirect',
component: Layout, component: Layout,
hidden: true, hidden: true,
children: [ children: [
{ {
path: '/redirect/:path(.*)', path: '/redirect/:path(.*)',
component: (resolve) => require(['@/views/redirect'], resolve) component: (resolve) => require(['@/views/redirect'], resolve)
} }
] ]
}, },
{ {
path: '/login', path: '/login',
component: (resolve) => require(['@/views/login'], resolve), component: (resolve) => require(['@/views/login'], resolve),
hidden: true hidden: true
}, },
{ {
path: '/register', path: '/register',
component: (resolve) => require(['@/views/register'], resolve), component: (resolve) => require(['@/views/register'], resolve),
hidden: true hidden: true
}, },
{ {
path: '/404', path: '/404',
component: (resolve) => require(['@/views/error/404'], resolve), component: (resolve) => require(['@/views/error/404'], resolve),
hidden: true hidden: true
}, },
{ {
path: '/401', path: '/401',
component: (resolve) => require(['@/views/error/401'], resolve), component: (resolve) => require(['@/views/error/401'], resolve),
hidden: true hidden: true
}, },
{ {
path: '', path: '',
component: Layout, component: Layout,
redirect: 'index', redirect: 'index',
children: [ children: [
{ {
path: 'index', path: 'index',
component: (resolve) => require(['@/views/index'], resolve), component: (resolve) => require(['@/views/index'], resolve),
name: 'Index', name: 'Index',
meta: { title: '首页', icon: 'dashboard', affix: true } meta: { title: '首页', icon: 'dashboard', affix: true }
} }
] ]
}, },
{ {
path: '/user', path: '/user',
component: Layout, component: Layout,
hidden: true, hidden: true,
redirect: 'noredirect', redirect: 'noredirect',
children: [ children: [
{ {
path: 'profile', path: 'profile',
component: (resolve) => require(['@/views/system/user/profile/index'], resolve), component: (resolve) => require(['@/views/system/user/profile/index'], resolve),
name: 'Profile', name: 'Profile',
meta: { title: '个人中心', icon: 'user' } meta: { title: '个人中心', icon: 'user' }
} }
] ]
}, },
{ {
path: '/system/user-auth', path: '/system/user-auth',
component: Layout, component: Layout,
hidden: true, hidden: true,
children: [ children: [
{ {
path: 'role/:userId(\\d+)', path: 'role/:userId(\\d+)',
component: (resolve) => require(['@/views/system/user/authRole'], resolve), component: (resolve) => require(['@/views/system/user/authRole'], resolve),
name: 'AuthRole', name: 'AuthRole',
meta: { title: '分配角色', activeMenu: '/system/user'} meta: { title: '分配角色', activeMenu: '/system/user'}
} }
] ]
}, },
{ {
path: '/system/role-auth', path: '/system/role-auth',
component: Layout, component: Layout,
hidden: true, hidden: true,
children: [ children: [
{ {
path: 'user/:roleId(\\d+)', path: 'user/:roleId(\\d+)',
component: (resolve) => require(['@/views/system/role/authUser'], resolve), component: (resolve) => require(['@/views/system/role/authUser'], resolve),
name: 'AuthUser', name: 'AuthUser',
meta: { title: '分配用户', activeMenu: '/system/role'} meta: { title: '分配用户', activeMenu: '/system/role'}
} }
] ]
}, },
{ {
path: '/system/dict-data', path: '/system/dict-data',
component: Layout, component: Layout,
hidden: true, hidden: true,
children: [ children: [
{ {
path: 'index/:dictId(\\d+)', path: 'index/:dictId(\\d+)',
component: (resolve) => require(['@/views/system/dict/data'], resolve), component: (resolve) => require(['@/views/system/dict/data'], resolve),
name: 'Data', name: 'Data',
meta: { title: '字典数据', activeMenu: '/system/dict'} meta: { title: '字典数据', activeMenu: '/system/dict'}
} }
] ]
}, },
{ {
path: '/monitor/job-log', path: '/monitor/job-log',
component: Layout, component: Layout,
hidden: true, hidden: true,
children: [ children: [
{ {
path: 'index', path: 'index',
component: (resolve) => require(['@/views/monitor/job/log'], resolve), component: (resolve) => require(['@/views/monitor/job/log'], resolve),
name: 'JobLog', name: 'JobLog',
meta: { title: '调度日志', activeMenu: '/monitor/job'} meta: { title: '调度日志', activeMenu: '/monitor/job'}
} }
] ]
}, },
{ {
path: '/tool/gen-edit', path: '/tool/gen-edit',
component: Layout, component: Layout,
hidden: true, hidden: true,
children: [ children: [
{ {
path: 'index/:tableId(\\d+)', path: 'index',
component: (resolve) => require(['@/views/tool/gen/editTable'], resolve), component: (resolve) => require(['@/views/tool/gen/editTable'], resolve),
name: 'GenEdit', name: 'GenEdit',
meta: { title: '修改生成配置', activeMenu: '/tool/gen'} meta: { title: '修改生成配置', activeMenu: '/tool/gen'}
} }
] ]
} }
] ]
export default new Router({ export default new Router({
mode: 'history', // 去掉url中的# mode: 'history', // 去掉url中的#
scrollBehavior: () => ({ y: 0 }), scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes routes: constantRoutes
}) })

View File

@ -1,232 +1,232 @@
<template> <template>
<el-card> <el-card>
<el-tabs v-model="activeName"> <el-tabs v-model="activeName">
<el-tab-pane label="基本信息" name="basic"> <el-tab-pane label="基本信息" name="basic">
<basic-info-form ref="basicInfo" :info="info" /> <basic-info-form ref="basicInfo" :info="info" />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="字段信息" name="cloum"> <el-tab-pane label="字段信息" name="cloum">
<el-table ref="dragTable" :data="cloumns" row-key="columnId" :max-height="tableHeight"> <el-table ref="dragTable" :data="cloumns" row-key="columnId" :max-height="tableHeight">
<el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag" /> <el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag" />
<el-table-column <el-table-column
label="字段列名" label="字段列名"
prop="columnName" prop="columnName"
min-width="10%" min-width="10%"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
/> />
<el-table-column label="字段描述" min-width="10%"> <el-table-column label="字段描述" min-width="10%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-input v-model="scope.row.columnComment"></el-input> <el-input v-model="scope.row.columnComment"></el-input>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
label="物理类型" label="物理类型"
prop="columnType" prop="columnType"
min-width="10%" min-width="10%"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
/> />
<el-table-column label="Java类型" min-width="11%"> <el-table-column label="Java类型" min-width="11%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-select v-model="scope.row.javaType"> <el-select v-model="scope.row.javaType">
<el-option label="Long" value="Long" /> <el-option label="Long" value="Long" />
<el-option label="String" value="String" /> <el-option label="String" value="String" />
<el-option label="Integer" value="Integer" /> <el-option label="Integer" value="Integer" />
<el-option label="Double" value="Double" /> <el-option label="Double" value="Double" />
<el-option label="BigDecimal" value="BigDecimal" /> <el-option label="BigDecimal" value="BigDecimal" />
<el-option label="Date" value="Date" /> <el-option label="Date" value="Date" />
</el-select> </el-select>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="java属性" min-width="10%"> <el-table-column label="java属性" min-width="10%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-input v-model="scope.row.javaField"></el-input> <el-input v-model="scope.row.javaField"></el-input>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="插入" min-width="5%"> <el-table-column label="插入" min-width="5%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-checkbox true-label="1" v-model="scope.row.isInsert"></el-checkbox> <el-checkbox true-label="1" v-model="scope.row.isInsert"></el-checkbox>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="编辑" min-width="5%"> <el-table-column label="编辑" min-width="5%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-checkbox true-label="1" v-model="scope.row.isEdit"></el-checkbox> <el-checkbox true-label="1" v-model="scope.row.isEdit"></el-checkbox>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="列表" min-width="5%"> <el-table-column label="列表" min-width="5%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-checkbox true-label="1" v-model="scope.row.isList"></el-checkbox> <el-checkbox true-label="1" v-model="scope.row.isList"></el-checkbox>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="查询" min-width="5%"> <el-table-column label="查询" min-width="5%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-checkbox true-label="1" v-model="scope.row.isQuery"></el-checkbox> <el-checkbox true-label="1" v-model="scope.row.isQuery"></el-checkbox>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="查询方式" min-width="10%"> <el-table-column label="查询方式" min-width="10%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-select v-model="scope.row.queryType"> <el-select v-model="scope.row.queryType">
<el-option label="=" value="EQ" /> <el-option label="=" value="EQ" />
<el-option label="!=" value="NE" /> <el-option label="!=" value="NE" />
<el-option label=">" value="GT" /> <el-option label=">" value="GT" />
<el-option label=">=" value="GTE" /> <el-option label=">=" value="GTE" />
<el-option label="<" value="LT" /> <el-option label="<" value="LT" />
<el-option label="<=" value="LTE" /> <el-option label="<=" value="LTE" />
<el-option label="LIKE" value="LIKE" /> <el-option label="LIKE" value="LIKE" />
<el-option label="BETWEEN" value="BETWEEN" /> <el-option label="BETWEEN" value="BETWEEN" />
</el-select> </el-select>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="必填" min-width="5%"> <el-table-column label="必填" min-width="5%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-checkbox true-label="1" v-model="scope.row.isRequired"></el-checkbox> <el-checkbox true-label="1" v-model="scope.row.isRequired"></el-checkbox>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="显示类型" min-width="12%"> <el-table-column label="显示类型" min-width="12%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-select v-model="scope.row.htmlType"> <el-select v-model="scope.row.htmlType">
<el-option label="文本框" value="input" /> <el-option label="文本框" value="input" />
<el-option label="文本域" value="textarea" /> <el-option label="文本域" value="textarea" />
<el-option label="下拉框" value="select" /> <el-option label="下拉框" value="select" />
<el-option label="单选框" value="radio" /> <el-option label="单选框" value="radio" />
<el-option label="复选框" value="checkbox" /> <el-option label="复选框" value="checkbox" />
<el-option label="日期控件" value="datetime" /> <el-option label="日期控件" value="datetime" />
<el-option label="图片上传" value="imageUpload" /> <el-option label="图片上传" value="imageUpload" />
<el-option label="文件上传" value="fileUpload" /> <el-option label="文件上传" value="fileUpload" />
<el-option label="富文本控件" value="editor" /> <el-option label="富文本控件" value="editor" />
</el-select> </el-select>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="字典类型" min-width="12%"> <el-table-column label="字典类型" min-width="12%">
<template slot-scope="scope"> <template slot-scope="scope">
<el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择"> <el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择">
<el-option <el-option
v-for="dict in dictOptions" v-for="dict in dictOptions"
:key="dict.dictType" :key="dict.dictType"
:label="dict.dictName" :label="dict.dictName"
:value="dict.dictType"> :value="dict.dictType">
<span style="float: left">{{ dict.dictName }}</span> <span style="float: left">{{ dict.dictName }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span> <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span>
</el-option> </el-option>
</el-select> </el-select>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="生成信息" name="genInfo"> <el-tab-pane label="生成信息" name="genInfo">
<gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus"/> <gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus"/>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
<el-form label-width="100px"> <el-form label-width="100px">
<el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;"> <el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
<el-button type="primary" @click="submitForm()">提交</el-button> <el-button type="primary" @click="submitForm()">提交</el-button>
<el-button @click="close()">返回</el-button> <el-button @click="close()">返回</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-card> </el-card>
</template> </template>
<script> <script>
import { getGenTable, updateGenTable } from "@/api/tool/gen"; import { getGenTable, updateGenTable } from "@/api/tool/gen";
import { optionselect as getDictOptionselect } from "@/api/system/dict/type"; import { optionselect as getDictOptionselect } from "@/api/system/dict/type";
import { listMenu as getMenuTreeselect } from "@/api/system/menu"; import { listMenu as getMenuTreeselect } from "@/api/system/menu";
import basicInfoForm from "./basicInfoForm"; import basicInfoForm from "./basicInfoForm";
import genInfoForm from "./genInfoForm"; import genInfoForm from "./genInfoForm";
import Sortable from 'sortablejs' import Sortable from 'sortablejs'
export default { export default {
name: "GenEdit", name: "GenEdit",
components: { components: {
basicInfoForm, basicInfoForm,
genInfoForm genInfoForm
}, },
data() { data() {
return { return {
// name // name
activeName: "cloum", activeName: "cloum",
// //
tableHeight: document.documentElement.scrollHeight - 245 + "px", tableHeight: document.documentElement.scrollHeight - 245 + "px",
// //
tables: [], tables: [],
// //
cloumns: [], cloumns: [],
// //
dictOptions: [], dictOptions: [],
// //
menus: [], menus: [],
// //
info: {} info: {}
}; };
}, },
created() { created() {
const tableId = this.$route.params && this.$route.params.tableId; const tableId = this.$route.query && this.$route.query.tableId;
if (tableId) { if (tableId) {
// //
getGenTable(tableId).then(res => { getGenTable(tableId).then(res => {
this.cloumns = res.data.rows; this.cloumns = res.data.rows;
this.info = res.data.info; this.info = res.data.info;
this.tables = res.data.tables; this.tables = res.data.tables;
}); });
/** 查询字典下拉列表 */ /** 查询字典下拉列表 */
getDictOptionselect().then(response => { getDictOptionselect().then(response => {
this.dictOptions = response.data; this.dictOptions = response.data;
}); });
/** 查询菜单下拉列表 */ /** 查询菜单下拉列表 */
getMenuTreeselect().then(response => { getMenuTreeselect().then(response => {
this.menus = this.handleTree(response.data, "menuId"); this.menus = this.handleTree(response.data, "menuId");
}); });
} }
}, },
methods: { methods: {
/** 提交按钮 */ /** 提交按钮 */
submitForm() { submitForm() {
const basicForm = this.$refs.basicInfo.$refs.basicInfoForm; const basicForm = this.$refs.basicInfo.$refs.basicInfoForm;
const genForm = this.$refs.genInfo.$refs.genInfoForm; const genForm = this.$refs.genInfo.$refs.genInfoForm;
Promise.all([basicForm, genForm].map(this.getFormPromise)).then(res => { Promise.all([basicForm, genForm].map(this.getFormPromise)).then(res => {
const validateResult = res.every(item => !!item); const validateResult = res.every(item => !!item);
if (validateResult) { if (validateResult) {
const genTable = Object.assign({}, basicForm.model, genForm.model); const genTable = Object.assign({}, basicForm.model, genForm.model);
genTable.columns = this.cloumns; genTable.columns = this.cloumns;
genTable.params = { genTable.params = {
treeCode: genTable.treeCode, treeCode: genTable.treeCode,
treeName: genTable.treeName, treeName: genTable.treeName,
treeParentCode: genTable.treeParentCode, treeParentCode: genTable.treeParentCode,
parentMenuId: genTable.parentMenuId parentMenuId: genTable.parentMenuId
}; };
updateGenTable(genTable).then(res => { updateGenTable(genTable).then(res => {
this.msgSuccess(res.msg); this.msgSuccess(res.msg);
if (res.code === 200) { if (res.code === 200) {
this.close(); this.close();
} }
}); });
} else { } else {
this.msgError("表单校验未通过,请重新检查提交内容"); this.msgError("表单校验未通过,请重新检查提交内容");
} }
}); });
}, },
getFormPromise(form) { getFormPromise(form) {
return new Promise(resolve => { return new Promise(resolve => {
form.validate(res => { form.validate(res => {
resolve(res); resolve(res);
}); });
}); });
}, },
/** 关闭按钮 */ /** 关闭按钮 */
close() { close() {
this.$store.dispatch("tagsView/delView", this.$route); this.$store.dispatch("tagsView/delView", this.$route);
this.$router.push({ path: "/tool/gen", query: { t: Date.now()}}) this.$router.push({ path: "/tool/gen", query: { t: Date.now(), pageNum: this.$route.query.pageNum } })
} }
}, },
mounted() { mounted() {
const el = this.$refs.dragTable.$el.querySelectorAll(".el-table__body-wrapper > table > tbody")[0]; const el = this.$refs.dragTable.$el.querySelectorAll(".el-table__body-wrapper > table > tbody")[0];
const sortable = Sortable.create(el, { const sortable = Sortable.create(el, {
handle: ".allowDrag", handle: ".allowDrag",
onEnd: evt => { onEnd: evt => {
const targetRow = this.cloumns.splice(evt.oldIndex, 1)[0]; const targetRow = this.cloumns.splice(evt.oldIndex, 1)[0];
this.cloumns.splice(evt.newIndex, 0, targetRow); this.cloumns.splice(evt.newIndex, 0, targetRow);
for (let index in this.cloumns) { for (let index in this.cloumns) {
this.cloumns[index].sort = parseInt(index) + 1; this.cloumns[index].sort = parseInt(index) + 1;
} }
} }
}); });
} }
}; };
</script> </script>

View File

@ -1,340 +1,343 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="表名称" prop="tableName"> <el-form-item label="表名称" prop="tableName">
<el-input <el-input
v-model="queryParams.tableName" v-model="queryParams.tableName"
placeholder="请输入表名称" placeholder="请输入表名称"
clearable clearable
size="small" size="small"
@keyup.enter.native="handleQuery" @keyup.enter.native="handleQuery"
/> />
</el-form-item> </el-form-item>
<el-form-item label="表描述" prop="tableComment"> <el-form-item label="表描述" prop="tableComment">
<el-input <el-input
v-model="queryParams.tableComment" v-model="queryParams.tableComment"
placeholder="请输入表描述" placeholder="请输入表描述"
clearable clearable
size="small" size="small"
@keyup.enter.native="handleQuery" @keyup.enter.native="handleQuery"
/> />
</el-form-item> </el-form-item>
<el-form-item label="创建时间"> <el-form-item label="创建时间">
<el-date-picker <el-date-picker
v-model="dateRange" v-model="dateRange"
size="small" size="small"
style="width: 240px" style="width: 240px"
value-format="yyyy-MM-dd" value-format="yyyy-MM-dd"
type="daterange" type="daterange"
range-separator="-" range-separator="-"
start-placeholder="开始日期" start-placeholder="开始日期"
end-placeholder="结束日期" end-placeholder="结束日期"
></el-date-picker> ></el-date-picker>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> <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-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-row :gutter="10" class="mb8"> <el-row :gutter="10" class="mb8">
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="primary" type="primary"
plain plain
icon="el-icon-download" icon="el-icon-download"
size="mini" size="mini"
@click="handleGenTable" @click="handleGenTable"
v-hasPermi="['tool:gen:code']" v-hasPermi="['tool:gen:code']"
>生成</el-button> >生成</el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="info" type="info"
plain plain
icon="el-icon-upload" icon="el-icon-upload"
size="mini" size="mini"
@click="openImportTable" @click="openImportTable"
v-hasPermi="['tool:gen:import']" v-hasPermi="['tool:gen:import']"
>导入</el-button> >导入</el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="success" type="success"
plain plain
icon="el-icon-edit" icon="el-icon-edit"
size="mini" size="mini"
:disabled="single" :disabled="single"
@click="handleEditTable" @click="handleEditTable"
v-hasPermi="['tool:gen:edit']" v-hasPermi="['tool:gen:edit']"
>修改</el-button> >修改</el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="danger" type="danger"
plain plain
icon="el-icon-delete" icon="el-icon-delete"
size="mini" size="mini"
:disabled="multiple" :disabled="multiple"
@click="handleDelete" @click="handleDelete"
v-hasPermi="['tool:gen:remove']" v-hasPermi="['tool:gen:remove']"
>删除</el-button> >删除</el-button>
</el-col> </el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
<el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
<el-table-column type="selection" align="center" width="55"></el-table-column> <el-table-column type="selection" align="center" width="55"></el-table-column>
<el-table-column label="序号" type="index" width="50" align="center"> <el-table-column label="序号" type="index" width="50" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span> <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
label="表名称" label="表名称"
align="center" align="center"
prop="tableName" prop="tableName"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
width="120" width="120"
/> />
<el-table-column <el-table-column
label="表描述" label="表描述"
align="center" align="center"
prop="tableComment" prop="tableComment"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
width="120" width="120"
/> />
<el-table-column <el-table-column
label="实体" label="实体"
align="center" align="center"
prop="className" prop="className"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
width="120" width="120"
/> />
<el-table-column label="创建时间" align="center" prop="createTime" width="160" /> <el-table-column label="创建时间" align="center" prop="createTime" width="160" />
<el-table-column label="更新时间" align="center" prop="updateTime" width="160" /> <el-table-column label="更新时间" align="center" prop="updateTime" width="160" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button
type="text" type="text"
size="small" size="small"
icon="el-icon-view" icon="el-icon-view"
@click="handlePreview(scope.row)" @click="handlePreview(scope.row)"
v-hasPermi="['tool:gen:preview']" v-hasPermi="['tool:gen:preview']"
>预览</el-button> >预览</el-button>
<el-button <el-button
type="text" type="text"
size="small" size="small"
icon="el-icon-edit" icon="el-icon-edit"
@click="handleEditTable(scope.row)" @click="handleEditTable(scope.row)"
v-hasPermi="['tool:gen:edit']" v-hasPermi="['tool:gen:edit']"
>编辑</el-button> >编辑</el-button>
<el-button <el-button
type="text" type="text"
size="small" size="small"
icon="el-icon-delete" icon="el-icon-delete"
@click="handleDelete(scope.row)" @click="handleDelete(scope.row)"
v-hasPermi="['tool:gen:remove']" v-hasPermi="['tool:gen:remove']"
>删除</el-button> >删除</el-button>
<el-button <el-button
type="text" type="text"
size="small" size="small"
icon="el-icon-refresh" icon="el-icon-refresh"
@click="handleSynchDb(scope.row)" @click="handleSynchDb(scope.row)"
v-hasPermi="['tool:gen:edit']" v-hasPermi="['tool:gen:edit']"
>同步</el-button> >同步</el-button>
<el-button <el-button
type="text" type="text"
size="small" size="small"
icon="el-icon-download" icon="el-icon-download"
@click="handleGenTable(scope.row)" @click="handleGenTable(scope.row)"
v-hasPermi="['tool:gen:code']" v-hasPermi="['tool:gen:code']"
>生成代码</el-button> >生成代码</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination <pagination
v-show="total>0" v-show="total>0"
:total="total" :total="total"
:page.sync="queryParams.pageNum" :page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize" :limit.sync="queryParams.pageSize"
@pagination="getList" @pagination="getList"
/> />
<!-- 预览界面 --> <!-- 预览界面 -->
<el-dialog :title="preview.title" :visible.sync="preview.open" width="80%" top="5vh" append-to-body class="scrollbar"> <el-dialog :title="preview.title" :visible.sync="preview.open" width="80%" top="5vh" append-to-body class="scrollbar">
<el-tabs v-model="preview.activeName"> <el-tabs v-model="preview.activeName">
<el-tab-pane <el-tab-pane
v-for="(value, key) in preview.data" v-for="(value, key) in preview.data"
:label="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))" :label="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))"
:name="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))" :name="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))"
:key="key" :key="key"
> >
<pre><code class="hljs" v-html="highlightedCode(value, key)"></code></pre> <pre><code class="hljs" v-html="highlightedCode(value, key)"></code></pre>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</el-dialog> </el-dialog>
<import-table ref="import" @ok="handleQuery" /> <import-table ref="import" @ok="handleQuery" />
</div> </div>
</template> </template>
<script> <script>
import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/gen"; import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/gen";
import importTable from "./importTable"; import importTable from "./importTable";
import { downLoadZip } from "@/utils/zipdownload"; import { downLoadZip } from "@/utils/zipdownload";
import hljs from "highlight.js/lib/highlight"; import hljs from "highlight.js/lib/highlight";
import "highlight.js/styles/github-gist.css"; import "highlight.js/styles/github-gist.css";
hljs.registerLanguage("java", require("highlight.js/lib/languages/java")); hljs.registerLanguage("java", require("highlight.js/lib/languages/java"));
hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml")); hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml"));
hljs.registerLanguage("html", 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("vue", require("highlight.js/lib/languages/xml"));
hljs.registerLanguage("javascript", require("highlight.js/lib/languages/javascript")); hljs.registerLanguage("javascript", require("highlight.js/lib/languages/javascript"));
hljs.registerLanguage("sql", require("highlight.js/lib/languages/sql")); hljs.registerLanguage("sql", require("highlight.js/lib/languages/sql"));
export default { export default {
name: "Gen", name: "Gen",
components: { importTable }, components: { importTable },
data() { data() {
return { return {
// //
loading: true, loading: true,
// //
uniqueId: "", uniqueId: "",
// //
ids: [], ids: [],
// //
tableNames: [], tableNames: [],
// //
single: true, single: true,
// //
multiple: true, multiple: true,
// //
showSearch: true, showSearch: true,
// //
total: 0, total: 0,
// //
tableList: [], tableList: [],
// //
dateRange: "", dateRange: "",
// //
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
tableName: undefined, tableName: undefined,
tableComment: undefined tableComment: undefined
}, },
// //
preview: { preview: {
open: false, open: false,
title: "代码预览", title: "代码预览",
data: {}, data: {},
activeName: "domain.java" activeName: "domain.java"
} }
}; };
}, },
created() { created() {
this.getList(); this.getList();
}, },
activated() { activated() {
const time = this.$route.query.t; const time = this.$route.query.t;
if (time != null && time != this.uniqueId) { if (time != null && time != this.uniqueId) {
this.uniqueId = time; this.uniqueId = time;
this.resetQuery(); this.queryParams.pageNum = Number(this.$route.query.pageNum);
} this.dateRange = [];
}, this.resetForm("queryForm");
methods: { this.getList();
/** 查询表集合 */ }
getList() { },
this.loading = true; methods: {
listTable(this.addDateRange(this.queryParams, this.dateRange)).then(response => { /** 查询表集合 */
this.tableList = response.rows; getList() {
this.total = response.total; this.loading = true;
this.loading = false; listTable(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
} this.tableList = response.rows;
); this.total = response.total;
}, this.loading = false;
/** 搜索按钮操作 */ }
handleQuery() { );
this.queryParams.pageNum = 1; },
this.getList(); /** 搜索按钮操作 */
}, handleQuery() {
/** 生成代码操作 */ this.queryParams.pageNum = 1;
handleGenTable(row) { this.getList();
const tableNames = row.tableName || this.tableNames; },
if (tableNames == "") { /** 生成代码操作 */
this.msgError("请选择要生成的数据"); handleGenTable(row) {
return; const tableNames = row.tableName || this.tableNames;
} if (tableNames == "") {
if(row.genType === "1") { this.msgError("请选择要生成的数据");
genCode(row.tableName).then(response => { return;
this.msgSuccess("成功生成到自定义路径:" + row.genPath); }
}); if(row.genType === "1") {
} else { genCode(row.tableName).then(response => {
downLoadZip("/tool/gen/batchGenCode?tables=" + tableNames, "ruoyi"); this.msgSuccess("成功生成到自定义路径:" + row.genPath);
} });
}, } else {
/** 同步数据库操作 */ downLoadZip("/tool/gen/batchGenCode?tables=" + tableNames, "ruoyi");
handleSynchDb(row) { }
const tableName = row.tableName; },
this.$confirm('确认要强制同步"' + tableName + '"表结构吗?', "警告", { /** 同步数据库操作 */
confirmButtonText: "确定", handleSynchDb(row) {
cancelButtonText: "取消", const tableName = row.tableName;
type: "warning" this.$confirm('确认要强制同步"' + tableName + '"表结构吗?', "警告", {
}).then(function() { confirmButtonText: "确定",
return synchDb(tableName); cancelButtonText: "取消",
}).then(() => { type: "warning"
this.msgSuccess("同步成功"); }).then(function() {
}).catch(() => {}); return synchDb(tableName);
}, }).then(() => {
/** 打开导入表弹窗 */ this.msgSuccess("同步成功");
openImportTable() { }).catch(() => {});
this.$refs.import.show(); },
}, /** 打开导入表弹窗 */
/** 重置按钮操作 */ openImportTable() {
resetQuery() { this.$refs.import.show();
this.dateRange = []; },
this.resetForm("queryForm"); /** 重置按钮操作 */
this.handleQuery(); resetQuery() {
}, this.dateRange = [];
/** 预览按钮 */ this.resetForm("queryForm");
handlePreview(row) { this.handleQuery();
previewTable(row.tableId).then(response => { },
this.preview.data = response.data; /** 预览按钮 */
this.preview.open = true; handlePreview(row) {
}); previewTable(row.tableId).then(response => {
}, this.preview.data = response.data;
/** 高亮显示 */ this.preview.open = true;
highlightedCode(code, key) { });
const vmName = key.substring(key.lastIndexOf("/") + 1, key.indexOf(".vm")); },
var language = vmName.substring(vmName.indexOf(".") + 1, vmName.length); /** 高亮显示 */
const result = hljs.highlight(language, code || "", true); highlightedCode(code, key) {
return result.value || '&nbsp;'; const vmName = key.substring(key.lastIndexOf("/") + 1, key.indexOf(".vm"));
}, var language = vmName.substring(vmName.indexOf(".") + 1, vmName.length);
// const result = hljs.highlight(language, code || "", true);
handleSelectionChange(selection) { return result.value || '&nbsp;';
this.ids = selection.map(item => item.tableId); },
this.tableNames = selection.map(item => item.tableName); //
this.single = selection.length != 1; handleSelectionChange(selection) {
this.multiple = !selection.length; this.ids = selection.map(item => item.tableId);
}, this.tableNames = selection.map(item => item.tableName);
/** 修改按钮操作 */ this.single = selection.length != 1;
handleEditTable(row) { this.multiple = !selection.length;
const tableId = row.tableId || this.ids[0]; },
this.$router.push("/tool/gen-edit/index/" + tableId); /** 修改按钮操作 */
}, handleEditTable(row) {
/** 删除按钮操作 */ const tableId = row.tableId || this.ids[0];
handleDelete(row) { this.$router.push({ path: '/tool/gen-edit/index', query: { tableId: tableId, pageNum: this.queryParams.pageNum } });
const tableIds = row.tableId || this.ids; },
this.$confirm('是否确认删除表编号为"' + tableIds + '"的数据项?', "警告", { /** 删除按钮操作 */
confirmButtonText: "确定", handleDelete(row) {
cancelButtonText: "取消", const tableIds = row.tableId || this.ids;
type: "warning" this.$confirm('是否确认删除表编号为"' + tableIds + '"的数据项?', "警告", {
}).then(function() { confirmButtonText: "确定",
return delTable(tableIds); cancelButtonText: "取消",
}).then(() => { type: "warning"
this.getList(); }).then(function() {
this.msgSuccess("删除成功"); return delTable(tableIds);
}).catch(() => {}); }).then(() => {
} this.getList();
} this.msgSuccess("删除成功");
}; }).catch(() => {});
</script> }
}
};
</script>