若依(根据不同权限判断是否显示首页)(vue2)

借鉴: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)
        }
      }
    },
}
  1. 在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)
  },

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值