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() {