Browse Source

13

xiaowang
是小王呀\24601 8 months ago
parent
commit
4ba0cd18de
  1. 15
      src/router/index.js

15
src/router/index.js

@ -5,7 +5,7 @@ import { constantRouterMap } from './router.config.js'
import { checkWxmpRegister, login } from '@/api/user'
import { title } from '@/config'
const whiteList = ['/login', '/register', '/errorPage','/selectAgency','/houseQR','/event']
const whiteList = ['/login', '/register', '/errorPage','/selectAgency','/houseQR','/event','/scanQrCode']
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
@ -51,18 +51,15 @@ function paramsFormat(params) {
router.beforeEach((to, from, next) => {
let urlParams = getQueryParams()
console.log(urlParams,'路由参数');
if(urlParams.houseId){
console.log(urlParams,'初始路由参数');
store.commit('SET_HOUSE_ID', urlParams.houseId)
}else{
store.commit('SET_HOUSE_ID', null)
}
if(urlParams.unitId){
store.commit('SET_UNIT_ID', urlParams.unitId)
if(urlParams.type && !localStorage.getItem('token')&&to.path !=='/scanQrCode' ){
next('/scanQrCode')
}else{
store.commit('SET_UNIT_ID', null)
}
if (urlParams.appId) {
if (localStorage.getItem('appId') && urlParams.appId !== localStorage.getItem('appId')) {
localStorage.removeItem('token')
@ -73,7 +70,7 @@ router.beforeEach((to, from, next) => {
} else {
store.commit('SET_APP_ID', localStorage.getItem('appId'))
}
if (!localStorage.getItem('appId') && to.path !== '/errorPage'&& to.path != '/houseQR') {
if (!localStorage.getItem('appId') && to.path !== '/errorPage'&& to.path != '/houseQR' && to.path != '/scanQrCode') {
if(to.path === '/errorPage'){
next('/errorPage')
}else{
@ -101,7 +98,7 @@ router.beforeEach((to, from, next) => {
next({ path: '/login'})
})
} else {
if (getQueryStringByName('code') && to.path != '/houseQR') {
if (getQueryStringByName('code') && to.path != '/houseQR' && to.path != '/scanQrCode') {
login({ wxCode: getQueryStringByName('code'),appId:'wx1078fa1e99424de9'}).then(res => {
localStorage.setItem('token', res.data.token)
localStorage.setItem('userId', res.data.userH5DTO.id)
@ -136,6 +133,8 @@ router.beforeEach((to, from, next) => {
}
}
}
}
})
function getQueryParams() {

Loading…
Cancel
Save