fix(strategy_overview): 优化策略执行概览的错误处理与提示信息

在后端API中增强了对策略执行概览的错误处理逻辑,确保在无法加载策略执行数据时提供明确的提示信息。前端组件更新以显示相应的错误信息,提升用户体验并指导用户进行后续操作。此改动增强了系统的可用性与用户友好性。
This commit is contained in:
薇薇安 2026-02-25 09:49:11 +08:00
parent 41e53755ea
commit 693a2306ca
2 changed files with 34 additions and 16 deletions

View File

@ -1300,20 +1300,32 @@ async def market_overview(_admin: Dict[str, Any] = Depends(require_system_admin)
data["beta_filter_triggered"] = triggered
# 策略执行概览:当前执行方案与配置项执行情况(易读文字)
get_strategy_execution_overview = None
try:
from market_overview import get_strategy_execution_overview
except ImportError:
try:
from backend.market_overview import get_strategy_execution_overview
except ImportError:
get_strategy_execution_overview = None
pass
if get_strategy_execution_overview is None:
try:
import sys
backend_dir = Path(__file__).resolve().parent.parent.parent
if str(backend_dir) not in sys.path:
sys.path.insert(0, str(backend_dir))
from market_overview import get_strategy_execution_overview
except ImportError:
pass
if get_strategy_execution_overview is not None:
try:
data["strategy_execution_overview"] = get_strategy_execution_overview()
except Exception as e:
data["strategy_execution_overview"] = {"sections": [{"title": "加载失败", "content": str(e)}]}
else:
data["strategy_execution_overview"] = {"sections": []}
data["strategy_execution_overview"] = {
"sections": [{"title": "策略执行概览暂不可用", "content": "请确认后端已重启并已部署最新代码;若已重启仍无数据,请检查 backend/market_overview.py 与 config_manager 是否可正常导入。"}]
}
return data

View File

@ -1303,21 +1303,27 @@ const GlobalConfig = () => {
</div>
</div>
{/* 策略执行概览:当前执行方案与配置项执行情况(易读文字) */}
{marketOverview.strategy_execution_overview?.sections?.length > 0 && (
<div className="strategy-execution-overview" style={{ marginTop: '20px', padding: '16px', background: '#fafafa', borderRadius: '8px', border: '1px solid #eee' }}>
<h4 style={{ margin: '0 0 12px 0', fontSize: '15px', fontWeight: 600, color: '#333' }}>策略执行概览</h4>
<p style={{ margin: '0 0 14px 0', fontSize: '13px', color: '#666', lineHeight: 1.5 }}>
以下为当前生效的整体策略执行标准与机制说明由数据库/Redis 配置生成刷新市场行情时一并更新
{/* 策略执行概览:当前执行方案与配置项执行情况(易读文字),有数据则展示,无数据也显示区块并提示 */}
<div className="strategy-execution-overview" style={{ marginTop: '20px', padding: '16px', background: '#fafafa', borderRadius: '8px', border: '1px solid #eee' }}>
<h4 style={{ margin: '0 0 12px 0', fontSize: '15px', fontWeight: 600, color: '#333' }}>策略执行概览</h4>
{marketOverview.strategy_execution_overview?.sections?.length > 0 ? (
<>
<p style={{ margin: '0 0 14px 0', fontSize: '13px', color: '#666', lineHeight: 1.5 }}>
以下为当前生效的整体策略执行标准与机制说明由数据库/Redis 配置生成刷新市场行情时一并更新
</p>
{marketOverview.strategy_execution_overview.sections.map((sec, idx) => (
<div key={idx} style={{ marginBottom: idx < marketOverview.strategy_execution_overview.sections.length - 1 ? '14px' : 0 }}>
<div style={{ fontSize: '13px', fontWeight: 600, color: '#1976d2', marginBottom: '4px' }}>{sec.title}</div>
<div style={{ fontSize: '13px', color: '#444', lineHeight: 1.6, whiteSpace: 'pre-wrap' }}>{sec.content}</div>
</div>
))}
</>
) : (
<p style={{ margin: 0, fontSize: '13px', color: '#888' }}>
暂无数据请点击上方刷新重试若仍无内容请确认后端已重启并已部署包含策略执行概览的最新代码
</p>
{marketOverview.strategy_execution_overview.sections.map((sec, idx) => (
<div key={idx} style={{ marginBottom: idx < marketOverview.strategy_execution_overview.sections.length - 1 ? '14px' : 0 }}>
<div style={{ fontSize: '13px', fontWeight: 600, color: '#1976d2', marginBottom: '4px' }}>{sec.title}</div>
<div style={{ fontSize: '13px', color: '#444', lineHeight: 1.6, whiteSpace: 'pre-wrap' }}>{sec.content}</div>
</div>
))}
</div>
)}
)}
</div>
</>
) : (
<div style={{ color: '#888', fontSize: '14px' }}>加载中或拉取失败请点击刷新</div>