Files
douhuo-h5/router/index.js
2023-07-11 14:47:30 +08:00

71 lines
1.5 KiB
JavaScript

/**
* 手太欠
* 愿这世界都如故事里一样 美好而动人~
*/
import { RouterMount, createRouter } from 'uni-simple-router';
import { authFollow } from '@/apis/interfaces/index'
import store from '../store/index'
import form from 'uview-ui/libs/config/props/form';
const router = createRouter({
h5: {
paramsToQuery: true
},
platform: process.env.VUE_APP_PLATFORM,
routes: [...ROUTES, {
path: '*',
name:'404',
component: ()=> import('@/pages/404/404')
}]
})
// 全局路由前置守卫
router.beforeEach((to, from, next) => {
const token = store.getters.getToken || uni.getStorageSync('token')
const openId = store.getters.getOpenId || uni.getStorageSync('openId')
if(to.name === 'appESign'){
next()
return
}
// 检查用户是否授权了微信
// if(to.name != 'webWechatIndex' && openId === ''){
// authFollow({
// // url: 'https://web.douhuotest.douhuofalv.com/webWechat/index'
// url: 'https://web.douhuofalv.com/webWechat/index'
// }).then(res => {
// window.location.href = res
// }).catch(err => {
// uni.showToast({
// title: err.message,
// icon: "none"
// })
// })
// return
// }
// 检查是否需要登录
if(to.auth && token === ''){
next({
name: 'Login',
NAVTYPE: 'push',
params: {
toName: to.name
}
})
return
}
next()
})
// 全局路由后置守卫
router.afterEach((to, from) => {
// console.log('跳转结束--暂无应用场景')
})
export {
router,
RouterMount
}