Commit 9c50cb87 by 展昭

add router.beforeach autologin

parent 2e07d1c5
Showing with 77 additions and 77 deletions
...@@ -28,88 +28,88 @@ const router = new VueRouter({ ...@@ -28,88 +28,88 @@ const router = new VueRouter({
} }
}) })
// //自动登录 //自动登录
// 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
// } }
// }); });
// } }
// 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);
// } }
// return null; return null;
// } }
// //如果有登录参数则优先登录 //如果有登录参数则优先登录
// 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 || to.query.authcode; const authcode = to.query.authCode || to.query.authcode;
// const appid = to.query.appId || to.query.appid; const appid = to.query.appId || to.query.appid;
// const userId = to.query.userid || to.query.userId||0; const userId = to.query.userid || to.query.userId||0;
// if (!!authcode && !!appid) { if (!!authcode && !!appid) {
// var toPath = to.path || "/"; var toPath = to.path || "/";
// for (let key in to.query) { for (let key in to.query) {
// if (key == 'authcode'||key == 'authCode') { if (key == 'authcode'||key == 'authCode') {
// continue; continue;
// } }
// toPath += toPath.indexOf("?") > -1 ? "&" : "?"; toPath += toPath.indexOf("?") > -1 ? "&" : "?";
// toPath += `${key}=${to.query[key]}`; toPath += `${key}=${to.query[key]}`;
// } }
// const storeAppId = localStorage.getItem('appid'); const storeAppId = localStorage.getItem('appid');
// store.dispatch("getOidcUser").then(oidcUser => { store.dispatch("getOidcUser").then(oidcUser => {
// if (oidcUser) { if (oidcUser) {
// if(storeAppId!= appid){ if(storeAppId!= appid){
// localStorage.setItem('appid',appid); localStorage.setItem('appid',appid);
// setAutoLogin({ autoCode: authcode, redirectPath: toPath }) setAutoLogin({ autoCode: authcode, redirectPath: toPath })
// store.dispatch("signOutOidc") store.dispatch("signOutOidc")
// }else{ }else{
// //如果登录用户与当前登录用户不匹配,则保存登录参数,退出 //如果登录用户与当前登录用户不匹配,则保存登录参数,退出
// console.log('userId=',userId); console.log('userId=',userId);
// console.log('oidcUser.profile.sub=',oidcUser.profile.sub); console.log('oidcUser.profile.sub=',oidcUser.profile.sub);
// console.log('oidcUser.profile.sub==userId:',oidcUser.profile.sub==userId); console.log('oidcUser.profile.sub==userId:',oidcUser.profile.sub==userId);
// if (userId > 0 && oidcUser.profile.sub != userId) { if (userId > 0 && 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 {
// localStorage.setItem('appid',appid); localStorage.setItem('appid',appid);
// autoLogin({ autoCode: authcode, redirectPath: toPath }) autoLogin({ autoCode: authcode, redirectPath: toPath })
// } }
// }).catch(() => { }).catch(() => {
// localStorage.setItem('appid',appid); localStorage.setItem('appid',appid);
// autoLogin({ autoCode: authcode, redirectPath: toPath }) autoLogin({ autoCode: authcode, redirectPath: toPath })
// }); });
// } else { } else {
// next() next()
// } }
// }) })
router.beforeEach(vuexOidcCreateRouterMiddleware(store)); router.beforeEach(vuexOidcCreateRouterMiddleware(store));
......
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