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