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.

41 lines
965 B

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