refactor(layout, i18n, admin): 优化布局结构与多语言支持
调整 AdminShell 组件的子组件顺序,提升代码可读性。更新 admin-breadcrumb 组件,简化导航标签翻译逻辑,确保多语言支持的一致性。重构 admin-language-switcher 组件,优化语言切换的用户体验,增强界面交互性。更新多语言配置,新增登录界面的副标题,提升用户体验。
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { CheckIcon, GlobeIcon } from "lucide-react";
|
||||
import { CheckIcon, ChevronDownIcon, GlobeIcon } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
@@ -22,12 +22,6 @@ import {
|
||||
} from "@/lib/admin-locale";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const LOCALE_FLAGS: Record<AdminApiLocale, string> = {
|
||||
zh: "🇨🇳",
|
||||
en: "🇺🇸",
|
||||
ne: "🇳🇵",
|
||||
};
|
||||
|
||||
export function AdminLanguageSwitcher() {
|
||||
const { i18n, t } = useTranslation("common");
|
||||
// Match SSR: do not read document/localStorage until after mount.
|
||||
@@ -57,25 +51,27 @@ export function AdminLanguageSwitcher() {
|
||||
);
|
||||
}
|
||||
|
||||
const currentFlag = LOCALE_FLAGS[locale];
|
||||
const currentLabel = t(`language.${locale}`);
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger className="inline-flex h-8 items-center gap-1.5 rounded-full border border-slate-200 bg-white px-2 text-left text-slate-700 shadow-[0_1px_2px_rgba(15,23,42,0.04)] outline-none transition hover:border-slate-300 hover:bg-slate-50 focus-visible:ring-2 focus-visible:ring-ring">
|
||||
<span className="flex size-5 shrink-0 items-center justify-center rounded-full bg-slate-100 text-xs">
|
||||
{currentFlag}
|
||||
</span>
|
||||
<DropdownMenuTrigger
|
||||
aria-label={t("language.title")}
|
||||
className="inline-flex h-9 max-w-[9rem] items-center gap-1.5 rounded-lg px-2.5 text-sm font-medium text-foreground outline-none transition-colors hover:bg-muted/80 focus-visible:ring-2 focus-visible:ring-ring"
|
||||
>
|
||||
<GlobeIcon
|
||||
className="size-4 shrink-0 stroke-[1.75] text-slate-400 sm:hidden"
|
||||
className="size-4 shrink-0 text-muted-foreground"
|
||||
aria-hidden
|
||||
/>
|
||||
<span className="min-w-0 truncate">{currentLabel}</span>
|
||||
<ChevronDownIcon
|
||||
className="size-3.5 shrink-0 text-muted-foreground/80"
|
||||
aria-hidden
|
||||
/>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
align="end"
|
||||
className="w-[188px] overflow-hidden rounded-xl border border-slate-200 bg-white p-1 shadow-[0_16px_40px_rgba(15,23,42,0.12)]"
|
||||
>
|
||||
<DropdownMenuGroup className="space-y-0.5">
|
||||
<DropdownMenuLabel className="sr-only">
|
||||
<DropdownMenuContent align="end" className="min-w-[10.5rem]">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuLabel className="text-xs text-muted-foreground">
|
||||
{t("language.title")}
|
||||
</DropdownMenuLabel>
|
||||
{ADMIN_API_LOCALES.map((code) => {
|
||||
@@ -85,29 +81,17 @@ export function AdminLanguageSwitcher() {
|
||||
<DropdownMenuItem
|
||||
key={code}
|
||||
className={cn(
|
||||
"flex min-h-[42px] items-center gap-2 rounded-md border border-transparent px-2 py-1.5 text-slate-700 outline-none transition",
|
||||
active
|
||||
? "border-rose-100 bg-rose-50 text-rose-600"
|
||||
: "hover:bg-slate-50 focus:bg-slate-50",
|
||||
"flex items-center justify-between gap-2",
|
||||
active && "bg-accent text-accent-foreground",
|
||||
)}
|
||||
onClick={() => void onSelectLocale(code)}
|
||||
>
|
||||
<span className="flex size-8 shrink-0 items-center justify-center rounded-md bg-white text-lg shadow-[inset_0_0_0_1px_rgba(148,163,184,0.16)]">
|
||||
{LOCALE_FLAGS[code]}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span
|
||||
className={cn(
|
||||
"block truncate text-[14px] font-semibold leading-5",
|
||||
active ? "text-rose-600" : "text-slate-800",
|
||||
)}
|
||||
>
|
||||
<span className="truncate font-medium">
|
||||
{ADMIN_LOCALE_LABELS[code]}
|
||||
</span>
|
||||
</span>
|
||||
<span className="flex w-3 shrink-0 justify-end">
|
||||
{active ? <CheckIcon className="size-3.5 text-rose-500" /> : null}
|
||||
</span>
|
||||
{active ? (
|
||||
<CheckIcon className="size-4 shrink-0 text-primary" />
|
||||
) : null}
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
|
||||
Reference in New Issue
Block a user