a
This commit is contained in:
parent
9a62528c93
commit
490e94f7c7
|
|
@ -38,9 +38,7 @@ const GlobalConfig = ({ currentUser }) => {
|
||||||
'ENTRY_MAX_DRIFT_PCT_RANGING',
|
'ENTRY_MAX_DRIFT_PCT_RANGING',
|
||||||
])
|
])
|
||||||
|
|
||||||
const isAdmin = (currentUser?.role || '') === 'admin'
|
// 预设方案配置(必须在函数定义之前,常量定义)
|
||||||
|
|
||||||
// 预设方案配置(必须在函数定义之前)
|
|
||||||
const presets = {
|
const presets = {
|
||||||
swing: {
|
swing: {
|
||||||
name: '波段回归(推荐)',
|
name: '波段回归(推荐)',
|
||||||
|
|
@ -613,18 +611,6 @@ 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)
|
|
||||||
const currentPreset = React.useMemo(() => {
|
|
||||||
return detectCurrentPreset()
|
|
||||||
}, [configs])
|
|
||||||
|
|
||||||
const handleCreateUser = async () => {
|
const handleCreateUser = async () => {
|
||||||
if (!newUser.username || !newUser.password) {
|
if (!newUser.username || !newUser.password) {
|
||||||
setMessage('用户名和密码不能为空')
|
setMessage('用户名和密码不能为空')
|
||||||
|
|
@ -695,6 +681,56 @@ 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) {
|
if (loading) {
|
||||||
return <div className="global-config">加载中...</div>
|
return <div className="global-config">加载中...</div>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user