Commit aeebe25c by Elune

代码生成同步功能完成

parent 1e1705be
...@@ -23,3 +23,11 @@ export function save(data) { ...@@ -23,3 +23,11 @@ export function save(data) {
}) })
} }
export function sync(tables) {
return request({
url: 'api/generator/sync',
method: 'post',
data: tables
})
}
<template> <template>
<div class="app-container"> <div class="app-container">
<el-row :gutter="15"> <el-row :gutter="15">
<!--角色管理-->
<el-col style="margin-bottom: 10px"> <el-col style="margin-bottom: 10px">
<el-card class="box-card" shadow="never"> <el-card class="box-card" shadow="never">
<div slot="header" class="clearfix"> <div slot="header" class="clearfix">
...@@ -10,10 +9,18 @@ ...@@ -10,10 +9,18 @@
:loading="columnLoading" :loading="columnLoading"
icon="el-icon-check" icon="el-icon-check"
size="mini" size="mini"
style="float: right; padding: 6px 9px" style="float: right; padding: 6px 9px;"
type="primary" type="primary"
@click="saveColumnConfig" @click="saveColumnConfig"
>保存</el-button> >保存</el-button>
<el-button
:loading="syncLoading"
icon="el-icon-refresh"
size="mini"
style="float: right; padding: 6px 9px;margin-right: 10px"
type="success"
@click="sync"
>同步</el-button>
</div> </div>
<el-form size="small" label-width="90px"> <el-form size="small" label-width="90px">
<el-table v-loading="loading" :data="data" :max-height="tableHeight" size="small" style="width: 100%;margin-bottom: 15px"> <el-table v-loading="loading" :data="data" :max-height="tableHeight" size="small" style="width: 100%;margin-bottom: 15px">
...@@ -179,7 +186,7 @@ ...@@ -179,7 +186,7 @@
<script> <script>
import crud from '@/mixins/crud' import crud from '@/mixins/crud'
import { update, get } from '@/api/generator/genConfig' import { update, get } from '@/api/generator/genConfig'
import { save } from '@/api/generator/generator' import { save, sync } from '@/api/generator/generator'
import { getDicts } from '@/api/system/dict' import { getDicts } from '@/api/system/dict'
export default { export default {
name: 'GeneratorConfig', name: 'GeneratorConfig',
...@@ -187,7 +194,7 @@ export default { ...@@ -187,7 +194,7 @@ export default {
mixins: [crud], mixins: [crud],
data() { data() {
return { return {
activeName: 'first', tableName: '', tableHeight: 550, columnLoading: false, configLoading: false, dicts: [], activeName: 'first', tableName: '', tableHeight: 550, columnLoading: false, configLoading: false, dicts: [], syncLoading: false,
form: { id: null, tableName: '', author: '', pack: '', path: '', moduleName: '', cover: 'false', apiPath: '', prefix: '', apiAlias: null }, form: { id: null, tableName: '', author: '', pack: '', path: '', moduleName: '', cover: 'false', apiPath: '', prefix: '', apiAlias: null },
rules: { rules: {
author: [ author: [
...@@ -235,11 +242,7 @@ export default { ...@@ -235,11 +242,7 @@ export default {
saveColumnConfig() { saveColumnConfig() {
this.columnLoading = true this.columnLoading = true
save(this.data).then(res => { save(this.data).then(res => {
this.$notify({ this.notify('保存成功', 'success')
title: '保存成功',
type: 'success',
duration: 2500
})
this.columnLoading = false this.columnLoading = false
}).catch(err => { }).catch(err => {
this.columnLoading = false this.columnLoading = false
...@@ -251,11 +254,7 @@ export default { ...@@ -251,11 +254,7 @@ export default {
if (valid) { if (valid) {
this.configLoading = true this.configLoading = true
update(this.form).then(res => { update(this.form).then(res => {
this.$notify({ this.notify('保存成功', 'success')
title: '保存成功',
type: 'success',
duration: 2500
})
this.form = res this.form = res
this.form.cover = this.form.cover.toString() this.form.cover = this.form.cover.toString()
this.configLoading = false this.configLoading = false
...@@ -265,6 +264,16 @@ export default { ...@@ -265,6 +264,16 @@ export default {
}) })
} }
}) })
},
sync() {
this.syncLoading = true
sync([this.tableName]).then(() => {
this.init()
this.notify('同步成功', 'success')
this.syncLoading = false
}).then(() => {
this.syncLoading = false
})
} }
} }
} }
......
...@@ -2,21 +2,31 @@ ...@@ -2,21 +2,31 @@
<div class="app-container"> <div class="app-container">
<!--工具栏--> <!--工具栏-->
<div class="head-container"> <div class="head-container">
<el-input v-model="query.name" clearable size="small" placeholder="请输入表名" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" /> <div v-if="crud.props.searchToggle">
<el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button> <el-input v-model="query.name" clearable size="small" placeholder="请输入表名" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
<rrOperation :crud="crud" />
</div>
<crudOperation>
<el-button
slot="left"
class="filter-item"
size="mini"
type="success"
icon="el-icon-refresh"
:loading="syncLoading"
:disabled="crud.selections.length === 0"
@click="sync"
>同步</el-button>
</crudOperation>
</div> </div>
<!--表格渲染--> <!--表格渲染-->
<el-table v-loading="loading" :data="data" style="width: 100%;"> <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
<el-table-column label="序号" width="85" align="center"> <el-table-column type="selection" width="55" />
<template slot-scope="scope"> <el-table-column v-if="columns.visible('tableName')" :show-overflow-tooltip="true" prop="tableName" label="表名" />
<div>{{ scope.$index + 1 }}</div> <el-table-column v-if="columns.visible('engine')" :show-overflow-tooltip="true" prop="engine" label="数据库引擎" />
</template> <el-table-column v-if="columns.visible('coding')" :show-overflow-tooltip="true" prop="coding" label="字符编码集" />
</el-table-column> <el-table-column v-if="columns.visible('remark')" :show-overflow-tooltip="true" prop="remark" label="备注" />
<el-table-column :show-overflow-tooltip="true" prop="tableName" label="表名" /> <el-table-column v-if="columns.visible('createTime')" prop="createTime" label="创建日期">
<el-table-column :show-overflow-tooltip="true" prop="engine" label="数据库引擎" />
<el-table-column :show-overflow-tooltip="true" prop="coding" label="字符编码集" />
<el-table-column :show-overflow-tooltip="true" prop="remark" label="备注" />
<el-table-column prop="createTime" label="创建日期">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span> <span>{{ parseTime(scope.row.createTime) }}</span>
</template> </template>
...@@ -39,37 +49,32 @@ ...@@ -39,37 +49,32 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
<!--分页组件--> <!--分页组件-->
<el-pagination <pagination />
:total="total"
:current-page="page + 1"
style="margin-top: 8px;"
layout="total, prev, pager, next, sizes"
@size-change="sizeChange"
@current-change="pageChange"
/>
</div> </div>
</template> </template>
<script> <script>
import crud from '@/mixins/crud' import { generator, sync } from '@/api/generator/generator'
import { generator } from '@/api/generator/generator' import CRUD, { presenter, header } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
// crud交由presenter持有
const defaultCrud = CRUD({ url: 'api/generator/tables' })
export default { export default {
name: 'GeneratorIndex', name: 'GeneratorIndex',
mixins: [crud], components: { pagination, crudOperation, rrOperation },
mixins: [presenter(defaultCrud), header()],
data() { data() {
return { return {
syncLoading: false
} }
}, },
created() { created() {
this.$nextTick(() => { this.crud.optShow = { add: false, edit: false, del: false, download: false }
this.init()
})
}, },
methods: { methods: {
beforeInit() {
this.url = 'api/generator/tables'
return true
},
toGen(tableName) { toGen(tableName) {
// 生成代码 // 生成代码
generator(tableName, 0).then(data => { generator(tableName, 0).then(data => {
...@@ -85,6 +90,20 @@ export default { ...@@ -85,6 +90,20 @@ export default {
generator(tableName, 2).then(data => { generator(tableName, 2).then(data => {
this.downloadFile(data, tableName, 'zip') this.downloadFile(data, tableName, 'zip')
}) })
},
sync() {
const tables = []
this.crud.selections.forEach(val => {
tables.push(val.tableName)
})
this.syncLoading = true
sync(tables).then(() => {
this.crud.refresh()
this.crud.notify('同步成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
this.syncLoading = false
}).then(() => {
this.syncLoading = false
})
} }
} }
} }
......
<template> <template>
<el-tabs v-if="!error" v-model="activeName" type="card"> <el-tabs v-model="activeName" type="card">
<el-tab-pane v-for="item in data" :key="item.name" :lazy="true" :label="item.name" :name="item.name"> <el-tab-pane v-for="item in data" :key="item.name" :lazy="true" :label="item.name" :name="item.name">
<Java :value="item.content" :height="height" /> <Java :value="item.content" :height="height" />
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
<div v-else class="app-container">
<el-alert
:title="error"
type="error"
/>
</div>
</template> </template>
<script> <script>
...@@ -20,18 +14,16 @@ export default { ...@@ -20,18 +14,16 @@ export default {
components: { Java }, components: { Java },
data() { data() {
return { return {
data: null, error: null, height: '', activeName: 'Entity' data: null, height: '', activeName: 'Entity'
} }
}, },
created() { created() {
this.height = document.documentElement.clientHeight - 180 + 'px' this.height = document.documentElement.clientHeight - 180 + 'px'
const tableName = this.$route.params.tableName const tableName = this.$route.params.tableName
this.$nextTick(() => {
generator(tableName, 1).then(data => { generator(tableName, 1).then(data => {
this.data = data this.data = data
}).catch(err => { }).catch(() => {
this.error = err.response.data.message this.$router.go(-1)
})
}) })
} }
} }
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
class="filter-item" class="filter-item"
size="mini" size="mini"
type="success" type="success"
icon="el-icon-upload" icon="el-icon-refresh"
:loading="syncLoading" :loading="syncLoading"
@click="sync" @click="sync"
>同步</el-button> >同步</el-button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment