借鉴:https://zhuanlan.zhihu.com/p/622467762?utm_id=0
需求:根据不同的角色权限,最下级不显示首页,页面进来就显示第一个菜单的第一项,其他根据不同的权限展示不同的首页
效果图:
4.在src/layout/components/TagsView/index.vue。防止关闭所有tagview后页面空白一片。但是在peimission和login中添加了affix属性,不写也没有关系。
import { mapState } from 'vuex'
import { getDeptType } from '@/utils/auth'
computed:{
...mapState(['permission']),
indexPage() {
if (getDeptType() === '2') {
return this.$store.state.permission.indexPage
} else {
return '/'
}
},
},
methods:{
isAffix(tag) {
if (tag.fullPath === this.indexPage) {
return true
} else {
return tag.meta && tag.meta.affix
}
},
toLastView(visitedViews, view) {
const latestView = visitedViews.slice(-1)[0]
if (latestView) {
this.$router.push(latestView.fullPath)
} else {
// now the default is to redirect to the home page if there is no tags-view,
// you can adjust it according to your needs.
if (view.name === 'Dashboard') {
// to reload home page
this.$router.replace({ path: '/redirect' + view.fullPath })
} else {
this.$router.push(this.indexPage)
}
}
},
}
- 在src/plugns/tab.js。设置个人中心编辑,点击关闭后跳转的页面
import { getDeptType } from '@/utils/auth'
// 关闭指定tab页签
closePage(obj) {
let indexPage = store.state.permission.indexPage
if (obj === undefined) {
return store.dispatch('tagsView/delView', router.currentRoute).then(({ lastPath }) => {
if (getDeptType() === '2') {
return router.push(lastPath || indexPage)
} else {
return router.push(lastPath || '/')
}
})
}
return store.dispatch('tagsView/delView', obj)
},