fix: 附件上传改用 UiFile changed + fetch FormData

UiFile changed 事件 → script fetch POST multipart → 成功后 render Tabular
无需点击上传按钮,选择文件即自动上传
This commit is contained in:
yumoqing 2026-07-03 16:46:14 +08:00
parent 5968b3a527
commit a63b6ce427

View File

@ -23,19 +23,20 @@
} }
}, },
{ {
"widgettype": "Form", "widgettype": "UiFile",
"id": "upload_form", "id": "file_input",
"options": { "options": {
"submit_url": "{{entire_url('/filemgr/upload_file.dspy')}}", "name": "upfile",
"fields": [ "multiple": true,
{"name": "folderid", "uitype": "hide", "value": "{{folder}}"}, "label": "选择文件(支持多选及拖拽)",
{"name": "fiid", "uitype": "hide", "value": "{{fiid}}"}, "cwidth": 30
{"name": "upfile", "uitype": "file", "multiple": true, "label": "选择文件"} },
], "binds": [{
"buttons": [ "wid": "self",
{"name": "submit", "label": "上传", "css": "primary"} "event": "changed",
] "actiontype": "script",
} "script": "var files=this.get_files();if(!files||!files.length)return;var fd=new FormData();fd.append('folderid','{{folder}}');fd.append('fiid','{{fiid}}');for(var i=0;i<files.length;i++)fd.append('upfile',files[i]);var self=this;fetch('{{entire_url(\"/filemgr/upload_file.dspy\")}}',{method:'POST',body:fd}).then(function(r){if(r.ok){var tbl=bricks.app.getWidgetById('attach_tbl');if(tbl)tbl.render({});}else{r.text().then(function(t){bricks.app.show_error('上传失败',t)})}}).catch(function(e){bricks.app.show_error('上传失败',e.message)})"
}]
}, },
{ {
"widgettype": "Tabular", "widgettype": "Tabular",