| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- // router.js
- import { RouterMount, createRouter, runtimeQuit } from '@/js_sdk/hhyang-uni-simple-router/uni-simple-router';
- import tools from "@/service/tools";
- const router = createRouter({
- platform: process.env.VUE_APP_PLATFORM,
- routerErrorEach:({type,level,...args})=>{
- // console.log({type,level,...args})
- // #ifdef APP-PLUS
- if(type===3){
- router.$lockStatus=false;
- tools.onBackPress()
- }
- // #endif
- },
- routes: [...ROUTES]
- });
- //全局路由前置守卫
- const whiteList = ['/pages/login/index']
- router.beforeEach((to, from, next) => {
- next();
-
- // let userToken = uni.getStorageSync('token')
- // if(userToken){
- // next();
- // }else{
- // let isWeiXin = tools.isWx();
- // if(isWeiXin && to.path!=='/pages/login/index'){
- // let wx_key = uni.getStorageSync('wx_key')
- // if(wx_key && to.path==='/pages/login/register'){
- // next()
- // }else{
- // const href = window.location.href;
- // if (href.indexOf('?code=') > -1 || href.indexOf('&code=') > -1){
- // const urlArr = href.split('?')
- // const rightUrlArr = urlArr[1].split('#/')
- // const queryObj = {}
- // rightUrlArr[0].split('&').map((item) => {
- // const splitStr = item.split('=')
- // return {
- // key: splitStr[0],
- // value: splitStr[1],
- // }
- // }).forEach((item) => {
- // queryObj[item.key] = item.value
- // })
- // if(urlArr.length>=3){
- // rightUrlArr[1]= "?"+urlArr[2]
- // }
- // let from = {
- // code: queryObj.code,
- // wx_type:1,
- // invite_code:uni.getStorageSync("invite_code"),
- // memberCode:uni.getStorageSync("memberCode"),
- // }
- // // await userWxAppletLogin(from).then((res)=>{
- // // if (res.code === 1) {
- // // if(res.data.wx_key){
- // // uni.setStorageSync('wx_key',res.data.wx_key)
- // // next('/pages/login/register')
- // // }else{
- // // uni.setStorageSync('token',res.data.token)
- // // uni.setStorageSync('m_id',res.data.m_id)
- // // next(to.path)
- // // }
- // // } else {
- // // tools.error(res.msg);
- // // }
- // // })
- // }else{
- // uni.removeStorageSync('token')
- // uni.removeStorageSync('m_id')
- // tools.wxLogin();
- // }
- // }
- // }else if(whiteList.indexOf(to.path)>-1){
- // next()
- // }else {
- // next('/pages/login/index')
- // }
- // }
- });
- // 全局路由后置守卫
- router.afterEach((to, from) => {
- // console.log('后置守卫to------', to)
- })
- export {
- router,
- RouterMount
- }
|