diff --git a/ui/building_page.py b/ui/building_page.py index bd1414a..b849ecb 100644 --- a/ui/building_page.py +++ b/ui/building_page.py @@ -32,21 +32,37 @@ def save_connection(values): CONNECTION_FILE.write_text(json.dumps(values, ensure_ascii=False, indent=2), encoding="utf-8") +def _clear(state_key): + st.session_state[state_key] = "" + + +def connection_input(label, key, placeholder=None): + """带一键清除按钮的文本框;按钮不能放在 form 内,所以连接信息独立于表单。""" + state_key = f"conn_{key}" + text_col, clear_col = st.columns([14, 1], vertical_alignment="bottom") + value = text_col.text_input(label, key=state_key, placeholder=placeholder) + clear_col.button("", icon=":material/close:", key=f"clear_{key}", help="清除", + on_click=_clear, args=(state_key,), use_container_width=True) + return value + + def render(): st.markdown("## 楼宇数据查询") st.caption("按楼宇轮廓(WKT)查询:先计算落在轮廓内部的点,再按该点查询。") source = file_input("楼宇轮廓清单", "source/NRBuildPolygon.csv", "csv", "building_csv") - saved = load_connection() + if "conn_URL" not in st.session_state: + for key, value in load_connection().items(): + st.session_state[f"conn_{key}"] = value + st.markdown("**连接信息**(默认显示脚本内配置或上次保存值;修改后保存到本地,下次自动读取)") + url = connection_input("服务地址", "URL", "https://...wfs?...ak=...&sig=...") + cookies = connection_input("登录信息(Cookies)", "COOKIES", "CASTGC=...") + referer = connection_input("来源页(可留空)", "REFERER") with st.form("building_run"): c1, c2, c3 = st.columns(3) start = c1.number_input("起始行", 1, value=1) limit = c2.number_input("查询数量(0 表示全部)", 0, value=1000) concurrency = c3.number_input("并发数", 1, 32, 8) encoding = st.selectbox("文件编码(按内容自动识别,识别不出时按此项)", ["gbk", "utf-8-sig"]) - st.markdown("**连接信息**(默认显示脚本内配置或上次保存值;修改后保存到本地,下次自动读取)") - url = st.text_input("服务地址", value=saved["URL"], placeholder="https://...wfs?...ak=...&sig=...") - cookies = st.text_input("登录信息(Cookies)", value=saved["COOKIES"], placeholder="CASTGC=...") - referer = st.text_input("来源页(可留空)", value=saved["REFERER"]) with st.expander("高级参数"): timeout = st.number_input("超时(秒)", 1, 300, 30) retries = st.number_input("失败重试", 0, 10, 2) diff --git a/ui/layout.py b/ui/layout.py index 6f4be21..06de382 100644 --- a/ui/layout.py +++ b/ui/layout.py @@ -120,6 +120,10 @@ h2, h3 { hr { margin: 0.35rem 0 !important; } +/* 去掉输入框右下角 “Press Enter to submit form / apply” 提示 */ +[data-testid="InputInstructions"] { + display: none !important; +} """