From 313b25c6310af0391ed89825b474905ba903566a Mon Sep 17 00:00:00 2001 From: v6ole Date: Fri, 26 Jun 2026 15:18:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20WecomBind.vue=20=E2=80=94=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20auth.user=20=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit auth store 暴露的是独立字段 (name/userId/role) 而非 user 对象, 导致 auth.user?.name 始终为 undefined。 修复: - auth.name 替代 auth.user?.name - 调用 /users/me 获取 wecom_userid (store 不存储该字段) - window.location.href 替代 router.push (企微浏览器兼容) Co-Authored-By: Claude --- frontend/src/views/WecomBind.vue | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/frontend/src/views/WecomBind.vue b/frontend/src/views/WecomBind.vue index 8d60033..04f7fbe 100644 --- a/frontend/src/views/WecomBind.vue +++ b/frontend/src/views/WecomBind.vue @@ -11,20 +11,25 @@ const auth = useAuthStore() const binding = ref(false) const bound = ref(false) const errorMsg = ref('') +const wecomUserId = ref('') const bindToken = (route.query.token as string) || '' -onMounted(() => { +onMounted(async () => { if (!bindToken) { errorMsg.value = '无效的绑定链接' setTimeout(() => router.replace('/'), 2000) return } if (!auth.isLoggedIn) { - // Not logged in yet — redirect to login (use window.location for WeChat Work browser compat) window.location.href = `/login?redirect=${encodeURIComponent(route.fullPath)}` return } + // Fetch current user's wecom_userid + try { + const res = await api.get('/users/me') + wecomUserId.value = res.data.wecom_userid || '' + } catch (_) {} }) async function doBind() { @@ -34,7 +39,7 @@ async function doBind() { const res = await api.post('/wecom/bind-confirm', { token: bindToken }) if (res.data.code === 200) { bound.value = true - auth.user!.wecom_userid = res.data.wecom_userid + wecomUserId.value = res.data.wecom_userid ElMessage.success('绑定成功!') setTimeout(() => router.replace('/'), 1500) } else { @@ -61,23 +66,23 @@ async function doBind() {
当前账号 - {{ auth.user?.name || '--' }} + {{ auth.name || '--' }}
绑定状态 - - {{ auth.user?.wecom_userid ? '已绑定' : '未绑定' }} + + {{ wecomUserId ? '已绑定' : '未绑定' }}
-
+
企微ID - {{ auth.user.wecom_userid }} + {{ wecomUserId }}