fix: inline upload script with kb_id from jinja2 + folder from tree selection
This commit is contained in:
parent
1a85c77ba4
commit
8d4e707c7c
@ -34,6 +34,7 @@
|
|||||||
"widgettype": "Tree",
|
"widgettype": "Tree",
|
||||||
"options": {
|
"options": {
|
||||||
"title": "目录",
|
"title": "目录",
|
||||||
|
"id": "dir_tree",
|
||||||
"parentField": "parentid",
|
"parentField": "parentid",
|
||||||
"idField": "id",
|
"idField": "id",
|
||||||
"textField": "label",
|
"textField": "label",
|
||||||
@ -47,7 +48,15 @@
|
|||||||
"update_url": "{{entire_url('./update_tree_item.dspy')}}",
|
"update_url": "{{entire_url('./update_tree_item.dspy')}}",
|
||||||
"delete_url": "{{entire_url('./delete_tree_item.dspy')}}"
|
"delete_url": "{{entire_url('./delete_tree_item.dspy')}}"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"binds": [
|
||||||
|
{
|
||||||
|
"wid": "self",
|
||||||
|
"event": "selected",
|
||||||
|
"actiontype": "script",
|
||||||
|
"script": "window._rag_current_folder = event.params.id ? event.params.id : ''"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -57,18 +66,9 @@
|
|||||||
"subwidgets": [
|
"subwidgets": [
|
||||||
{
|
{
|
||||||
"widgettype": "VBox",
|
"widgettype": "VBox",
|
||||||
"options": {
|
"options": {"id": "drop_zone", "width": "100%", "cheight": 8, "bgcolor": "#f8f9fa", "padding": "16px", "css": "card", "border": "2px dashed #3b82f6", "alignItems": "center", "justifyContent": "center"},
|
||||||
"width": "100%",
|
|
||||||
"cheight": 8,
|
|
||||||
"bgcolor": "#f8f9fa",
|
|
||||||
"padding": "16px",
|
|
||||||
"css": "card",
|
|
||||||
"border": "2px dashed #3b82f6",
|
|
||||||
"alignItems": "center",
|
|
||||||
"justifyContent": "center"
|
|
||||||
},
|
|
||||||
"subwidgets": [
|
"subwidgets": [
|
||||||
{"widgettype": "Text", "options": {"text": "📂 点击或拖拽文件到此处上传", "cfontsize": 15, "color": "#888"}},
|
{"widgettype": "Text", "options": {"text": "📂 点击选择文件上传", "cfontsize": 15, "color": "#888"}},
|
||||||
{"widgettype": "Text", "options": {"text": "支持 TXT/PDF/JPG/PNG/MP3/WAV/MP4", "cfontsize": 12, "color": "#aaa"}},
|
{"widgettype": "Text", "options": {"text": "支持 TXT/PDF/JPG/PNG/MP3/WAV/MP4", "cfontsize": 12, "color": "#aaa"}},
|
||||||
{
|
{
|
||||||
"widgettype": "Button",
|
"widgettype": "Button",
|
||||||
@ -76,12 +76,11 @@
|
|||||||
"binds": [{
|
"binds": [{
|
||||||
"wid": "self",
|
"wid": "self",
|
||||||
"event": "click",
|
"event": "click",
|
||||||
"actiontype": "urlwidget",
|
"actiontype": "script",
|
||||||
"target": "app.detail_content",
|
"script": "var i=document.createElement('input');i.type='file';i.multiple=true;i.onchange=function(){var kb='{{params_kw.kb_id}}';var fd=window._rag_current_folder||'';for(var j=0;j<i.files.length;j++){var f=i.files[j];var x=new XMLHttpRequest();x.open('POST','/api/doc/upload?kb_id='+kb+'&file_name='+encodeURIComponent(f.name)+'&folder='+fd);x.onload=function(){if(x.status===200){var st=document.getElementById('upload_status');if(st)st.innerText='上传成功: '+f.name;else location.reload()}};x.send(f)}};i.click()"
|
||||||
"mode": "replace",
|
|
||||||
"options": {"url": "{{entire_url('./upload.dspy')}}", "params": {"kb_id": "{{params_kw.kb_id}}"}}
|
|
||||||
}]
|
}]
|
||||||
}
|
},
|
||||||
|
{"widgettype": "Text", "options": {"id": "upload_status", "cfontsize": 12, "color": "#50b86c", "marginTop": "8px", "text": ""}}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{"widgettype": "Text", "options": {"text": "暂无文件", "cfontsize": 13, "color": "#aaa", "halign": "center"}}
|
{"widgettype": "Text", "options": {"text": "暂无文件", "cfontsize": 13, "color": "#aaa", "halign": "center"}}
|
||||||
|
|||||||
@ -13,17 +13,11 @@ body = json.dumps({
|
|||||||
"options": {"id": "upload_zone", "width": "100%", "cheight": 10, "bgcolor": "#f8f9fa", "padding": "24px", "css": "card", "border": "2px dashed #3b82f6", "alignItems": "center", "justifyContent": "center"},
|
"options": {"id": "upload_zone", "width": "100%", "cheight": 10, "bgcolor": "#f8f9fa", "padding": "24px", "css": "card", "border": "2px dashed #3b82f6", "alignItems": "center", "justifyContent": "center"},
|
||||||
"subwidgets": [
|
"subwidgets": [
|
||||||
{"widgettype": "Text", "options": {"text": "📂", "cfontsize": 40}},
|
{"widgettype": "Text", "options": {"text": "📂", "cfontsize": 40}},
|
||||||
{"widgettype": "Text", "options": {"text": "拖拽文件到此处上传", "cfontsize": 15, "color": "#888"}},
|
{"widgettype": "Text", "options": {"text": "拖拽文件或点击按钮上传", "cfontsize": 15, "color": "#888"}},
|
||||||
{"widgettype": "Text", "options": {"text": "支持: TXT,PDF,JPG,PNG,MP3,WAV,MP4", "cfontsize": 12, "color": "#aaa"}},
|
{"widgettype": "Text", "options": {"text": "支持: TXT,PDF,JPG,PNG,MP3,WAV,MP4", "cfontsize": 12, "color": "#aaa"}},
|
||||||
{
|
{
|
||||||
"widgettype": "Button",
|
"widgettype": "Button",
|
||||||
"options": {"label": "选择文件上传", "bgcolor": "#3b82f6", "color": "#fff", "marginTop": "12px"},
|
"options": {"label": "选择文件上传", "bgcolor": "#3b82f6", "color": "#fff", "marginTop": "12px"}
|
||||||
"binds": [{
|
|
||||||
"wid": "self",
|
|
||||||
"event": "click",
|
|
||||||
"actiontype": "script",
|
|
||||||
"script": "var i=document.createElement('input');i.type='file';i.onchange=function(){for(var j=0;j<i.files.length;j++){var f=i.files[j];var x=new XMLHttpRequest();x.open('POST','/api/doc/upload?kb_id=" + kb_id + "&file_name='+encodeURIComponent(f.name));x.send(f)}};i.click()"
|
|
||||||
}]
|
|
||||||
},
|
},
|
||||||
{"widgettype": "Text", "options": {"text": "", "id": "upload_status", "cfontsize": 12, "color": "#50b86c", "marginTop": "8px"}}
|
{"widgettype": "Text", "options": {"text": "", "id": "upload_status", "cfontsize": 12, "color": "#50b86c", "marginTop": "8px"}}
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user