fix: UiFile-based upload with drag-drop support, download/delete toolbar

This commit is contained in:
yumoqing 2026-07-03 17:57:48 +08:00
parent 07d5173d75
commit 7c0acb5245

View File

@ -6,8 +6,6 @@
{% set fiid = 'dist_agreement_attach' %}
{% endif %}
{% set folder = ensure_contract_folder(request, contract_id, fiid) %}
{% set upload_url = entire_url('contract_upload.dspy') %}
{% set list_url = entire_url('contract_attach_list.dspy') %}
{% set delete_url = entire_url('contract_attach_delete.dspy') %}
{
"widgettype": "VBox",
@ -17,13 +15,24 @@
},
"subwidgets": [
{
"widgettype": "Title4",
"widgettype": "HBox",
"options": {
"fontWeight": "600",
"otext": "合同附件",
"i18n": true,
"marginBottom": "8px"
}
"alignItems": "center",
"marginBottom": "12px"
},
"subwidgets": [
{
"widgettype": "Title4",
"options": {
"fontWeight": "600",
"otext": "合同附件",
"i18n": true
}
},
{
"widgettype": "Filler"
}
]
},
{
"widgettype": "UiFile",
@ -31,14 +40,13 @@
"options": {
"name": "upfile",
"multiple": true,
"label": "选择文件(支持多选及拖拽)",
"cwidth": 30
"label": "拖拽文件到此处,或点击选择文件"
},
"binds": [{
"wid": "self",
"event": "changed",
"actiontype": "script",
"script": "var files=this.value;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]);fetch('{{upload_url}}',{method:'POST',body:fd}).then(function(r){if(r.ok){var tbl=bricks.getWidgetById('attach_tbl');if(tbl)tbl.render({});}}).catch(function(e){console.error('upload failed',e)})"
"script": "var files=this.value;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('contract_upload.dspy')}}',{method:'POST',body:fd}).then(function(r){if(r.ok){var tbl=bricks.getWidgetById('attach_tbl');if(tbl)tbl.render({});self.value=null;}}).catch(function(e){console.error('upload failed',e)})"
}]
},
{
@ -48,7 +56,7 @@
"css": "card",
"width": "100%",
"height": "auto",
"data_url": "{{list_url}}?folderid={{folder}}&fiid={{fiid}}",
"data_url": "{{entire_url('contract_attach_list.dspy')}}?folderid={{folder}}&fiid={{fiid}}",
"data_method": "GET",
"page_rows": 50,
"record_toolbar": [
@ -61,8 +69,8 @@
"cwidth": {}
},
"fields": [
{"name": "filename", "title": "文件名", "type": "str", "uitype": "str", "label": "文件名", "cwidth": 28},
{"name": "filesize", "title": "大小(KB)", "type": "str", "uitype": "str", "label": "大小", "cwidth": 10},
{"name": "filename", "title": "文件名", "type": "str", "uitype": "str", "label": "文件名", "cwidth": 30},
{"name": "filesize", "title": "大小(bytes)", "type": "int", "uitype": "int", "label": "大小", "cwidth": 10},
{"name": "filetype", "title": "类型", "type": "str", "uitype": "str", "label": "类型", "cwidth": 8}
]
}