/* * @Author: 小明丶 * @Date: 2019-08-19 15:23:17 * @LastEditors: 小明丶 * @LastEditTime: 2021-01-08 10:00:52 * @Description: */ import Vue from "vue"; import VueRouter from 'vue-router'; import routes from './routes'; import Store from '@/store'; Vue.use(VueRouter); let router = new VueRouter({ mode:"hash", //history routes, scrollBehavior (to, from, savedPosition) { return { x:0, y:0 } }, }) // 全局前置守卫:页面跳转前拦截 router.beforeEach((to, from, next) => { // 解决叮咚助学自动登录主题色设置问题 window.sessionStorage.setItem("gotoPagetemp", to.path); // if(to.name == 'login-by-wx'){ // localStorage.user_pwd = 'undefined' // } if(to.meta && typeof to.meta.isLogin !=='undefined' ){ //判断地址是否带有token参数有就截取存储 if(location.href.split('?')[1]){ if(location.href.split('?')[1].split('token=')[1]){ console.log('qqq:',location.href.split('?')[1]) let str = location.href.split('?')[1].split('token=')[1] localStorage.hjToken = str } if(location.href.split('?')[1].split('appToken=')[1]){ let str = location.href.split('?')[1].split('appToken=')[1] if(str.indexOf('&') != -1){ var backUrl = str.split('&')[1].split('backUrl=')[1] var appToken = str.split('&')[0] }else{ var appToken = str } } } let user_pwd = localStorage.user_pwd; let hjToken = localStorage.hjToken; // let appToken = sessionStorage.appToken; // 红茄登录 if(typeof hjToken !='undefined' && hjToken){ Store.dispatch('loginByToken',{ vm:Vue.prototype, hjToken, next }) return } // app跳转登录 if(typeof appToken !='undefined' && appToken){ document.title = '' Store.dispatch('loginByAppToken',{ vm:Vue.prototype, appToken, backUrl, next }) return } // 自动登录 if(typeof user_pwd !=='undefined'){ let userNo = localStorage.user_account, password = user_pwd; Store.dispatch('login',{ vm:Vue.prototype, userNo, password, sib_mer_sysPlat: localStorage.sib_mer_sysPlat, next }) return } if(typeof hjToken =='undefined' && !hjToken){ next() } }else{ // 需要登录的页面 if(Store.state.sessionId || to.name == 'login-by-wx' || to.name == 'supplement'){ next() }else{ // if(sessionStorage.isLoginByOpenId == 1){ // next() // }else{ next('/') // } } } }) //全局后置守卫:页面跳转后执行 router.afterEach((to, from) => { }) export default router;