This commit is contained in:
薇薇安 2026-01-22 11:39:47 +08:00
parent 9a62528c93
commit 490e94f7c7

View File

@ -38,9 +38,7 @@ const GlobalConfig = ({ currentUser }) => {
'ENTRY_MAX_DRIFT_PCT_RANGING',
])
const isAdmin = (currentUser?.role || '') === 'admin'
//
//
const presets = {
swing: {
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 () => {
if (!newUser.username || !newUser.password) {
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) {
return <div className="global-config">加载中...</div>
}