前言:

项目使用人数不多,功能也不涉及到权限,开发vue-element-adminq权限比较花时间,屏蔽权限是最快的方法。网上其他的教程说的太复杂了,对于小白来说确实不好理解。

操作

只需要修改一个文件即可。
找到src/permission.js文件,替换成以下内容即可。

import router from './router'
import store from './store'
import { Message } from 'element-ui'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // get token from cookie
import getPageTitle from '@/utils/get-page-title'

NProgress.configure({ showSpinner: false }) // NProgress Configuration

const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist

router.beforeEach(async (to, from, next) => {
  // start progress bar
  NProgress.start()

  // set page title
  document.title = getPageTitle(to.meta.title)

  // determine whether the user has logged in
  // const hasToken = getToken()

  // if (hasToken) {
  //   if (to.path === '/login') {
  //     // if is logged in, redirect to the home page
  //     next({ path: '/' })
  //     NProgress.done()
  //   } else {
  //     // determine whether the user has obtained his permission roles through getInfo
  //     const hasRoles = store.getters.roles && store.getters.roles.length > 0
  //     if (hasRoles) {
  //       next()
  //     } else {
  //       try {
  //         // get user info
  //         // note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
  //         const { roles } = await store.dispatch('user/getInfo')

  //         // generate accessible routes map based on roles
  //         const accessRoutes = await store.dispatch('permission/generateRoutes', roles)

  //         // dynamically add accessible routes
  //         router.addRoutes(accessRoutes)

  //         // hack method to ensure that addRoutes is complete
  //         // set the replace: true, so the navigation will not leave a history record
  //         next({ ...to, replace: true })
  //       } catch (error) {
  //         // remove token and go to login page to re-login
  //         await store.dispatch('user/resetToken')
  //         Message.error(error || 'Has Error')
  //         next(`/login?redirect=${to.path}`)
  //         NProgress.done()
  //       }
  //     }
  //   }
  // } else {
  //   /* has no token*/

  //   if (whiteList.indexOf(to.path) !== -1) {
  //     // in the free login whitelist, go directly
  //     next()
  //   } else {
  //     // other pages that do not have permission to access are redirected to the login page.
  //     next(`/login?redirect=${to.path}`)
  //     NProgress.done()
  //   }
  // }
  const hasToken = 'admin-token'
  const role = 'admin'
  if (hasToken) {
    next()
    const accessRoutes = await store.dispatch('permission/generateRoutes', role)
    // dynamically add accessible routes
    router.addRoutes(accessRoutes)
  }
})

router.afterEach(() => {
  // finish progress bar
  NProgress.done()
})

屏蔽后右上角的退出小窗口也还在,跳过登录后,图标显示会有点问题,取消掉该窗口
在这里插入图片描述
在vue-element-admin\src\layout\components\Navbar.vue
屏蔽掉以下一段代码:

<!-- <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click"> -->
      <!-- <div class="avatar-wrapper">
          <img :src="avatar+'?imageView2/1/w/80/h/80'" class="user-avatar">
          <i class="el-icon-caret-bottom" />
        </div> -->
      <!-- <el-dropdown-menu slot="dropdown"> -->
      <!-- <router-link to="/profile/index">
            <el-dropdown-item>Profile</el-dropdown-item>
          </router-link> -->
      <!-- <router-link to="/">
            <el-dropdown-item>项目配置</el-dropdown-item>
          </router-link> -->
      <!-- <a target="_blank" href="https://github.com/PanJiaChen/vue-element-admin/">
            <el-dropdown-item>Github</el-dropdown-item>
          </a>
          <a target="_blank" href="https://panjiachen.github.io/vue-element-admin-site/#/">
            <el-dropdown-item>Docs</el-dropdown-item>
          </a> -->
      <!-- <el-dropdown-item divided @click.native="logout">
            <span style="display:block;">退出</span>
          </el-dropdown-item> -->
      <!-- </el-dropdown-menu> -->
      <!-- </el-dropdown> -->

取消后,完美的暂时屏蔽权限相关的功能。
在这里插入图片描述

Logo

前往低代码交流专区

更多推荐