feat(tenant): show rich workspace-switch confirmation that survives reload

Replace the lightweight "switch success" message with a richer
NotifyPlugin notification that reports the new workspace name and the
user's role in it. Because the post-switch flow does a hard reload,
the notification is stashed in sessionStorage before navigation and
consumed by App.vue on the next mount, so the toast actually appears
on the destination page with its full 6s duration instead of being
torn down a frame after it is shown.

For the cross-tenant superuser path (TenantSelector), the role line is
omitted when the user has no membership row in the target tenant,
avoiding a misleading empty/raw role value. Role labels are formatted
through the shared useRoleLabel composable so any future role text
change still lives in one place.

i18n keys updated across zh-CN, en-US, ko-KR, ru-RU.
This commit is contained in:
wizardchen
2026-05-18 19:34:06 +08:00
committed by lyingbug
parent c19d3543c8
commit 0655b545be
8 changed files with 83 additions and 10 deletions
+33
View File
@@ -22,3 +22,36 @@ export function tenantSwitchTargetPath(_currentPath: string): string {
export function navigateAfterTenantSwitch(): void {
window.location.href = tenantSwitchTargetPath(window.location.pathname)
}
// 切换成功后的 toast 跨 hard reload 传递:调用方在 reload 前把信息塞进
// sessionStorage,App.vue 启动时 consume 一次再弹出。直接在 reload 前调
// NotifyPlugin 会被刷掉,根本来不及看清。
const PENDING_TOAST_KEY = 'weknora_pending_tenant_switch_toast'
export interface PendingTenantSwitchToast {
name: string
role?: string
}
export function stashTenantSwitchToast(payload: PendingTenantSwitchToast): void {
try {
sessionStorage.setItem(PENDING_TOAST_KEY, JSON.stringify(payload))
} catch {
// sessionStorage 写失败(隐私模式等)就静默放弃,toast 是锦上添花
}
}
export function consumePendingTenantSwitchToast(): PendingTenantSwitchToast | null {
try {
const raw = sessionStorage.getItem(PENDING_TOAST_KEY)
if (!raw) return null
sessionStorage.removeItem(PENDING_TOAST_KEY)
const parsed = JSON.parse(raw)
if (parsed && typeof parsed.name === 'string') {
return { name: parsed.name, role: typeof parsed.role === 'string' ? parsed.role : undefined }
}
return null
} catch {
return null
}
}