refactor(layout, i18n, admin): 优化布局结构与多语言支持
调整 AdminShell 组件的子组件顺序,提升代码可读性。更新 admin-breadcrumb 组件,简化导航标签翻译逻辑,确保多语言支持的一致性。重构 admin-language-switcher 组件,优化语言切换的用户体验,增强界面交互性。更新多语言配置,新增登录界面的副标题,提升用户体验。
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
@@ -50,6 +51,16 @@ import type {
|
||||
OddsVersionDetail,
|
||||
} from "@/types/api/admin-config";
|
||||
|
||||
import { ConfigWorkflowSection } from "@/modules/config/config-workflow-section";
|
||||
import {
|
||||
OddsConfigSummaryPanel,
|
||||
playRebatePercentFromScopes,
|
||||
} from "@/modules/config/doc/odds-config-summary-panel";
|
||||
import {
|
||||
buildOddsPlayFilterGroups,
|
||||
filterOddsPlayTypesByCategory,
|
||||
type OddsCategoryTab,
|
||||
} from "@/modules/config/doc/odds-play-type-groups";
|
||||
import {
|
||||
PRIZE_SCOPE_MULTIPLIER_HINT,
|
||||
PRIZE_SCOPE_ORDER,
|
||||
@@ -57,7 +68,7 @@ import {
|
||||
type PrizeScopeCode,
|
||||
} from "@/modules/config/doc/prize-scopes";
|
||||
|
||||
type CatTab = "all" | "d4" | "d3" | "d2";
|
||||
type CatTab = OddsCategoryTab;
|
||||
|
||||
function oddsMultiplierLabel(oddsValue: number): string {
|
||||
return (oddsValue / 10000).toFixed(4);
|
||||
@@ -72,17 +83,13 @@ function parseOddsMultiplierInput(raw: string): number {
|
||||
return Number.isSafeInteger(scaled) ? scaled : 0;
|
||||
}
|
||||
|
||||
function filterTypes(tab: CatTab, types: AdminPlayTypeRow[]): AdminPlayTypeRow[] {
|
||||
if (tab === "all") {
|
||||
return types;
|
||||
}
|
||||
const dim = tab === "d4" ? 4 : tab === "d3" ? 3 : 2;
|
||||
return types.filter((t) => t.dimension === dim);
|
||||
}
|
||||
|
||||
type OddsConfigDocScreenProps = {
|
||||
/** 嵌入「赔率与回水」合并页时去掉外层 ConfigDocPage */
|
||||
embedded?: boolean;
|
||||
/** 合并页:左侧三步骤 + 右侧配置摘要(参考设计稿) */
|
||||
mergedLayout?: boolean;
|
||||
/** 合并页第 3 步:佣金 / 回水 */
|
||||
rebateSection?: ReactNode;
|
||||
/** 合并页共享数据层(避免与回水区块重复拉取版本详情) */
|
||||
workspace?: OddsConfigWorkspace;
|
||||
/** 与回水分区共用版本选择(无 workspace 时) */
|
||||
@@ -92,6 +99,8 @@ type OddsConfigDocScreenProps = {
|
||||
|
||||
export function OddsConfigDocScreen({
|
||||
embedded = false,
|
||||
mergedLayout = false,
|
||||
rebateSection,
|
||||
workspace,
|
||||
versionId: controlledVersionId,
|
||||
onVersionIdChange,
|
||||
@@ -234,7 +243,15 @@ export function OddsConfigDocScreen({
|
||||
[resolvedTypes],
|
||||
);
|
||||
|
||||
const filteredTypes = useMemo(() => filterTypes(catTab, sortedTypes), [catTab, sortedTypes]);
|
||||
const filteredTypes = useMemo(
|
||||
() => filterOddsPlayTypesByCategory(catTab, sortedTypes),
|
||||
[catTab, sortedTypes],
|
||||
);
|
||||
|
||||
const playFilterGroups = useMemo(
|
||||
() => buildOddsPlayFilterGroups(catTab, sortedTypes),
|
||||
[catTab, sortedTypes],
|
||||
);
|
||||
|
||||
const resolvedPlayCode = useMemo(() => {
|
||||
if (filteredTypes.length === 0) {
|
||||
@@ -483,8 +500,13 @@ export function OddsConfigDocScreen({
|
||||
{ id: "d2", label: "2D" },
|
||||
];
|
||||
|
||||
const filtersBlock = (
|
||||
<div className={cn("space-y-3", embedded ? "border-t border-border/50 px-3 py-3 sm:px-4" : "rounded-xl border border-border/60 bg-card p-4")}>
|
||||
const activeCatLabel = catTabs.find((tab) => tab.id === catTab)?.label ?? catTab;
|
||||
const activePlayLabel = resolvedPlayCode
|
||||
? resolveAdminPlayTypeDisplayName(resolvedPlayCode, i18n.language, sortedTypes.find((t) => t.play_code === resolvedPlayCode))
|
||||
: "—";
|
||||
|
||||
const filtersInner = (
|
||||
<>
|
||||
<ConfigChipGroup label={t("odds.category", { ns: "config" })}>
|
||||
{catTabs.map((tab) => (
|
||||
<ConfigChip
|
||||
@@ -496,24 +518,62 @@ export function OddsConfigDocScreen({
|
||||
</ConfigChip>
|
||||
))}
|
||||
</ConfigChipGroup>
|
||||
<ConfigChipGroup label={t("odds.playType", { ns: "config" })}>
|
||||
{filteredTypes.length === 0 ? (
|
||||
<span className="text-sm text-muted-foreground">{t("odds.noPlayTypes", { ns: "config" })}</span>
|
||||
) : (
|
||||
<div className="-mx-1 flex gap-1.5 overflow-x-auto px-1 pb-0.5">
|
||||
{filteredTypes.map((type) => (
|
||||
<ConfigChip
|
||||
key={type.play_code}
|
||||
active={resolvedPlayCode === type.play_code}
|
||||
onClick={() => setPlayCode(type.play_code)}
|
||||
className="shrink-0"
|
||||
{mergedLayout ? (
|
||||
<div className="space-y-4">
|
||||
{playFilterGroups.length === 0 ? (
|
||||
<span className="text-sm text-muted-foreground">{t("odds.noPlayTypes", { ns: "config" })}</span>
|
||||
) : (
|
||||
playFilterGroups.map((group) => (
|
||||
<ConfigChipGroup
|
||||
key={group.key}
|
||||
label={t(`odds.playGroups.${group.key}`, { ns: "config" })}
|
||||
>
|
||||
{resolveAdminPlayTypeDisplayName(type.play_code, i18n.language, type)}
|
||||
</ConfigChip>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</ConfigChipGroup>
|
||||
{group.types.map((type) => (
|
||||
<ConfigChip
|
||||
key={type.play_code}
|
||||
active={resolvedPlayCode === type.play_code}
|
||||
onClick={() => setPlayCode(type.play_code)}
|
||||
>
|
||||
{resolveAdminPlayTypeDisplayName(type.play_code, i18n.language, type)}
|
||||
</ConfigChip>
|
||||
))}
|
||||
</ConfigChipGroup>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<ConfigChipGroup label={t("odds.playType", { ns: "config" })}>
|
||||
{filteredTypes.length === 0 ? (
|
||||
<span className="text-sm text-muted-foreground">{t("odds.noPlayTypes", { ns: "config" })}</span>
|
||||
) : (
|
||||
<div className="-mx-1 flex gap-1.5 overflow-x-auto px-1 pb-0.5">
|
||||
{filteredTypes.map((type) => (
|
||||
<ConfigChip
|
||||
key={type.play_code}
|
||||
active={resolvedPlayCode === type.play_code}
|
||||
onClick={() => setPlayCode(type.play_code)}
|
||||
className="shrink-0"
|
||||
>
|
||||
{resolveAdminPlayTypeDisplayName(type.play_code, i18n.language, type)}
|
||||
</ConfigChip>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</ConfigChipGroup>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
const filtersBlock = mergedLayout ? (
|
||||
filtersInner
|
||||
) : (
|
||||
<div
|
||||
className={cn(
|
||||
"space-y-3",
|
||||
embedded ? "border-t border-border/50 px-3 py-3 sm:px-4" : "rounded-xl border border-border/60 bg-card p-4",
|
||||
)}
|
||||
>
|
||||
{filtersInner}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -578,16 +638,12 @@ export function OddsConfigDocScreen({
|
||||
{resolvedError ? <p className="text-sm text-destructive">{resolvedError}</p> : null}
|
||||
|
||||
{resolvedLoadingDetail || resolvedLoadingTypes ? (
|
||||
<p className="py-8 text-center text-sm text-muted-foreground">
|
||||
<p className={cn("text-center text-sm text-muted-foreground", mergedLayout ? "py-6" : "py-8")}>
|
||||
{t("odds.loadingDetails", { ns: "config" })}
|
||||
</p>
|
||||
) : resolvedPlayCode ? (
|
||||
<div
|
||||
className={cn(
|
||||
embedded ? "rounded-xl border border-border/60 bg-card p-4" : undefined,
|
||||
)}
|
||||
>
|
||||
<div className="grid grid-cols-2 gap-x-4 gap-y-4 sm:grid-cols-3 lg:grid-cols-6">
|
||||
<div className={cn(!mergedLayout && embedded ? "rounded-xl border border-border/60 bg-card p-4" : undefined)}>
|
||||
<div className="grid grid-cols-2 gap-x-4 gap-y-4 sm:grid-cols-3">
|
||||
{PRIZE_SCOPE_ORDER.map((scope) => {
|
||||
const row = scopeRows[scope];
|
||||
const hint = embedded ? null : PRIZE_SCOPE_MULTIPLIER_HINT[scope];
|
||||
@@ -721,6 +777,43 @@ export function OddsConfigDocScreen({
|
||||
</>
|
||||
);
|
||||
|
||||
if (embedded && mergedLayout) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="overflow-hidden rounded-xl border border-border/60 bg-card">{toolbarBlock}</div>
|
||||
<div className="grid gap-6 xl:grid-cols-[minmax(0,1fr)_min(100%,300px)] xl:items-start">
|
||||
<div className="space-y-6">
|
||||
<ConfigWorkflowSection step={1} title={t("odds.sections.playScope", { ns: "config" })}>
|
||||
{filtersBlock}
|
||||
</ConfigWorkflowSection>
|
||||
<ConfigWorkflowSection
|
||||
step={2}
|
||||
title={t("odds.sections.oddsConfig", { ns: "config" })}
|
||||
description={t("odds.currentSelection", {
|
||||
ns: "config",
|
||||
category: activeCatLabel,
|
||||
play: activePlayLabel,
|
||||
})}
|
||||
>
|
||||
{mainBlock}
|
||||
</ConfigWorkflowSection>
|
||||
{rebateSection}
|
||||
</div>
|
||||
<OddsConfigSummaryPanel
|
||||
catTabLabel={activeCatLabel}
|
||||
playLabel={activePlayLabel}
|
||||
detail={resolvedDetail}
|
||||
draftRows={resolvedDraftRows}
|
||||
types={sortedTypes}
|
||||
scopeRows={scopeRows}
|
||||
playRebatePercent={playRebatePercentFromScopes(scopeRows, PRIZE_SCOPE_ORDER)}
|
||||
/>
|
||||
</div>
|
||||
{dialogs}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (embedded) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
|
||||
157
src/modules/config/doc/odds-config-summary-panel.tsx
Normal file
157
src/modules/config/doc/odds-config-summary-panel.tsx
Normal file
@@ -0,0 +1,157 @@
|
||||
"use client";
|
||||
|
||||
import { FileText, Info } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { ConfigStatusBadge } from "@/modules/config/config-status-badge";
|
||||
import { inferRebatePercentFromDimension, rateToPercentUi } from "@/modules/config/doc/odds-rebate-rates";
|
||||
import { prizeScopeLabel, type PrizeScopeCode } from "@/modules/config/doc/prize-scopes";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { AdminPlayTypeRow, OddsItemRow, OddsVersionDetail } from "@/types/api/admin-config";
|
||||
|
||||
function oddsMultiplierLabel(oddsValue: number): string {
|
||||
return (oddsValue / 10000).toFixed(4);
|
||||
}
|
||||
|
||||
type SummaryRow = {
|
||||
label: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
type OddsConfigSummaryPanelProps = {
|
||||
catTabLabel: string;
|
||||
playLabel: string;
|
||||
detail: OddsVersionDetail | null;
|
||||
draftRows: OddsItemRow[];
|
||||
types: AdminPlayTypeRow[];
|
||||
scopeRows: Partial<Record<PrizeScopeCode, OddsItemRow>>;
|
||||
playRebatePercent: string;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export function OddsConfigSummaryPanel({
|
||||
catTabLabel,
|
||||
playLabel,
|
||||
detail,
|
||||
draftRows,
|
||||
types,
|
||||
scopeRows,
|
||||
playRebatePercent,
|
||||
className,
|
||||
}: OddsConfigSummaryPanelProps) {
|
||||
const { t } = useTranslation("config");
|
||||
|
||||
const isDraft = detail?.status === "draft";
|
||||
const isActive = detail?.status === "active";
|
||||
|
||||
const rows: SummaryRow[] = [
|
||||
{ label: t("odds.category"), value: catTabLabel },
|
||||
{ label: t("odds.playType"), value: playLabel || "—" },
|
||||
];
|
||||
|
||||
for (const scope of ["first", "second", "third", "starter", "consolation"] as PrizeScopeCode[]) {
|
||||
const row = scopeRows[scope];
|
||||
rows.push({
|
||||
label: prizeScopeLabel(scope, t),
|
||||
value: row ? oddsMultiplierLabel(row.odds_value) : "—",
|
||||
});
|
||||
}
|
||||
|
||||
rows.push({
|
||||
label: t("odds.rebateRate"),
|
||||
value: playRebatePercent,
|
||||
});
|
||||
|
||||
rows.push(
|
||||
{
|
||||
label: t("rebate.fields.d2"),
|
||||
value: inferRebatePercentFromDimension(2, draftRows, types),
|
||||
},
|
||||
{
|
||||
label: t("rebate.fields.d3"),
|
||||
value: inferRebatePercentFromDimension(3, draftRows, types),
|
||||
},
|
||||
{
|
||||
label: t("rebate.fields.d4"),
|
||||
value: inferRebatePercentFromDimension(4, draftRows, types),
|
||||
},
|
||||
);
|
||||
|
||||
const versionLabel = detail ? `v${detail.version_no}` : "—";
|
||||
|
||||
return (
|
||||
<aside
|
||||
className={cn(
|
||||
"lg:sticky lg:top-24 lg:max-h-[calc(100vh-7rem)] lg:overflow-y-auto",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<div className="overflow-hidden rounded-xl border border-border/60 bg-card">
|
||||
<div className="flex items-center gap-2 border-b border-border/50 px-4 py-3.5">
|
||||
<FileText className="size-4 text-primary" aria-hidden />
|
||||
<h3 className="text-base font-semibold">{t("odds.summary.title")}</h3>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4 px-4 py-4">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-sm text-muted-foreground">{t("odds.summary.version")}</span>
|
||||
<span className="font-mono text-sm font-medium">{versionLabel}</span>
|
||||
{detail ? <ConfigStatusBadge status={detail.status} /> : null}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-sm text-muted-foreground">{t("odds.summary.statusLabel")}</span>
|
||||
{detail && !isDraft ? (
|
||||
<span className="inline-flex items-center rounded-md border border-border/60 bg-muted/40 px-2 py-0.5 text-xs font-medium text-muted-foreground">
|
||||
{t("odds.summary.readOnlyTag")}
|
||||
</span>
|
||||
) : isDraft ? (
|
||||
<span className="inline-flex items-center rounded-md border border-primary/25 bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary">
|
||||
{t("versionStatus.draft")}
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-sm">—</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<dl className="space-y-2.5">
|
||||
{rows.map((row) => (
|
||||
<div key={row.label} className="grid grid-cols-[minmax(0,1fr)_auto] gap-3 text-sm">
|
||||
<dt className="text-muted-foreground">{row.label}</dt>
|
||||
<dd className="font-mono text-right tabular-nums text-foreground">{row.value}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
|
||||
{detail && !isDraft ? (
|
||||
<Alert className="border-sky-500/30 bg-sky-500/5 text-foreground">
|
||||
<Info className="size-4 text-sky-600 dark:text-sky-400" aria-hidden />
|
||||
<AlertDescription className="text-xs leading-relaxed">
|
||||
{t("odds.summary.readOnlyHint")}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
) : isActive ? (
|
||||
<Alert className="border-emerald-500/30 bg-emerald-500/5 text-foreground">
|
||||
<AlertDescription className="text-xs leading-relaxed">
|
||||
{t("odds.summary.activeHint")}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
/** 当前玩法在摘要中展示的回水百分比(与赔率区输入一致)。 */
|
||||
export function playRebatePercentFromScopes(
|
||||
scopeRows: Partial<Record<PrizeScopeCode, OddsItemRow>>,
|
||||
order: readonly PrizeScopeCode[],
|
||||
): string {
|
||||
const first = order.map((s) => scopeRows[s]).find(Boolean);
|
||||
if (!first) {
|
||||
return "0";
|
||||
}
|
||||
return rateToPercentUi(String(first.rebate_rate));
|
||||
}
|
||||
60
src/modules/config/doc/odds-play-type-groups.ts
Normal file
60
src/modules/config/doc/odds-play-type-groups.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import type { AdminPlayTypeRow } from "@/types/api/admin-config";
|
||||
|
||||
export type OddsCategoryTab = "all" | "d4" | "d3" | "d2";
|
||||
|
||||
export type OddsPlayFilterGroupKey = "bigSmall" | "combo4" | "number3" | "number2" | "other";
|
||||
|
||||
type GroupDef = {
|
||||
key: OddsPlayFilterGroupKey;
|
||||
match: (row: AdminPlayTypeRow) => boolean;
|
||||
};
|
||||
|
||||
const ODDS_PLAY_FILTER_GROUPS: GroupDef[] = [
|
||||
{
|
||||
key: "bigSmall",
|
||||
match: (row) => row.play_code === "big" || row.play_code === "small",
|
||||
},
|
||||
{
|
||||
key: "combo4",
|
||||
match: (row) => row.category === "position" && row.dimension === 4,
|
||||
},
|
||||
{
|
||||
key: "number3",
|
||||
match: (row) => row.category === "position" && row.dimension === 3,
|
||||
},
|
||||
{
|
||||
key: "number2",
|
||||
match: (row) => row.category === "position" && row.dimension === 2,
|
||||
},
|
||||
{
|
||||
key: "other",
|
||||
match: (row) =>
|
||||
row.category === "box"
|
||||
|| row.category === "attribute"
|
||||
|| (row.category === "standard" && row.play_code !== "big" && row.play_code !== "small"),
|
||||
},
|
||||
];
|
||||
|
||||
export function filterOddsPlayTypesByCategory(
|
||||
tab: OddsCategoryTab,
|
||||
types: AdminPlayTypeRow[],
|
||||
): AdminPlayTypeRow[] {
|
||||
if (tab === "all") {
|
||||
return types;
|
||||
}
|
||||
const dim = tab === "d4" ? 4 : tab === "d3" ? 3 : 2;
|
||||
return types.filter((t) => t.dimension === dim);
|
||||
}
|
||||
|
||||
export function buildOddsPlayFilterGroups(
|
||||
tab: OddsCategoryTab,
|
||||
types: AdminPlayTypeRow[],
|
||||
): { key: OddsPlayFilterGroupKey; types: AdminPlayTypeRow[] }[] {
|
||||
const filtered = filterOddsPlayTypesByCategory(tab, types);
|
||||
return ODDS_PLAY_FILTER_GROUPS.map((def) => ({
|
||||
key: def.key,
|
||||
types: filtered
|
||||
.filter(def.match)
|
||||
.sort((a, b) => a.sort_order - b.sort_order || a.play_code.localeCompare(b.play_code)),
|
||||
})).filter((group) => group.types.length > 0);
|
||||
}
|
||||
29
src/modules/config/doc/odds-rebate-rates.ts
Normal file
29
src/modules/config/doc/odds-rebate-rates.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { PRIZE_SCOPE_ORDER } from "@/modules/config/doc/prize-scopes";
|
||||
import type { AdminPlayTypeRow, OddsItemRow } from "@/types/api/admin-config";
|
||||
|
||||
export function rateToPercentUi(rateStr: string): string {
|
||||
const n = Number.parseFloat(rateStr);
|
||||
if (!Number.isFinite(n)) {
|
||||
return "0.00";
|
||||
}
|
||||
return (Math.round(n * 10000) / 100).toFixed(2);
|
||||
}
|
||||
|
||||
export function inferRebatePercentFromDimension(
|
||||
dim: 2 | 3 | 4,
|
||||
rows: OddsItemRow[],
|
||||
typeList: AdminPlayTypeRow[],
|
||||
): string {
|
||||
const codes = typeList
|
||||
.filter((t) => (t.dimension ?? 2) === dim)
|
||||
.map((t) => t.play_code)
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
const scope = PRIZE_SCOPE_ORDER[0];
|
||||
for (const code of codes) {
|
||||
const hit = rows.find((r) => r.play_code === code && r.prize_scope === scope);
|
||||
if (hit) {
|
||||
return rateToPercentUi(String(hit.rebate_rate));
|
||||
}
|
||||
}
|
||||
return "0.00";
|
||||
}
|
||||
@@ -51,34 +51,16 @@ import type {
|
||||
OddsVersionDetail,
|
||||
} from "@/types/api/admin-config";
|
||||
|
||||
import { ConfigWorkflowSection } from "@/modules/config/config-workflow-section";
|
||||
import {
|
||||
inferRebatePercentFromDimension,
|
||||
rateToPercentUi,
|
||||
} from "@/modules/config/doc/odds-rebate-rates";
|
||||
import { PRIZE_SCOPE_ORDER } from "@/modules/config/doc/prize-scopes";
|
||||
|
||||
const SETTLEMENT_GROUP = "settlement";
|
||||
const APPLY_REBATE_TO_PAYOUT_KEY = "settlement.apply_rebate_to_payout";
|
||||
|
||||
function rateToPercentUi(rateStr: string): string {
|
||||
const n = Number.parseFloat(rateStr);
|
||||
if (!Number.isFinite(n)) {
|
||||
return "0.00";
|
||||
}
|
||||
return (Math.round(n * 10000) / 100).toFixed(2);
|
||||
}
|
||||
|
||||
function inferPercentFrom(dim: 2 | 3 | 4, rows: OddsItemRow[], typeList: AdminPlayTypeRow[]): string {
|
||||
const codes = typeList
|
||||
.filter((t) => (t.dimension ?? 2) === dim)
|
||||
.map((t) => t.play_code)
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
const scope = PRIZE_SCOPE_ORDER[0];
|
||||
for (const code of codes) {
|
||||
const hit = rows.find((r) => r.play_code === code && r.prize_scope === scope);
|
||||
if (hit) {
|
||||
return rateToPercentUi(String(hit.rebate_rate));
|
||||
}
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
function dimensionDistinctPrimaryScopePercents(
|
||||
dim: 2 | 3 | 4,
|
||||
rows: OddsItemRow[],
|
||||
@@ -101,6 +83,8 @@ function dimensionDistinctPrimaryScopePercents(
|
||||
|
||||
type RebateConfigDocScreenProps = {
|
||||
embedded?: boolean;
|
||||
/** 合并页第 3 步卡片 */
|
||||
mergedSection?: boolean;
|
||||
workspace?: OddsConfigWorkspace;
|
||||
versionId?: string;
|
||||
onVersionIdChange?: (id: string) => void;
|
||||
@@ -108,6 +92,7 @@ type RebateConfigDocScreenProps = {
|
||||
|
||||
export function RebateConfigDocScreen({
|
||||
embedded = false,
|
||||
mergedSection = false,
|
||||
workspace,
|
||||
versionId: controlledVersionId,
|
||||
onVersionIdChange,
|
||||
@@ -205,9 +190,9 @@ export function RebateConfigDocScreen({
|
||||
if (!workspace) {
|
||||
return;
|
||||
}
|
||||
setP2(inferPercentFrom(2, workspace.draftRows, workspace.types));
|
||||
setP3(inferPercentFrom(3, workspace.draftRows, workspace.types));
|
||||
setP4(inferPercentFrom(4, workspace.draftRows, workspace.types));
|
||||
setP2(inferRebatePercentFromDimension(2, workspace.draftRows, workspace.types));
|
||||
setP3(inferRebatePercentFromDimension(3, workspace.draftRows, workspace.types));
|
||||
setP4(inferRebatePercentFromDimension(4, workspace.draftRows, workspace.types));
|
||||
}, [workspace?.draftRows, workspace?.types, workspace]);
|
||||
|
||||
async function handleWinEnjoyChange(checked: boolean): Promise<void> {
|
||||
@@ -236,9 +221,9 @@ export function RebateConfigDocScreen({
|
||||
const rows = d.items.map((it) => ({ ...it }));
|
||||
setDetail(d);
|
||||
setDraftRows(rows);
|
||||
setP2(inferPercentFrom(2, rows, typeList));
|
||||
setP3(inferPercentFrom(3, rows, typeList));
|
||||
setP4(inferPercentFrom(4, rows, typeList));
|
||||
setP2(inferRebatePercentFromDimension(2, rows, typeList));
|
||||
setP3(inferRebatePercentFromDimension(3, rows, typeList));
|
||||
setP4(inferRebatePercentFromDimension(4, rows, typeList));
|
||||
} catch (e) {
|
||||
toast.error(e instanceof LotteryApiBizError ? e.message : t("errors.loadFailed", { ns: "common" }));
|
||||
setDetail(null);
|
||||
@@ -357,9 +342,9 @@ export function RebateConfigDocScreen({
|
||||
setDetail(d);
|
||||
setDraftRows(rows);
|
||||
}
|
||||
setP2(inferPercentFrom(2, rows, resolvedTypes));
|
||||
setP3(inferPercentFrom(3, rows, resolvedTypes));
|
||||
setP4(inferPercentFrom(4, rows, resolvedTypes));
|
||||
setP2(inferRebatePercentFromDimension(2, rows, resolvedTypes));
|
||||
setP3(inferRebatePercentFromDimension(3, rows, resolvedTypes));
|
||||
setP4(inferRebatePercentFromDimension(4, rows, resolvedTypes));
|
||||
toast.success(t("versionActions.saveDraft", { ns: "config" }));
|
||||
void (workspace?.refreshList() ?? refreshList());
|
||||
} catch (e) {
|
||||
@@ -383,9 +368,9 @@ export function RebateConfigDocScreen({
|
||||
setDetail(d);
|
||||
setDraftRows(rows);
|
||||
}
|
||||
setP2(inferPercentFrom(2, rows, resolvedTypes));
|
||||
setP3(inferPercentFrom(3, rows, resolvedTypes));
|
||||
setP4(inferPercentFrom(4, rows, resolvedTypes));
|
||||
setP2(inferRebatePercentFromDimension(2, rows, resolvedTypes));
|
||||
setP3(inferRebatePercentFromDimension(3, rows, resolvedTypes));
|
||||
setP4(inferRebatePercentFromDimension(4, rows, resolvedTypes));
|
||||
toast.success(t("rebate.publishSuccess", { ns: "config" }));
|
||||
void (workspace?.refreshList() ?? refreshList());
|
||||
setSelectedId(String(d.id));
|
||||
@@ -414,9 +399,9 @@ export function RebateConfigDocScreen({
|
||||
setDetail(d);
|
||||
setDraftRows(rows);
|
||||
}
|
||||
setP2(inferPercentFrom(2, rows, resolvedTypes));
|
||||
setP3(inferPercentFrom(3, rows, resolvedTypes));
|
||||
setP4(inferPercentFrom(4, rows, resolvedTypes));
|
||||
setP2(inferRebatePercentFromDimension(2, rows, resolvedTypes));
|
||||
setP3(inferRebatePercentFromDimension(3, rows, resolvedTypes));
|
||||
setP4(inferRebatePercentFromDimension(4, rows, resolvedTypes));
|
||||
} catch (e) {
|
||||
toast.error(e instanceof LotteryApiBizError ? e.message : t("rebate.createDraftFailed", { ns: "config" }));
|
||||
} finally {
|
||||
@@ -457,9 +442,9 @@ export function RebateConfigDocScreen({
|
||||
setDetail(d);
|
||||
setDraftRows(rows);
|
||||
}
|
||||
setP2(inferPercentFrom(2, rows, resolvedTypes));
|
||||
setP3(inferPercentFrom(3, rows, resolvedTypes));
|
||||
setP4(inferPercentFrom(4, rows, resolvedTypes));
|
||||
setP2(inferRebatePercentFromDimension(2, rows, resolvedTypes));
|
||||
setP3(inferRebatePercentFromDimension(3, rows, resolvedTypes));
|
||||
setP4(inferRebatePercentFromDimension(4, rows, resolvedTypes));
|
||||
setRollbackOpen(false);
|
||||
setRollbackTarget(null);
|
||||
} catch (e) {
|
||||
@@ -658,6 +643,23 @@ export function RebateConfigDocScreen({
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
if (embedded && mergedSection) {
|
||||
return (
|
||||
<>
|
||||
<ConfigWorkflowSection
|
||||
step={3}
|
||||
title={t("nav.items.rebate", { ns: "config" })}
|
||||
description={t("rebate.sectionHint", { ns: "config" })}
|
||||
contentClassName="space-y-5"
|
||||
>
|
||||
{fieldsBlock}
|
||||
</ConfigWorkflowSection>
|
||||
{rollbackDialog}
|
||||
<ConfirmDialog />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (embedded) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { Trash2 } from "lucide-react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
publishRiskCapVersion,
|
||||
putRiskCapItems,
|
||||
} from "@/api/admin-config";
|
||||
import { AdminRowActionsMenu } from "@/components/admin/admin-row-actions-menu";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ConfigDocPage, ConfigDocToolbar } from "@/modules/config/config-doc-page";
|
||||
import {
|
||||
@@ -505,7 +507,7 @@ export function RiskCapDocScreen() {
|
||||
<TableRow>
|
||||
<TableHead className="w-[110px]">{t("riskCap.table.number", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[140px]">{t("riskCap.table.capAmount", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[160px]">{t("riskCap.table.actions", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-14 text-center">{t("riskCap.table.actions", { ns: "config" })}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
@@ -549,17 +551,20 @@ export function RiskCapDocScreen() {
|
||||
</ConfigReadonlyValue>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<TableCell className="text-center">
|
||||
{canEditDraft ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
className="text-destructive"
|
||||
disabled={saving}
|
||||
onClick={() => removeRow(idx)}
|
||||
>
|
||||
{t("actions.delete", { ns: "adminUsers" })}
|
||||
</Button>
|
||||
<AdminRowActionsMenu
|
||||
busy={saving}
|
||||
actions={[
|
||||
{
|
||||
key: "delete",
|
||||
label: t("actions.delete", { ns: "adminUsers" }),
|
||||
icon: Trash2,
|
||||
destructive: true,
|
||||
onClick: () => removeRow(idx),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
) : (
|
||||
<span className="text-sm text-muted-foreground">{t("riskCap.readOnly", { ns: "config" })}</span>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user