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') {