From 4d7710d2cc56fdfbd153be37a2d46134b0260b1d Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 23 Apr 2026 15:42:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=20state=20=E9=A2=84?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E7=BD=91=E5=85=B3=E9=80=89=E9=A1=B9=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=98=BE=E7=A4=BAID=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=9B=E4=BF=AE=E5=A4=8D=20gofmt=20=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/gateway.go | 2 +- web/src/pages/assets/AssetPost.tsx | 37 ++++++++++-------------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/server/service/gateway.go b/server/service/gateway.go index adbc0800c..257386b7f 100644 --- a/server/service/gateway.go +++ b/server/service/gateway.go @@ -36,7 +36,7 @@ func (r gatewayService) GetGatewayById(accessGatewayId string) (g *gateway.Gatew func (r gatewayService) loadSshGateway(m *model.SshGateway) (g *gateway.Gateway, err error) { r.DisconnectById(m.ID) - log.Debug("loadSshGateway", + log.Debug("loadSshGateway", log.String("id", m.ID), log.String("name", m.Name), log.String("configMode", m.ConfigMode), diff --git a/web/src/pages/assets/AssetPost.tsx b/web/src/pages/assets/AssetPost.tsx index b4452df4e..f7f2b77f7 100644 --- a/web/src/pages/assets/AssetPost.tsx +++ b/web/src/pages/assets/AssetPost.tsx @@ -46,6 +46,7 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps) let [decrypted, setDecrypted] = useState(false); let [mfaOpen, setMfaOpen] = useState(false); let [mfaSupported, setMfaSupported] = useState(false); + let [gatewayOptions, setGatewayOptions] = useState<{label: string, value: string}[]>([]); let {message} = App.useApp(); @@ -55,6 +56,15 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps) }); }, []); + useEffect(() => { + sshGatewayApi.getAll().then(items => { + setGatewayOptions(items.map(item => ({ + label: item.name, + value: item.id, + }))); + }); + }, []); + const handleViewSecret = async () => { if (mfaSupported) { setMfaOpen(true); @@ -88,28 +98,7 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps) } // 处理网关类型 if (asset.accessGatewayId && asset.accessGatewayId !== '-') { - // 获取网关名称 - 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; - } + asset.gatewayType = 'ssh'; } else { asset.gatewayType = ''; asset.accessGatewayId = undefined; @@ -351,11 +340,9 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps) key="ssh" label={t('menus.gateway.submenus.ssh_gateway')} name='accessGatewayId' - request={sshGatewayRequest} - params={{gatewayType}} + options={gatewayOptions} showSearch rules={[{required: true}]} - debounceTime={0} /> ); } else if (gatewayType === 'agent') {