refactor: support i18n

This commit is contained in:
mlogclub
2026-05-25 12:06:15 +08:00
parent 309ac1fe9e
commit 988f55c80d
179 changed files with 10968 additions and 3763 deletions
+10 -6
View File
@@ -5,6 +5,7 @@ import { Suspense, useEffect, useRef } from "react"
import { toast } from "sonner"
import { exchangeOIDCTicket } from "@/lib/api/auth"
import { useI18n } from "@/i18n/provider"
export default function OIDCLoginCallbackPage() {
return (
@@ -15,6 +16,7 @@ export default function OIDCLoginCallbackPage() {
}
function OIDCLoginCallbackContent() {
const t = useI18n()
const router = useRouter()
const searchParams = useSearchParams()
const ranRef = useRef(false)
@@ -30,32 +32,34 @@ function OIDCLoginCallbackContent() {
const nextPath = next && next.startsWith("/") ? next : "/dashboard"
if (!ticket) {
toast.error("OIDC 登录票据不存在")
toast.error(t("auth.oidcMissingTicket"))
router.replace("/dashboard/login")
return
}
void exchangeOIDCTicket(ticket)
.then(() => {
toast.success("登录成功,正在进入系统")
toast.success(t("auth.loginSuccess"))
router.replace(nextPath)
})
.catch((error) => {
toast.error(error instanceof Error ? error.message : "OIDC 登录失败")
toast.error(error instanceof Error ? error.message : t("auth.oidcFailed"))
router.replace("/dashboard/login")
})
}, [router, searchParams])
}, [router, searchParams, t])
return <OIDCLoginCallbackFallback />
}
function OIDCLoginCallbackFallback() {
const t = useI18n()
return (
<div className="flex min-h-svh items-center justify-center bg-[linear-gradient(145deg,#fff7ed_0%,#ffffff_32%,#ecfeff_100%)] px-6">
<div className="w-full max-w-md rounded-[28px] border border-white/70 bg-white/90 p-8 text-center shadow-[0_24px_80px_rgba(15,23,42,0.08)] backdrop-blur">
<h1 className="text-2xl font-semibold tracking-tight">OIDC </h1>
<h1 className="text-2xl font-semibold tracking-tight">{t("auth.oidcSigningIn")}</h1>
<p className="mt-3 text-sm text-muted-foreground">
{t("auth.checkingTicket")}
</p>
</div>
</div>
+20 -18
View File
@@ -1,9 +1,20 @@
"use client"
import { LoginForm } from "@/components/login-form"
import { LocaleSwitcher } from "@/components/locale-switcher"
import { useI18n } from "@/i18n/provider"
import { ShieldCheckIcon } from "lucide-react"
import Link from "next/link"
import { Suspense } from "react"
export default function LoginPage() {
const t = useI18n()
const heroPoints = [
t("auth.heroPoint1"),
t("auth.heroPoint2"),
t("auth.heroPoint3"),
]
return (
<div className="grid min-h-svh bg-[linear-gradient(145deg,#fff7ed_0%,#ffffff_32%,#ecfeff_100%)] lg:grid-cols-[1.1fr_0.9fr]">
<div className="relative hidden overflow-hidden border-r bg-[radial-gradient(circle_at_top_left,rgba(251,191,36,0.18),transparent_30%),radial-gradient(circle_at_bottom_right,rgba(6,182,212,0.18),transparent_28%),linear-gradient(145deg,#111827_0%,#1f2937_35%,#0f172a_100%)] lg:block">
@@ -12,51 +23,42 @@ export default function LoginPage() {
<div className="space-y-5">
<div className="inline-flex items-center gap-2 rounded-full border border-white/15 bg-white/8 px-3 py-1 text-xs tracking-[0.2em] uppercase text-white/80">
<ShieldCheckIcon className="size-3.5" />
Secure Admin Space
{t("auth.heroBadge")}
</div>
<div className="space-y-3">
<h2 className="max-w-lg text-5xl font-semibold tracking-tight">
AI客服
{t("auth.heroTitle")}
</h2>
<p className="max-w-xl text-sm leading-6 text-white/72">
{t("auth.heroSubtitle")}
</p>
</div>
</div>
<div className="grid gap-3">
{[
{
text: "让每一次咨询,都通向可追踪的结果。",
},
{
text: "从接待到转派到复盘,一条链路跑到底。",
},
{
text: "多渠道接入,智能分配,人机协同提效。",
},
].map((item, index) => (
{heroPoints.map((text, index) => (
<div
key={index}
className="rounded-2xl border border-white/10 bg-white/7 p-4 backdrop-blur"
>
<p className="text-sm leading-6 text-white/70">{item.text}</p>
<p className="text-sm leading-6 text-white/70">{text}</p>
</div>
))}
</div>
</div>
</div>
<div className="flex flex-col gap-4 p-6 md:p-10">
<div className="flex justify-center gap-2 md:justify-start">
<div className="flex items-center justify-between gap-2">
<Link href="/dashboard/login" className="flex items-center gap-2 font-medium">
<img
src="/images/logo.svg"
alt="CS Agent"
alt={t("app.brand")}
width="32"
height="32"
className="size-7 shrink-0 object-contain"
/>
CS Agent
{t("app.brand")}
</Link>
<LocaleSwitcher />
</div>
<div className="flex flex-1 items-center justify-center">
<div className="w-full max-w-md rounded-[28px] border border-white/70 bg-white/90 p-8 shadow-[0_24px_80px_rgba(15,23,42,0.08)] backdrop-blur">
@@ -5,6 +5,7 @@ import { Suspense, useEffect, useRef } from "react"
import { toast } from "sonner"
import { exchangeWxWorkTicket } from "@/lib/api/auth"
import { useI18n } from "@/i18n/provider"
export default function WxWorkLoginCallbackPage() {
return (
@@ -15,6 +16,7 @@ export default function WxWorkLoginCallbackPage() {
}
function WxWorkLoginCallbackContent() {
const t = useI18n()
const router = useRouter()
const searchParams = useSearchParams()
const ranRef = useRef(false)
@@ -30,21 +32,21 @@ function WxWorkLoginCallbackContent() {
const nextPath = next && next.startsWith("/") ? next : "/dashboard"
if (!ticket) {
toast.error("企业微信登录票据不存在")
toast.error(t("auth.wxworkMissingTicket"))
router.replace("/dashboard/login")
return
}
void exchangeWxWorkTicket(ticket)
.then(() => {
toast.success("登录成功,正在进入系统")
toast.success(t("auth.loginSuccess"))
router.replace(nextPath)
})
.catch((error) => {
toast.error(error instanceof Error ? error.message : "企业微信登录失败")
toast.error(error instanceof Error ? error.message : t("auth.wxworkFailed"))
router.replace("/dashboard/login")
})
}, [router, searchParams])
}, [router, searchParams, t])
return (
<WxWorkLoginCallbackFallback />
@@ -52,12 +54,14 @@ function WxWorkLoginCallbackContent() {
}
function WxWorkLoginCallbackFallback() {
const t = useI18n()
return (
<div className="flex min-h-svh items-center justify-center bg-[linear-gradient(145deg,#fff7ed_0%,#ffffff_32%,#ecfeff_100%)] px-6">
<div className="w-full max-w-md rounded-[28px] border border-white/70 bg-white/90 p-8 text-center shadow-[0_24px_80px_rgba(15,23,42,0.08)] backdrop-blur">
<h1 className="text-2xl font-semibold tracking-tight"></h1>
<h1 className="text-2xl font-semibold tracking-tight">{t("auth.wxworkSigningIn")}</h1>
<p className="mt-3 text-sm text-muted-foreground">
{t("auth.checkingTicket")}
</p>
</div>
</div>