a
This commit is contained in:
parent
490e94f7c7
commit
3ef66fb54a
|
|
@ -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 <div className="global-config">加载中...</div>
|
||||
}
|
||||
|
||||
// 简单计算:全局策略账号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: '纯限价' },
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user