permission.js 889 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {
  2. getAccessToken
  3. } from '@/utils/auth'
  4. // 登录页面
  5. const loginPage = "/pages/login"
  6. // 页面白名单
  7. const whiteList = [
  8. '/pages/login', '/pages/common/webview/index'
  9. ]
  10. // 检查地址白名单
  11. function checkWhite(url) {
  12. const path = url.split('?')[0]
  13. return whiteList.indexOf(path) !== -1
  14. }
  15. // 页面跳转验证拦截器
  16. // let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
  17. // list.forEach(item => {
  18. // uni.addInterceptor(item, {
  19. // invoke(to) {
  20. // if (getAccessToken()) {
  21. // if (to.path === loginPage) {
  22. // uni.reLaunch({ url: "/" })
  23. // }
  24. // return true
  25. // } else {
  26. // if (checkWhite(to.url)) {
  27. // return true
  28. // }
  29. // uni.reLaunch({ url: loginPage })
  30. // return false
  31. // }
  32. // },
  33. // fail(err) {
  34. // console.log(err)
  35. // }
  36. // })
  37. // })