feat: 增加管理端多语言与多模块界面国际化支持
This commit is contained in:
@@ -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}`}>蓄水比例 0–1</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}`}>爆池派彩比例 0–1</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>
|
||||
|
||||
Reference in New Issue
Block a user