feat(ui): render workspace-context notifications with styled chips

The login-success and tenant-switch toasts previously showed the
workspace name and role inline as bracketed plain text, which read
flat and made the two key data points hard to scan at a glance.

Render them through a shared `renderWorkspaceNotifyContent` helper
that produces a NotifyPlugin VNode with:

* a neutral rounded chip for the workspace name (with a generic
  workspace icon), and
* a role-coloured chip for the role (with the existing per-role icon
  from useRoleLabel), so owner / admin / contributor / viewer each
  get a distinct visual identity that matches the role badges used
  elsewhere in the product.

The i18n templates lose the surrounding 「」 / "" / «» quote marks
because the chip itself now provides the visual delineation; double
emphasis looked off. Translators control the surrounding wording via
`{name}` and `{role}` placeholders and the renderer splits on those
markers to interleave plain text and chips in the original order.

The PendingTenantSwitchToast payload (sessionStorage-stashed for the
hard-reload survival trick) grows a `roleEnum` field so the post-
reload toast can colour the chip — without that, the switch toast
would fall back to a neutral chip while the login toast got the
colour treatment.

Note on icon resolution: the chip renderer imports TDesign's `Icon`
component directly rather than referencing it by string tag in `h()`
— Vue's render function does not auto-resolve component names the
way templates do, so `h('t-icon', ...)` would silently render an
unknown HTML element.
This commit is contained in:
wizardchen
2026-05-18 20:32:50 +08:00
committed by lyingbug
parent 60a579d869
commit 559b5a6e20
11 changed files with 224 additions and 31 deletions
+13 -5
View File
@@ -10,6 +10,7 @@ import { getCurrentUser } from '@/api/auth'
import { consumePendingTenantSwitchToast } from '@/utils/tenantSwitch'
import { useRoleLabel } from '@/composables/useRoleLabel'
import { notifyLoginSuccess } from '@/utils/loginNotify'
import { renderWorkspaceNotifyContent } from '@/utils/workspaceNotifyContent'
// TDesign locale configs
import enUSConfig from 'tdesign-vue-next/esm/locale/en_US'
@@ -18,7 +19,7 @@ import koKRConfig from 'tdesign-vue-next/esm/locale/ko_KR'
import ruRUConfig from 'tdesign-vue-next/esm/locale/ru_RU'
const { locale, t } = useI18n()
const { formatRole } = useRoleLabel()
const { formatRole, roleIcon } = useRoleLabel()
const router = useRouter()
const authStore = useAuthStore()
const settingsStore = useSettingsStore()
@@ -143,7 +144,7 @@ const handleGlobalOIDCCallback = async () => {
if (response.success) {
clearOIDCCallbackState('/')
await persistOIDCLoginResponse(response)
notifyLoginSuccess(response, t, formatRole)
notifyLoginSuccess(response, t, formatRole, roleIcon)
return
}
@@ -203,11 +204,18 @@ watch(
const showPendingTenantSwitchToast = () => {
const pending = consumePendingTenantSwitchToast()
if (!pending) return
const templateKey = pending.role
? 'tenant.switchSuccessContentWithRole'
: 'tenant.switchSuccessContent'
NotifyPlugin.success({
title: t('tenant.switchSuccessTitle'),
content: pending.role
? t('tenant.switchSuccessContentWithRole', { name: pending.name, role: pending.role })
: t('tenant.switchSuccessContent', { name: pending.name }),
content: renderWorkspaceNotifyContent({
template: t(templateKey),
name: pending.name,
roleLabel: pending.role,
roleEnum: pending.roleEnum,
roleIconName: pending.roleEnum ? roleIcon(pending.roleEnum) : undefined,
}),
duration: 6000,
closeBtn: true,
})