From a28a641706fd6e056976ed38d38ce6b4e7a59434 Mon Sep 17 00:00:00 2001 From: qq787203167 <787203167@qq.com> Date: Thu, 9 Jun 2022 16:48:03 +0800 Subject: [PATCH] =?UTF-8?q?sso=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jero-web/src/components/tools/UserMenu.vue | 3 +- jero-web/src/permission.js | 53 ++++++++++++++++++++-- jero-web/src/views/user/Login.vue | 2 +- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/jero-web/src/components/tools/UserMenu.vue b/jero-web/src/components/tools/UserMenu.vue index 12a0a75f2..d44114306 100644 --- a/jero-web/src/components/tools/UserMenu.vue +++ b/jero-web/src/components/tools/UserMenu.vue @@ -114,7 +114,7 @@ import { mixinDevice } from '@/utils/mixin.js' import { getFileAccessHttpUrl, getAction } from '@/api/manage' import Vue from 'vue' - import { UI_CACHE_DB_DICT_DATA } from '@/store/mutation-types' + import { UI_CACHE_DB_DICT_DATA ,ACCESS_TOKEN} from '@/store/mutation-types' import moment from 'moment' import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN' import enUS from 'ant-design-vue/es/locale/en_US' @@ -223,6 +223,7 @@ return that.Logout({}).then(() => { // update-begin author:wangshuai date:20200601 for: 退出登录跳转登录页面 that.$router.push({ path: '/user/login' }) + // window.location.href = 'https://signin-test.nio.com/oauth2/authorize?client_id=100679&redirect_uri=' + encodeURIComponent('http://localhost:3000/dashboard/analysis') + '&response_type=code' localStorage.removeItem('language') // update-end author:wangshuai date:20200601 for: 退出登录跳转登录页面 //window.location.reload() diff --git a/jero-web/src/permission.js b/jero-web/src/permission.js index ed185df30..121f30ec3 100644 --- a/jero-web/src/permission.js +++ b/jero-web/src/permission.js @@ -4,16 +4,48 @@ import store from './store' import NProgress from 'nprogress' // progress bar import 'nprogress/nprogress.css' // progress bar style import notification from 'ant-design-vue/es/notification' -import { ACCESS_TOKEN, INDEX_MAIN_PAGE_PATH } from '@/store/mutation-types' +import { ACCESS_TOKEN, USER_NAME, USER_INFO, UI_CACHE_DB_DICT_DATA, INDEX_MAIN_PAGE_PATH } from '@/store/mutation-types' import { generateIndexRouter } from '@/utils/util' +import { JSEncrypt } from 'jsencrypt' +import { getAction } from '@/api/manage' +import { welcome } from '@/utils/util' NProgress.configure({ showSpinner: false }) // NProgress Configuration -const whiteList = ['/user/login', '/user/register', '/user/register-result', '/user/alteration'] // no redirect whitelist +const whiteList = ['/user/login', '/user/register', '/user/register-result', '/user/alteration'] +// const whiteList = [] +// no redirect whitelist router.beforeEach((to, from, next) => { NProgress.start() // start progress bar - + if (to.query.code) { + getAction(`opensso/callback`, { code: to.query.code }).then(res => { + if (res.success) { + Vue.ls.set(ACCESS_TOKEN, res.result.token, 7 * 24 * 60 * 60 * 1000) + Vue.ls.set(USER_NAME, res.result.userInfo.username, 7 * 24 * 60 * 60 * 1000) + Vue.ls.set(USER_INFO, res.result.userInfo, 7 * 24 * 60 * 60 * 1000) + Vue.ls.set(UI_CACHE_DB_DICT_DATA, res.result.sysAllDictItems, 7 * 24 * 60 * 60 * 1000) + store.commit('SET_TOKEN', res.result.token) + store.commit('SET_INFO', res.result.userInfo) + store.commit('SET_NAME', { + username: res.result.userInfo.username, + realname: res.result.userInfo.realname, + welcome: welcome() + }) + store.commit('SET_AVATAR', res.result.userInfo.avatar) + let fullPath = '' + if (to.fullPath == '/') { + fullPath = INDEX_MAIN_PAGE_PATH + } else { + fullPath = to.path + } + let query = to.query + delete query.code + next({ path: fullPath, query: query }) + } + }) + return + } if (Vue.ls.get(ACCESS_TOKEN)) { /* has token */ if (to.path === '/user/login') { @@ -52,6 +84,13 @@ router.beforeEach((to, from, next) => { // query: { redirect: to.fullPath } store.dispatch('Logout').then(() => { next({ path: '/user/login', query: { redirect: to.fullPath } }) + let fullPath = '' + if (to.fullPath == '/') { + fullPath = INDEX_MAIN_PAGE_PATH + } else { + fullPath = to.fullPath + } + // window.location.href = 'https://signin-test.nio.com/oauth2/authorize?client_id=100679&redirect_uri=' + encodeURIComponent('http://grp.nioint.com' + fullPath) + '&response_type=code' }) }) } else { @@ -63,8 +102,14 @@ router.beforeEach((to, from, next) => { // 在免登录白名单,直接进入 next() } else { - next({ path: '/user/login', query: { redirect: to.fullPath } }) + let fullPath = '' + if (to.fullPath == '/') { + fullPath = INDEX_MAIN_PAGE_PATH + '?id=123' + } else { + fullPath = to.fullPath + } + // window.location.href = 'https://signin-test.nio.com/oauth2/authorize?client_id=100679&redirect_uri=' + encodeURIComponent('http://grp.nioint.com' + fullPath) + '&response_type=code' NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it } } diff --git a/jero-web/src/views/user/Login.vue b/jero-web/src/views/user/Login.vue index a5e5370ee..868eb8246 100644 --- a/jero-web/src/views/user/Login.vue +++ b/jero-web/src/views/user/Login.vue @@ -414,7 +414,7 @@ }, //sso登录跳转 ssoLogin(){ - window.open('https://signin-test.nio.com/oauth2/authorize?client_id=100679&redirect_uri=http%3A%2F%2F39.98.140.126&response_type=code', '_blank') + window.open('https://signin-test.nio.com/oauth2/authorize?client_id=100679&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fdashboard%2Fanalysis&response_type=code', '_blank') }, //sso登录 ssoLoginSuccess(){