diff --git a/apps/web-antd/src/views/_core/profile/modules/user-social.vue b/apps/web-antd/src/views/_core/profile/modules/user-social.vue index 462ad60ee..d2621cdd9 100644 --- a/apps/web-antd/src/views/_core/profile/modules/user-social.vue +++ b/apps/web-antd/src/views/_core/profile/modules/user-social.vue @@ -44,7 +44,7 @@ const allBindList = computed(() => { .filter((social) => !HIDDEN_SOCIAL_TYPES.has(social.type)) .map((social) => { const socialUser = bindList.value.find( - (item) => item.type === social.type, + (item) => Number(item.type) === social.type, ); return { ...social, @@ -77,7 +77,9 @@ async function onBind(bind: SocialBindItem) { return; } try { - const redirectUri = `${location.origin}/profile?${encodeURIComponent(`type=${type}`)}`; + // 将 type 存入 sessionStorage,避免放入 redirect_uri 导致参数被截断 + sessionStorage.setItem('socialBindType', String(type)); + const redirectUri = `${location.origin}/profile`; window.location.href = await socialAuthRedirect(type, redirectUri); } catch (error) { console.error('社交绑定处理失败:', error); @@ -86,17 +88,30 @@ async function onBind(bind: SocialBindItem) { /** 监听路由变化,处理社交绑定回调 */ async function bindSocial() { - const type = Number(getUrlValue('type')); const code = route.query.code as string; const state = route.query.state as string; if (!code) { return; } - await socialBind({ type, code, state }); - message.success('绑定成功'); - emit('update:activeName', 'userSocial'); - await loadBindList(); - window.history.replaceState({}, '', location.pathname); + // 优先从 sessionStorage 获取 type,兼容从 URL 参数获取 + const storedType = sessionStorage.getItem('socialBindType'); + const type = storedType ? Number(storedType) : Number(getUrlValue('type')); + sessionStorage.removeItem('socialBindType'); + if (!type) { + message.error('绑定失败:缺少社交平台类型'); + return; + } + try { + await socialBind({ type, code, state }); + message.success('绑定成功'); + emit('update:activeName', 'userSocial'); + await loadBindList(); + } catch (error) { + console.error('社交绑定失败:', error); + message.error('绑定失败,请重试'); + } finally { + window.history.replaceState({}, '', location.pathname); + } } /** 初始化 */