From 91eec657340ded9673ac421eba0ad29fdf6d382a Mon Sep 17 00:00:00 2001 From: lzh Date: Mon, 23 Mar 2026 17:19:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(@vben/web-antd):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=E7=BB=91=E5=AE=9A=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=20type=20=E5=8F=82=E6=95=B0=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit redirect_uri 中的查询参数会被企业微信 OAuth 截断, 改用 sessionStorage 暂存社交平台类型,同时增加绑定 错误处理和类型匹配的健壮性。 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../_core/profile/modules/user-social.vue | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) 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); + } } /** 初始化 */