permission.js 962 B

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