From 6ecbaf5fb4275c81525d4c2eb3e84cc8ecee1e78 Mon Sep 17 00:00:00 2001 From: kang Date: Wed, 20 May 2026 16:57:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=AB=AF=E9=85=8D=E7=BD=AE=E9=A1=B5=E7=B4=A7=E5=87=91?= =?UTF-8?q?=E5=B8=83=E5=B1=80=E4=B8=8E=E6=97=B6=E9=97=B4=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/admin/admin-shell.tsx | 4 +- src/components/ui/button.tsx | 4 +- src/lib/admin-datetime.ts | 57 +++++++++++++++---- src/modules/config/config-version-actions.tsx | 8 +-- .../config/config-version-switcher.tsx | 6 +- src/modules/config/config-workspace-shell.tsx | 4 +- .../config/doc/odds-config-doc-screen.tsx | 41 +++++++------ .../config/doc/play-config-doc-screen.tsx | 7 +-- .../config/doc/rebate-config-doc-screen.tsx | 3 - .../config/doc/risk-cap-doc-screen.tsx | 8 +-- .../config/doc/wallet-config-doc-screen.tsx | 15 ----- .../settings/system-settings-screen.tsx | 29 +--------- src/modules/wallet/wallet-console.tsx | 4 +- 13 files changed, 93 insertions(+), 97 deletions(-) diff --git a/src/components/admin/admin-shell.tsx b/src/components/admin/admin-shell.tsx index 814e0c8..2a65f14 100644 --- a/src/components/admin/admin-shell.tsx +++ b/src/components/admin/admin-shell.tsx @@ -16,7 +16,7 @@ export function AdminShell({ children }: { children: ReactNode }) { return ( - +
@@ -25,7 +25,7 @@ export function AdminShell({ children }: { children: ReactNode }) {
-
+
{children}
diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx index 6042c42..a4895f6 100644 --- a/src/components/ui/button.tsx +++ b/src/components/ui/button.tsx @@ -20,9 +20,9 @@ const buttonVariants = cva( link: "text-primary underline-offset-4 hover:underline", }, size: { - default: - "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2", xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3", + default: + "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5", sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5", lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2", icon: "size-8", diff --git a/src/lib/admin-datetime.ts b/src/lib/admin-datetime.ts index d4eea5d..137140b 100644 --- a/src/lib/admin-datetime.ts +++ b/src/lib/admin-datetime.ts @@ -1,7 +1,26 @@ import type { AdminApiLocale } from "@/lib/admin-locale"; -function pad2(n: number): string { - return String(n).padStart(2, "0"); +function formatParts(date: Date, timeZone?: string): string { + const parts = new Intl.DateTimeFormat("en-CA", { + timeZone, + year: "numeric", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + second: "2-digit", + hourCycle: "h23", + }).formatToParts(date); + + const map = new Map(parts.map((part) => [part.type, part.value])); + const year = map.get("year") ?? "0000"; + const month = map.get("month") ?? "00"; + const day = map.get("day") ?? "00"; + const hour = map.get("hour") ?? "00"; + const minute = map.get("minute") ?? "00"; + const second = map.get("second") ?? "00"; + + return `${year}-${month}-${day} ${hour}:${minute}:${second}`; } /** @@ -21,12 +40,30 @@ export function formatAdminInstant( if (Number.isNaN(ms)) { return "—"; } - const date = new Date(ms); - const y = date.getFullYear(); - const m = pad2(date.getMonth() + 1); - const d = pad2(date.getDate()); - const h = pad2(date.getHours()); - const min = pad2(date.getMinutes()); - const s = pad2(date.getSeconds()); - return `${y}-${m}-${d} ${h}:${min}:${s}`; + return formatParts(new Date(ms)); +} + +/** + * 将接口返回的 ISO 时间串格式化到指定时区,便于并列展示多个地区的时间。 + */ +export function formatAdminInstantInTimeZone( + iso: string | null | undefined, + options: { + locale: AdminApiLocale; + timeZone: string; + }, +): string { + void options.locale; + if (iso == null || iso === "") { + return "—"; + } + const ms = Date.parse(iso); + if (Number.isNaN(ms)) { + return "—"; + } + try { + return formatParts(new Date(ms), options.timeZone); + } catch { + return formatParts(new Date(ms)); + } } diff --git a/src/modules/config/config-version-actions.tsx b/src/modules/config/config-version-actions.tsx index 17885b9..6f4719a 100644 --- a/src/modules/config/config-version-actions.tsx +++ b/src/modules/config/config-version-actions.tsx @@ -40,7 +40,7 @@ export function ConfigVersionActions({