From 225f8f758e6fbd2c287fe852bbf709d28569de27 Mon Sep 17 00:00:00 2001 From: kx_guo Date: Sun, 13 Sep 2026 16:21:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=92=89=E9=92=89=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E6=97=B6=E5=90=8C=E6=AD=A5=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 18 +++++++++++++++--- src/stores/auth.store.ts | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/App.vue b/src/App.vue index 1ba91c8..9b5c46b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,6 +2,7 @@ import { onMounted, onUnmounted } from "vue"; import { RouterView } from "vue-router"; +import { isDingTalkContainer } from "@/api/dingtalk"; import router from "@/router"; import { useAuthStore } from "@/stores/auth.store"; @@ -17,9 +18,20 @@ function handleAuthExpired() { } } -onMounted(() => - window.addEventListener("risk-auth-expired", handleAuthExpired), -); +onMounted(() => { + window.addEventListener("risk-auth-expired", handleAuthExpired); + // A persisted JWT only refreshes /auth/me and cannot update stale DingTalk + // department/name fields. Re-sync the organization identity once per page + // load when the app is opened inside DingTalk, without logging out on error. + if ( + isDingTalkContainer() && + auth.token && + auth.user?.dingtalkId && + !auth.user.dingtalkId.startsWith("local-") + ) { + void auth.dingTalkLogin(true); + } +}); onUnmounted(() => window.removeEventListener("risk-auth-expired", handleAuthExpired), ); diff --git a/src/stores/auth.store.ts b/src/stores/auth.store.ts index bda4f84..74ae593 100644 --- a/src/stores/auth.store.ts +++ b/src/stores/auth.store.ts @@ -61,7 +61,7 @@ export const useAuthStore = defineStore("auth", () => { } } - async function dingTalkLogin() { + async function dingTalkLogin(preserveSessionOnFailure = false) { loading.value = true; error.value = null; try { @@ -69,7 +69,7 @@ export const useAuthStore = defineStore("auth", () => { saveToken(response.accessToken); user.value = response.user; } catch (reason) { - clear(); + if (!preserveSessionOnFailure) clear(); error.value = reason instanceof Error ? reason.message : "钉钉免登失败"; throw reason; } finally {