fix: 附件上传改用 UiFile changed + fetch FormData
UiFile changed 事件 → script fetch POST multipart → 成功后 render Tabular 无需点击上传按钮,选择文件即自动上传
This commit is contained in:
parent
5968b3a527
commit
a63b6ce427
@ -23,19 +23,20 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Form",
|
||||
"id": "upload_form",
|
||||
"widgettype": "UiFile",
|
||||
"id": "file_input",
|
||||
"options": {
|
||||
"submit_url": "{{entire_url('/filemgr/upload_file.dspy')}}",
|
||||
"fields": [
|
||||
{"name": "folderid", "uitype": "hide", "value": "{{folder}}"},
|
||||
{"name": "fiid", "uitype": "hide", "value": "{{fiid}}"},
|
||||
{"name": "upfile", "uitype": "file", "multiple": true, "label": "选择文件"}
|
||||
],
|
||||
"buttons": [
|
||||
{"name": "submit", "label": "上传", "css": "primary"}
|
||||
]
|
||||
}
|
||||
"name": "upfile",
|
||||
"multiple": true,
|
||||
"label": "选择文件(支持多选及拖拽)",
|
||||
"cwidth": 30
|
||||
},
|
||||
"binds": [{
|
||||
"wid": "self",
|
||||
"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",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user