This commit is contained in:
薇薇安 2026-01-22 13:05:42 +08:00
parent 7d3d9c7de1
commit 0ecdff4530

View File

@ -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>
))}