| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import store from '@/store'
- import common from './common'
- // 标记的路由 未开放
- const notOpen = []
- // 公共跳转方法
- function jump(obj, params = {}, type = 'navigateTo') {
- store.state.params = params
- uni[type](obj)
- }
- // 路由拦截
- uni.addInterceptor('navigateTo', {
- invoke({ url }) {
- // 判断当前是否在登录页
- let pages = getCurrentPages()
- let route = pages[pages.length - 1] && pages[pages.length - 1].route
- // 如果当前页和跳转页是相同的,则拦截
- if ('/' + route === url) return false
- if (url.includes('/pages/') || url.includes('webview')) return true
- else if (url.includes('goodsDetail') || url.includes('about') || url.includes('editPass')) {
- return true
- } else if (!store.state.token) {
- // 没有 token
- common.toLogin()
- return false
- } else if (notOpen.includes(url)) {
- common.toast('暂未开放')
- return false
- }
- return true
- }
- })
- // 切换tab拦截
- uni.addInterceptor('switchTab', {
- invoke({ url }) {
- if (url.includes('/warehouse') && !store.state.token) {
- common.toLogin()
- return false
- }
- }
- })
- export default jump
|