mirror of
https://gitee.com/xiaonuobase/snowy.git
synced 2026-03-22 10:47:16 +08:00
【升级】嵌入模式完成登录交互,可以将本系统嵌入到三方系统内
This commit is contained in:
@@ -61,5 +61,9 @@ export default {
|
||||
// B端判断是否登录
|
||||
isLogin(data) {
|
||||
return request('isLogin', data, 'get')
|
||||
},
|
||||
// B端第三方Token交换登录(iframe嵌入免登)
|
||||
doLoginByThirdToken(data) {
|
||||
return request('doLoginByThirdToken', data, 'post', false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import { useMenuStore } from '@/store/menu'
|
||||
import { useUserStore } from '@/store/user'
|
||||
import { useDictStore } from '@/store/dict'
|
||||
import { pathToRegexp } from 'path-to-regexp'
|
||||
import loginApi from '@/api/auth/loginApi'
|
||||
import { afterLogin } from '@/views/auth/login/util'
|
||||
|
||||
// 进度条配置
|
||||
NProgress.configure({ showSpinner: false, speed: 500 })
|
||||
@@ -57,7 +59,7 @@ const exportWhiteListFromRouter = (router) => {
|
||||
const { regexp } = pathToRegexp(item.path)
|
||||
res.push({
|
||||
path: item.path,
|
||||
regex: regexp // 使用解构后的正则表达式
|
||||
regex: regexp // 使用解构后的正则表达式
|
||||
})
|
||||
}
|
||||
return res
|
||||
@@ -74,11 +76,35 @@ router.beforeEach(async (to, from, next) => {
|
||||
: `${sysBaseConfig.SNOWY_SYS_NAME}`
|
||||
|
||||
// 过滤白名单
|
||||
if (whiteList.some(currentRoute => currentRoute.regex.test(to.path))) {
|
||||
if (whiteList.some((currentRoute) => currentRoute.regex.test(to.path))) {
|
||||
next()
|
||||
// NProgress.done()
|
||||
return false
|
||||
}
|
||||
|
||||
// ========== iframe嵌入免登:检测URL中的第三方accessToken ==========
|
||||
const thirdAccessToken = to.query.accessToken
|
||||
if (thirdAccessToken && !tool.data.get('TOKEN')) {
|
||||
// 调用第三方Token交换登录接口
|
||||
loginApi
|
||||
.doLoginByThirdToken({
|
||||
accessToken: thirdAccessToken
|
||||
})
|
||||
.then(async (loginToken) => {
|
||||
// 复用登录后流程,传入目标路径
|
||||
await afterLogin(loginToken, to.path)
|
||||
})
|
||||
return false
|
||||
}
|
||||
// 如果已有TOKEN且URL带accessToken,直接放行(避免重复登录)
|
||||
if (thirdAccessToken && tool.data.get('TOKEN')) {
|
||||
// 去掉URL中的accessToken参数,保持路由干净
|
||||
const query = { ...to.query }
|
||||
delete query.accessToken
|
||||
next({ path: to.path, query, replace: true })
|
||||
return false
|
||||
}
|
||||
|
||||
// C端检验逻辑
|
||||
if (to.path.includes('/front/client/')) {
|
||||
return validateClientAccess(to.path).valid ? next() : next({ path: validateClientAccess(to.path).redirectPath })
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useMenuStore } from '@/store/menu'
|
||||
import { useUserStore } from '@/store/user'
|
||||
import { globalStore } from '@/store'
|
||||
|
||||
export const afterLogin = async (loginToken) => {
|
||||
export const afterLogin = async (loginToken, targetPath) => {
|
||||
const route = router.currentRoute.value
|
||||
const menuStore = useMenuStore()
|
||||
const userStore = useUserStore()
|
||||
@@ -51,6 +51,12 @@ export const afterLogin = async (loginToken) => {
|
||||
tool.data.set('DICT_TYPE_TREE_DATA', data)
|
||||
})
|
||||
|
||||
// 第三方Token登录:直接跳转到指定目标路径
|
||||
if (targetPath) {
|
||||
router.replace({ path: targetPath }).then(() => {})
|
||||
return
|
||||
}
|
||||
|
||||
// 此处判断是否存在跳转页面,如存在则跳转,否则走原来逻辑
|
||||
if (route.query.redirect_uri) {
|
||||
// 跳转到回调页
|
||||
|
||||
Reference in New Issue
Block a user