Commit 0e8d4466 by 展昭

update

parent da373d1e
No preview for this file type
......@@ -23,15 +23,15 @@ const router = new VueRouter({
component: () => import("@/views/test.vue")
}
],
scrollBehavior (to, from, savedPosition) {
scrollBehavior(to, from, savedPosition) {
return { x: 0, y: 0 }
}
})
//自动登录
function autoLogin(payload = {autoCode, redirectPath}){
store.dispatch("authenticateOidc",{
options:{
extraQueryParams:{
function autoLogin(payload = { autoCode, redirectPath }) {
store.dispatch("authenticateOidc", {
options: {
extraQueryParams: {
authcode: payload.autoCode
},
redirectPath: payload.redirectPath
......@@ -41,12 +41,12 @@ function autoLogin(payload = {autoCode, redirectPath}){
const loginStorage = localStorage;
const autoLoginParamsKey = "autoLoginParams";
function setAutoLogin(payload = {autoCode, redirectPath}){
loginStorage.setItem(autoLoginParamsKey,JSON.stringify(payload))
function setAutoLogin(payload = { autoCode, redirectPath }) {
loginStorage.setItem(autoLoginParamsKey, JSON.stringify(payload))
}
function getAutoLoginParams(){
function getAutoLoginParams() {
const paramStr = loginStorage.getItem(autoLoginParamsKey);
if(!!paramStr){
if (!!paramStr) {
loginStorage.removeItem(autoLoginParamsKey);
return JSON.parse(paramStr);
}
......@@ -54,50 +54,47 @@ function getAutoLoginParams(){
}
//如果有登录参数则优先登录
router.beforeEach((to,from,next)=>{
router.beforeEach((to, from, next) => {
const autoLoginParams = getAutoLoginParams();
if(autoLoginParams){
if (autoLoginParams) {
autoLogin(autoLoginParams);
}else{
} else {
next();
}
})
router.beforeEach((to,from, next)=>{
const authcode= to.query.authcode;
if(!!authcode){
var toPath = to.path||"/";
for(let key in to.query){
if(key=='authcode'){
router.beforeEach((to, from, next) => {
const authcode = to.query.authCode;
if (!!authcode) {
var toPath = to.path || "/";
for (let key in to.query) {
if (key == 'authcode') {
continue;
}
toPath+= toPath.indexOf("?")>-1?"&":"?";
toPath+=`${key}=${to.query}`;
toPath += toPath.indexOf("?") > -1 ? "&" : "?";
toPath += `${key}=${to.query}`;
}
const userId = to.query.userid || to.query.userId;
const isAuth = store.getters.oidcIsAuthenticated;
console.log(isAuth)
// if(isAuth){
store.dispatch("getOidcUser").then(oidcUser=>{
if(oidcUser){
store.dispatch("getOidcUser").then(oidcUser => {
console.log('oidcUser=', 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")
}else{
} else {
next()
}
}else{
autoLogin({autoCode: authcode,redirectPath: toPath})
} else {
autoLogin({ autoCode: authcode, redirectPath: toPath })
}
}).catch(()=>{
autoLogin({autoCode: authcode,redirectPath: toPath})
}).catch(() => {
autoLogin({ autoCode: authcode, redirectPath: toPath })
});
}else{
} else {
next()
}
......
......@@ -64,17 +64,17 @@ export default {
this.oidcSignInCallback()
.then(redirectPath => {
console.log(2,redirectPath);
this.getOidcUser()
.then(user => {
// this.getOidcUser()
// .then(user => {
let urlsearch = redirectPath.split("?")[1];
let appid = this.getQueryString(urlsearch, "appid");
this.getToken(user.access_token, appid, redirectPath);
})
.catch(err => {
console.log("err=", err);
});
//this.$router.push(redirectPath);
// let urlsearch = redirectPath.split("?")[1];
// let appid = this.getQueryString(urlsearch, "appid");
// this.getToken(user.access_token, appid, redirectPath);
// })
// .catch(err => {
// console.log("err=", err);
// });
this.$router.push(redirectPath);
})
.catch(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