文章回顾:

  • Spring Security(一):整合JWT实现登录功能
  • Spring Security(二):获取用户权限菜单树
  • Spring Security(三):与Vue.js整合
  • Spring Security(四):更新前端路由获取方式
  • Spring Security(五):前后端权限控制详解
  • Spring Security(六):前端菜单,角色权限页面的搭建

目前项目中做了几个有关权限控制的页面,主要做了三个,角色管理,资源管理,角色权限的页面。

角色管理

该页面主要是对角色的crud,这个比较简单就不多讲了。

资源管理

这个页面其实是对菜单的配置,也就是路由的设置,我采用了组件复用的思路,就是增加和更新页面用的是同一个组件,启用前判断是增加还是更新就好了。

如果是新增的话有一个会初始化

更新的话就会得到信息,显示出来

Vue代码

  1. 新建srcviewsprepermedit.vue文件,这个其实编辑按钮引用的组件,通过这里可以设置我们要进行的操作的是编辑,然后通过scope获取到数据
        <template><div><el-button size="mini" type="success" @click="to">编辑</el-button><eForm ref="form" :menus="menus" :sup_this="sup_this" :is-add="false"/></div></template><script>import eForm from './form'export default {components: { eForm },props: {data: {type: Object,required: true},sup_this: {type: Object,required: true},menus: {type: Array,required: true}},methods: {to() {const _this = this.$refs.form_this.roleIds = []_this.form = { per_id: this.data.per_id, per_component: this.data.per_component, per_name: this.data.per_name, per_sort: this.data.per_sort,per_parent_id: this.data.per_parent_id, per_resource: this.data.per_resource, per_icon: this.data.per_icon, per_describe: this.data.per_describe }_this.dialog = true}}}</script><style scoped>div{display: inline-block;margin-right: 3px;}</style>

2.新建一个srcviewsprepermform.vue文件
这个就是我们要复用的组件了

    <template><el-dialog :append-to-body="true" :visible.sync="dialog" :title="isAdd ? '新增菜单' : '编辑菜单'" width="600px"><el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px"><el-form-item label="菜单图标"><el-popoverplacement="bottom-start"width="460"trigger="click"@show="$refs['iconSelect'].reset()"><el-input slot="reference" v-model="form.icon" style="width: 460px;" placeholder="点击选择图标" readonly><svg-icon v-if="form.icon" slot="prefix" :icon-class="form.icon" class="el-input__icon" style="height: 32px;width: 16px;" /><i v-else slot="prefix" class="el-icon-search el-input__icon"/></el-input></el-popover></el-form-item><el-form-item label="菜单名称" prop="per_name"><el-input v-model="form.per_name" placeholder="名称" style="width: 460px;"/></el-form-item><el-form-item label="菜单排序" prop="per_sort"><el-input v-model.number="form.per_sort" placeholder="序号越小越靠前" style="width: 460px;"/></el-form-item><el-form-item label="URL地址"><el-input v-model="form.per_resource" placeholder="组件路径" style="width: 460px;"/></el-form-item><el-form-item label="组件路径"><el-input v-model="form.per_component" placeholder="组件路径" style="width: 460px;"/></el-form-item><el-form-item label="上级菜单"><treeselect v-model="form.per_parent_id" :options="menus" style="width: 460px;" placeholder="选择上级类目" /></el-form-item><el-form-item label="菜单描述" prop="per_describe"><el-input v-model.number="form.per_describe" placeholder="请填写菜单描述" style="width: 460px;"/></el-form-item></el-form><div slot="footer" class="dialog-footer"><el-button type="text" @click="cancel">取消</el-button><el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button></div></el-dialog></template><script>// import the componentimport Treeselect from '@riophae/vue-treeselect'// import the stylesimport '@riophae/vue-treeselect/dist/vue-treeselect.css'import { add, edit } from '@/api/menu'export default {components: { Treeselect },props: {menus: {type: Array,required: true},isAdd: {type: Boolean,required: true},sup_this: {type: Object,default: null}},data() {return {loading: false, dialog: false,form: { per_id: null, per_name: '', per_sort: 999, per_resource: '', per_component: '', per_parent_id: 0, per_icon: '', per_describe: '' },roleIds: [],rules: {per_name: [{ required: true, message: '请输入名称', trigger: 'blur' }],per_sort: [{ required: true, message: '请输入序号', trigger: 'blur', type: 'number' }]}}},methods: {cancel() {this.resetForm()},doSubmit() {this.$refs['form'].validate((valid) => {if (valid) {this.loading = truethis.form.roles = []const _this = thisthis.roleIds.forEach(function(data, index) {const role = { id: data }_this.form.roles.push(role)})if (this.isAdd) {this.doAdd()} else this.doEdit()} else {return false}})},doAdd() {add(this.form).then(res => {this.resetForm()this.$notify({title: '添加成功',type: 'success',duration: 2500})this.loading = falsethis.$parent.$parent.init()this.$parent.$parent.getMenus()}).catch(error => {this.loading = falsethis.$message({showClose: true,message: error,type: 'error'})})},doEdit() {edit(this.form).then(res => {this.resetForm()this.$notify({title: '修改成功',type: 'success',duration: 2500})this.loading = falsethis.sup_this.init()this.sup_this.getMenus()}).catch(err => {this.loading = falseconsole.log(err.msg)})},resetForm() {this.dialog = falsethis.$refs['form'].resetFields()this.form = { name: '', sort: 999, path: '', component: '', iframe: 'false', pid: 0, icon: '' }this.roleIds = []},selected(name) {this.form.icon = name}}}</script><style scoped></style>

做了这个通用的组件就不用在代码中同时引用两个组件了。

角色权限

我的这个项目前端对权限的控制对象主要是页面的路由,可以动态的去设置角色可以显示哪些菜单。使用了el-tree这个组件…不会css…页面很丑莫见怪…
系统管理员的页面

测试用户,当然正常情况下用户是不应该可以看到这些关于全县的页面的,我这里只是拿来测试。

可以看到测试用户那边的路由页面根据我们的配置就显示出来了

动态配置的思路

角色权限这个页面中的树形组件其实是对我们数据库中的RolePermission组件进行增删改查,大致过程是:

  • 通过角色id获得用户的路由集合,然后通过el-tree组件去渲染是否被选中
  • 更新的思路是首先删除RolePermission表中这个角色id所有的数据,然后根据我们前端拿到的id集合去批量增加。

小问题

由于el-tree组件拿到我们后台给的父节点的id,会直接把子节点全部选中,但是这个明显不符合我们的要求,目前的解决办法是把父子节点的关联移除,这样有个问题是我们自己去配置的时候选中父节点,子节点要一个一个去选择…我还在想解决办法…

欢迎关注我的个人微信公众号哦~

easyui dialog 不执行页面js_Spring Security(六):前端菜单,角色权限页面的搭建相关推荐

  1. easyui dialog 中嵌入html页面

    最近使用easyui比较多,这个插件确实很好用.在使用时也遇到了大大小小的问题,好在都一一解决了. 记录一下今天遇到的问题. 目的:用easyui的dialog嵌入一个html页面(html中仍有要执 ...

  2. 【Spring Security】入门——使用Themeleaf渲染页面

    一.项目框架 1. 项目结构 2. 选择依赖 二.数据库 三.代码实现 实现思路 1. 配置文件 2. 编写测试页面 index.html login.html register.html 3. 配置 ...

  3. easyui dialog 中打开地图

    首先:使用href属性,加载html页面,页面中地图打开失败. 经过测试,如果easyui dialog的地址属性用href超链接,easyui 不会加载整个url页面,只会截取url目标页的body ...

  4. 第二十四章:页面导航(六)

    制作导航菜单 如果您的应用程序包含各种不同但在架构上相同的页面,所有这些页面都可以从主页导航,那么您可能有兴趣构建有时称为导航菜单的页面. 这是一个菜单,其中每个条目都是特定的页面类型. ViewGa ...

  5. 第二十四章:页面导航(六) 1

    制作导航菜单 如果您的应用程序包含各种不同但在架构上相同的页面,所有这些页面都可以从主页导航,那么您可能有兴趣构建有时称为导航菜单的页面. 这是一个菜单,其中每个条目都是特定的页面类型. ViewGa ...

  6. springboot系列六、springboot配置错误页面及全局异常

    springboot系列六.springboot配置错误页面及全局异常 参考文章: (1)springboot系列六.springboot配置错误页面及全局异常 (2)https://www.cnbl ...

  7. 前端直接访问登录页面报错_如何实现登录、URL和页面按钮的访问控制

    作者:社会主义接班人 http://cnblogs.com/5ishare/p/10461073.html 用户权限管理一般是对用户页面.按钮的访问权限管理.Shiro框架是一个强大且易用的Java安 ...

  8. Vue 实例实战之 Vue webpack 仿去哪儿网App页面开发(应用中的几个页面简单实现)

    Vue 实例实战之 Vue webpack 仿去哪儿网App页面开发(应用中的几个页面简单实现) 目录 Vue 实例实战之 Vue webpack 仿去哪儿网App页面开发(应用中的几个页面简单实现) ...

  9. 【Microsoft Azure 的1024种玩法】六十.通过Azure Virtual Machines快速搭建个人Ghost博客系统

    [简介] Ghost 是一套基于Node.js 语言开发构建的开源博客系统,它的整体架构为前端管理系统基于Ember.js, 后端的模板引擎采用的handlebars, 数据库是基于MySQL的,本篇 ...

最新文章

  1. mysql 优化_常用MySQL优化
  2. 14条Yahoo(雅虎)十四条优化原则【转】
  3. JSP和Servlet里的Cookie处理
  4. SAP Fiori Launchpad tile跳转目标的解析逻辑
  5. Mysql 取用逗号分隔的字串的子串的方法:SUBSTRING_INDEX
  6. C++ 中的 #pragma warning(push) 和 #pragma warning(pop)有什么用
  7. 螺旋天线matlab仿真,用AMDS进行螺旋天线仿真
  8. CCF NOI1004 填充矩形
  9. sql函数REPLACE用法,根据指定字符串替换成想要的字符串
  10. easyscreen调用html,840D——EasyScreen输入密码跳转界面的编写-工业支持中心-西门子中国...
  11. MySQL的sql大于号(小于号)的使用
  12. bad assignment报错
  13. BGP----工作工程,路由黑洞,防环机制,基本配置
  14. Mac下文件Non-ISO extended-ASCII编码问题
  15. 方根法公式_初中数学根式运算法则公式
  16. vscode写R语言代码
  17. LuaForWindows(SciTE) 5.1 常见问题
  18. 【网络安全】文件上传漏洞及中国蚁剑安装
  19. n行Python代码系列:三行程序实现从视频截取子窗内容输出
  20. 【Proteus】Proteus里的蜂鸣器的使用

热门文章

  1. docker项目部署 php_docker部署php的web项目
  2. ActiveXObject文件读写
  3. 打印机如何共享多台电脑_多台电脑打印机共享的方法
  4. [Unity脚本运行时更新]C#7.2新特性
  5. 鸿蒙应用runtime,鸿蒙OS初探
  6. vsftp pam mysql_实验记录:vsftp整合mysql-pam管理虚拟账号
  7. Leecode刷题热题HOT100(12)——整数转罗马数字
  8. OpenShift 4 - 查看关键证书到期日期
  9. Hands-on Lab (15) - 使用Prometheus Operator监控应用
  10. 在TypeScript中使用React钩子