fix: 使用 state 预加载网关选项,修复显示ID问题;修复 gofmt 格式错误

This commit is contained in:
2026-04-23 15:42:58 +08:00
parent c540e73082
commit 4d7710d2cc
2 changed files with 13 additions and 26 deletions
+1 -1
View File
@@ -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),
+12 -25
View File
@@ -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') {