sso登录
This commit is contained in:
@@ -114,7 +114,7 @@
|
|||||||
import { mixinDevice } from '@/utils/mixin.js'
|
import { mixinDevice } from '@/utils/mixin.js'
|
||||||
import { getFileAccessHttpUrl, getAction } from '@/api/manage'
|
import { getFileAccessHttpUrl, getAction } from '@/api/manage'
|
||||||
import Vue from 'vue'
|
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 moment from 'moment'
|
||||||
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
|
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
|
||||||
import enUS from 'ant-design-vue/es/locale/en_US'
|
import enUS from 'ant-design-vue/es/locale/en_US'
|
||||||
@@ -223,6 +223,7 @@
|
|||||||
return that.Logout({}).then(() => {
|
return that.Logout({}).then(() => {
|
||||||
// update-begin author:wangshuai date:20200601 for: 退出登录跳转登录页面
|
// update-begin author:wangshuai date:20200601 for: 退出登录跳转登录页面
|
||||||
that.$router.push({ path: '/user/login' })
|
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')
|
localStorage.removeItem('language')
|
||||||
// update-end author:wangshuai date:20200601 for: 退出登录跳转登录页面
|
// update-end author:wangshuai date:20200601 for: 退出登录跳转登录页面
|
||||||
//window.location.reload()
|
//window.location.reload()
|
||||||
|
|||||||
@@ -4,16 +4,48 @@ import store from './store'
|
|||||||
import NProgress from 'nprogress' // progress bar
|
import NProgress from 'nprogress' // progress bar
|
||||||
import 'nprogress/nprogress.css' // progress bar style
|
import 'nprogress/nprogress.css' // progress bar style
|
||||||
import notification from 'ant-design-vue/es/notification'
|
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 { generateIndexRouter } from '@/utils/util'
|
||||||
|
import { JSEncrypt } from 'jsencrypt'
|
||||||
|
import { getAction } from '@/api/manage'
|
||||||
|
import { welcome } from '@/utils/util'
|
||||||
|
|
||||||
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
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) => {
|
router.beforeEach((to, from, next) => {
|
||||||
NProgress.start() // start progress bar
|
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)) {
|
if (Vue.ls.get(ACCESS_TOKEN)) {
|
||||||
/* has token */
|
/* has token */
|
||||||
if (to.path === '/user/login') {
|
if (to.path === '/user/login') {
|
||||||
@@ -52,6 +84,13 @@ router.beforeEach((to, from, next) => {
|
|||||||
// query: { redirect: to.fullPath }
|
// query: { redirect: to.fullPath }
|
||||||
store.dispatch('Logout').then(() => {
|
store.dispatch('Logout').then(() => {
|
||||||
next({ path: '/user/login', query: { redirect: to.fullPath } })
|
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 {
|
} else {
|
||||||
@@ -63,8 +102,14 @@ router.beforeEach((to, from, next) => {
|
|||||||
// 在免登录白名单,直接进入
|
// 在免登录白名单,直接进入
|
||||||
next()
|
next()
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
next({ path: '/user/login', query: { redirect: to.fullPath } })
|
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
|
NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -414,7 +414,7 @@
|
|||||||
},
|
},
|
||||||
//sso登录跳转
|
//sso登录跳转
|
||||||
ssoLogin(){
|
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登录
|
//sso登录
|
||||||
ssoLoginSuccess(){
|
ssoLoginSuccess(){
|
||||||
|
|||||||
Reference in New Issue
Block a user