Commit 0e8d4466 by 展昭

update

parent da373d1e
No preview for this file type
...@@ -23,15 +23,15 @@ const router = new VueRouter({ ...@@ -23,15 +23,15 @@ const router = new VueRouter({
component: () => import("@/views/test.vue") component: () => import("@/views/test.vue")
} }
], ],
scrollBehavior (to, from, savedPosition) { scrollBehavior(to, from, savedPosition) {
return { x: 0, y: 0 } return { x: 0, y: 0 }
} }
}) })
//自动登录 //自动登录
function autoLogin(payload = {autoCode, redirectPath}){ function autoLogin(payload = { autoCode, redirectPath }) {
store.dispatch("authenticateOidc",{ store.dispatch("authenticateOidc", {
options:{ options: {
extraQueryParams:{ extraQueryParams: {
authcode: payload.autoCode authcode: payload.autoCode
}, },
redirectPath: payload.redirectPath redirectPath: payload.redirectPath
...@@ -41,12 +41,12 @@ function autoLogin(payload = {autoCode, redirectPath}){ ...@@ -41,12 +41,12 @@ function autoLogin(payload = {autoCode, redirectPath}){
const loginStorage = localStorage; const loginStorage = localStorage;
const autoLoginParamsKey = "autoLoginParams"; const autoLoginParamsKey = "autoLoginParams";
function setAutoLogin(payload = {autoCode, redirectPath}){ function setAutoLogin(payload = { autoCode, redirectPath }) {
loginStorage.setItem(autoLoginParamsKey,JSON.stringify(payload)) loginStorage.setItem(autoLoginParamsKey, JSON.stringify(payload))
} }
function getAutoLoginParams(){ function getAutoLoginParams() {
const paramStr = loginStorage.getItem(autoLoginParamsKey); const paramStr = loginStorage.getItem(autoLoginParamsKey);
if(!!paramStr){ if (!!paramStr) {
loginStorage.removeItem(autoLoginParamsKey); loginStorage.removeItem(autoLoginParamsKey);
return JSON.parse(paramStr); return JSON.parse(paramStr);
} }
...@@ -54,50 +54,47 @@ function getAutoLoginParams(){ ...@@ -54,50 +54,47 @@ function getAutoLoginParams(){
} }
//如果有登录参数则优先登录 //如果有登录参数则优先登录
router.beforeEach((to,from,next)=>{ router.beforeEach((to, from, next) => {
const autoLoginParams = getAutoLoginParams(); const autoLoginParams = getAutoLoginParams();
if(autoLoginParams){ if (autoLoginParams) {
autoLogin(autoLoginParams); autoLogin(autoLoginParams);
}else{ } else {
next(); next();
} }
}) })
router.beforeEach((to,from, next)=>{ router.beforeEach((to, from, next) => {
const authcode= to.query.authcode; const authcode = to.query.authCode;
if(!!authcode){ if (!!authcode) {
var toPath = to.path||"/"; var toPath = to.path || "/";
for(let key in to.query){ for (let key in to.query) {
if(key=='authcode'){ if (key == 'authcode') {
continue; continue;
} }
toPath+= toPath.indexOf("?")>-1?"&":"?"; toPath += toPath.indexOf("?") > -1 ? "&" : "?";
toPath+=`${key}=${to.query}`; toPath += `${key}=${to.query}`;
} }
const userId = to.query.userid || to.query.userId;
const isAuth = store.getters.oidcIsAuthenticated; const isAuth = store.getters.oidcIsAuthenticated;
console.log(isAuth)
// if(isAuth){
store.dispatch("getOidcUser").then(oidcUser=>{ store.dispatch("getOidcUser").then(oidcUser => {
console.log('oidcUser=', oidcUser);
if(oidcUser){ if (oidcUser) {
//如果登录用户与当前登录用户不匹配,则保存登录参数,退出 //如果登录用户与当前登录用户不匹配,则保存登录参数,退出
if(oidcUser.profile.sub!= userId){ if (oidcUser.profile.sub != userId) {
setAutoLogin({autoCode: authcode, redirectPath: toPath}) setAutoLogin({ autoCode: authcode, redirectPath: toPath })
store.dispatch("signOutOidc") store.dispatch("signOutOidc")
}else{ } else {
next() next()
} }
}else{ } else {
autoLogin({autoCode: authcode,redirectPath: toPath}) autoLogin({ autoCode: authcode, redirectPath: toPath })
} }
}).catch(()=>{ }).catch(() => {
autoLogin({autoCode: authcode,redirectPath: toPath}) autoLogin({ autoCode: authcode, redirectPath: toPath })
}); });
}else{ } else {
next() next()
} }
......
...@@ -64,17 +64,17 @@ export default { ...@@ -64,17 +64,17 @@ export default {
this.oidcSignInCallback() this.oidcSignInCallback()
.then(redirectPath => { .then(redirectPath => {
console.log(2,redirectPath); console.log(2,redirectPath);
this.getOidcUser() // this.getOidcUser()
.then(user => { // .then(user => {
let urlsearch = redirectPath.split("?")[1]; // let urlsearch = redirectPath.split("?")[1];
let appid = this.getQueryString(urlsearch, "appid"); // let appid = this.getQueryString(urlsearch, "appid");
this.getToken(user.access_token, appid, redirectPath); // this.getToken(user.access_token, appid, redirectPath);
}) // })
.catch(err => { // .catch(err => {
console.log("err=", err); // console.log("err=", err);
}); // });
//this.$router.push(redirectPath); this.$router.push(redirectPath);
}) })
.catch(err => { .catch(err => {
console.error(err); console.error(err);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment