add 单点登录

This commit is contained in:
赵霄
2023-10-17 16:54:03 +08:00
parent 0f492fec6b
commit c185a29c01
2 changed files with 28 additions and 10 deletions
+11 -7
View File
@@ -18,6 +18,8 @@ const frozenBatch = (params) => postAction('/sys/user/frozenBatch', params)
const checkOnlyUser = (params) => getAction('/sys/user/checkOnlyUser', params) const checkOnlyUser = (params) => getAction('/sys/user/checkOnlyUser', params)
// 改变密码 // 改变密码
const changePassword = (params) => postAction('/sys/user/changePassword', params) const changePassword = (params) => postAction('/sys/user/changePassword', params)
// 单点登录获取用户信息
const getSSOUserInfo = (params) => postAction('/iam/loginByOauth2', params)
// 权限管理 // 权限管理
const addPermission = (params) => postAction('/sys/permission/add', params) const addPermission = (params) => postAction('/sys/permission/add', params)
@@ -69,6 +71,7 @@ const getFormDictTreeList = (params) => getAction('/sys/dictItem/treeListOption'
// 字典标签专用(通过code获取字典数组) // 字典标签专用(通过code获取字典数组)
export const ajaxGetDictItems = (code, params) => getAction(`/sys/dict/getDictItems/${code}`, params) export const ajaxGetDictItems = (code, params) => getAction(`/sys/dict/getDictItems/${code}`, params)
// 从缓存中获取字典配置 // 从缓存中获取字典配置
function getDictItemsFromCache (dictCode) { function getDictItemsFromCache (dictCode) {
if (Vue.ls.get(UI_CACHE_DB_DICT_DATA) && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode] && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode].length > 0) { if (Vue.ls.get(UI_CACHE_DB_DICT_DATA) && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode] && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode].length > 0) {
@@ -187,21 +190,22 @@ export {
queryMyDepartTreeList, queryMyDepartTreeList,
getUserNoticeInfo, getUserNoticeInfo,
getDictItemsFromCache, getDictItemsFromCache,
getShowAreaData, getShowAreaData,
addAreaData, addAreaData,
editAreaData, editAreaData,
getFileInfo, getFileInfo,
addTag, addTag,
editTag, editTag,
addCategoryItem, addCategoryItem,
editCategoryItem, editCategoryItem,
getStandardList, getStandardList,
getWorkGroupTreeList, getWorkGroupTreeList,
getEnterpriseLevelMapList getEnterpriseLevelMapList,
getSSOUserInfo
} }
+17 -3
View File
@@ -3,15 +3,29 @@ import router from './router'
import store from './store' 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 { ACCESS_TOKEN, OAUTH2_LOGIN_PAGE_PATH } from '@/store/mutation-types' import { ACCESS_TOKEN, OAUTH2_LOGIN_PAGE_PATH, UI_CACHE_DB_DICT_DATA, USER_INFO, USER_NAME } from '@/store/mutation-types'
import { generateIndexRouter, isOAuth2AppEnv, findFirstRoute } from '@/utils/util' import { generateIndexRouter, isOAuth2AppEnv, findFirstRoute, welcome } from '@/utils/util'
import { getSSOUserInfo } from './api/api'
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'] // no redirect whitelist
whiteList.push(OAUTH2_LOGIN_PAGE_PATH) whiteList.push(OAUTH2_LOGIN_PAGE_PATH)
router.beforeEach((to, from, next) => { router.beforeEach(async (to, from, next) => {
// 单点登录
if (to.query.code) {
const result = await getSSOUserInfo({ code: to.query.code })
const userInfo = result.userInfo
Vue.ls.set(ACCESS_TOKEN, result.token, 7 * 24 * 60 * 60 * 1000)
Vue.ls.set(USER_NAME, userInfo.username, 7 * 24 * 60 * 60 * 1000)
Vue.ls.set(USER_INFO, userInfo, 7 * 24 * 60 * 60 * 1000)
Vue.ls.set(UI_CACHE_DB_DICT_DATA, result.sysAllDictItems, 7 * 24 * 60 * 60 * 1000)
store.commit('SET_TOKEN', result.token)
store.commit('SET_INFO', userInfo)
store.commit('SET_NAME', { username: userInfo.username, realname: userInfo.realname, welcome: welcome() })
store.commit('SET_AVATAR', userInfo.avatar)
}
// 处理是否是嵌入其他系统,是需要隐藏左侧和上面,如果当前值是true,就不需要修改了 // 处理是否是嵌入其他系统,是需要隐藏左侧和上面,如果当前值是true,就不需要修改了
const isEmbedded = store.getters.isEmbedded const isEmbedded = store.getters.isEmbedded
// 用是否iframe嵌套判断 // 用是否iframe嵌套判断