SpringBoot整合SpringSecurity实现权限控制之实现多标签页
一、需求描述
多标签页 (Tabs) 的设计对于多窗口多任务管理有着无与伦比的高效率与方便性
在上面的文章中已经实现了后台管理的基本权限功能,包括用户、角色、菜单管理及权限分配。
用户通过单击侧边栏的菜单,就可以调出对应的功能页面进行使用。但在使用的过程中,我们发现程序只能在同一时间打开一个页面。我们更希望打开多个功能页面时,这些页面以标签的形式集成在同一个窗口显示,要想切换到某个页面或是关闭某个页面,我们只需要操作相应的标签即可,非常方便快捷。

二、前端实现
1.使用element tabs组件搭建基础的多标签页,示例如下:
<template>
<div class="tabbar-container">
<el-tabs v-model="pageCurrent" type="card" closable @tab-click="tabChange" @tab-remove="removeTab">
<el-tab-pane
v-for="(item) in pageList"
:key="item.name"
:name="item.name"
class="tabbar-item"
>
<span slot="label">
<span><i :class="item.icon" />{{ }} {{ item.label }}</span>
</span>
</el-tab-pane>
</el-tabs>
</div>
</template>

2. 监控路由变化情况,将路由信息与tabs panel列表进行关联
watch: {
$route: {
handler(to, form = null) {
// 当路由改变时,检测该路由是否已经在打开的页面之中,如果不在,就添加进去
if (to.meta) {
this.pageCurrent = to.path
var index = this.pageList.findIndex(value => {
return value.name === to.path
})
if (index < 0) {
this.pageList.push({ name: to.path, label: to.meta.title, icon: to.meta.icon })
}
}
},
immediate: true
}
},
增加移除tab页与切换tab页事件
methods: {
// 移除tab页
removeTab(targetName) {
if (targetName === '/dashboard') return
const tabs = this.pageList
let activeName = this.pageCurrent
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.name === targetName) {
const nextTab = tabs[index + 1] || tabs[index - 1]
if (nextTab) {
activeName = nextTab.name
}
}
})
}
this.pageCurrent = activeName
this.pageList = tabs.filter(tab => tab.name !== targetName)
this.$router.push({ path: activeName })
},
// 切换标签页
tabChange(tab, event) {
this.$router.push({ path: tab.name })
}
}
在布局主界面中加入多标签组件
<template>
<div :class="classObj" class="app-wrapper">
<div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
<sidebar class="sidebar-container" />
<div class="main-container">
<div :class="{'fixed-header':fixedHeader}">
<navbar />
<!-- 加入多标签组件 -->
<tabbar />
</div>
<app-main />
</div>
</div>
</template>
<script>
import { Navbar, Sidebar, AppMain, Tabbar } from './components'
...
</script>
三、效果演示

四、源码
前端
https://gitee.com/zhuhuix/startup-frontend
https://github.com/zhuhuix/startup-frontend
后端
https://gitee.com/zhuhuix/startup-backend
https://github.com/zhuhuix/startup-backend
到此这篇关于SpringBoot整合SpringSecurity实现权限控制之实现多标签页的文章就介绍到这了,更多相关SpringBoot整合SpringSecurity实现多标签页内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
- SpringBoot整合SpringSecurityOauth2实现鉴权动态权限问题
- SpringBoot如何整合Springsecurity实现数据库登录及权限控制
- springboot整合springsecurity与mybatis-plus的简单实现
- Springboot安全框架整合SpringSecurity实现方式
- SpringSecurity整合springBoot、redis实现登录互踢功能
- SpringBoot与SpringSecurity整合方法附源码
- SpringBoot2.0 整合 SpringSecurity 框架实现用户权限安全管理方法
- 详解SpringBoot+SpringSecurity+jwt整合及初体验
- Springboot详解整合SpringSecurity实现全过程
相关文章
基于Java反射的map自动装配JavaBean工具类设计示例代码
这篇文章主要给大家介绍了关于基于Java反射的map自动装配JavaBean工具类设计的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用java具有一定的参考学习价值,需要的朋友们下面来一起看看吧2018-10-10
详解spring applicationContext.xml 配置文件
本篇文章主要介绍了详解spring applicationContext.xml 配置文件 ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-02-02
spring boot整合mybatis利用Mysql实现主键UUID的方法
这篇文章主要给大家介绍了关于spring boot整合mybatis利用Mysql实现主键UUID的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。2018-03-03
Spring Bean Scope 有状态的Bean与无状态的Bean
这篇文章主要介绍了Spring Bean Scope 有状态的Bean与无状态的Bean,每个用户有自己特有的一个实例,在用户的生存期内,bean保持了用户的信息,下面来了解有状态和无状态的区别吧2022-01-01


最新评论