fix: view_assets — use actiontype:urlwidget + target + mode:replace

Replace custom JS fetch script with proper bricks-native pattern:
- actiontype: urlwidget, target: app.rl_asset_results, mode: replace
- method: POST in urlwidget options (required for form data)
- Remove duplicate id from dspy response widgets (id belongs to container only)
This commit is contained in:
yumoqing 2026-05-30 10:54:48 +08:00
parent f94207dd86
commit 7c3e77e612
2 changed files with 7 additions and 5 deletions

View File

@ -22,7 +22,6 @@ assets = result.get('assets', [])
if not assets: if not assets:
return json.dumps({ return json.dumps({
"widgettype": "VBox", "widgettype": "VBox",
"id": "rl_asset_results",
"options": {"padding": "16px", "gap": "12px"}, "options": {"padding": "16px", "gap": "12px"},
"subwidgets": [ "subwidgets": [
{ {
@ -131,7 +130,6 @@ for a in assets:
# Wrap cards in ResponsableBox for responsive grid # Wrap cards in ResponsableBox for responsive grid
result_widget = { result_widget = {
"widgettype": "VBox", "widgettype": "VBox",
"id": "rl_asset_results",
"options": {"padding": "16px", "gap": "12px"}, "options": {"padding": "16px", "gap": "12px"},
"subwidgets": [ "subwidgets": [
{"widgettype": "Text", "options": {"text": f"共 {len(assets)} 个素材", "fontWeight": "bold"}}, {"widgettype": "Text", "options": {"text": f"共 {len(assets)} 个素材", "fontWeight": "bold"}},

View File

@ -35,9 +35,13 @@
{ {
"wid": "self", "wid": "self",
"event": "submit", "event": "submit",
"actiontype": "script", "actiontype": "urlwidget",
"target": "self", "target": "app.rl_asset_results",
"script": "(async function(){var form=bricks.getWidgetById('view_assets_form',bricks.app);if(!form)return;var vals=form._getValue();var params=new URLSearchParams();for(var k in vals){if(vals[k]!==undefined&&vals[k]!==null)params.append(k,vals[k])}var url=bricks.app.baseUrl+'/reallife_asset/api/submit_list_assets.dspy?_webbricks_=1';var resp=await fetch(url,{method:'POST',body:params});var desc=await resp.json();var target=bricks.getWidgetById('rl_asset_results',bricks.app);if(!target)return;if(target.destroy_subwidgets)target.destroy_subwidgets();target.subwidgets=[];target.el.innerHTML='';if(desc&&desc.widgettype){await bricks.widgetBuild(desc,target)}})()" "options": {
"method": "POST",
"url": "{{entire_url('api/submit_list_assets.dspy')}}"
},
"mode": "replace"
} }
] ]
}, },