67 lines
2.8 KiB
Plaintext
67 lines
2.8 KiB
Plaintext
# opp_references_popup.dspy - 数据参考(references):主题列表(agent_menu_open 弹窗内嵌内容)
|
||
# 点主题「查看分项」→ opp_references_items.dspy 列分项(每条带来源,点击新窗口查证)
|
||
|
||
import json as _json
|
||
|
||
uid = await get_user()
|
||
if not uid:
|
||
return {"widgettype": "Text", "options": {"text": "请先登录", "color": "#dc2626", "padding": "12px"}}
|
||
|
||
dbname = get_module_dbname('pipeline-opportunity')
|
||
|
||
items_url = entire_url("/pipeline-opportunity/api/opp_references_items.dspy")
|
||
|
||
async with DBPools().sqlorContext(dbname) as sor:
|
||
from pipeline_opportunity.opp_data_capability import hot_software
|
||
ok, res = await hot_software(sor, days=30, top=10)
|
||
await sor.sqlExe("COMMIT", {})
|
||
|
||
rows = []
|
||
if not ok:
|
||
rows.append({"widgettype": "Text", "options": {
|
||
"text": "数据爬取平台暂不可用:" + str(res)[:200],
|
||
"color": "#dc2626", "padding": "12px", "halign": "left"}})
|
||
else:
|
||
ranking = res.get("ranking") or []
|
||
if not ranking:
|
||
rows.append({"widgettype": "Text", "options": {
|
||
"text": "近30天暂无招标数据", "color": "#64748b", "padding": "12px", "halign": "left"}})
|
||
for i, r in enumerate(ranking):
|
||
cat = str(r.get("category", ""))
|
||
cnt = r.get("tender_count", 0)
|
||
budget = r.get("total_budget_wan", 0)
|
||
script = ("var old=bricks.getWidgetById('opp_refs_items_pw',bricks.app);"
|
||
"if(old&&old.destroy){old.destroy();}"
|
||
"var rp=await fetch(" + _json.dumps(items_url) + "+'?category='+encodeURIComponent(" + _json.dumps(cat) + "));"
|
||
"var d=await rp.json();"
|
||
"if(d){bricks.widgetBuild(d,bricks.app);}")
|
||
rows.append({
|
||
"widgettype": "HBox",
|
||
"options": {"width": "100%", "gap": "10px", "alignItems": "center",
|
||
"padding": "8px 14px", "border": "1px solid #e2e8f0",
|
||
"borderRadius": "8px", "margin": "0 0 8px 0", "bgcolor": "#ffffff"},
|
||
"subwidgets": [
|
||
{"widgettype": "Text", "options": {"text": cat, "cfontsize": 1.0,
|
||
"color": "#0f172a", "halign": "left"}},
|
||
{"widgettype": "Filler"},
|
||
{"widgettype": "Text", "options": {"text": "%d 条" % cnt,
|
||
"cfontsize": 0.85, "color": "#64748b"}},
|
||
{"widgettype": "Text", "options": {"text": "预算 %s 万" % ("{:,.0f}".format(budget) if budget else "—"),
|
||
"cfontsize": 0.85, "color": "#64748b"}},
|
||
{"widgettype": "Button", "options": {"label": "查看分项", "css": "small"},
|
||
"binds": [{"wid": "self", "event": "click", "actiontype": "script",
|
||
"target": "self", "script": script}]}
|
||
]
|
||
})
|
||
|
||
return {
|
||
"widgettype": "VBox",
|
||
"options": {"css": "filler", "width": "100%", "height": "100%", "padding": "12px 16px",
|
||
"gap": "6px", "overflow": "auto"},
|
||
"subwidgets": [
|
||
{"widgettype": "Text", "options": {
|
||
"text": "点击「查看分项」列出该主题的全部招标分项;每条分项带公告原文链接,可逐条查证。",
|
||
"cfontsize": 0.8, "color": "#64748b", "halign": "left", "margin": "0 0 8px 0"}}
|
||
] + rows
|
||
}
|