更新
This commit is contained in:
+66
-6
@@ -8,7 +8,7 @@ import logging
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from textcomplete import textcomplete, StrategyProps
|
||||
|
||||
from streamlit.components.v1 import html
|
||||
# 添加项目根目录到路径
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
@@ -577,7 +577,7 @@ def render_indicator_management_expander():
|
||||
"""渲染指标管理扩展面板"""
|
||||
with st.expander("新建指标工具", expanded=True):
|
||||
# 显示清除指标链接
|
||||
col1, col2, col3 = st.columns([2, 1, 1])
|
||||
col1, col2, col3 = st.columns([1, 1, 1])
|
||||
with col1:
|
||||
st.subheader("指标列表")
|
||||
with col2:
|
||||
@@ -591,7 +591,7 @@ def render_indicator_management_expander():
|
||||
|
||||
def render_new_indicator_button():
|
||||
"""渲染新建指标按钮"""
|
||||
if st.button("➕新建"):
|
||||
if st.button("新建"):
|
||||
try:
|
||||
# 生成新指标名称
|
||||
indicator_count = len(st.session_state.indicator_manager.get_all_indicators())
|
||||
@@ -613,7 +613,7 @@ def render_new_indicator_button():
|
||||
|
||||
def render_clear_indicators_button():
|
||||
"""渲染清空指标按钮"""
|
||||
if st.button("🗑️清空", help="删除所有指标", type="secondary"):
|
||||
if st.button("清空", help="删除所有指标", type="secondary"):
|
||||
st.session_state.indicator_manager.clear_all_indicators()
|
||||
st.session_state.current_indicator_id = None
|
||||
# 清除已生成的代码
|
||||
@@ -714,6 +714,57 @@ def render_main_area():
|
||||
else:
|
||||
st.info("请在左侧创建或选择一个指标")
|
||||
|
||||
# HTML/JS 实现可拖动面板
|
||||
panel_js = """
|
||||
<script>
|
||||
function createCollapsible() {
|
||||
const panel = document.createElement('div');
|
||||
panel.innerHTML = `
|
||||
<div style="
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: #f5f5f5;
|
||||
border-top: 1px solid #ddd;
|
||||
z-index: 1000;
|
||||
">
|
||||
<button onclick="togglePanel()" style="
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
background: #4a8fe7;
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
">▼ 输出窗口</button>
|
||||
<div id="content" style="
|
||||
display: none;
|
||||
padding: 10px;
|
||||
max-height: 250px;
|
||||
overflow-y: auto;
|
||||
">
|
||||
<!-- 内容通过Streamlit更新 -->
|
||||
<div id="dynamic-content"></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(panel);
|
||||
|
||||
window.togglePanel = () => {
|
||||
const content = document.getElementById('content');
|
||||
content.style.display = content.style.display === 'none' ? 'block' : 'none';
|
||||
};
|
||||
}
|
||||
createCollapsible();
|
||||
</script>
|
||||
"""
|
||||
|
||||
# 渲染面板
|
||||
html(panel_js, height=200)
|
||||
|
||||
# 动态更新面板内容
|
||||
if st.button("生成日志"):
|
||||
st.write('<div id="dynamic-content">新的日志消息...</div>', unsafe_allow_html=True)
|
||||
|
||||
def render_library_indicator_detail():
|
||||
"""渲染指标库详情"""
|
||||
@@ -922,7 +973,12 @@ def execute_and_update_code(current_indicator, title_code_result):
|
||||
result = st.session_state.code_executor.execute_code(st.session_state.generated_code)
|
||||
if result and hasattr(result, 'get') and result.get('status'):
|
||||
title_code_result.success("执行成功")
|
||||
title_code_result.json(result.get('data', {}))
|
||||
data = result.get('data', {})
|
||||
if isinstance(data, (str, int, float)):
|
||||
title_code_result.write(data)
|
||||
else:
|
||||
title_code_result.json(data)
|
||||
|
||||
# 更新指标的代码
|
||||
st.session_state.indicator_manager.update_indicator(
|
||||
current_indicator.id,
|
||||
@@ -940,7 +996,11 @@ def execute_indicator_code(code, result_container):
|
||||
result = st.session_state.code_executor.execute_code(code)
|
||||
if result and hasattr(result, 'get') and result.get('status'):
|
||||
result_container.success("执行成功")
|
||||
result_container.json(result.get('data', {}))
|
||||
data = result.get('data', {})
|
||||
if isinstance(data, (str, int, float)):
|
||||
result_container.write(data)
|
||||
else:
|
||||
result_container.json(data)
|
||||
else:
|
||||
result_container.error(f"执行失败: {result.get('message', '未知错误') if hasattr(result, 'get') else str(result)}")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user