diff --git a/flash-api/src/main/java/cn/enilu/flash/api/controller/system/CfgController.java b/flash-api/src/main/java/cn/enilu/flash/api/controller/system/CfgController.java index 89c26368..51ede2c7 100644 --- a/flash-api/src/main/java/cn/enilu/flash/api/controller/system/CfgController.java +++ b/flash-api/src/main/java/cn/enilu/flash/api/controller/system/CfgController.java @@ -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 page = new PageFactory().defaultPage(); if (StringUtil.isNotEmpty(cfgName)) { @@ -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) { diff --git a/flash-core/src/main/java/cn/enilu/flash/bean/entity/system/Menu.java b/flash-core/src/main/java/cn/enilu/flash/bean/entity/system/Menu.java index 0b8ad8c3..8870408b 100644 --- a/flash-core/src/main/java/cn/enilu/flash/bean/entity/system/Menu.java +++ b/flash-core/src/main/java/cn/enilu/flash/bean/entity/system/Menu.java @@ -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; diff --git a/flash-core/src/main/java/cn/enilu/flash/security/ApiRealm.java b/flash-core/src/main/java/cn/enilu/flash/security/ApiRealm.java index 11da3489..aee59515 100644 --- a/flash-core/src/main/java/cn/enilu/flash/security/ApiRealm.java +++ b/flash-core/src/main/java/cn/enilu/flash/security/ApiRealm.java @@ -50,7 +50,9 @@ protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(); simpleAuthorizationInfo.addRoles(user.getRoleCodes()); Set permission = user.getPermissions(); + //资源的权限标识采用menu中的code和url,建议统一以url为准 simpleAuthorizationInfo.addStringPermissions(permission); + simpleAuthorizationInfo.addStringPermissions(user.getUrls()); return simpleAuthorizationInfo; } diff --git a/flash-generator/src/main/resources/code/controller.vm b/flash-generator/src/main/resources/code/controller.vm index 3e525ce8..e549903a 100644 --- a/flash-generator/src/main/resources/code/controller.vm +++ b/flash-generator/src/main/resources/code/controller.vm @@ -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 { @@ -26,6 +30,7 @@ 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); @@ -33,17 +38,22 @@ public class ${table.ControllerClassName} extends BaseController { 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); diff --git a/flash-generator/src/main/resources/code/view/api.js.vm b/flash-generator/src/main/resources/code/view/api.js.vm index a2586576..f0943d1a 100644 --- a/flash-generator/src/main/resources/code/view/api.js.vm +++ b/flash-generator/src/main/resources/code/view/api.js.vm @@ -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 + } + }) + } } diff --git a/flash-generator/src/main/resources/code/view/index.js.vm b/flash-generator/src/main/resources/code/view/index.js.vm index 869b10aa..857cbd18 100644 --- a/flash-generator/src/main/resources/code/view/index.js.vm +++ b/flash-generator/src/main/resources/code/view/index.js.vm @@ -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, @@ -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 @@ -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 } @@ -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' diff --git a/flash-generator/src/main/resources/code/view/index.vue.vm b/flash-generator/src/main/resources/code/view/index.vue.vm index 72221c07..97e7765e 100644 --- a/flash-generator/src/main/resources/code/view/index.vue.vm +++ b/flash-generator/src/main/resources/code/view/index.vue.vm @@ -13,9 +13,9 @@
- {{ $t('button.add') }} - {{ $t('button.edit') }} - {{ $t('button.delete') }} + {{ $t('button.add') }} + {{ $t('button.edit') }} + {{ $t('button.delete') }} @@ -32,8 +32,8 @@ #end diff --git a/flash-vue-admin/src/api/system/cfg.js b/flash-vue-admin/src/api/system/cfg.js index 44a4309e..e40e5ebd 100644 --- a/flash-vue-admin/src/api/system/cfg.js +++ b/flash-vue-admin/src/api/system/cfg.js @@ -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 + } + }) + } } diff --git a/flash-vue-admin/src/api/table.js b/flash-vue-admin/src/api/table.js deleted file mode 100644 index e29c2943..00000000 --- a/flash-vue-admin/src/api/table.js +++ /dev/null @@ -1,9 +0,0 @@ -import request from '@/utils/request' - -export function getList(params) { - return request({ - url: '/table/list', - method: 'get', - params - }) -} diff --git a/flash-vue-admin/src/views/system/cfg/cfg.js b/flash-vue-admin/src/views/system/cfg/cfg.js index b01397b2..f47e4018 100644 --- a/flash-vue-admin/src/views/system/cfg/cfg.js +++ b/flash-vue-admin/src/views/system/cfg/cfg.js @@ -1,4 +1,4 @@ -import { remove, getList, save, exportXls } from '@/api/system/cfg' +import cfgApi from '@/api/system/cfg' import { getApiUrl } from '@/utils/utils' import permission from '@/directive/permission/index.js' @@ -60,7 +60,7 @@ export default { }, fetchData() { this.listLoading = true - getList(this.listQuery).then(response => { + cfgApi.getList(this.listQuery).then(response => { this.list = response.data.records this.listLoading = false this.total = response.data.total @@ -119,19 +119,32 @@ export default { save() { this.$refs['form'].validate((valid) => { if (valid) { - save({ + const formData = { id: this.form.id, cfgName: this.form.cfgName, cfgValue: this.form.cfgValue, cfgDesc: this.form.cfgDesc - }).then(response => { - this.$message({ - message: this.$t('common.optionSuccess'), - type: 'success' + } + if(this.form.id){ + cfgApi.update(formData).then(response => { + this.$message({ + message: this.$t('common.optionSuccess'), + type: 'success' + }) + this.fetchData() + this.formVisible = false }) - this.fetchData() - this.formVisible = false - }) + }else{ + cfgApi.add(formData).then(response => { + this.$message({ + message: this.$t('common.optionSuccess'), + type: 'success' + }) + this.fetchData() + this.formVisible = false + }) + } + } else { return false } @@ -171,7 +184,7 @@ export default { cancelButtonText: this.$t('button.cancel'), type: 'warning' }).then(() => { - remove(id).then(response => { + cfgApi.remove(id).then(response => { this.$message({ message: this.$t('common.optionSuccess'), type: 'success' diff --git a/flash-vue-admin/src/views/system/menu/index.vue b/flash-vue-admin/src/views/system/menu/index.vue index ea32c199..c370ff5f 100644 --- a/flash-vue-admin/src/views/system/menu/index.vue +++ b/flash-vue-admin/src/views/system/menu/index.vue @@ -70,7 +70,7 @@ - + diff --git a/flash-vue-admin/src/views/system/menu/menu.js b/flash-vue-admin/src/views/system/menu/menu.js index 00fb1a30..60d11484 100644 --- a/flash-vue-admin/src/views/system/menu/menu.js +++ b/flash-vue-admin/src/views/system/menu/menu.js @@ -39,7 +39,7 @@ export default { { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' } ], url: [ - { required: true, message: '请输入请求地址', trigger: 'blur' } + { required: true, message: '请输入资源地址', trigger: 'blur' } ], num: [ { required: true, message: '请输入排序', trigger: 'blur' }