From 34f91753046a3a1984fcdada31115a87b1b9011f Mon Sep 17 00:00:00 2001 From: kang Date: Sat, 16 May 2026 11:02:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor(config):=20=E4=BC=98=E5=8C=96=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=88=87=E6=8D=A2=E6=8A=BD=E5=B1=89=E4=B8=8E=E7=8E=A9?= =?UTF-8?q?=E6=B3=95=E9=85=8D=E7=BD=AE=E8=BE=93=E5=85=A5=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/config-version-switcher.tsx | 234 +++++++++++------- .../config/doc/play-config-doc-screen.tsx | 24 +- 2 files changed, 155 insertions(+), 103 deletions(-) diff --git a/src/modules/config/config-version-switcher.tsx b/src/modules/config/config-version-switcher.tsx index 439c7b5..1b2edf8 100644 --- a/src/modules/config/config-version-switcher.tsx +++ b/src/modules/config/config-version-switcher.tsx @@ -13,13 +13,6 @@ import { DialogTitle, } from "@/components/ui/dialog"; import { Label } from "@/components/ui/label"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select"; import { Sheet, SheetContent, @@ -45,10 +38,6 @@ function versionStatusLabel(status: string): string { return status; } -function versionSelectLabel(v: ConfigVersionSummary): string { - return `#${v.id} · v${v.version_no} · ${versionStatusLabel(v.status)}`; -} - const STATUS_ORDER = ["draft", "active", "archived"] as const; export type ConfigVersionSwitcherProps = { @@ -101,6 +90,11 @@ export function ConfigVersionSwitcher({ return groups; }, [sortedVersions]); + const selectedVersion = useMemo( + () => sortedVersions.find((v) => String(v.id) === selectedId) ?? null, + [selectedId, sortedVersions], + ); + const statusCounts = useMemo( () => STATUS_ORDER.map((status) => ({ @@ -135,47 +129,69 @@ export function ConfigVersionSwitcher({ return ( <>
- +
- -
- - - {sheetTitle} - {sheetDescription} - -
- {statusCounts.map((s) => ( -
- {s.label} - {s.count} -
- ))} + +
+
+
+ + + {sheetTitle} + + + {sheetDescription} + +
-
+
+
+ {statusCounts.map((s) => ( +
+

{s.label}

+

+ {s.count} +

+
+ ))} +
+
+
{sortedVersions.length === 0 ? ( - 暂无版本记录。 + + 暂无版本记录。 + ) : ( STATUS_ORDER.map((status) => { const rows = groupedVersions.get(status) ?? []; @@ -183,72 +199,110 @@ export function ConfigVersionSwitcher({ return null; } return ( -
+
-
- -

{versionStatusLabel(status)}

+
+
+

+ {versionStatusLabel(status)} +

-

{rows.length} 条

+

+ {rows.length} 条 +

-
+
{rows.map((v) => { const isCurrent = selectedId === String(v.id); return ( -
-
-
- v{v.version_no} - - #{v.id} +
+
+
+
+
+
+ + v{v.version_no} + + + + #{v.id} + +
+

+ 生效时间:{v.effective_at ? formatDt(v.effective_at) : "—"} + {v.reason ? ` · 备注:${v.reason}` : ""} +

+
+ {isCurrent ? ( + + 当前查看 + + ) : null}
-

- 生效时间:{v.effective_at ? formatDt(v.effective_at) : "—"} - {v.reason ? ` · 备注:${v.reason}` : ""} -

-
-
- - {onRollbackVersion && v.status !== "draft" ? ( +
- ) : null} - {onDeleteVersion && v.status !== "active" ? ( - - ) : null} + {onRollbackVersion && v.status !== "draft" ? ( + + ) : null} + {onDeleteVersion && v.status !== "active" ? ( + + ) : null} +
diff --git a/src/modules/config/doc/play-config-doc-screen.tsx b/src/modules/config/doc/play-config-doc-screen.tsx index f2b88cb..7e2cee3 100644 --- a/src/modules/config/doc/play-config-doc-screen.tsx +++ b/src/modules/config/doc/play-config-doc-screen.tsx @@ -315,19 +315,16 @@ export function PlayConfigDocScreen() { {detail ? (

- 当前版本:v{detail.version_no} ·{" "} - {detail.status === "active" ? "生效中" : detail.status === "draft" ? "草稿" : "已归档"} {activeHead ? ( <> - {" "} - · 线上生效版本 v{activeHead.version_no} + 线上生效版本 v{activeHead.version_no} {activeHead.effective_at ? ` · ${activeHead.effective_at}` : ""} ) : null} {!isDraft ? ( - {" "} - — 限额与规则为只读,请先新建草稿。 + {activeHead ? " — " : ""} + 限额与规则为只读,请先新建草稿。 ) : null}

@@ -378,10 +375,11 @@ export function PlayConfigDocScreen() { }} /> - + { @@ -394,8 +392,8 @@ export function PlayConfigDocScreen() {