permission.js 991B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { getToken } from '@/utils/auth'
  2. //跳转页面
  3. const loginPage = "/pages/switchSystem"
  4. // 登录页面
  5. // const loginPage = "/pages/login"
  6. // 页面白名单
  7. const whiteList = [
  8. '/pages/switchSystem', '/pages/login', '/pages/register', '/pages/common/webview/index','/pages/realName','/mp_ecard_sdk/index/index', '/pages/personalInfoCollection'
  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 (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. })