SpringBoot整合SpringSecurity實現(xiàn)權(quán)限控制之實現(xiàn)多標簽頁
一、需求描述
多標簽頁 (Tabs) 的設計對于多窗口多任務管理有著無與倫比的高效率與方便性
在上面的文章中已經(jīng)實現(xiàn)了后臺管理的基本權(quán)限功能,包括用戶、角色、菜單管理及權(quán)限分配。
用戶通過單擊側(cè)邊欄的菜單,就可以調(diào)出對應的功能頁面進行使用。但在使用的過程中,我們發(fā)現(xiàn)程序只能在同一時間打開一個頁面。我們更希望打開多個功能頁面時,這些頁面以標簽的形式集成在同一個窗口顯示,要想切換到某個頁面或是關(guān)閉某個頁面,我們只需要操作相應的標簽即可,非常方便快捷。

二、前端實現(xiàn)
1.使用element tabs組件搭建基礎(chǔ)的多標簽頁,示例如下:
<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. 監(jiān)控路由變化情況,將路由信息與tabs panel列表進行關(guān)聯(lián)
watch: {
$route: {
handler(to, form = null) {
// 當路由改變時,檢測該路由是否已經(jīng)在打開的頁面之中,如果不在,就添加進去
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
到此這篇關(guān)于SpringBoot整合SpringSecurity實現(xiàn)權(quán)限控制之實現(xiàn)多標簽頁的文章就介紹到這了,更多相關(guān)SpringBoot整合SpringSecurity實現(xiàn)多標簽頁內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- SpringBoot整合SpringSecurityOauth2實現(xiàn)鑒權(quán)動態(tài)權(quán)限問題
- SpringBoot如何整合Springsecurity實現(xiàn)數(shù)據(jù)庫登錄及權(quán)限控制
- springboot整合springsecurity與mybatis-plus的簡單實現(xiàn)
- Springboot安全框架整合SpringSecurity實現(xiàn)方式
- SpringSecurity整合springBoot、redis實現(xiàn)登錄互踢功能
- SpringBoot與SpringSecurity整合方法附源碼
- SpringBoot2.0 整合 SpringSecurity 框架實現(xiàn)用戶權(quán)限安全管理方法
- 詳解SpringBoot+SpringSecurity+jwt整合及初體驗
- Springboot詳解整合SpringSecurity實現(xiàn)全過程
相關(guān)文章
基于Java反射的map自動裝配JavaBean工具類設計示例代碼
這篇文章主要給大家介紹了關(guān)于基于Java反射的map自動裝配JavaBean工具類設計的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用java具有一定的參考學習價值,需要的朋友們下面來一起看看吧2018-10-10
詳解spring applicationContext.xml 配置文件
本篇文章主要介紹了詳解spring applicationContext.xml 配置文件 ,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02
Java通過切面實現(xiàn)統(tǒng)一處理Token設置用戶信息
這篇文章主要介紹了Java切面統(tǒng)一處理Token設置用戶信息,常見的后端開發(fā)中,接口請求中一般前端都是先通過用戶登錄獲取token,每次接口請求都需要在頭信息中攜帶token信息,后端每次都需要手動處理token信息,從token信息中解析獲取用戶信息,需要的朋友可以參考下2023-10-10
解決Spring Security的權(quán)限配置不生效問題
這篇文章主要介紹了解決Spring Security的權(quán)限配置不生效問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03
spring boot整合mybatis利用Mysql實現(xiàn)主鍵UUID的方法
這篇文章主要給大家介紹了關(guān)于spring boot整合mybatis利用Mysql實現(xiàn)主鍵UUID的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。2018-03-03
Spring Bean Scope 有狀態(tài)的Bean與無狀態(tài)的Bean
這篇文章主要介紹了Spring Bean Scope 有狀態(tài)的Bean與無狀態(tài)的Bean,每個用戶有自己特有的一個實例,在用戶的生存期內(nèi),bean保持了用戶的信息,下面來了解有狀態(tài)和無狀態(tài)的區(qū)別吧2022-01-01

