zhangtao
laozt 2 years ago
parent edf40adb18
commit 2879f64b93

@ -142,15 +142,19 @@ export default {
// ? "/demo/suzhouyingjiPC/" // ? "/demo/suzhouyingjiPC/"
// : "/"; // : "/";
let isGovernmentAffairsNetwork = localStorage.getItem('isGovernmentAffairsNetwork') let isGovernmentAffairsNetwork = localStorage.getItem(
if(process.env.NODE_ENV === "production") { "isGovernmentAffairsNetwork"
if(isGovernmentAffairsNetwork == '1') { );
location.href = process.env.VUE_APP_LOCATION + '/sso-server/oauth2/login?aid=17847210&cbu=http%3A%2F%2F180.108.205.123%3A13001%2F&response_type=code' if (process.env.NODE_ENV === "production") {
if (isGovernmentAffairsNetwork == "1") {
location.href =
process.env.VUE_APP_LOCATION +
"/sso-server/oauth2/sso?aid=17847210&cbu=http%3A%2F%2F180.108.205.123%3A13001%2F&response_type=code";
} else { } else {
location.href = "/login" location.href = "/login";
} }
} else { } else {
location.href = "/" location.href = "/";
} }
}); });
}) })

@ -115,17 +115,21 @@ export default {
// location.href = process.env.NODE_ENV === "production" // location.href = process.env.NODE_ENV === "production"
// ? "/demo/suzhouyingjiPC/" // ? "/demo/suzhouyingjiPC/"
// : "/"; // : "/";
let isGovernmentAffairsNetwork = localStorage.getItem('isGovernmentAffairsNetwork') let isGovernmentAffairsNetwork = localStorage.getItem(
if(process.env.NODE_ENV === "production") { "isGovernmentAffairsNetwork"
console.log('production') );
if(isGovernmentAffairsNetwork == '1') { if (process.env.NODE_ENV === "production") {
console.log('进入跳转政务网的登录页') console.log("production");
location.href = process.env.VUE_APP_LOCATION + '/sso-server/oauth2/login?aid=17847210&cbu=http%3A%2F%2F180.108.205.123%3A13001%2F&response_type=code' if (isGovernmentAffairsNetwork == "1") {
console.log("进入跳转政务网的登录页");
location.href =
process.env.VUE_APP_LOCATION +
"/sso-server/oauth2/sso?aid=17847210&cbu=http%3A%2F%2F180.108.205.123%3A13001%2F&response_type=code";
} else { } else {
location.href = "/login" location.href = "/login";
} }
} else { } else {
location.href = "/" location.href = "/";
} }
}); });
}) })

@ -1,92 +1,109 @@
import router from './router' import router from "./router";
import store from './store' import store from "./store";
import { Message } from 'element-ui' import { Message } from "element-ui";
import NProgress from 'nprogress' import NProgress from "nprogress";
import 'nprogress/nprogress.css' import "nprogress/nprogress.css";
import { getToken } from '@/utils/auth' import { getToken } from "@/utils/auth";
import { isRelogin } from '@/utils/request' import { isRelogin } from "@/utils/request";
import { getUseInfo } from '@/api/login.js' import { getUseInfo } from "@/api/login.js";
NProgress.configure({ showSpinner: false }) NProgress.configure({ showSpinner: false });
const whiteList = ['/login', '/register'] const whiteList = ["/login", "/register"];
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start() NProgress.start();
if (getToken()) { if (getToken()) {
to.meta.title && store.dispatch('settings/setTitle', to.meta.title) to.meta.title && store.dispatch("settings/setTitle", to.meta.title);
/* has token*/ /* has token*/
if (to.path === '/login') { if (to.path === "/login") {
next({ path: '/' }) next({ path: "/" });
NProgress.done() NProgress.done();
} else { } else {
// store.dispatch("Getdistrict"); // store.dispatch("Getdistrict");
if (store.getters.roles.length === 0) { if (store.getters.roles.length === 0) {
isRelogin.show = true isRelogin.show = true;
// 判断当前用户是否已拉取完user_info信息 // 判断当前用户是否已拉取完user_info信息
store.dispatch('GetInfo').then((res) => { store
isRelogin.show = false .dispatch("GetInfo")
store.dispatch('GenerateRoutes').then(accessRoutes => { .then((res) => {
// 根据roles权限生成可访问的路由表 isRelogin.show = false;
console.log(res); store.dispatch("GenerateRoutes").then((accessRoutes) => {
router.addRoutes(accessRoutes) // 动态添加可访问路由表 // 根据roles权限生成可访问的路由表
//刷新之后,要去的路由肯定是自己已经保存过的新路由 console.log(res);
let refresh = '' router.addRoutes(accessRoutes); // 动态添加可访问路由表
if (store.state.user.new1.indexOf(to.path) != -1) { //刷新之后,要去的路由肯定是自己已经保存过的新路由
refresh = to.path let refresh = "";
} if (store.state.user.new1.indexOf(to.path) != -1) {
console.log(to.path); refresh = to.path;
//进入添加的第一个路由 }
next({ path: refresh || res[0].path }) console.log(to.path);
//进入添加的第一个路由
next({ path: refresh || res[0].path });
});
}) })
}).catch(err => { .catch((err) => {
store.dispatch('LogOut').then(() => { store.dispatch("LogOut").then(() => {
Message.error(err) Message.error(err);
next({ path: '/' }) next({ path: "/" });
}) });
}) });
} else { } else {
if (store.state.user.old1.indexOf(to.path) != -1 && store.state.user.new1.indexOf(to.path) == -1) { if (
next({ path: '/404' }) store.state.user.old1.indexOf(to.path) != -1 &&
store.state.user.new1.indexOf(to.path) == -1
) {
next({ path: "/404" });
} else { } else {
next() next();
} }
} }
} }
} else { } else {
// 没有token // 没有token
if(window.location.href.includes('?code')){ if (window.location.href.includes("?code")) {
// console.log(window.location.href) // console.log(window.location.href)
var reg = new RegExp(/[?&]code=([^&#]+)/) var reg = new RegExp(/[?&]code=([^&#]+)/);
var r = window.location.href.match(reg) var r = window.location.href.match(reg);
// console.log('有code') // console.log('有code')
// const code = window.location.href.split("?")[1].split('=')[1]; // const code = window.location.href.split("?")[1].split('=')[1];
const code = r && r[1] const code = r && r[1];
// console.log(code) // console.log(code)
getUseInfo({code:code}).then(user=>{ getUseInfo({ code: code })
console.log(user,'用户信息') .then((user) => {
localStorage.setItem('isGovernmentAffairsNetwork','1') console.log(user, "用户信息");
store.dispatch('LoginNoCaptcha',{username:'admin',password:'admin@123Jichuang'}).then((res) => { localStorage.setItem("isGovernmentAffairsNetwork", "1");
next('/home') store
.dispatch("LoginNoCaptcha", {
username: "admin",
password: "admin@123Jichuang",
})
.then((res) => {
next("/home");
});
}) })
}).catch(err=>{ .catch((err) => {
location.href = process.env.VUE_APP_LOCATION + '/sso-server/oauth2/login?aid=17847210&cbu=http%3A%2F%2F180.108.205.123%3A13001%2F&response_type=code' location.href =
}) process.env.VUE_APP_LOCATION +
"/sso-server/oauth2/sso?aid=17847210&cbu=http%3A%2F%2F180.108.205.123%3A13001%2F&response_type=code";
});
} else { } else {
// console.log('没code') // console.log('没code')
// location.href = process.env.VUE_APP_LOCATION + '/sso-server/oauth2/login?aid=17847210&cbu=http%3A%2F%2F180.108.205.123%3A13001%2F' // location.href = process.env.VUE_APP_LOCATION + '/sso-server/oauth2/sso?aid=17847210&cbu=http%3A%2F%2F180.108.205.123%3A13001%2F'
if (whiteList.indexOf(to.path) !== -1) { if (whiteList.indexOf(to.path) !== -1) {
// 在免登录白名单,直接进入 // 在免登录白名单,直接进入
next() next();
NProgress.done() NProgress.done();
} else { } else {
location.href = process.env.VUE_APP_LOCATION + '/sso-server/oauth2/login?aid=17847210&cbu=http%3A%2F%2F180.108.205.123%3A13001%2F&response_type=code' location.href =
NProgress.done() process.env.VUE_APP_LOCATION +
"/sso-server/oauth2/sso?aid=17847210&cbu=http%3A%2F%2F180.108.205.123%3A13001%2F&response_type=code";
NProgress.done();
} }
} }
} }
}) });
router.afterEach(() => { router.afterEach(() => {
NProgress.done() NProgress.done();
}) });

Loading…
Cancel
Save