diff --git a/frontend/src/components/GlobalConfig.jsx b/frontend/src/components/GlobalConfig.jsx index f41a97a..5bf07a0 100644 --- a/frontend/src/components/GlobalConfig.jsx +++ b/frontend/src/components/GlobalConfig.jsx @@ -681,60 +681,24 @@ const GlobalConfig = ({ currentUser }) => { } } - // 计算全局策略账号ID(依赖 configMeta) - const globalStrategyAccountId = React.useMemo(() => { - return parseInt(String(configMeta?.global_strategy_account_id || '1'), 10) || 1 - }, [configMeta]) - - const isGlobalStrategyAccount = isAdmin && currentAccountId === globalStrategyAccountId - - // 计算当前预设(在 render 时计算,依赖 configs) - // 注意:这里直接内联 detectCurrentPreset 的逻辑,避免函数调用时序问题 - const currentPreset = React.useMemo(() => { - if (!configs || Object.keys(configs).length === 0) return null - try { - // 内联检测逻辑,避免函数调用问题 - for (const [presetKey, preset] of Object.entries(presets)) { - let match = true - for (const [key, expectedValue] of Object.entries(preset.configs)) { - const currentConfig = configs[key] - if (!currentConfig) { - match = false - break - } - let currentValue = currentConfig.value - if (key.includes('PERCENT') || key.includes('PCT')) { - if (PCT_LIKE_KEYS.has(key)) { - currentValue = currentValue <= 0.05 ? currentValue * 100 : currentValue - } else { - currentValue = currentValue * 100 - } - } - if (typeof expectedValue === 'number' && typeof currentValue === 'number') { - if (Math.abs(currentValue - expectedValue) > 0.01) { - match = false - break - } - } else if (currentValue !== expectedValue) { - match = false - break - } - } - if (match) { - return presetKey - } - } - return null - } catch (e) { - console.error('detectCurrentPreset error:', e) - return null - } - }, [configs]) - if (loading) { return
加载中...
} + // 简单计算:全局策略账号ID + const globalStrategyAccountId = configMeta?.global_strategy_account_id ? parseInt(String(configMeta.global_strategy_account_id), 10) : 1 + const isGlobalStrategyAccount = isAdmin && currentAccountId === globalStrategyAccountId + + // 简单计算:当前预设(直接在 render 时计算,不使用 useMemo) + let currentPreset = null + if (configs && Object.keys(configs).length > 0) { + try { + currentPreset = detectCurrentPreset() + } catch (e) { + console.error('detectCurrentPreset error:', e) + } + } + const presetUiMeta = { swing: { group: 'limit', tag: '纯限价' }, strict: { group: 'limit', tag: '纯限价' },