permission.js 937 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { getToken } from '@/utils/auth'
  2. // 登录页面
  3. const loginPage = "/pages/login"
  4. // 页面白名单
  5. const whiteList = [
  6. '/pages/login', '/pages/common/webview/index',
  7. '/pages/business/mhxf/unitInfoCollection/index', '/pages/business/mhxf/unitInfoCollection/index',
  8. ]
  9. // 检查地址白名单
  10. function checkWhite(url) {
  11. const path = url.split('?')[0]
  12. return whiteList.indexOf(path) !== -1
  13. }
  14. // 页面跳转验证拦截器
  15. let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
  16. list.forEach(item => {
  17. uni.addInterceptor(item, {
  18. invoke(to) {
  19. console.log(to)
  20. if (getToken()) {
  21. if (to.url === 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. })