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:
@@ -76,11 +76,13 @@ import { useAuthStore } from '@/stores/auth'
|
||||
import { searchTenants, type TenantInfo } from '@/api/tenant'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { navigateAfterTenantSwitch } from '@/utils/tenantSwitch'
|
||||
import { navigateAfterTenantSwitch, stashTenantSwitchToast } from '@/utils/tenantSwitch'
|
||||
import CreateTenantDialog from '@/components/CreateTenantDialog.vue'
|
||||
import { useRoleLabel } from '@/composables/useRoleLabel'
|
||||
|
||||
const { t } = useI18n()
|
||||
const authStore = useAuthStore()
|
||||
const { formatRole } = useRoleLabel()
|
||||
|
||||
const showDropdown = ref(false)
|
||||
const searchQuery = ref('')
|
||||
@@ -164,7 +166,16 @@ const selectTenant = (tenantId: number) => {
|
||||
authStore.setSelectedTenant(tenantId, selectedTenant?.name || null)
|
||||
}
|
||||
closeDropdown()
|
||||
MessagePlugin.success(t('tenant.switchSuccess'))
|
||||
const displayName = selectedTenant?.name
|
||||
|| (tenantId === defaultTenantId.value ? authStore.tenant?.name : null)
|
||||
|| `#${tenantId}`
|
||||
// Cross-tenant superusers may not have a membership row in the target
|
||||
// tenant; in that case skip the role line rather than show a misleading
|
||||
// empty/raw value.
|
||||
const membership = (authStore.memberships ?? []).find((m) => Number(m.tenant_id) === tenantId)
|
||||
const roleLabel = membership ? formatRole(membership.role) : ''
|
||||
// Toast 在 reload 后由 App.vue 弹出(直接在这里弹会被 hard reload 干掉)。
|
||||
stashTenantSwitchToast({ name: displayName, role: roleLabel || undefined })
|
||||
// 切换租户后跳转到新租户下安全的入口(详见 tenantSwitch.ts 注释)。
|
||||
setTimeout(() => {
|
||||
navigateAfterTenantSwitch()
|
||||
|
||||
@@ -236,7 +236,7 @@ import { useI18n } from 'vue-i18n'
|
||||
import IMChannelsOverviewPanel from '@/components/IMChannelsOverviewPanel.vue'
|
||||
import CreateTenantDialog from '@/components/CreateTenantDialog.vue'
|
||||
import { listAllIMChannels, type IMChannelOverview } from '@/api/agent'
|
||||
import { navigateAfterTenantSwitch } from '@/utils/tenantSwitch'
|
||||
import { navigateAfterTenantSwitch, stashTenantSwitchToast } from '@/utils/tenantSwitch'
|
||||
import type { TenantInfo } from '@/api/tenant'
|
||||
import { useRoleLabel, useHomeTenant } from '@/composables/useRoleLabel'
|
||||
|
||||
@@ -446,7 +446,11 @@ const switchToTenant = (m: Membership) => {
|
||||
authStore.setSelectedTenant(m.tenant_id, tenantDisplayName(m))
|
||||
}
|
||||
closeAll()
|
||||
MessagePlugin.success(t('tenant.switchSuccess'))
|
||||
// Toast 在 reload 后由 App.vue 弹出(直接在这里弹会被 hard reload 干掉)。
|
||||
stashTenantSwitchToast({
|
||||
name: tenantDisplayName(m),
|
||||
role: formatRole(m.role) || undefined,
|
||||
})
|
||||
// Hard reload so every cached store / open SSE stream / in-flight
|
||||
// request gets re-keyed under the new tenant. If the current path
|
||||
// embeds a tenant-scoped resource id, reload would white-screen the
|
||||
|
||||
Reference in New Issue
Block a user