jump.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import store from '@/store'
  2. import common from './common'
  3. // 标记的路由 未开放
  4. const notOpen = []
  5. // 公共跳转方法
  6. function jump(obj, params = {}, type = 'navigateTo') {
  7. store.state.params = params
  8. uni[type](obj)
  9. }
  10. // 路由拦截
  11. uni.addInterceptor('navigateTo', {
  12. invoke({ url }) {
  13. // 判断当前是否在登录页
  14. let pages = getCurrentPages()
  15. let route = pages[pages.length - 1] && pages[pages.length - 1].route
  16. // 如果当前页和跳转页是相同的,则拦截
  17. if ('/' + route === url) return false
  18. if (url.includes('/pages/') || url.includes('webview')) return true
  19. else if (url.includes('goodsDetail') || url.includes('about') || url.includes('editPass')) {
  20. return true
  21. } else if (!store.state.token) {
  22. // 没有 token
  23. common.toLogin()
  24. return false
  25. } else if (notOpen.includes(url)) {
  26. common.toast('暂未开放')
  27. return false
  28. }
  29. return true
  30. }
  31. })
  32. // 切换tab拦截
  33. uni.addInterceptor('switchTab', {
  34. invoke({ url }) {
  35. if (url.includes('/warehouse') && !store.state.token) {
  36. common.toLogin()
  37. return false
  38. }
  39. }
  40. })
  41. export default jump