# workspace_popup.dspy - 返回 PopupWindow,内含 ResourceBrowser(含打开/删除 tools) import json as _json uid = await get_user() if not uid: uid = 'user-01' dbname = get_module_dbname('pipeline-sdlc') import os async with DBPools().sqlorContext(dbname) as sor: ws_dir, _ = await get_workspace_dir(sor, uid) pname = os.path.basename(ws_dir) if ws_dir else '' if not ws_dir: resp = { "widgettype": "PopupWindow", "options": {"title": "提示", "cwidth": 30, "cheight": 8, "auto_open": True}, "subwidgets": [{ "widgettype": "Text", "options": {"text": "请先选择项目", "cfontsize": 1, "color": "#64748b", "padding": "20px"} }] } else: open_url = entire_url("/pipeline-sdlc/api/workspace_open.dspy") delete_url = entire_url("/pipeline-sdlc/api/workspace_delete.dspy") # 打开:预览选中文件 open_script = ( "if(!bricks.app._ws_sel)return;" "var r=await fetch(" + _json.dumps(open_url) + "+'?id='+encodeURIComponent(bricks.app._ws_sel.id));" "var d=await r.json();" "bricks.widgetBuild(d,bricks.app);" ) # 删除:删除选中文件并刷新 delete_script = ( "if(!bricks.app._ws_sel)return;" "var body=new URLSearchParams();" "body.append('id',bricks.app._ws_sel.id);" "var resp=await fetch(" + _json.dumps(delete_url) + ",{method:'POST',body:body});" "var rj=await resp.json();" "if(rj.status=='ok'){" "bricks.app._ws_sel=null;bricks.app._ws_sel_el=null;" "var rb=bricks.getWidgetById('ws_rb',bricks.app);" "if(rb){var cid=rb.current_id;rb.current_id=undefined;await rb.render_browser(cid);}" "}else{var m=new bricks.Message({title:'删除失败',message:rj.message||'未知错误'});m.open();}" ) resp = { "widgettype": "PopupWindow", "options": { "title": pname + " - 工作空间", "width": "85%", "height": "80%", "auto_open": True }, "subwidgets": [{ "widgettype": "ResourceBrowser", "id": "ws_rb", "options": { "tree_options": { "widgettype": "Tree", "options": { "dataurl": entire_url("/pipeline-sdlc/api/workspace_tree.dspy"), "textField": "label", "idField": "id", "cfontsize": 1.0 } }, "browser_options": { "widgettype": "urlwidget", "options": { "url": entire_url("/pipeline-sdlc/api/workspace_files.dspy") }, "tools": [ { "widgettype": "Button", "options": {"label": "打开", "css": "small"}, "binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": open_script}] }, { "widgettype": "Button", "options": {"label": "删除", "css": "small"}, "binds": [{ "wid": "self", "event": "click", "actiontype": "script", "target": "self", "conform": { "title": "删除确认", "message": "确认删除选中的文件?", "conform": {"label": "删除"}, "discard": {"label": "取消"} }, "script": delete_script }] } ] }, "tree_width": "280px" } }] } return _json.dumps(resp, ensure_ascii=False)