From c540e73082ca00bba902659490e4fdfd78077a0b Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 23 Apr 2026 15:23:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BD=91=E5=85=B3?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=99=A8=E6=98=BE=E7=A4=BAID=E5=92=8C?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=90=8E=E7=BD=91=E5=85=B3=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/asset.go | 6 +---- web/src/pages/assets/AssetPost.tsx | 37 ++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/server/service/asset.go b/server/service/asset.go index b1ccbd443..33378d4d6 100644 --- a/server/service/asset.go +++ b/server/service/asset.go @@ -313,11 +313,7 @@ func (s assetService) UpdateById(id string, m maps.Map) error { } if item.AccessGatewayId == "" { - if gatewayId, ok := m["gatewayId"]; ok && gatewayId != "" && gatewayId != "-" { - item.AccessGatewayId = gatewayId.(string) - } else { - item.AccessGatewayId = "-" - } + item.AccessGatewayId = "-" } return s.Transaction(context.Background(), func(ctx context.Context) error { diff --git a/web/src/pages/assets/AssetPost.tsx b/web/src/pages/assets/AssetPost.tsx index 966d378c5..b4452df4e 100644 --- a/web/src/pages/assets/AssetPost.tsx +++ b/web/src/pages/assets/AssetPost.tsx @@ -86,14 +86,33 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps) } else if (!asset.tags) { asset.tags = [] as any; } + // 处理网关类型 if (asset.accessGatewayId && asset.accessGatewayId !== '-') { - asset.gatewayType = 'ssh'; - setTimeout(() => { - formRef.current?.setFieldsValue({ - gatewayType: 'ssh', - accessGatewayId: asset.accessGatewayId - }); - }, 100); + // 获取网关名称 + try { + const gateways = await sshGatewayApi.getAll(); + const gateway = gateways.find(g => g.id === asset.accessGatewayId); + if (gateway) { + asset.gatewayType = 'ssh'; + // 使用 setTimeout 确保表单已加载完成 + setTimeout(() => { + formRef.current?.setFieldsValue({ + gatewayType: 'ssh', + accessGatewayId: { value: asset.accessGatewayId, label: gateway.name } + }); + }, 100); + } else { + // 网关不存在,设置为不使用网关 + asset.gatewayType = ''; + asset.accessGatewayId = undefined; + } + } catch (e) { + asset.gatewayType = ''; + asset.accessGatewayId = undefined; + } + } else { + asset.gatewayType = ''; + asset.accessGatewayId = undefined; } return asset; } @@ -109,6 +128,7 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps) }, groupId: groupId, tags: [], + gatewayType: '', } as Asset; } @@ -120,6 +140,9 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps) // 处理网关字段 if (!values['gatewayType']) { values['accessGatewayId'] = '-'; + } else if (values['accessGatewayId'] && typeof values['accessGatewayId'] === 'object') { + // 如果是对象,提取 value + values['accessGatewayId'] = values['accessGatewayId'].value; } delete values['gatewayType']; if (!copy && values['id']) {