From 3dc29afbd44ac6633b5108ed8e930f3dfed7d077 Mon Sep 17 00:00:00 2001 From: chengkai3 Date: Sun, 28 Jun 2026 13:58:11 +0800 Subject: [PATCH] =?UTF-8?q?[feat]:[FL-206][=E4=BC=98=E5=8C=96=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 维度类型改为允许手动输入创建 - 字段标签优化:编码→维度编码,名称→维度名称,父节点ID→父维度 - 父维度改为下拉选择,支持搜索 - 添加循环引用检查,防止选择自己的子孙节点作为父节点 - 表格中父维度显示为"名称 (编码)"格式 Co-Authored-By: Claude Sonnet 4.6 Co-authored-by: multica-agent --- web/src/app/admin/dimensions/page.tsx | 116 +++++++++++++++++--------- 1 file changed, 76 insertions(+), 40 deletions(-) diff --git a/web/src/app/admin/dimensions/page.tsx b/web/src/app/admin/dimensions/page.tsx index ddce7a4..f480077 100644 --- a/web/src/app/admin/dimensions/page.tsx +++ b/web/src/app/admin/dimensions/page.tsx @@ -48,16 +48,8 @@ type EditDimensionValues = { sort_order: number; }; -const DIMENSION_TYPES = [ - { value: "voltage_level", label: "电压等级" }, - { value: "tower_type", label: "塔型" }, - { value: "scenario", label: "场景" }, - { value: "arrester_combination", label: "避雷器组合" }, -]; - function dimensionTypeLabel(type: string): string { - const found = DIMENSION_TYPES.find((t) => t.value === type); - return found ? found.label : type; + return type; } function statusLabel(enabled: boolean): string { @@ -122,6 +114,27 @@ export default function AdminDimensionsPage() { const dimensions = useMemo(() => dimensionsQuery.data?.items ?? [], [dimensionsQuery.data?.items]); + const uniqueDimensionTypes = useMemo(() => { + const types = new Set(dimensions.map((d) => d.dimension_type)); + return Array.from(types).sort(); + }, [dimensions]); + + const getAvailableParents = useCallback((currentItemId?: string) => { + return dimensions.filter((d) => { + if (currentItemId && d.id === currentItemId) return false; + if (currentItemId) { + const isDescendant = (itemId: string, ancestorId: string): boolean => { + const item = dimensions.find((dim) => dim.id === itemId); + if (!item || !item.parent_id) return false; + if (item.parent_id === ancestorId) return true; + return isDescendant(item.parent_id, ancestorId); + }; + if (isDescendant(d.id, currentItemId)) return false; + } + return true; + }); + }, [dimensions]); + const refreshData = async () => { await queryClient.refetchQueries({ queryKey: ["admin.dimensions"] }); }; @@ -258,20 +271,24 @@ export default function AdminDimensionsPage() { render: (value: string) => dimensionTypeLabel(value), }, { - title: "编码", + title: "维度编码", dataIndex: "code", width: 140, }, { - title: "名称", + title: "维度名称", dataIndex: "name", width: 180, }, { - title: "父节点ID", + title: "父维度", dataIndex: "parent_id", - width: 120, - render: (value: string | null) => value || "-", + width: 180, + render: (value: string | null) => { + if (!value) return "-"; + const parent = dimensions.find((d) => d.id === value); + return parent ? `${parent.name} (${parent.code})` : value; + }, }, { title: "描述", @@ -409,7 +426,7 @@ export default function AdminDimensionsPage() { value={selectedDimensionType} allowClear placeholder="全部" - options={DIMENSION_TYPES} + options={uniqueDimensionTypes.map((type) => ({ value: type, label: type }))} onChange={(value) => { setSelectedDimensionType(value); setPagination((prev) => ({ ...prev, current: 1 })); @@ -472,40 +489,48 @@ export default function AdminDimensionsPage() { - - - + + - - + +