fix: use TextFiles widget (UiText+file+send) instead of broken render event
This commit is contained in:
parent
87f0fa6045
commit
614c883863
@ -83,70 +83,22 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"widgettype": "TextFiles",
|
||||
"id": "chat_input",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"bgcolor": "#fff",
|
||||
"border": "1px solid #e2e8f0",
|
||||
"borderTop": "none",
|
||||
"borderRadius": "0 0 8px 8px",
|
||||
"padding": "10px 14px 10px 14px",
|
||||
"gap": "6px"
|
||||
"padding": "10px 14px 10px 14px"
|
||||
},
|
||||
"subwidgets": [
|
||||
"binds": [
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"id": "file_list",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"wrap": "wrap",
|
||||
"gap": "4px",
|
||||
"minHeight": "0"
|
||||
},
|
||||
"subwidgets": []
|
||||
},
|
||||
{
|
||||
"widgettype": "Form",
|
||||
"id": "chat_form",
|
||||
"options": {
|
||||
"name": "chat_form",
|
||||
"padding": "0",
|
||||
"fields": [
|
||||
{ "name": "message_text", "uitype": "textarea", "placeholder": "输入需求或回复 Agent...", "rows": 2 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"alignItems": "center",
|
||||
"gap": "8px",
|
||||
"padding": "4px 0 0 0"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": { "name": "attach_btn", "label": "添加文件" },
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self", "event": "click", "actiontype": "script", "target": "self",
|
||||
"script": "var inp=document.createElement('input');inp.type='file';inp.multiple=true;inp.onchange=function(){var list=document.getElementById('cockpit_file_bag');if(!list){list=document.createElement('div');list.id='cockpit_file_bag';list.style.cssText='display:flex;flex-wrap:wrap;gap:4px';var fl=bricks.getWidgetById('file_list');if(fl)fl.dom_element.appendChild(list);}for(var i=0;i<this.files.length;i++){var n=this.files[i].name;if(list.querySelector('[data-fn=\"'+n.replace(/\"/g,'')+'\"]'))continue;var chip=document.createElement('span');chip.setAttribute('data-fn',n);chip.style.cssText='display:inline-flex;align-items:center;gap:3px;background:#e8f0fe;color:#1e40af;padding:2px 8px;border-radius:12px;font-size:12px;max-width:200px';chip.innerHTML='<span style=\"overflow:hidden;text-overflow:ellipsis;white-space:nowrap\">'+n+'</span><span style=\"cursor:pointer;font-weight:bold;color:#ef4444;margin-left:2px\" onclick=\"this.parentElement.remove()\">×</span>';list.appendChild(chip);}};inp.click();"
|
||||
}
|
||||
]
|
||||
},
|
||||
{ "widgettype": "Filler" },
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": { "name": "send_btn", "label": "发送", "css": "primary" },
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self", "event": "click", "actiontype": "script", "target": "self",
|
||||
"script": "var form=bricks.getWidgetById('chat_form');var msg=form?form.getValue('message_text'):'';if(!msg||!msg.trim()){bricks.show_error({title:'提示',message:'请输入内容'});return;}var iter=bricks.getWidgetById('current_iteration_id');var iid=iter?iter.options.value:'';if(!iid){bricks.show_error({title:'提示',message:'请先选择迭代'});return;}var files=[];var bag=document.getElementById('cockpit_file_bag');if(bag){var chips=bag.querySelectorAll('[data-fn]');for(var j=0;j<chips.length;j++)files.push(chips[j].getAttribute('data-fn'));}var body='message_text='+encodeURIComponent(msg)+'&iteration_id='+encodeURIComponent(iid)+'&action=send_message&file_paths='+encodeURIComponent(JSON.stringify(files));fetch('/pipeline-sdlc/api/cockpit_chat.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:body}).then(function(r){return r.json()}).then(function(r){if(r.success||r.error){form.setValue('message_text','');if(bag)bag.innerHTML='';var c=bricks.getWidgetById('chat_scroll');if(c)c.render({});}});"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
"wid": "self",
|
||||
"event": "inputed",
|
||||
"actiontype": "script",
|
||||
"target": "self",
|
||||
"script": "var prompt=e.params.prompt;var files=e.params.add_files||[];var iter=bricks.getWidgetById('current_iteration_id');var iid=iter?iter.options.value:'';if(!iid){bricks.show_error({title:'提示',message:'请先选择迭代'});return;}var body='message_text='+encodeURIComponent(prompt)+'&iteration_id='+encodeURIComponent(iid)+'&action=send_message&file_paths='+encodeURIComponent(JSON.stringify(files.map(function(f){return f.name||f})));fetch('/pipeline-sdlc/api/cockpit_chat.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:body}).then(function(r){return r.json()}).then(function(r){if(r.success||r.error){var c=bricks.getWidgetById('chat_scroll');if(c)c.render({});}});"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -83,75 +83,22 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"widgettype": "TextFiles",
|
||||
"id": "chat_input",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"bgcolor": "#fff",
|
||||
"border": "1px solid #e2e8f0",
|
||||
"borderTop": "none",
|
||||
"borderRadius": "0 0 8px 8px",
|
||||
"padding": "10px 14px 10px 14px",
|
||||
"gap": "6px"
|
||||
"padding": "10px 14px 10px 14px"
|
||||
},
|
||||
"subwidgets": [
|
||||
"binds": [
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"id": "file_list",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"wrap": "wrap",
|
||||
"gap": "4px",
|
||||
"minHeight": "0"
|
||||
},
|
||||
"subwidgets": []
|
||||
},
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"id": "uitext_wrapper",
|
||||
"options": {
|
||||
"width": "100%"
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "render",
|
||||
"actiontype": "script",
|
||||
"target": "self",
|
||||
"script": "if(!this._built){this._built=true;var c=this.dom_element;var ut=new bricks.UiText({name:'cockpit_input',placeholder:'输入需求或回复 Agent...'});ut.dom_element.style.cssText='width:100%;min-height:44px;max-height:160px;padding:10px 12px;border:1px solid #e2e8f0;border-radius:8px;font-size:14px;font-family:inherit;resize:none;outline:none;box-sizing:border-box;line-height:1.5';c.appendChild(ut.dom_element);ut.handleInput();this._uitext=ut;}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"alignItems": "center",
|
||||
"gap": "8px",
|
||||
"padding": "4px 0 0 0"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": { "name": "attach_btn", "label": "添加文件" },
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self", "event": "click", "actiontype": "script", "target": "self",
|
||||
"script": "var inp=document.createElement('input');inp.type='file';inp.multiple=true;inp.onchange=function(){var list=document.getElementById('cockpit_file_bag');if(!list){list=document.createElement('div');list.id='cockpit_file_bag';list.style.cssText='display:flex;flex-wrap:wrap;gap:4px';var fl=bricks.getWidgetById('file_list');if(fl)fl.dom_element.appendChild(list);}for(var i=0;i<this.files.length;i++){var n=this.files[i].name;if(list.querySelector('[data-fn=\"'+n.replace(/\"/g,'')+'\"]'))continue;var chip=document.createElement('span');chip.setAttribute('data-fn',n);chip.style.cssText='display:inline-flex;align-items:center;gap:3px;background:#e8f0fe;color:#1e40af;padding:2px 8px;border-radius:12px;font-size:12px;max-width:200px';chip.innerHTML='<span style=\"overflow:hidden;text-overflow:ellipsis;white-space:nowrap\">'+n+'</span><span style=\"cursor:pointer;font-weight:bold;color:#ef4444;margin-left:2px\" onclick=\"this.parentElement.remove()\">×</span>';list.appendChild(chip);}};inp.click();"
|
||||
}
|
||||
]
|
||||
},
|
||||
{ "widgettype": "Filler" },
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": { "name": "send_btn", "label": "发送", "css": "primary" },
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self", "event": "click", "actiontype": "script", "target": "self",
|
||||
"script": "var ut=document.getElementsByName('cockpit_input')[0];var msg=ut?ut.value.trim():'';if(!msg){bricks.show_error({title:'提示',message:'请输入内容'});return;}var iter=bricks.getWidgetById('current_iteration_id');var iid=iter?iter.options.value:'';if(!iid){bricks.show_error({title:'提示',message:'请先选择迭代'});return;}var files=[];var bag=document.getElementById('cockpit_file_bag');if(bag){var chips=bag.querySelectorAll('[data-fn]');for(var j=0;j<chips.length;j++)files.push(chips[j].getAttribute('data-fn'));}var body='message_text='+encodeURIComponent(msg)+'&iteration_id='+encodeURIComponent(iid)+'&action=send_message&file_paths='+encodeURIComponent(JSON.stringify(files));fetch('/pipeline-sdlc/api/cockpit_chat.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:body}).then(function(r){return r.json()}).then(function(r){if(r.success||r.error){ut.value='';ut.dispatchEvent(new Event('input',{bubbles:true}));if(bag)bag.innerHTML='';var c=bricks.getWidgetById('chat_scroll');if(c)c.render({});}});"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
"wid": "self",
|
||||
"event": "inputed",
|
||||
"actiontype": "script",
|
||||
"target": "self",
|
||||
"script": "var prompt=e.params.prompt;var files=e.params.add_files||[];var iter=bricks.getWidgetById('current_iteration_id');var iid=iter?iter.options.value:'';if(!iid){bricks.show_error({title:'提示',message:'请先选择迭代'});return;}var body='message_text='+encodeURIComponent(prompt)+'&iteration_id='+encodeURIComponent(iid)+'&action=send_message&file_paths='+encodeURIComponent(JSON.stringify(files.map(function(f){return f.name||f})));fetch('/pipeline-sdlc/api/cockpit_chat.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:body}).then(function(r){return r.json()}).then(function(r){if(r.success||r.error){var c=bricks.getWidgetById('chat_scroll');if(c)c.render({});}});"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user