feat: real file upload page with file picker + XHR post, replace non-functional drop zone with upload button

This commit is contained in:
yumoqing 2026-07-23 14:02:08 +08:00
parent 481dacde23
commit 6c6cc1110e
2 changed files with 22 additions and 28 deletions

View File

@ -57,25 +57,23 @@
"subwidgets": [
{"widgettype": "Text", "options": {"text": "📂 请选择左侧目录查看文件", "cfontsize": 14, "color": "#888"}},
{
"widgettype": "VBox",
"widgettype": "Button",
"options": {
"id": "upload_dropzone",
"width": "100%",
"cheight": 10,
"bgcolor": "#f8f9fa",
"padding": "24px",
"css": "card",
"border": "2px dashed #d0d0d0",
"alignItems": "center",
"justifyContent": "center",
"marginTop": "16px"
"label": "📤 上传文件",
"bgcolor": "#3b82f6",
"color": "#fff",
"padding": "10px 24px",
"marginTop": "16px",
"cfontsize": 14
},
"subwidgets": [
{"widgettype": "Text", "options": {"text": "📂", "cfontsize": 32}},
{"widgettype": "Text", "options": {"text": "拖拽文件到此处上传", "cfontsize": 16, "color": "#888"}},
{"widgettype": "Text", "options": {"text": "支持: TXT, PDF, JPG, PNG, MP3, WAV, MP4, AVI", "cfontsize": 12, "color": "#aaa"}},
{"widgettype": "Text", "options": {"text": "单个文件最大 500MB · 自动向量化入库", "cfontsize": 12, "color": "#aaa"}}
]
"binds": [{
"wid": "self",
"event": "click",
"actiontype": "urlwidget",
"target": "app.rag_main_content",
"mode": "replace",
"options": {"url": "{{entire_url('./upload.dspy')}}?kb_id=kb1"}
}]
}
]
}

View File

@ -21,22 +21,18 @@ result = {
},
"subwidgets": [
{"widgettype": "Text", "options": {"text": "📂", "cfontsize": 40}},
{"widgettype": "Text", "options": {"text": "点击或拖拽文件到此处上传", "cfontsize": 16, "color": "#555"}},
{"widgettype": "Text", "options": {"text": "支持: TXT, PDF, JPG, PNG, MP3, WAV, MP4, AVI", "cfontsize": 12, "color": "#999"}},
{"widgettype": "Text", "options": {"text": "单个文件最大 500MB · 自动向量化入库", "cfontsize": 12, "color": "#999"}}
{"widgettype": "Text", "options": {"text": "点击选择文件上传", "cfontsize": 16, "color": "#555"}},
{"widgettype": "Text", "options": {"text": "支持: TXT, PDF, JPG, PNG, MP3, WAV, MP4", "cfontsize": 12, "color": "#999"}},
{"widgettype": "Button", "options": {"label": "选择文件", "bgcolor": "#3b82f6", "color": "#fff", "padding": "8px 20px", "marginTop": "12px"},
"binds": [{"wid": "self", "event": "click", "actiontype": "script",
"script": "var inp=document.createElement('input');inp.type='file';inp.onchange=function(e){var f=e.target.files[0];if(!f)return;var st=document.getElementById('status_text');if(st)st.innerText='上传中: '+f.name;var r=new XMLHttpRequest();r.open('POST','/api/doc/upload?kb_id=" + kb_id + "&file_name='+encodeURIComponent(f.name));r.onload=function(){if(st)st.innerText=r.status===200?'上传成功: '+f.name:'上传失败: HTTP '+r.status;location.reload()};r.send(f)};inp.click()"}]}
]
},
{
"widgettype": "VBox",
"options": {
"id": "upload_status",
"width": "100%",
"padding": "12px",
"bgcolor": "#f0fdf4",
"border": "1px solid #86efac"
},
"options": {"id": "upload_status", "width": "100%", "padding": "12px", "bgcolor": "#f0fdf4", "border": "1px solid #86efac"},
"subwidgets": [
{"widgettype": "Text", "options": {"text": "⏳ 等待上传...", "cfontsize": 13, "color": "#666", "id": "status_text"}}
{"widgettype": "Text", "options": {"text": "⏳ 选择文件开始上传", "cfontsize": 13, "color": "#666", "id": "status_text"}}
]
}
]