青島網(wǎng)站專(zhuān)業(yè)制作重慶關(guān)鍵詞排名首頁(yè)
登入的角色本身屬于領(lǐng)導(dǎo)級(jí)別(集團(tuán)權(quán)限),沒(méi)有下級(jí)的不同權(quán)限:
切換不同身份(公司),以獲得相應(yīng)部門(mén)的不同導(dǎo)航菜單及權(quán)限
這里實(shí)現(xiàn):更改角色權(quán)限后,實(shí)現(xiàn)頁(yè)面 不刷新 更改其展示出來(lái)的 導(dǎo)航菜單
1、在右上角頁(yè)面代碼內(nèi),通過(guò)后端接口獲取子角色(公司)的對(duì)應(yīng)菜單路由(圖2中data)
2、將路由數(shù)據(jù)和自身代碼寫(xiě)入方式一樣,寫(xiě)入store
存儲(chǔ)路由數(shù)據(jù)(參考自己代碼首次獲取路由后存儲(chǔ)數(shù)據(jù)的方法)
3、通過(guò)事件總線$eventBus
監(jiān)聽(tīng)頁(yè)面路由替換導(dǎo)航
4、清空、重新添加路由$router.addRoutes
導(dǎo)航組件里監(jiān)聽(tīng)并操作:
代碼片:
async toMenuChange(id) {//...省略前面非必要 此處調(diào)用自己的接口await getMenuListChange().then((mresult) => {// console.log('得到新路由列表:' , mresult);// 對(duì)數(shù)據(jù)進(jìn)行改造:const sdata = JSON.parse(JSON.stringify(mresult.data)); const rdata = JSON.parse(JSON.stringify(mresult.data));const sidebarRoutes = this.filterAsyncRouter(sdata);const rewriteRoutes = this.filterAsyncRouter(rdata, false, true);rewriteRoutes.push({ path: "*", redirect: "/404", hidden: true });store.commit("SET_ROUTES", rewriteRoutes);store.commit("SET_SIDEBAR_ROUTERS",constantRoutes.concat(sidebarRoutes));store.commit("SET_DEFAULT_ROUTES", sidebarRoutes);store.commit("SET_TOPBAR_ROUTES", sidebarRoutes);// 在事件總線中發(fā)布事件 this.$bus.$emit('xxx','傳遞參數(shù)')this.$eventBus.$emit("changeTopBar");// 重置導(dǎo)航resetRouter();this.$router.addRoutes(sidebarRoutes);});
}
this.$eventBus.$on("changeTopBar", () => {// ...
});this.$eventBus.$off(["changeTopBar"]);