提交 e27b4745 authored 作者: lidongxu's avatar lidongxu

fix(feishu): 修复:飞书授权登录回调积木问题

上级 3d1a09de
import { ElMessage } from 'element-plus'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import router from './router'
import { getToken } from '@/utils/auth'
import { isHttp, isPathMatch } from '@/utils/validate'
import { isRelogin } from '@/utils/request'
import cache from '@/plugins/cache'
import useUserStore from '@/store/modules/user'
import useSettingsStore from '@/store/modules/settings'
import usePermissionStore from '@/store/modules/permission'
......@@ -61,6 +61,7 @@ router.beforeEach((to, from, next) => {
if (isWhiteList(to.path)) {
next()
} else {
cache.set('redirect_uri', to.fullPath)
next(`/login?redirect=${to.fullPath}`)
NProgress.done()
}
......
......@@ -80,27 +80,7 @@ export function param(json) {
).join('&')
}
/**
* @param {string} url
* @returns {Object}
*/
export function param2Obj(url) {
const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
if (!search) {
return {}
}
const obj = {}
const searchArr = search.split('&')
searchArr.forEach(v => {
const index = v.indexOf('=')
if (index !== -1) {
const name = v.substring(0, index)
const val = v.substring(index + 1, v.length)
obj[name] = val
}
})
return obj
}
/**
* @param {string} val
......
......@@ -4,10 +4,33 @@ export function getQueryString(name) {
const queryObj = {}
urlList.forEach(item => {
const list = item.split('&')
list.forEach(o =>{
list.forEach(o => {
const [key, value] = o.split('=')
queryObj[key] = value
})
})
return queryObj[name] || null
return queryObj[name] || ''
}
/**
* 查询参数转对象
* @param {string} url
* @returns {Object}
*/
export function param2Obj(url) {
const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
if (!search) {
return {}
}
const obj = {}
const searchArr = search.split('&')
searchArr.forEach(v => {
const index = v.indexOf('=')
if (index !== -1) {
const name = v.substring(0, index)
const val = v.substring(index + 1, v.length)
obj[name] = val
}
})
return obj
}
\ No newline at end of file
......@@ -70,7 +70,7 @@
<script setup>
import { fsOAuthUrl, fsClientAuth } from "@/api"
import Cookies from "js-cookie"
import { encrypt, decrypt, getQueryString } from "@/utils"
import { encrypt, decrypt, getQueryString, param2Obj } from "@/utils"
import useUserStore from '@/store/modules/user'
const userStore = useUserStore()
......@@ -96,7 +96,6 @@ const locationHref = ref(window.location.href)
console.log('locationHref', locationHref)
watch(route, (newRoute) => {
console.log('URL 上要跳转的地址', newRoute)
redirect.value = newRoute.query?.redirect
}, { immediate: true })
......@@ -162,15 +161,19 @@ async function loginByType(type, data) {
type,
data
}).then(() => {
// 把 redirect.value 上的查询参数拿下来,单独跳转发送如果有的话
const redirectQuery = redirect.value.split('?')[1]
// 字符串转对象结构
const redirectQueryObj = redirectQuery?.split('&').reduce((pre, cur) => {
pre[cur.split('=')[0]] = cur.split('=')[1]
return pre
}, {})
console.log('redirectQueryObj', redirectQueryObj)
router.push({ path: redirect.value || "/", query: redirectQueryObj });
const state = getQueryString('state')
// 飞书回跳
if (state.includes('fs')) {
const redirectUri = cache.get('redirect_uri') // 未遂地址
if (redirectUri) {
cache.remove('redirect_uri')
router.push({ path: redirectUri || "/", query: param2Obj(redirect.value) });
} else {
router.push({ path: "/" }); // 正常飞书客户端里登录
}
} else {
router.push({ path: redirect.value || "/", query: param2Obj(redirect.value) });
}
}).catch((err) => {
console.log(err)
accountPassLoading.value = false;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论