优化代码生成器,优化角色级别配置

This commit is contained in:
Elune
2019-12-22 10:39:59 +08:00
parent aeebe25c60
commit a3d7193ea0
5 changed files with 89 additions and 33 deletions

View File

@@ -54,4 +54,4 @@ export function editMenu(data) {
}) })
} }
export default { add, edit, del, get, editMenu } export default { add, edit, del, get, editMenu, getLevel }

View File

@@ -1,7 +1,7 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<p class="warn-content"> <p class="warn-content">
Markdown 基于 富文本基于
<el-link type="primary" href="https://www.kancloud.cn/wangfupeng/wangeditor3/332599" target="_blank">wangEditor</el-link> <el-link type="primary" href="https://www.kancloud.cn/wangfupeng/wangeditor3/332599" target="_blank">wangEditor</el-link>
图片上传使用 <el-link type="primary" href="https://sm.ms/" target="_blank">SM.MS</el-link> 图片上传使用 <el-link type="primary" href="https://sm.ms/" target="_blank">SM.MS</el-link>
</p> </p>

View File

@@ -5,22 +5,32 @@
<el-card class="box-card" shadow="never"> <el-card class="box-card" shadow="never">
<div slot="header" class="clearfix"> <div slot="header" class="clearfix">
<span class="role-span">字段配置{{ tableName }}</span> <span class="role-span">字段配置{{ tableName }}</span>
<el-button
:loading="genLoading"
icon="el-icon-s-promotion"
size="mini"
style="float: right; padding: 6px 9px;"
type="success"
@click="toGen"
>保存&生成</el-button>
<el-button <el-button
: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;margin-right: 9px"
type="primary" type="primary"
@click="saveColumnConfig" @click="saveColumnConfig"
>保存</el-button> >保存</el-button>
<el-button <el-tooltip class="item" effect="dark" content="数据库中表字段变动时使用该功能" placement="top-start">
:loading="syncLoading" <el-button
icon="el-icon-refresh" :loading="syncLoading"
size="mini" icon="el-icon-refresh"
style="float: right; padding: 6px 9px;margin-right: 10px" size="mini"
type="success" style="float: right; padding: 6px 9px;"
@click="sync" type="info"
>同步</el-button> @click="sync"
>同步</el-button>
</el-tooltip>
</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">
@@ -95,6 +105,10 @@
label="Like" label="Like"
value="Like" value="Like"
/> />
<el-option
label="NotNull"
value="NotNull"
/>
<el-option <el-option
label="BetWeen" label="BetWeen"
value="BetWeen" value="BetWeen"
@@ -161,14 +175,14 @@
<el-input v-model="form.path" style="width: 40%" /> <el-input v-model="form.path" style="width: 40%" />
<span style="color: #C0C0C0;margin-left: 10px;">输入views文件夹下的目录不存在即创建</span> <span style="color: #C0C0C0;margin-left: 10px;">输入views文件夹下的目录不存在即创建</span>
</el-form-item> </el-form-item>
<!-- <el-form-item label="接口目录">-->
<!-- <el-input v-model="form.apiPath" style="width: 40%" />-->
<!-- <span style="color: #C0C0C0;margin-left: 10px;">Api存放路径[src/api]为空则自动生成路径</span>-->
<!-- </el-form-item>-->
<el-form-item label="去表前缀" prop="prefix"> <el-form-item label="去表前缀" prop="prefix">
<el-input v-model="form.prefix" placeholder="默认不去除表前缀" style="width: 40%" /> <el-input v-model="form.prefix" placeholder="默认不去除表前缀" style="width: 40%" />
<span style="color: #C0C0C0;margin-left: 10px;">默认不去除表前缀可自定义</span> <span style="color: #C0C0C0;margin-left: 10px;">默认不去除表前缀可自定义</span>
</el-form-item> </el-form-item>
<!-- <el-form-item label="Api路径">-->
<!-- <el-input v-model="form.apiPath"/>-->
<!-- <span style="color: #C0C0C0;margin-left: 10px;">Sender mailbox</span>-->
<!-- </el-form-item>-->
<el-form-item label="是否覆盖" prop="cover"> <el-form-item label="是否覆盖" prop="cover">
<el-radio-group v-model="form.cover" size="mini" style="width: 40%"> <el-radio-group v-model="form.cover" size="mini" style="width: 40%">
<el-radio-button label="true"></el-radio-button> <el-radio-button label="true"></el-radio-button>
@@ -186,7 +200,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, sync } from '@/api/generator/generator' import { save, sync, generator } from '@/api/generator/generator'
import { getDicts } from '@/api/system/dict' import { getDicts } from '@/api/system/dict'
export default { export default {
name: 'GeneratorConfig', name: 'GeneratorConfig',
@@ -194,7 +208,7 @@ export default {
mixins: [crud], mixins: [crud],
data() { data() {
return { return {
activeName: 'first', tableName: '', tableHeight: 550, columnLoading: false, configLoading: false, dicts: [], syncLoading: false, activeName: 'first', tableName: '', tableHeight: 550, columnLoading: false, configLoading: false, dicts: [], syncLoading: false, genLoading: 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: [
@@ -274,6 +288,23 @@ export default {
}).then(() => { }).then(() => {
this.syncLoading = false this.syncLoading = false
}) })
},
toGen() {
this.genLoading = true
save(this.data).then(res => {
this.notify('保存成功', 'success')
// 生成代码
generator(this.tableName, 0).then(data => {
this.genLoading = false
this.notify('生成成功', 'success')
}).catch(err => {
this.genLoading = false
console.log(err.response.data.message)
})
}).catch(err => {
this.genLoading = false
console.log(err.response.data.message)
})
} }
} }
} }

View File

@@ -7,16 +7,17 @@
<rrOperation :crud="crud" /> <rrOperation :crud="crud" />
</div> </div>
<crudOperation> <crudOperation>
<el-button <el-tooltip slot="right" class="item" effect="dark" content="数据库中表字段变动时使用该功能" placement="top-start">
slot="left" <el-button
class="filter-item" class="filter-item"
size="mini" size="mini"
type="success" type="success"
icon="el-icon-refresh" icon="el-icon-refresh"
:loading="syncLoading" :loading="syncLoading"
:disabled="crud.selections.length === 0" :disabled="crud.selections.length === 0"
@click="sync" @click="sync"
>同步</el-button> >同步</el-button>
</el-tooltip>
</crudOperation> </crudOperation>
</div> </div>
<!--表格渲染--> <!--表格渲染-->
@@ -54,7 +55,9 @@
</template> </template>
<script> <script>
import { generator, sync } from '@/api/generator/generator' import { generator, sync } from '@/api/generator/generator'
import { downloadFile } from '@/utils/index'
import CRUD, { presenter, header } from '@crud/crud' import CRUD, { presenter, header } from '@crud/crud'
import rrOperation from '@crud/RR.operation' import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation' import crudOperation from '@crud/CRUD.operation'
@@ -88,7 +91,7 @@ export default {
toDownload(tableName) { toDownload(tableName) {
// 打包下载 // 打包下载
generator(tableName, 2).then(data => { generator(tableName, 2).then(data => {
this.downloadFile(data, tableName, 'zip') downloadFile(data, tableName, 'zip')
}) })
}, },
sync() { sync() {

View File

@@ -62,7 +62,7 @@
<span class="role-span">角色列表</span> <span class="role-span">角色列表</span>
</div> </div>
<el-table ref="table" v-loading="crud.loading" highlight-current-row style="width: 100%;" :data="crud.data" @selection-change="crud.selectionChangeHandler" @current-change="handleCurrentChange"> <el-table ref="table" v-loading="crud.loading" highlight-current-row style="width: 100%;" :data="crud.data" @selection-change="crud.selectionChangeHandler" @current-change="handleCurrentChange">
<el-table-column type="selection" width="55" /> <el-table-column :selectable="checkboxT" type="selection" width="55" />
<el-table-column v-if="columns.visible('name')" prop="name" label="名称" /> <el-table-column v-if="columns.visible('name')" prop="name" label="名称" />
<el-table-column v-if="columns.visible('dataScope')" prop="dataScope" label="数据权限" /> <el-table-column v-if="columns.visible('dataScope')" prop="dataScope" label="数据权限" />
<el-table-column v-if="columns.visible('permission')" prop="permission" label="角色权限" /> <el-table-column v-if="columns.visible('permission')" prop="permission" label="角色权限" />
@@ -76,6 +76,7 @@
<el-table-column v-permission="['admin','roles:edit','roles:del']" label="操作" width="130px" align="center" fixed="right"> <el-table-column v-permission="['admin','roles:edit','roles:del']" label="操作" width="130px" align="center" fixed="right">
<template slot-scope="scope"> <template slot-scope="scope">
<udOperation <udOperation
v-if="scope.row.level >= level"
:data="scope.row" :data="scope.row"
:permission="permission" :permission="permission"
/> />
@@ -142,7 +143,7 @@ export default {
data() { data() {
return { return {
defaultProps: { children: 'children', label: 'label' }, defaultProps: { children: 'children', label: 'label' },
dateScopes: ['全部', '本级', '自定义'], dateScopes: ['全部', '本级', '自定义'], level: 3,
currentId: 0, menuLoading: false, showButton: false, currentId: 0, menuLoading: false, showButton: false,
menus: [], menuIds: [], depts: [], menus: [], menuIds: [], depts: [],
permission: { permission: {
@@ -162,6 +163,10 @@ export default {
}, },
created() { created() {
this.getMenus() this.getMenus()
crudRoles.getLevel().then(data => {
this.level = data.level
console.log(this.level)
})
this.$nextTick(() => { this.$nextTick(() => {
this.crud.toQuery() this.crud.toQuery()
}) })
@@ -189,16 +194,31 @@ export default {
type: 'warning' type: 'warning'
}) })
return false return false
} else { } else if (crud.form.dataScope === '自定义') {
const depts = [] const depts = []
crud.form.depts.forEach(function(data, index) { crud.form.depts.forEach(function(data, index) {
const dept = { id: data } const dept = { id: data }
depts.push(dept) depts.push(dept)
}) })
crud.form.depts = depts crud.form.depts = depts
} else {
crud.form.depts = []
} }
return true return true
}, },
[CRUD.HOOK.afterAddError](crud) {
this.afterErrorMethod(crud)
},
[CRUD.HOOK.afterEditError](crud) {
this.afterErrorMethod(crud)
},
afterErrorMethod(crud) {
const depts = []
crud.form.depts.forEach(function(dept, index) {
depts.push(dept.id)
})
crud.form.depts = depts
},
// 获取所有菜单 // 获取所有菜单
getMenus() { getMenus() {
getMenusTree().then(res => { getMenusTree().then(res => {
@@ -213,8 +233,7 @@ export default {
this.$refs.menu.setCheckedKeys([]) this.$refs.menu.setCheckedKeys([])
// 保存当前的角色id // 保存当前的角色id
this.currentId = val.id this.currentId = val.id
// 点击后显示按钮 this.showButton = this.level <= val.level
this.showButton = true
// 初始化 // 初始化
this.menuIds = [] this.menuIds = []
// 菜单数据需要特殊处理 // 菜单数据需要特殊处理
@@ -269,6 +288,9 @@ export default {
if (this.form.dataScope === '自定义') { if (this.form.dataScope === '自定义') {
this.getDepts() this.getDepts()
} }
},
checkboxT(row, rowIndex) {
return row.level >= this.level
} }
} }
} }