You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

permission.js 1.4 KiB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * 全站权限配置
  3. *
  4. */
  5. import router from './router/router'
  6. import store from '@/store'
  7. import { validatenull } from '@/util/validate'
  8. import NProgress from 'nprogress' // progress bar
  9. import 'nprogress/nprogress.css' // progress bar style
  10. NProgress.configure({ showSpinner: false })
  11. router.beforeEach((to, from, next) => {
  12. NProgress.start()
  13. const meta = to.meta || {}
  14. if (store.getters.access_token) {
  15. if (store.getters.isLock && to.path !== '/lock') {
  16. next({ path: '/lock' })
  17. } else if (to.path === '/login') {
  18. next({ path: '/' })
  19. } else {
  20. const value = to.query.src || to.fullPath
  21. const label = to.query.name || to.name
  22. // 针对外链跳转
  23. if (value.includes('http') || value.includes('https')) {
  24. window.open(value, '_blank')
  25. return
  26. }
  27. if (meta.isTab !== false && !validatenull(value) && !validatenull(label)) {
  28. store.commit('ADD_TAG', {
  29. label: label,
  30. value: value,
  31. params: to.params,
  32. query: to.query,
  33. group: router.$avueRouter.group || []
  34. })
  35. }
  36. next()
  37. }
  38. } else {
  39. if (meta.isAuth === false) {
  40. next()
  41. } else {
  42. next('/login')
  43. }
  44. }
  45. })
  46. router.afterEach(() => {
  47. NProgress.done()
  48. let title = store.getters.tag.label;
  49. if (!store.getters.access_token) title = undefined;
  50. router.$avueRouter.setTitle(title)
  51. })