Skip to content

Commit

Permalink
Issue #I1OQBA #I1OMTL 完善权限管理功能
Browse files Browse the repository at this point in the history
  • Loading branch information
enilu committed Jul 26, 2020
1 parent 7e6b6f2 commit 3fc42dd
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CfgController extends BaseController {
* 查询参数列表
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
@RequiresPermissions(value = {Permission.CFG})
@RequiresPermissions(value = {"/cfg"})
public Object list(@RequestParam(required = false) String cfgName, @RequestParam(required = false) String cfgValue) {
Page<Cfg> page = new PageFactory<Cfg>().defaultPage();
if (StringUtil.isNotEmpty(cfgName)) {
Expand Down Expand Up @@ -83,25 +83,29 @@ public Object export(@RequestParam(required = false) String cfgName, @RequestPar
}

@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "新增参数", key = "cfgName")
@RequiresPermissions(value = {"/cfg/add"})
public Object add(@ModelAttribute @Valid Cfg cfg) {
cfgService.saveOrUpdate(cfg);
return Rets.success();
}

@RequestMapping(method = RequestMethod.PUT)
@BussinessLog(value = "编辑参数", key = "cfgName")
@RequiresPermissions(value = {Permission.CFG_EDIT})
public Object save(@ModelAttribute @Valid Cfg cfg) {
if (cfg.getId() != null) {
Cfg old = cfgService.get(cfg.getId());
LogObjectHolder.me().set(old);
old.setCfgName(cfg.getCfgName());
old.setCfgValue(cfg.getCfgValue());
old.setCfgDesc(cfg.getCfgDesc());
cfgService.saveOrUpdate(old);
} else {
cfgService.saveOrUpdate(cfg);
}
@RequiresPermissions(value = {"/cfg/update"})
public Object update(@ModelAttribute @Valid Cfg cfg) {
Cfg old = cfgService.get(cfg.getId());
LogObjectHolder.me().set(old);
old.setCfgName(cfg.getCfgName());
old.setCfgValue(cfg.getCfgValue());
old.setCfgDesc(cfg.getCfgDesc());
cfgService.saveOrUpdate(old);
return Rets.success();
}

@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除参数", key = "id")
@RequiresPermissions(value = {Permission.CFG_DEL})
@RequiresPermissions(value = {"/cfg/delete"})
public Object remove(@RequestParam Long id) {
logger.info("id:{}", id);
if (id == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Menu extends BaseEntity {
/**
* 如果当前配置为非菜单(按钮)也需要配置链接,v-permission使用该配置,且不能与其他url重复
*/
@Column(columnDefinition = "VARCHAR(32) COMMENT '链接标识'")
@Column(columnDefinition = "VARCHAR(32) COMMENT '资源/权限标识'")
private String url;
@Column(columnDefinition = "INT COMMENT '顺序'", nullable = false)
private Integer num;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
simpleAuthorizationInfo.addRoles(user.getRoleCodes());
Set<String> permission = user.getPermissions();
//资源的权限标识采用menu中的code和url,建议统一以url为准
simpleAuthorizationInfo.addStringPermissions(permission);
simpleAuthorizationInfo.addStringPermissions(user.getUrls());
return simpleAuthorizationInfo;
}

Expand Down
24 changes: 17 additions & 7 deletions flash-generator/src/main/resources/code/controller.vm
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import ${table.basePackageName}.bean.vo.front.Rets;

import ${table.basePackageName}.utils.factory.Page;


import org.apache.shiro.authz.annotation.RequiresPermissions;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("${table.UriPrefix}")
public class ${table.ControllerClassName} extends BaseController {
Expand All @@ -26,24 +30,30 @@ public class ${table.ControllerClassName} extends BaseController {
private ${table.ServiceClassName} ${table.ServiceInstanceName};

@RequestMapping(value = "/list",method = RequestMethod.GET)
@RequiresPermissions(value = "${table.UriPrefix}")
public Object list(@RequestParam(required = false) Long id) {
Page<${table.EntityClassName}> page = new PageFactory<${table.EntityClassName}>().defaultPage();
page.addFilter("id",id);
page = ${table.ServiceInstanceName}.queryPage(page);
return Rets.success(page);
}
@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "编辑${table.Label}", key = "name")
public Object save(@ModelAttribute ${table.EntityClassName} ${table.EntityInstanceName}){
if(${table.EntityInstanceName}.getId()==null){
${table.ServiceInstanceName}.insert(${table.EntityInstanceName});
}else {
${table.ServiceInstanceName}.update(${table.EntityInstanceName});
}
@BussinessLog(value = "新增${table.Label}", key = "name")
@RequiresPermissions(value = "${table.UriPrefix}/add")
public Object add(@ModelAttribute ${table.EntityClassName} ${table.entityNameLowerFirstChar}){
${table.ServiceInstanceName}.insert(${table.entityNameLowerFirstChar});
return Rets.success();
}
@RequestMapping(method = RequestMethod.PUT)
@BussinessLog(value = "更新${table.Label}", key = "name")
@RequiresPermissions(value = "${table.UriPrefix}/update")
public Object update(@ModelAttribute ${table.EntityClassName} ${table.entityNameLowerFirstChar}){
${table.ServiceInstanceName}.update(${table.entityNameLowerFirstChar});
return Rets.success();
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除${table.Label}", key = "id")
@RequiresPermissions(value = "${table.UriPrefix}/delete")
public Object remove(Long id){
if (id == null) {
throw new ApplicationException(BizExceptionEnum.REQUEST_NULL);
Expand Down
57 changes: 31 additions & 26 deletions flash-generator/src/main/resources/code/view/api.js.vm
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import request from '@/utils/request'

export function getList(params) {
return request({
url: '${table.UriPrefix}/list',
method: 'get',
params
})
}


export function save(params) {
return request({
url: '${table.UriPrefix}',
method: 'post',
params
})
}

export function remove(id) {
return request({
url: '${table.UriPrefix}',
method: 'delete',
params: {
id: id
}
})
export default {
getList:function(params) {
return request({
url: '${table.UriPrefix}/list',
method: 'get',
params
})
},
add:function(params) {
return request({
url: '${table.UriPrefix}',
method: 'post',
params
})
},
update:function(params) {
return request({
url: '${table.UriPrefix}',
method: 'PUT',
params
})
},
remove:function(id) {
return request({
url: '${table.UriPrefix}',
method: 'delete',
params: {
id: id
}
})
}
}
44 changes: 29 additions & 15 deletions flash-generator/src/main/resources/code/view/index.js.vm
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#set($refForm = "this.$refs['form']")
import { remove, getList, save } from '@/api/${table.lastPackageName}/${table.entityNameLowerFirstChar}'
import ${table.entityNameLowerFirstChar}Api from '@/api/${table.lastPackageName}/${table.entityNameLowerFirstChar}'
import permission from '@/directive/permission/index.js'

export default {
directives: { permission },
data() {
return {
formVisible: false,
Expand Down Expand Up @@ -55,7 +57,7 @@ export default {
},
fetchData() {
this.listLoading = true
getList(this.listQuery).then(response => {
${table.entityNameLowerFirstChar}Api.getList(this.listQuery).then(response => {
this.list = response.data.records
this.listLoading = false
this.total = response.data.total
Expand Down Expand Up @@ -110,25 +112,37 @@ export default {
if(this.$refs['form'] !== undefined) {
this.$refs['form'].resetFields()
}
//如果表单初始化又特殊处理需求,可以在resetForm中处理
//如果表单初始化有特殊处理需求,可以在resetForm中处理
## this.resetForm()
},
save() {
${refForm}.validate((valid) => {
if (valid) {
save({
const formData = {
id:this.form.id,
#foreach ($column in $table.LabeledColumns)
${column.FieldName}:this.form.${column.FieldName},
${column.FieldName}:this.form.${column.FieldName},
#end
id: this.form.id
}).then(response => {
this.$message({
message: this.$t('common.optionSuccess'),
type: 'success'
})
this.fetchData()
this.formVisible = false
})
}
if(formData.id){
${table.entityNameLowerFirstChar}Api.update(formData).then(response => {
this.$message({
message: this.$t('common.optionSuccess'),
type: 'success'
})
this.fetchData()
this.formVisible = false
})
}else{
${table.entityNameLowerFirstChar}Api.add(formData).then(response => {
this.$message({
message: this.$t('common.optionSuccess'),
type: 'success'
})
this.fetchData()
this.formVisible = false
})
}
} else {
return false
}
Expand Down Expand Up @@ -174,7 +188,7 @@ export default {
cancelButtonText: this.$t('button.cancel'),
type: 'warning'
}).then(() => {
remove(id).then(response => {
${table.entityNameLowerFirstChar}Api.remove(id).then(response => {
this.$message({
message: this.$t('common.optionSuccess'),
type: 'success'
Expand Down
10 changes: 5 additions & 5 deletions flash-generator/src/main/resources/code/view/index.vue.vm
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<br>
<el-row>
<el-col :span="24">
<el-button type="success" size="mini" icon="el-icon-plus" @click.native="add">{{ $t('button.add') }}</el-button>
<el-button type="primary" size="mini" icon="el-icon-edit" @click.native="edit">{{ $t('button.edit') }}</el-button>
<el-button type="danger" size="mini" icon="el-icon-delete" @click.native="remove">{{ $t('button.delete') }}</el-button>
<el-button type="success" size="mini" icon="el-icon-plus" @click.native="add" v-permission="['${table.UriPrefix}/add']">{{ $t('button.add') }}</el-button>
<el-button type="primary" size="mini" icon="el-icon-edit" @click.native="edit" v-permission="['${table.UriPrefix}/update']">{{ $t('button.edit') }}</el-button>
<el-button type="danger" size="mini" icon="el-icon-delete" @click.native="remove" v-permission="['${table.UriPrefix}/delete']">{{ $t('button.delete') }}</el-button>
</el-col>
</el-row>
</div>
Expand All @@ -32,8 +32,8 @@
#end
<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="text" size="mini" icon="el-icon-edit" @click.native="editItem(scope.row)">{{ $t('button.edit') }}</el-button>
<el-button type="text" size="mini" icon="el-icon-delete" @click.native="removeItem(scope.row)">{{ $t('button.delete') }}</el-button>
<el-button type="text" size="mini" icon="el-icon-edit" @click.native="editItem(scope.row)" v-permission="['${table.UriPrefix}/update']">{{ $t('button.edit') }}</el-button>
<el-button type="text" size="mini" icon="el-icon-delete" @click.native="removeItem(scope.row)" v-permission="['${table.UriPrefix}/delete']">{{ $t('button.delete') }}</el-button>
</template>
</el-table-column>
</el-table>
Expand Down
69 changes: 38 additions & 31 deletions flash-vue-admin/src/api/system/cfg.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
import request from '@/utils/request'

export function getList(params) {
return request({
url: '/cfg/list',
method: 'get',
params
})
}

export default {

export function exportXls(params) {
return request({
url: '/cfg/export',
method: 'get',
params
})
}
getList: function (params) {
return request({
url: '/cfg/list',
method: 'get',
params
})
},


export function save(params) {
return request({
url: '/cfg',
method: 'post',
params
})
}

export function remove(id) {
return request({
url: '/cfg',
method: 'delete',
params: {
id: id
}
})
exportXls: function (params) {
return request({
url: '/cfg/export',
method: 'get',
params
})
},
add: function (params) {
return request({
url: '/cfg',
method: 'post',
params
})
},
update: function (params) {
return request({
url: '/cfg',
method: 'put',
params
})
},
remove: function (id) {
return request({
url: '/cfg',
method: 'delete',
params: {
id: id
}
})
}
}
9 changes: 0 additions & 9 deletions flash-vue-admin/src/api/table.js

This file was deleted.

Loading

0 comments on commit 3fc42dd

Please sign in to comment.