a
This commit is contained in:
parent
7d3d9c7de1
commit
0ecdff4530
|
|
@ -38,6 +38,9 @@ const GlobalConfig = ({ currentUser }) => {
|
|||
'ENTRY_MAX_DRIFT_PCT_RANGING',
|
||||
])
|
||||
|
||||
// 必须在所有使用之前定义 isAdmin
|
||||
const isAdmin = (currentUser?.role || '') === 'admin'
|
||||
|
||||
// 预设方案配置(必须在函数定义之前,常量定义)
|
||||
const presets = {
|
||||
swing: {
|
||||
|
|
@ -684,22 +687,52 @@ const GlobalConfig = ({ currentUser }) => {
|
|||
}
|
||||
}
|
||||
|
||||
// 必须在所有使用之前定义 isAdmin
|
||||
const isAdmin = (currentUser?.role || '') === 'admin'
|
||||
|
||||
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
|
||||
// 简单计算:全局策略账号ID(在 render 时计算)
|
||||
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) {
|
||||
if (configs && Object.keys(configs).length > 0 && presets) {
|
||||
try {
|
||||
currentPreset = detectCurrentPreset()
|
||||
// 直接内联检测逻辑,避免函数调用
|
||||
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) {
|
||||
currentPreset = presetKey
|
||||
break
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('detectCurrentPreset error:', e)
|
||||
}
|
||||
|
|
@ -856,7 +889,7 @@ const GlobalConfig = ({ currentUser }) => {
|
|||
<div className="current-preset-status">
|
||||
<span className="status-label">当前方案:</span>
|
||||
<span className={`status-badge ${currentPreset ? 'preset' : 'custom'}`}>
|
||||
{currentPreset ? presets[currentPreset].name : '自定义'}
|
||||
{currentPreset && presets && presets[currentPreset] ? presets[currentPreset].name : '自定义'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -884,15 +917,20 @@ const GlobalConfig = ({ currentUser }) => {
|
|||
</div>
|
||||
<div className="preset-buttons">
|
||||
{g.presetKeys
|
||||
.filter((k) => presets[k])
|
||||
.filter((k) => presets && presets[k])
|
||||
.map((k) => {
|
||||
const preset = presets[k]
|
||||
const meta = presetUiMeta[k] || { group: g.key, tag: '' }
|
||||
const preset = presets && presets[k] ? presets[k] : null
|
||||
if (!preset) return null
|
||||
const meta = presetUiMeta && presetUiMeta[k] ? presetUiMeta[k] : { group: g.key, tag: '' }
|
||||
return (
|
||||
<button
|
||||
key={k}
|
||||
className={`preset-btn ${currentPreset === k ? 'active' : ''}`}
|
||||
onClick={() => applyPreset(k)}
|
||||
onClick={() => {
|
||||
if (typeof applyPreset === 'function') {
|
||||
applyPreset(k)
|
||||
}
|
||||
}}
|
||||
disabled={saving}
|
||||
title={preset.desc}
|
||||
>
|
||||
|
|
@ -906,7 +944,8 @@ const GlobalConfig = ({ currentUser }) => {
|
|||
<div className="preset-desc">{preset.desc}</div>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
})
|
||||
.filter(Boolean)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user