refactor: 移除冗余注释和描述,优化管理员模块的代码结构

This commit is contained in:
2026-05-11 17:21:12 +08:00
parent 217ed7c02f
commit 76e318be8f
57 changed files with 163 additions and 382 deletions

View File

@@ -14,7 +14,6 @@ import {
RefreshCw,
ScrollText,
Shield,
ShieldCheck,
Ticket,
TrendingUp,
Wallet,
@@ -23,7 +22,7 @@ import {
import { getAdminDashboard } from "@/api/admin-dashboard";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button, buttonVariants } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
import { cn } from "@/lib/utils";
import { LotteryApiBizError } from "@/types/api/errors";
@@ -31,7 +30,7 @@ import type { AdminDrawFinanceSummaryData } from "@/types/api/admin-draw-finance
import type { AdminRiskPoolRow } from "@/types/api/admin-risk";
import type { DrawCurrentSnapshot } from "@/types/api/public-draw";
type HotPlayTab = "4D" | "3D" | "2D";
type HotPlayTab = "4D" | "3D" | "2D" | "特别";
type SoldOutBuckets = {
d4: number;
@@ -67,22 +66,28 @@ function formatSignedMoneyMinor(minor: number, currencyCode: string | null): str
return `${s}${formatMoneyMinor(Math.abs(minor), currencyCode)}`;
}
/** 与后端 {@see AdminDashboardSnapshotBuilder::soldOutBucketKey} 维度对齐 */
function poolPlayCategory(normalizedNumber: string): HotPlayTab | "other" {
const raw = normalizedNumber.trim();
if (/[A-Za-z]/.test(raw)) {
return "other";
}
const digits = raw.replace(/\D/g, "");
const len = digits.length > 0 ? digits.length : raw.length;
if (len >= 4) {
const digitLen = digits.length;
const hasLetter = /[A-Za-z]/.test(raw);
if (hasLetter && digitLen < 3) {
return "特别";
}
if (digitLen >= 4) {
return "4D";
}
if (len === 3) {
if (digitLen === 3) {
return "3D";
}
if (len === 2) {
if (digitLen === 2) {
return "2D";
}
if (hasLetter) {
return "特别";
}
return "other";
}
@@ -132,7 +137,7 @@ function HotBarChart({ rows }: { rows: AdminRiskPoolRow[] }): ReactElement {
return (
<div className="flex h-52 flex-col">
<div className="relative flex flex-1 items-end gap-1.5 border-b border-slate-200/90 pb-0.5 pl-7">
<div className="relative flex h-[168px] min-h-[168px] w-full items-stretch gap-1.5 border-b border-slate-200/90 pb-0.5 pl-7">
<span
className="pointer-events-none absolute bottom-6 left-0 top-2 w-6 rotate-180 text-[10px] leading-tight text-muted-foreground [writing-mode:vertical-rl]"
aria-hidden
@@ -144,15 +149,22 @@ function HotBarChart({ rows }: { rows: AdminRiskPoolRow[] }): ReactElement {
) : (
rows.map((row) => {
const u = row.usage_ratio ?? 0;
const h = Math.max(6, (u / maxU) * 100);
const h = Math.max(8, (u / maxU) * 100);
return (
<div key={row.normalized_number} className="flex min-w-0 flex-1 flex-col items-center gap-1">
<div
className="w-full max-w-[2.25rem] rounded-t-sm bg-[#c41e3a]/90 shadow-sm transition-all"
style={{ height: `${h}%` }}
title={`${row.normalized_number}: ${(u * 100).toFixed(1)}%`}
/>
<span className="truncate font-mono text-[10px] text-[#1a365d]">{row.normalized_number}</span>
<div
key={row.normalized_number}
className="flex min-h-0 min-w-0 flex-1 flex-col items-stretch gap-1"
>
<div className="flex min-h-0 flex-1 flex-col justify-end">
<div
className="mx-auto w-full max-w-[2.25rem] rounded-t-sm bg-[#c41e3a]/90 shadow-sm transition-all"
style={{ height: `${h}%`, minHeight: 6 }}
title={`${row.normalized_number}: ${(u * 100).toFixed(1)}%`}
/>
</div>
<span className="truncate text-center font-mono text-[10px] text-[#1a365d]">
{row.normalized_number.trim()}
</span>
</div>
);
})
@@ -345,7 +357,6 @@ export function DashboardConsole(): ReactElement {
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div>
<h1 className="text-2xl font-bold tracking-tight text-[#1a365d]"></h1>
<p className="text-sm text-muted-foreground"> · </p>
</div>
<div className="flex items-center gap-2">
<span className="text-sm text-muted-foreground">{todayLabel}</span>
@@ -372,7 +383,7 @@ export function DashboardConsole(): ReactElement {
{notice && !error ? (
<Alert className="border-sky-200 bg-sky-50 dark:border-sky-900/50 dark:bg-sky-950/30">
<AlertTitle></AlertTitle>
<AlertTitle></AlertTitle>
<AlertDescription>{notice}</AlertDescription>
</Alert>
) : null}
@@ -541,11 +552,10 @@ export function DashboardConsole(): ReactElement {
<CardHeader className="flex flex-row flex-wrap items-end justify-between gap-2 space-y-0 pb-2">
<div>
<CardTitle className="text-base font-semibold text-[#1a365d]"> Top 10</CardTitle>
<CardDescription> 100 </CardDescription>
</div>
<div className="flex items-center gap-3">
<div role="tablist" aria-label="玩法维度" className="flex gap-1 border-b border-transparent">
{(["4D", "3D", "2D"] as const).map((tab) => (
{(["4D", "3D", "2D", "特别"] as const).map((tab) => (
<button
key={tab}
type="button"
@@ -586,7 +596,6 @@ export function DashboardConsole(): ReactElement {
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<div>
<CardTitle className="text-base font-semibold text-[#1a365d]"></CardTitle>
<CardDescription></CardDescription>
</div>
{drawId != null ? (
<Link
@@ -621,7 +630,6 @@ export function DashboardConsole(): ReactElement {
<p className="mt-1 text-4xl font-bold tabular-nums text-[#c41e3a]">
{pendingReview ?? "—"}
</p>
<p className="text-xs text-muted-foreground"></p>
</div>
</div>
{drawId != null ? (
@@ -646,7 +654,6 @@ export function DashboardConsole(): ReactElement {
<p className="mt-1 text-4xl font-bold tabular-nums text-[#c41e3a]">
{abnormalTransferTotal ?? "—"}
</p>
<p className="text-xs text-muted-foreground"></p>
</div>
</div>
<Link
@@ -679,10 +686,6 @@ export function DashboardConsole(): ReactElement {
</CardContent>
</Card>
<footer className="flex items-center justify-center gap-2 text-xs text-muted-foreground">
<ShieldCheck className="size-4 text-[#c41e3a]" aria-hidden />
<span> · 访</span>
</footer>
</div>
);
}