|
@@ -1,8 +1,12 @@
|
|
|
import Vue from "vue"
|
|
|
import store from "@/store"
|
|
|
import VueRouter from "vue-router"
|
|
|
-import { query } from "@/utils/query"
|
|
|
-import { getPvUv } from "@/api/public.js"
|
|
|
+import {
|
|
|
+ query
|
|
|
+} from "@/utils/query"
|
|
|
+import {
|
|
|
+ getPvUv
|
|
|
+} from "@/api/public.js"
|
|
|
Vue.use(VueRouter)
|
|
|
const routes = [
|
|
|
// {
|
|
@@ -25,8 +29,7 @@ const routes = [
|
|
|
name: "home",
|
|
|
component: () => import("../views/index"),
|
|
|
redirect: "/home/homepage",
|
|
|
- children: [
|
|
|
- {
|
|
|
+ children: [{
|
|
|
path: "homepage",
|
|
|
name: "项目首页",
|
|
|
component: () => import("../views/homepage"),
|
|
@@ -85,15 +88,14 @@ const router = new VueRouter({
|
|
|
const ignore = ["/404"]
|
|
|
|
|
|
router.beforeEach(async (to, from, next) => {
|
|
|
- console.log('to',from.path,to.path)
|
|
|
+ console.log('to', from.path, to.path)
|
|
|
// 取出刷新时的 ssoToken, 路由拦截时app.vue 生命周期还没有执行,store中还没有数据,
|
|
|
let beforeunload = localStorage.getItem("beforeunload"),
|
|
|
__token = null
|
|
|
beforeunload && (__token = JSON.parse(beforeunload).ssoToken)
|
|
|
if (!ignore.includes(to.path)) {
|
|
|
//都是需要token检验的页面 首先优先获取路由上带的token
|
|
|
- // let token = null
|
|
|
- let token = to.query.token || store.getters["ssoToken"] || sessionStorage.getItem("SSOTOKEN")
|
|
|
+ let token = null
|
|
|
if (to.query.token) {
|
|
|
store.commit("SETSSOTOKEN", to.query.token) //存vuex
|
|
|
sessionStorage.setItem("SSOTOKEN", to.query.token)
|
|
@@ -129,7 +131,7 @@ router.beforeEach(async (to, from, next) => {
|
|
|
if (to.path == "/group" || to.path == "/home/homepage") {
|
|
|
if (store.state.accessLevel == -1) {
|
|
|
await store.dispatch("getUserInfo", router)
|
|
|
- console.log('getUserInfo',4)
|
|
|
+ console.log('getUserInfo', 4)
|
|
|
await store.dispatch("getBrand")
|
|
|
// await store.dispatch('getFact')
|
|
|
}
|
|
@@ -137,8 +139,17 @@ router.beforeEach(async (to, from, next) => {
|
|
|
console.log("token", token)
|
|
|
await store.dispatch("getFloors")
|
|
|
await store.dispatch("getBrand")
|
|
|
- // await store.dispatch('getFact')
|
|
|
- next()
|
|
|
+ // 如果在跳转获取token之前保存了指定的路径,则后去token后需要跳转到相关页面
|
|
|
+ // if (sessionStorage.getItem("TOURL")) {
|
|
|
+ // // 如果去的地址等于缓存的地址
|
|
|
+ // if (sessionStorage.getItem("TOURL") == to.path) {
|
|
|
+ // next()
|
|
|
+ // } else {
|
|
|
+ // next(sessionStorage.getItem("TOURL"))
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ next()
|
|
|
+ // }
|
|
|
} else {
|
|
|
let lastRoute = {
|
|
|
path: to.path,
|
|
@@ -152,7 +163,14 @@ router.beforeEach(async (to, from, next) => {
|
|
|
}
|
|
|
let systemcode = "CAD156",
|
|
|
signal = new Date().getTime(),
|
|
|
- version = "1.0.0"
|
|
|
+ version = "1.0.0";
|
|
|
+ // 获取token前需要保存跳转前路径
|
|
|
+ // if (!ignore.includes(to.path)) {
|
|
|
+ // sessionStorage.setItem("TOURL", to.path)
|
|
|
+ // } else {
|
|
|
+ // // 如果重定向前为404则跳入/
|
|
|
+ // sessionStorage.setItem("TOURL", '/')
|
|
|
+ // }
|
|
|
window.location.href = `${ssoServer}/login?systemcode=${systemcode}&signal=${signal}&version=${version}`
|
|
|
}
|
|
|
} else {
|
|
@@ -178,4 +196,4 @@ router.afterEach((to) => {
|
|
|
console.log("error", res)
|
|
|
})
|
|
|
})
|
|
|
-export default router
|
|
|
+export default router
|