feat: 增加管理端多语言与多模块界面国际化支持

This commit is contained in:
2026-05-19 09:11:55 +08:00
parent 49a4caf01e
commit 1b1dfc92ab
110 changed files with 4053 additions and 1308 deletions

View File

@@ -1,6 +1,7 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import {
getAdminJackpotPools,
@@ -53,6 +54,7 @@ function toDraft(p: AdminJackpotPoolRow): Draft {
}
export function JackpotPoolsConsole() {
const { t } = useTranslation(["jackpot", "common"]);
const [items, setItems] = useState<AdminJackpotPoolRow[]>([]);
const [drafts, setDrafts] = useState<Record<number, Draft>>({});
const [loading, setLoading] = useState(true);
@@ -70,11 +72,11 @@ export function JackpotPoolsConsole() {
}
setDrafts(d);
} catch (e) {
toast.error(e instanceof LotteryApiBizError ? e.message : "加载失败");
toast.error(e instanceof LotteryApiBizError ? e.message : t("loadFailed"));
} finally {
setLoading(false);
}
}, []);
}, [t]);
useEffect(() => {
queueMicrotask(() => {
@@ -107,10 +109,10 @@ export function JackpotPoolsConsole() {
.filter(Boolean),
status: Number.parseInt(d.status, 10),
});
toast.success("已保存");
toast.success(t("saveSuccess"));
await load();
} catch (e) {
toast.error(e instanceof LotteryApiBizError ? e.message : "保存失败");
toast.error(e instanceof LotteryApiBizError ? e.message : t("saveFailed"));
} finally {
setSavingId(null);
}
@@ -121,7 +123,7 @@ export function JackpotPoolsConsole() {
if (!d) return;
const drawId = Number.parseInt(d.manual_burst_draw_id, 10);
if (!Number.isFinite(drawId) || drawId <= 0) {
toast.error("请填写有效的期号 ID");
toast.error(t("invalidDrawId"));
return;
}
@@ -135,10 +137,10 @@ export function JackpotPoolsConsole() {
draw_id: drawId,
amount: amount !== undefined && Number.isFinite(amount) ? amount : undefined,
});
toast.success("已手动触发爆池");
toast.success(t("manualBurstSuccess"));
await load();
} catch (e) {
toast.error(e instanceof LotteryApiBizError ? e.message : "手动爆池失败");
toast.error(e instanceof LotteryApiBizError ? e.message : t("manualBurstFailed"));
} finally {
setBurstingId(null);
}
@@ -148,12 +150,12 @@ export function JackpotPoolsConsole() {
<ModuleScaffold>
<Card>
<CardHeader>
<CardTitle className="text-base">Jackpot </CardTitle>
<CardTitle className="text-base">{t("configTitle")}</CardTitle>
</CardHeader>
<CardContent className="space-y-8">
{loading ? <p className="text-muted-foreground text-sm"></p> : null}
{loading ? <p className="text-muted-foreground text-sm">{t("states.loading", { ns: "common" })}</p> : null}
{!loading && items.length === 0 ? (
<p className="text-muted-foreground text-sm"></p>
<p className="text-muted-foreground text-sm">{t("noPoolData")}</p>
) : null}
{items.map((p) => {
const d = drafts[p.id] ?? toDraft(p);
@@ -162,12 +164,14 @@ export function JackpotPoolsConsole() {
<div className="flex flex-wrap items-baseline justify-between gap-2">
<h3 className="font-mono text-sm font-semibold">{p.currency_code}</h3>
<span className="text-xs text-muted-foreground">
{formatAdminMinorUnits(p.current_amount, p.currency_code)}
{t("displayBalance", {
amount: formatAdminMinorUnits(p.current_amount, p.currency_code),
})}
</span>
</div>
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
<div className="space-y-1.5">
<Label htmlFor={`amt-${p.id}`}></Label>
<Label htmlFor={`amt-${p.id}`}>{t("currentAmount")}</Label>
<Input
id={`amt-${p.id}`}
className="font-mono"
@@ -176,7 +180,7 @@ export function JackpotPoolsConsole() {
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`cr-${p.id}`}> 01</Label>
<Label htmlFor={`cr-${p.id}`}>{t("contributionRate")}</Label>
<Input
id={`cr-${p.id}`}
className="font-mono"
@@ -185,7 +189,7 @@ export function JackpotPoolsConsole() {
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`th-${p.id}`}></Label>
<Label htmlFor={`th-${p.id}`}>{t("triggerThreshold")}</Label>
<Input
id={`th-${p.id}`}
className="font-mono"
@@ -194,7 +198,7 @@ export function JackpotPoolsConsole() {
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`pr-${p.id}`}> 01</Label>
<Label htmlFor={`pr-${p.id}`}>{t("payoutRate")}</Label>
<Input
id={`pr-${p.id}`}
className="font-mono"
@@ -203,7 +207,7 @@ export function JackpotPoolsConsole() {
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`gap-${p.id}`}></Label>
<Label htmlFor={`gap-${p.id}`}>{t("forceTriggerGap")}</Label>
<Input
id={`gap-${p.id}`}
className="font-mono"
@@ -212,7 +216,7 @@ export function JackpotPoolsConsole() {
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`min-${p.id}`}></Label>
<Label htmlFor={`min-${p.id}`}>{t("minBetAmount")}</Label>
<Input
id={`min-${p.id}`}
className="font-mono"
@@ -221,7 +225,7 @@ export function JackpotPoolsConsole() {
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`combo-${p.id}`}></Label>
<Label htmlFor={`combo-${p.id}`}>{t("comboTriggerPlays")}</Label>
<Input
id={`combo-${p.id}`}
className="font-mono"
@@ -231,7 +235,7 @@ export function JackpotPoolsConsole() {
/>
</div>
<div className="space-y-1.5">
<Label></Label>
<Label>{t("status")}</Label>
<Select
value={d.status}
onValueChange={(v) => updateDraft(p.id, { status: v ?? "0" })}
@@ -240,21 +244,21 @@ export function JackpotPoolsConsole() {
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="0"></SelectItem>
<SelectItem value="1"></SelectItem>
<SelectItem value="0">{t("disabled")}</SelectItem>
<SelectItem value="1">{t("enabled")}</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div className="flex justify-end">
<Button type="button" disabled={savingId === p.id} onClick={() => void save(p)}>
{savingId === p.id ? "保存中…" : "保存"}
{savingId === p.id ? t("saving") : t("save")}
</Button>
</div>
<div className="rounded-md border border-amber-200 bg-amber-50 p-3">
<div className="grid gap-3 sm:grid-cols-[1fr_1fr_auto] sm:items-end">
<div className="space-y-1.5">
<Label htmlFor={`burst-draw-${p.id}`}> ID</Label>
<Label htmlFor={`burst-draw-${p.id}`}>{t("manualBurstDrawId")}</Label>
<Input
id={`burst-draw-${p.id}`}
className="font-mono"
@@ -263,7 +267,7 @@ export function JackpotPoolsConsole() {
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`burst-amount-${p.id}`}></Label>
<Label htmlFor={`burst-amount-${p.id}`}>{t("manualBurstAmount")}</Label>
<Input
id={`burst-amount-${p.id}`}
className="font-mono"
@@ -277,7 +281,7 @@ export function JackpotPoolsConsole() {
disabled={burstingId === p.id}
onClick={() => void manualBurst(p)}
>
{burstingId === p.id ? "处理中…" : "手动爆池"}
{burstingId === p.id ? t("processing") : t("manualBurst")}
</Button>
</div>
</div>

View File

@@ -1,6 +1,7 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { getAdminJackpotContributions, getAdminJackpotPayoutLogs } from "@/api/admin-jackpot";
import { AdminListPaginationFooter } from "@/components/admin/admin-list-pagination-footer";
@@ -26,6 +27,7 @@ import type {
} from "@/types/api/admin-jackpot";
export function JackpotRecordsConsole() {
const { t } = useTranslation(["jackpot", "common"]);
const formatDt = useAdminDateTimeFormatter();
const [drawNo, setDrawNo] = useState("");
const [appliedDrawNo, setAppliedDrawNo] = useState("");
@@ -52,11 +54,11 @@ export function JackpotRecordsConsole() {
});
setPayouts(d);
} catch (e) {
setErr(e instanceof LotteryApiBizError ? e.message : "派彩记录加载失败");
setErr(e instanceof LotteryApiBizError ? e.message : t("payoutLoadFailed"));
} finally {
setLoadingP(false);
}
}, [pPage, pPer, appliedDrawNo]);
}, [pPage, pPer, appliedDrawNo, t]);
const loadContribs = useCallback(async () => {
setLoadingC(true);
@@ -68,11 +70,11 @@ export function JackpotRecordsConsole() {
});
setContribs(d);
} catch (e) {
setErr(e instanceof LotteryApiBizError ? e.message : "蓄水记录加载失败");
setErr(e instanceof LotteryApiBizError ? e.message : t("contributionLoadFailed"));
} finally {
setLoadingC(false);
}
}, [cPage, cPer, appliedDrawNo]);
}, [cPage, cPer, appliedDrawNo, t]);
useEffect(() => {
queueMicrotask(() => {
@@ -96,21 +98,21 @@ export function JackpotRecordsConsole() {
<ModuleScaffold>
<Card className="mb-6">
<CardHeader className="pb-3">
<CardTitle className="text-base"></CardTitle>
<CardTitle className="text-base">{t("filter")}</CardTitle>
</CardHeader>
<CardContent className="flex flex-col gap-3 sm:flex-row sm:items-end">
<div className="flex max-w-xs flex-1 flex-col gap-1.5">
<Label htmlFor="jk-draw"></Label>
<Label htmlFor="jk-draw">{t("drawNo")}</Label>
<Input
id="jk-draw"
className="font-mono"
value={drawNo}
onChange={(e) => setDrawNo(e.target.value)}
placeholder="可选"
placeholder={t("optional")}
/>
</div>
<Button type="button" onClick={applyDraw}>
{t("apply")}
</Button>
</CardContent>
</Card>
@@ -119,21 +121,21 @@ export function JackpotRecordsConsole() {
<Card className="mb-8">
<CardHeader>
<CardTitle className="text-base">Jackpot </CardTitle>
<CardTitle className="text-base">{t("payoutRecords")}</CardTitle>
</CardHeader>
<CardContent>
{loadingP && !payouts ? (
<p className="text-muted-foreground text-sm"></p>
<p className="text-muted-foreground text-sm">{t("states.loading", { ns: "common" })}</p>
) : (
<Table>
<TableHeader>
<TableRow>
<TableHead>ID</TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead></TableHead>
<TableHead>{t("drawNo")}</TableHead>
<TableHead>{t("trigger")}</TableHead>
<TableHead className="text-right">{t("payoutAmount")}</TableHead>
<TableHead className="text-right">{t("winnerCount")}</TableHead>
<TableHead>{t("time")}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
@@ -174,21 +176,21 @@ export function JackpotRecordsConsole() {
<Card>
<CardHeader>
<CardTitle className="text-base">Jackpot </CardTitle>
<CardTitle className="text-base">{t("contributionRecords")}</CardTitle>
</CardHeader>
<CardContent>
{loadingC && !contribs ? (
<p className="text-muted-foreground text-sm"></p>
<p className="text-muted-foreground text-sm">{t("states.loading", { ns: "common" })}</p>
) : (
<Table>
<TableHeader>
<TableRow>
<TableHead>ID</TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead></TableHead>
<TableHead>{t("drawNo")}</TableHead>
<TableHead>{t("ticketNo")}</TableHead>
<TableHead>{t("player")}</TableHead>
<TableHead className="text-right">{t("contributionAmount")}</TableHead>
<TableHead>{t("time")}</TableHead>
</TableRow>
</TableHeader>
<TableBody>

View File

@@ -2,19 +2,21 @@
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useTranslation } from "react-i18next";
import { cn } from "@/lib/utils";
const LINKS: { href: string; label: string }[] = [
{ href: "/admin/jackpot/pools", label: "奖池配置" },
{ href: "/admin/jackpot/records", label: "记录" },
{ href: "/admin/jackpot/pools", label: "subnavPools" },
{ href: "/admin/jackpot/records", label: "subnavRecords" },
];
export function JackpotSubNav() {
const { t } = useTranslation("jackpot");
const pathname = usePathname();
return (
<nav className="mb-6 flex flex-wrap gap-2 border-b border-border pb-3" aria-label="Jackpot 子导航">
<nav className="mb-6 flex flex-wrap gap-2 border-b border-border pb-3" aria-label={t("subnavLabel")}>
{LINKS.map(({ href, label }) => {
const active = pathname === href || pathname.startsWith(`${href}/`);
return (
@@ -28,7 +30,7 @@ export function JackpotSubNav() {
: "bg-muted/60 text-muted-foreground hover:bg-muted hover:text-foreground",
)}
>
{label}
{t(label)}
</Link>
);
})}

View File

@@ -1,4 +1,4 @@
export const jackpotModuleMeta = {
title: "奖池",
title: "Jackpot",
description: "",
} as const;