bi-sdk-react 0.0.44 → 0.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/js/bi-sdk.es.js
CHANGED
|
@@ -417,7 +417,7 @@ import*as e from"react";import t,{css as n}from"styled-components";import{AlignC
|
|
|
417
417
|
.conversation-list li small {
|
|
418
418
|
white-space: nowrap;
|
|
419
419
|
}
|
|
420
|
-
`,nM=[],nI="bi-design",nD=e=>{let t,n,r,i,a,o,s,{agentList:l=nM,headExtra:u,style:h={},onEffect:d}=e,{pageId:p,schema:f,fetch:g,atItems:v,onRemoveAtItem:y,clearAtItems:x}=(0,t_.useContext)(tb);if(!g)return null;let[b,w]=(0,t_.useState)(null),[S,C]=(0,t_.useState)([]),[k,T]=(0,t_.useState)([]),j=t_.default.useRef(null),M=()=>{setTimeout(()=>{j.current&&j.current.scrollToBottom()},100)},I=()=>{w(null),T([])},D=async e=>{$.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=g.ai)?void 0:t.removeConversation(e)),C(t=>t.filter(t=>t.id!==e)),T(t=>t.filter(t=>t.conversationId!==e)),b===e&&I()}})},O=async e=>{var t,n,r;w(e),C(t=>t.map(t=>({...t,isActived:t.id===e}))),await (null==(n=g.ai)||null==(t=n.activateConversation)?void 0:t.call(n,e)),T(await (null==(r=g.ai)?void 0:r.messageList(e))||[]),M()},A=async e=>{var t;let
|
|
420
|
+
`,nM=[],nI="bi-design",nD=e=>{let t,n,r,i,a,o,s,{agentList:l=nM,headExtra:u,style:h={},onEffect:d}=e,{pageId:p,schema:f,fetch:g,atItems:v,onRemoveAtItem:y,clearAtItems:x}=(0,t_.useContext)(tb);if(!g)return null;let[b,w]=(0,t_.useState)(null),[S,C]=(0,t_.useState)([]),[k,T]=(0,t_.useState)([]),j=t_.default.useRef(null),M=()=>{setTimeout(()=>{j.current&&j.current.scrollToBottom()},100)},I=()=>{w(null),T([])},D=async e=>{$.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=g.ai)?void 0:t.removeConversation(e)),C(t=>t.filter(t=>t.id!==e)),T(t=>t.filter(t=>t.conversationId!==e)),b===e&&I()}})},O=async e=>{var t,n,r;w(e),C(t=>t.map(t=>({...t,isActived:t.id===e}))),await (null==(n=g.ai)||null==(t=n.activateConversation)?void 0:t.call(n,e)),T(await (null==(r=g.ai)?void 0:r.messageList(e))||[]),M()},A=async e=>{var t,n,r;let i={id:em(),question:e.message,createdAt:new Date().toISOString(),files:e.files||[],agents:e.agents||[],atItems:JSON.stringify(v),sending:!0};T(e=>[...e,i]),M();let a=!b;x();try{let{id:n,answer:r,createdAt:o,conversation:s}=await (null==(t=g.ai)?void 0:t.chat(nI,p,b,{...e,page:f,pageItems:v||[]}));w((null==s?void 0:s.id)||""),C(e=>[a?s||{}:null,...e].filter(e=>null!==e)),Object.assign(i,{id:n,answer:r,createdAt:o,conversationId:(null==s?void 0:s.id)||"",sending:!1}),r.effect&&(null==d||d(r.effect))}catch(t){let e=(null==t||null==(r=t.response)||null==(n=r.data)?void 0:n.message)||t.message||"未知错误";console.error(e),Object.assign(i,{sending:!1,error:e})}T(e=>[...e]),M()},P=async e=>{var t;await (null==(t=g.ai)?void 0:t.removeMessage(e)),T(t=>t.filter(t=>t.id!==e))},z=(t=new Date,n=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),(r=new Date(t)).setDate(t.getDate()-1),i=[],a=[],o=[],s=[],S.forEach(e=>{let l=new Date(e.createdAt);if(n(l,t))i.push(e);else if(n(l,r))a.push(e);else l.getFullYear()===t.getFullYear()&&l.getMonth()===t.getMonth()?o.push(e):s.push(e)}),[{title:"今天",items:i},{title:"昨天",items:a},{title:"本月内",items:o},{title:"很久以前",items:s}].filter(e=>e.items.length>0)),L=async()=>{try{var e,t;let n=await (null==(e=g.ai)?void 0:e.conversationList(nI,p));C(n||[]);let r=null==n?void 0:n.find(e=>e.isActived);if(r){w(r.id);let e=await (null==(t=g.ai)?void 0:t.messageList(r.id));T(e||[]),M()}}catch(e){console.error(e)}};return(0,t_.useEffect)(()=>{L()},[g]),(0,t_.useEffect)(()=>{M()},[]),(0,tx.jsxs)(nj,{style:h,children:[(0,tx.jsx)(nT,{title:"智能助理",extra:(0,tx.jsxs)(er,{children:[(0,tx.jsx)(el,{title:"新对话",placement:"topRight",children:(0,tx.jsx)("a",{onClick:I,children:(0,tx.jsx)(na,{type:"icon-chat-plus"})})}),(0,tx.jsx)(G,{trigger:["click"],styles:{root:{boxShadow:"var(--ant-box-shadow-drawer-up)",backgroundColor:"#ffffff",borderRadius:"var(--ant-border-radius)"}},popupRender:()=>(0,tx.jsx)(nP,{children:z.map(e=>(0,tx.jsxs)("div",{className:"group",children:[(0,tx.jsx)("div",{className:"group-title",children:e.title}),(0,tx.jsx)("ul",{className:"group-list",children:e.items.map(e=>(0,tx.jsxs)("li",{className:e.isActived?"actived":"",children:[(0,tx.jsx)("a",{onClick:()=>O(e.id),children:e.name}),(0,tx.jsx)("small",{children:(0,tx.jsx)("a",{onClick:()=>D(e.id),children:(0,tx.jsx)(c,{})})})]},e.id))})]},e.title))}),placement:"topRight",children:(0,tx.jsx)("a",{children:(0,tx.jsx)(m,{})})}),u]}),style:{width:"initial"}}),(0,tx.jsxs)("div",{className:"body",children:[(0,tx.jsx)("div",{style:{flex:"1 1 auto",overflowY:"auto"},children:k.length?(0,tx.jsx)(nL,{ref:j,list:k,onDeleteMessage:P}):(0,tx.jsx)(nA,{})}),0===k.length&&S.length>0&&(0,tx.jsx)(E,{title:"历史记录",size:"small",variant:"borderless",styles:{header:{padding:0,border:"none"},body:{padding:0}},style:{padding:"12px 12px 0 12px"},children:(0,tx.jsx)("ul",{className:"conversation-list",children:S.slice(0,3).map(e=>(0,tx.jsxs)("li",{children:[(0,tx.jsxs)("a",{children:[(0,tx.jsx)(_,{}),e.name]}),(0,tx.jsx)("small",{children:nm(e.createdAt)})]},e.id))})}),(0,tx.jsx)(nC,{agentList:l,style:{padding:12},atItems:v,onUploading:null==g?void 0:g.upload,onSubmit:A,onRemoveAtItem:y})]})]})},nO=t.div`
|
|
421
421
|
flex: 1 1 auto;
|
|
422
422
|
display: flex;
|
|
423
423
|
align-items: center;
|
|
@@ -574,6 +574,11 @@ import*as e from"react";import t,{css as n}from"styled-components";import{AlignC
|
|
|
574
574
|
font-size: 13px;
|
|
575
575
|
line-height: 1.6;
|
|
576
576
|
white-space: pre-wrap;
|
|
577
|
+
|
|
578
|
+
&.error {
|
|
579
|
+
color: var(--ant-color-error-text);
|
|
580
|
+
padding: 10px 0;
|
|
581
|
+
}
|
|
577
582
|
}
|
|
578
583
|
.msg-meta {
|
|
579
584
|
display: flex;
|
|
@@ -632,7 +637,7 @@ import*as e from"react";import t,{css as n}from"styled-components";import{AlignC
|
|
|
632
637
|
}
|
|
633
638
|
}
|
|
634
639
|
}
|
|
635
|
-
`,nL=(0,t_.forwardRef)((e,t)=>{let{list:n,onDeleteMessage:r}=e,i=(0,t_.useRef)(null),a=()=>{setTimeout(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},100)};return(0,t_.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,tx.jsx)(nz,{className:"message-list beautified_scrollbar",ref:i,children:n.map(e=>{var t,n,i,a,o,s,l,u,h,d;return(0,tx.jsxs)("div",{className:"msg",children:[(0,tx.jsxs)("div",{className:"user-message",children:[(0,tx.jsx)("div",{className:"msg-header",children:(0,tx.jsx)("span",{children:nm(e.createdAt)})}),(0,tx.jsxs)("div",{className:"msg-section",children:[(0,tx.jsxs)(er,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,tx.jsx)(ec.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,tx.jsx)(Z,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>r(e.id),children:(0,tx.jsx)(el,{title:"删除",children:(0,tx.jsx)(R,{type:"link",size:"small",icon:(0,tx.jsx)(c,{})})})})]}),(0,tx.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(n=e.agents)?void 0:n.length)||(null==(i=e.atItems)?void 0:i.length)?(0,tx.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,tx.jsxs)(eo,{color:"processing",children:[(0,tx.jsx)(na,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(o=e.agents)?void 0:o.map(e=>(0,tx.jsxs)(eo,{color:"blue",children:[(0,tx.jsx)(na,{type:"icon-at"})," ",e.name]},e.id)),(e=>{try{if(e){if("object"==typeof e)return e;else if("string"==typeof e)return JSON.parse(e||"[]")}return[]}catch(e){return[]}})(e.atItems).map(e=>(0,tx.jsxs)(eo,{color:"blue",children:[(0,tx.jsx)(na,{type:"icon-number"})," ",e.name]},e.id))]}):null]})]}),(0,tx.jsxs)("div",{className:"assistant-message",children:[(0,tx.jsx)("div",{className:"msg-header",children:(0,tx.jsxs)("span",{className:"msg-title",children:[(0,tx.jsx)(T,{})," 智能助理"]})}),(0,tx.jsx)("div",{className:"msg-section",children:e.sending?(0,tx.jsx)(en,{active:!0}):(0,tx.jsxs)(tx.Fragment,{children:[(0,tx.jsx)("div",{className:"msg-content",children:(null==(s=e.answer)?void 0:s.answer)||""}),!!(null==(u=e.answer)||null==(l=u.plans)?void 0:l.length)&&(0,tx.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,tx.jsx)("summary",{className:"msg-ai-meta-title",children:"PLANS:"}),(0,tx.jsx)("div",{className:"msg-ai-meta-list",children:e.answer.plans.map((e,t)=>(0,tx.jsx)(el,{title:e.description,children:(0,tx.jsx)(eo,{color:"blue",children:e.name})},t))})]}),!!(null==(d=e.answer)||null==(h=d.extra)?void 0:h.length)&&(0,tx.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,tx.jsx)("summary",{className:"msg-ai-meta-title",children:"ACTIONS:"}),(0,tx.jsx)("div",{className:"msg-ai-meta-list vertical",children:e.answer.extra.map((e,t)=>(0,tx.jsxs)("div",{className:"msg-ai-meta-list-item",children:[(0,tx.jsx)(eo,{color:"gold",children:e.element}),(0,tx.jsx)("span",{children:e.action})]},t))})]})]})})]})]},e.id)})})}),nN=t.div`
|
|
640
|
+
`,nL=(0,t_.forwardRef)((e,t)=>{let{list:n,onDeleteMessage:r}=e,i=(0,t_.useRef)(null),a=()=>{setTimeout(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},100)};return(0,t_.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,tx.jsx)(nz,{className:"message-list beautified_scrollbar",ref:i,children:n.map(e=>{var t,n,i,a,o,s,l,u,h,d;return(0,tx.jsxs)("div",{className:"msg",children:[(0,tx.jsxs)("div",{className:"user-message",children:[(0,tx.jsx)("div",{className:"msg-header",children:(0,tx.jsx)("span",{children:nm(e.createdAt)})}),(0,tx.jsxs)("div",{className:"msg-section",children:[(0,tx.jsxs)(er,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,tx.jsx)(ec.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,tx.jsx)(Z,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>r(e.id),children:(0,tx.jsx)(el,{title:"删除",children:(0,tx.jsx)(R,{type:"link",size:"small",icon:(0,tx.jsx)(c,{})})})})]}),(0,tx.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(n=e.agents)?void 0:n.length)||(null==(i=e.atItems)?void 0:i.length)?(0,tx.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,tx.jsxs)(eo,{color:"processing",children:[(0,tx.jsx)(na,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(o=e.agents)?void 0:o.map(e=>(0,tx.jsxs)(eo,{color:"blue",children:[(0,tx.jsx)(na,{type:"icon-at"})," ",e.name]},e.id)),(e=>{try{if(e){if("object"==typeof e)return e;else if("string"==typeof e)return JSON.parse(e||"[]")}return[]}catch(e){return[]}})(e.atItems).map(e=>(0,tx.jsxs)(eo,{color:"blue",children:[(0,tx.jsx)(na,{type:"icon-number"})," ",e.name]},e.id))]}):null]})]}),(0,tx.jsxs)("div",{className:"assistant-message",children:[(0,tx.jsx)("div",{className:"msg-header",children:(0,tx.jsxs)("span",{className:"msg-title",children:[(0,tx.jsx)(T,{})," 智能助理"]})}),(0,tx.jsx)("div",{className:"msg-section",children:e.sending?(0,tx.jsx)(en,{active:!0}):(0,tx.jsxs)(tx.Fragment,{children:[e.error?(0,tx.jsxs)("div",{className:"msg-content error",children:["执行失败:",e.error]}):(0,tx.jsx)("div",{className:"msg-content",children:(null==(s=e.answer)?void 0:s.answer)||""}),!!(null==(u=e.answer)||null==(l=u.plans)?void 0:l.length)&&(0,tx.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,tx.jsx)("summary",{className:"msg-ai-meta-title",children:"PLANS:"}),(0,tx.jsx)("div",{className:"msg-ai-meta-list",children:e.answer.plans.map((e,t)=>(0,tx.jsx)(el,{title:e.description,children:(0,tx.jsx)(eo,{color:"blue",children:e.name})},t))})]}),!!(null==(d=e.answer)||null==(h=d.extra)?void 0:h.length)&&(0,tx.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,tx.jsx)("summary",{className:"msg-ai-meta-title",children:"ACTIONS:"}),(0,tx.jsx)("div",{className:"msg-ai-meta-list vertical",children:e.answer.extra.map((e,t)=>(0,tx.jsxs)("div",{className:"msg-ai-meta-list-item",children:[(0,tx.jsx)(eo,{color:"gold",children:e.element}),(0,tx.jsx)("span",{children:e.action})]},t))})]})]})})]})]},e.id)})})}),nN=t.div`
|
|
636
641
|
display: flex;
|
|
637
642
|
flex-direction: column;
|
|
638
643
|
height: 100%;
|
|
@@ -984,7 +989,7 @@ import*as e from"react";import t,{css as n}from"styled-components";import{AlignC
|
|
|
984
989
|
background: transparent;
|
|
985
990
|
}
|
|
986
991
|
}
|
|
987
|
-
`,n8=e=>{let{open:t,onCancel:n,onOk:r}=e,[i,a]=(0,t_.useState)(JSON.stringify({info:{},datasources:[],scripts:[],variables:[],items:[]}));return(0,tx.jsx)($,{title:"导入页面",open:t,width:800,onCancel:n,onOk:()=>null==r?void 0:r(JSON.parse(i)),okText:"导入",cancelText:"取消",styles:{body:{height:"calc(100vh - 250px)",overflow:"auto"}},children:(0,tx.jsx)("div",{className:"body",style:{flex:"1 1 auto",display:"flex",height:"100%"},children:(0,tx.jsx)(eg,{height:"100%",defaultLanguage:"json",value:i,options:{minimap:{enabled:!1}},onChange:e=>a(e||"")})})})},n9=t_.default.forwardRef((e,t)=>{var n;let r,{pageId:i,agentList:a=[],plugins:o=[],headerExtra:s,datasourceEnable:u=!0,scriptEnable:c=!0,datasetPanel:d,datasetSelector:g,datasetAdd:m,fetch:y,onSave:x,loading:_=!1}=e,b=(0,t_.useRef)(null),S=(0,t_.useRef)(null),[C,T]=(0,t_.useState)(1),[M,I]=(0,t_.useState)([]),[A,L]=(0,t_.useState)([]),[N,E]=(0,t_.useState)(!1),[B,F]=(0,t_.useState)("desktop"),[H,V]=(0,t_.useState)("component"),[G,U]=(0,t_.useState)((null==y?void 0:y.ai)?"ai":"props"),[q,X]=(0,t_.useState)(!0),[$,K]=(0,t_.useState)(!0),[Z,J]=(0,t_.useState)(null),[ee,et]=(0,t_.useState)({info:{},datasources:[],scripts:[],variables:[],items:[]}),[en,ei]=(0,t_.useState)(!0),[ea,eo]=(0,t_.useState)(!1),[es,eu]=(0,t_.useState)(!1),ec=(0,t_.useMemo)(()=>{let e=q?"250px":"",t=$?"400px":"";return{gridTemplateColumns:`${e} 1fr ${t}`}},[q,$]),eh=(0,t_.useMemo)(()=>({display:q?"flex":"none"}),[q]),ed=(0,t_.useMemo)(()=>({display:$?"flex":"none"}),[$]);n=[ee],(r=(0,t_.useRef)()).current===JSON.stringify(n)&&r.current||(r.current=JSON.stringify(n),(()=>{N||(I(e=>e.length?[...e,JSON.parse(JSON.stringify(ee))].slice(-50):[JSON.parse(JSON.stringify(ee))]),L([]))})()),(0,t_.useImperativeHandle)(t,()=>({handleOpen(e){E(!0),ep(e.items),et(e),I([JSON.parse(JSON.stringify(e))]),L([]),setTimeout(()=>E(!1),0)}}));let ep=(e,t)=>{e&&e.forEach(e=>{e.id||(e.id=t||em()),Array.isArray(e.children)?ep(e.children):"object"==typeof e.children&&e.children&&Object.keys(e.children).forEach(t=>{Array.isArray(e.children[t])&&ep(e.children[t],em())})})},ef=e=>{var t,n,r;if((null==(t=e.datasets)?void 0:t.length)&&(null==S||null==(n=S.current)?void 0:n.reload)&&S.current.reload(),e.schema){let t=JSON.parse(JSON.stringify(e.schema));ep(t.items),et(t)}else if(null==(r=e.pageItems)?void 0:r.length){let t=new Map;e.pageItems.forEach(e=>{t.has(e.targetId)||t.set(e.targetId,[]),t.get(e.targetId).push(e)});let n=JSON.parse(JSON.stringify(ee)),r=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];e.forEach((n,i)=>{t.has(n.id)&&t.get(n.id).forEach(t=>{let{position:r,insertSlot:a,pageItem:s}=t;switch(r){case"before":e.splice(i,0,s);break;case"after":e.splice(i+1,0,s);break;case"replace":Object.keys(n).forEach(e=>{"id"!==e&&delete n[e]}),Object.assign(n,s);break;case"insert":var l,u,c;let h=o.find(e=>e.key===n.type);Array.isArray(null==h||null==(l=h.defaultOptions)?void 0:l.children)?n.children=[...n.children||[],s]:"object"==typeof(null==h||null==(u=h.defaultOptions)?void 0:u.children)&&a&&(n.children={...n.children||{},[a]:[...(null==(c=n.children)?void 0:c[a])||[],s]})}}),Array.isArray(n.children)?r(n.children):"object"==typeof n.children&&n.children&&Object.keys(n.children).forEach(e=>{Array.isArray(n.children[e])&&r(n.children[e])})})};r(n.items),et(n)}},eg=(0,t_.useMemo)(()=>"cascade"!==G||(null==Z?void 0:Z.cascadeIds)?G:"props",[Z,G]);return(0,tx.jsxs)(tw,{pageId:i,designable:en,plugins:o,schema:ee,selectedItem:Z,setSchema:et,setSelectedItem:J,datasetSelector:g,datasetAdd:m,fetch:y,children:[(0,tx.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,tx.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 24px",borderBottom:"solid 1px #e8e8e8"},children:[(0,tx.jsxs)(er,{children:[(0,tx.jsx)("span",{style:{fontSize:16,fontWeight:500},children:"创建数据报表"}),(0,tx.jsx)(W,{orientation:"vertical"}),(0,tx.jsx)(el,{title:"保存",children:(0,tx.jsx)(R,{type:"link",className:"toolbar",onClick:()=>{null==x||x(ee)},loading:_,children:(0,tx.jsx)(j,{})})}),(0,tx.jsx)(W,{orientation:"vertical"}),(0,tx.jsx)(el,{title:"撤销",children:(0,tx.jsx)("a",{className:`toolbar ${M.length>1?"active":""}`,onClick:()=>{I(e=>{if(e.length<=1)return e;E(!0);let t=e[e.length-2];return L(e=>[...e,JSON.parse(JSON.stringify(ee))]),et(t),J(null),setTimeout(()=>E(!1),0),e.slice(0,-1)})},children:(0,tx.jsx)(O,{})})}),(0,tx.jsx)(el,{title:"重做",children:(0,tx.jsx)("a",{className:`toolbar ${A.length>0?"active":""}`,onClick:()=>{L(e=>e.length?(E(!0),I(e=>[...e,JSON.parse(JSON.stringify(ee))]),et(e[e.length-1]),J(null),setTimeout(()=>E(!1),0),e.slice(0,-1)):e)},children:(0,tx.jsx)(k,{})})}),(0,tx.jsx)(W,{orientation:"vertical"}),(0,tx.jsx)(el,{title:"导入JSON",children:(0,tx.jsx)("a",{className:`toolbar ${A.length>0?"active":""}`,onClick:()=>{eo(!0)},children:(0,tx.jsx)(v,{})})})]}),(0,tx.jsxs)(er,{children:[(0,tx.jsx)(el,{title:"缩小",children:(0,tx.jsx)("a",{className:"toolbar",onClick:()=>T(parseFloat(Math.max(C-.1,.5).toFixed(1))),children:(0,tx.jsx)(z,{})})}),(0,tx.jsxs)("div",{style:{fontSize:12,color:"#999",userSelect:"none"},children:[(100*C).toFixed(0),"%"]}),(0,tx.jsx)(el,{title:"放大",children:(0,tx.jsx)("a",{className:"toolbar",onClick:()=>T(parseFloat(Math.min(C+.1,2).toFixed(1))),children:(0,tx.jsx)(P,{})})}),(0,tx.jsx)(el,{title:"重置缩放",children:(0,tx.jsx)("a",{className:"toolbar",onClick:()=>T(1),children:(0,tx.jsx)(na,{type:"icon-zoom-reset"})})}),(0,tx.jsx)(W,{orientation:"vertical"}),(0,tx.jsx)(el,{title:"切换左侧栏",children:(0,tx.jsx)("a",{className:`toolbar ${q?"active":""}`,onClick:()=>{X(e=>!e),setTimeout(()=>{var e,t;return null==(t=b.current)||null==(e=t.handleResize)?void 0:e.call(t)},0)},children:(0,tx.jsx)(na,{type:"icon-sider-l"})})}),(0,tx.jsx)(el,{title:"切换右侧栏",children:(0,tx.jsx)("a",{className:`toolbar ${$?"active":""}`,onClick:()=>{K(e=>!e),setTimeout(()=>{var e,t;return null==(t=b.current)||null==(e=t.handleResize)?void 0:e.call(t)},0)},children:(0,tx.jsx)(na,{type:"icon-sider-r"})})}),s]})]}),(0,tx.jsxs)(n5,{style:ec,children:[(0,tx.jsxs)("div",{className:"left",style:eh,children:[(0,tx.jsx)("div",{style:{padding:"22px 1px 22px 0",borderRight:"solid 1px #e8e8e8"},children:(0,tx.jsxs)(Q.Group,{value:H,onChange:e=>V(e.target.value),buttonStyle:"outline",style:{fontWeight:"normal",display:"inline-flex",flexDirection:"column",gap:14},className:"left-pane-tabs",children:[(0,tx.jsx)(Q.Button,{value:"component",children:(0,tx.jsx)(el,{title:"组件",placement:"right",children:(0,tx.jsx)(na,{type:"icon-puzzle"})})}),(0,tx.jsx)(Q.Button,{value:"layer",children:(0,tx.jsx)(el,{title:"图层",placement:"right",children:(0,tx.jsx)(na,{type:"icon-outline"})})}),!!d&&(0,tx.jsx)(Q.Button,{value:"dataset",children:(0,tx.jsx)(el,{title:"数据集",placement:"right",children:(0,tx.jsx)(na,{type:"icon-dataset"})})}),u&&(0,tx.jsx)(Q.Button,{value:"datasource",title:"数据源",children:(0,tx.jsx)(el,{title:"数据源",placement:"right",children:(0,tx.jsx)(na,{type:"icon-datasource"})})}),c&&(0,tx.jsx)(Q.Button,{value:"script",children:(0,tx.jsx)(el,{title:"脚本",placement:"right",children:(0,tx.jsx)(na,{type:"icon-js"})})}),(0,tx.jsx)(Q.Button,{value:"env",children:(0,tx.jsx)(el,{title:"环境变量",placement:"right",children:(0,tx.jsx)(na,{type:"icon-variable"})})}),(0,tx.jsx)(Q.Button,{value:"code",children:(0,tx.jsx)(el,{title:"源码",placement:"right",children:(0,tx.jsx)(na,{type:"icon-json"})})})]})}),(0,tx.jsxs)("div",{style:{flex:"1 1 auto",display:"flex",flexDirection:"column",width:"calc(100% - 47px)"},children:["component"===H&&(0,tx.jsx)(nW,{}),"layer"===H&&(0,tx.jsx)(nX,{}),u&&"datasource"===H&&(0,tx.jsx)(nG,{}),c&&"script"===H&&(0,tx.jsx)(n1,{}),"env"===H&&(0,tx.jsx)(n2,{}),"code"===H&&(0,tx.jsx)(nF,{}),!!d&&"dataset"===H&&(0,tx.jsx)(n4,{ref:S,renderNode:d})]})]}),(0,tx.jsxs)("div",{className:"center",style:{flex:"1 1 auto"},children:[(0,tx.jsx)(nT,{title:"页面",extra:(0,tx.jsxs)(er,{children:[(0,tx.jsx)(R,{size:"small",type:en?"default":"primary",icon:en?(0,tx.jsx)(p,{}):(0,tx.jsx)(f,{}),onClick:()=>ei(!en)}),(0,tx.jsxs)(Q.Group,{value:B,onChange:e=>F(e.target.value),size:"small",buttonStyle:"outline",children:[(0,tx.jsx)(Q.Button,{value:"desktop",title:"桌面",children:(0,tx.jsx)(h,{})}),(0,tx.jsx)(Q.Button,{value:"mobile",title:"移动设备",children:(0,tx.jsx)(w,{})}),(0,tx.jsx)(Q.Button,{value:"tablet",title:"平板设备",children:(0,tx.jsx)(D,{})})]})]})}),(0,tx.jsx)("div",{className:["body beautified_scrollbar always",B].join(" "),children:(0,tx.jsx)("div",{style:{transform:`scale(${C})`,transformOrigin:"top center"},children:(0,tx.jsx)(nf,{ref:b,device:B})})})]}),(0,tx.jsxs)("div",{className:"right",style:ed,children:[(0,tx.jsxs)("div",{style:{flex:"1 1 auto",display:"flex",flexDirection:"column",width:"calc(100% - 47px)"},children:[(0,tx.jsx)(nD,{agentList:a,onEffect:ef,style:{display:"ai"===eg&&(null==y?void 0:y.ai)?void 0:"none"}}),"props"===eg&&(0,tx.jsx)(nZ,{datasourceEnable:u}),"cascade"===eg&&(null==Z?void 0:Z.cascadeIds)&&(0,tx.jsx)(nR,{})]}),(0,tx.jsx)("div",{style:{padding:"22px 0",borderLeft:"solid 1px #e8e8e8",display:"flex",flexDirection:"column",justifyContent:"space-between",alignItems:"center"},children:(0,tx.jsxs)(Q.Group,{value:eg,onChange:e=>U(e.target.value),buttonStyle:"outline",style:{fontWeight:"normal",display:"inline-flex",flexDirection:"column",gap:14},className:"right-pane-tabs",children:[(null==y?void 0:y.ai)&&(0,tx.jsx)(Q.Button,{value:"ai",children:(0,tx.jsx)(el,{title:"智能助理",placement:"right",children:(0,tx.jsx)(na,{type:"icon-assistant"})})}),(0,tx.jsx)(Q.Button,{value:"props",children:(0,tx.jsx)(el,{title:"属性",placement:"right",children:(0,tx.jsx)(na,{type:"icon-info"})})}),(null==Z?void 0:Z.cascadeIds)&&(0,tx.jsx)(Q.Button,{value:"cascade",children:(0,tx.jsx)(el,{title:"联动",placement:"right",children:(0,tx.jsx)(na,{type:"icon-cascade"})})})]})})]})]})]}),(0,tx.jsx)(n8,{open:ea,onOk:e=>{eo(!1),et(e)},onCancel:()=>eo(!1)}),(0,tx.jsx)(Y,{open:es,size:400,mask:!1,title:null,closable:!1,styles:{body:{padding:0}},onClose:()=>eu(!1),children:(0,tx.jsx)(nD,{agentList:a,headExtra:(0,tx.jsx)(R,{type:"link",icon:(0,tx.jsx)(l,{}),onClick:()=>eu(!1)}),onEffect:ef})})]})});var n6=((ez={}).STRING="STRING",ez.NUMBER="NUMBER",ez.BOOLEAN="BOOLEAN",ez.OBJECT="OBJECT",ez.ARRAY="ARRAY",ez);let n7=t(x)`
|
|
992
|
+
`,n8=e=>{let{open:t,onCancel:n,onOk:r}=e,[i,a]=(0,t_.useState)(JSON.stringify({info:{},datasources:[],scripts:[],variables:[],items:[]}));return(0,tx.jsx)($,{title:"导入页面",open:t,width:800,onCancel:n,onOk:()=>null==r?void 0:r(JSON.parse(i)),okText:"导入",cancelText:"取消",styles:{body:{height:"calc(100vh - 250px)",overflow:"auto"}},children:(0,tx.jsx)("div",{className:"body",style:{flex:"1 1 auto",display:"flex",height:"100%"},children:(0,tx.jsx)(eg,{height:"100%",defaultLanguage:"json",value:i,options:{minimap:{enabled:!1}},onChange:e=>a(e||"")})})})},n9=t_.default.forwardRef((e,t)=>{var n;let r,{pageId:i,agentList:a=[],plugins:o=[],headerExtra:s,datasourceEnable:u=!0,scriptEnable:c=!0,datasetPanel:d,datasetSelector:g,datasetAdd:m,fetch:y,onSave:x,loading:_=!1}=e,b=(0,t_.useRef)(null),S=(0,t_.useRef)(null),[C,T]=(0,t_.useState)(1),[M,I]=(0,t_.useState)([]),[A,L]=(0,t_.useState)([]),[N,E]=(0,t_.useState)(!1),[B,F]=(0,t_.useState)("desktop"),[H,V]=(0,t_.useState)("component"),[G,U]=(0,t_.useState)((null==y?void 0:y.ai)?"ai":"props"),[q,X]=(0,t_.useState)(!0),[$,K]=(0,t_.useState)(!0),[Z,J]=(0,t_.useState)(null),[ee,et]=(0,t_.useState)({info:{},datasources:[],scripts:[],variables:[],items:[]}),[en,ei]=(0,t_.useState)(!0),[ea,eo]=(0,t_.useState)(!1),[es,eu]=(0,t_.useState)(!1),ec=(0,t_.useMemo)(()=>{let e=q?"250px":"",t=$?"400px":"";return{gridTemplateColumns:`${e} 1fr ${t}`}},[q,$]),eh=(0,t_.useMemo)(()=>({display:q?"flex":"none"}),[q]),ed=(0,t_.useMemo)(()=>({display:$?"flex":"none"}),[$]);n=[ee],(r=(0,t_.useRef)()).current===JSON.stringify(n)&&r.current||(r.current=JSON.stringify(n),(()=>{N||(I(e=>e.length?[...e,JSON.parse(JSON.stringify(ee))].slice(-50):[JSON.parse(JSON.stringify(ee))]),L([]))})()),(0,t_.useImperativeHandle)(t,()=>({handleOpen(e){E(!0),ep(e.items),et(e),I([JSON.parse(JSON.stringify(e))]),L([]),setTimeout(()=>E(!1),0)}}));let ep=(e,t)=>{e&&e.forEach(e=>{e.id||(e.id=t||em()),Array.isArray(e.children)?ep(e.children):"object"==typeof e.children&&e.children&&Object.keys(e.children).forEach(t=>{Array.isArray(e.children[t])&&ep(e.children[t],em())})})},ef=e=>{var t,n,r;if((null==(t=e.datasets)?void 0:t.length)&&(null==S||null==(n=S.current)?void 0:n.reload)&&S.current.reload(),e.schema){let t=JSON.parse(JSON.stringify(e.schema));ep(t.items),et(t)}else if(null==(r=e.pageItems)?void 0:r.length){let t=new Map;e.pageItems.forEach(e=>{t.has(e.targetId)||t.set(e.targetId,[]),t.get(e.targetId).push(e)});let n=JSON.parse(JSON.stringify(ee)),r=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];e.forEach((n,i)=>{t.has(n.id)&&t.get(n.id).forEach(t=>{let{position:r,insertSlot:a,pageItem:s}=t;switch(r){case"before":e.splice(i,0,s);break;case"after":e.splice(i+1,0,s);break;case"replace":Object.keys(n).forEach(e=>{"id"!==e&&delete n[e]}),Object.assign(n,s);break;case"insert":var l,u,c;let h=o.find(e=>e.key===n.type);Array.isArray(null==h||null==(l=h.defaultOptions)?void 0:l.children)?n.children=[...n.children||[],s]:"object"==typeof(null==h||null==(u=h.defaultOptions)?void 0:u.children)&&a&&(n.children={...n.children||{},[a]:[...(null==(c=n.children)?void 0:c[a])||[],s]})}}),Array.isArray(n.children)?r(n.children):"object"==typeof n.children&&n.children&&Object.keys(n.children).forEach(e=>{Array.isArray(n.children[e])&&r(n.children[e])})})};r(n.items),et(n)}},eg=(0,t_.useMemo)(()=>"cascade"!==G||(null==Z?void 0:Z.cascadeIds)?G:"props",[Z,G]);return(0,tx.jsxs)(tw,{pageId:i,designable:en,plugins:o,schema:ee,selectedItem:Z,setSchema:et,setSelectedItem:J,datasetSelector:g,datasetAdd:m,fetch:y,children:[(0,tx.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,tx.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 24px",borderBottom:"solid 1px #e8e8e8"},children:[(0,tx.jsxs)(er,{children:[(0,tx.jsx)("span",{style:{fontSize:16,fontWeight:500},children:"创建数据报表"}),(0,tx.jsx)(W,{orientation:"vertical"}),(0,tx.jsx)(el,{title:"保存",children:(0,tx.jsx)(R,{type:"link",className:"toolbar",onClick:()=>{null==x||x(ee)},loading:_,children:(0,tx.jsx)(j,{})})}),(0,tx.jsx)(W,{orientation:"vertical"}),(0,tx.jsx)(el,{title:"撤销",children:(0,tx.jsx)("a",{className:`toolbar ${M.length>1?"active":""}`,onClick:()=>{I(e=>{if(e.length<=1)return e;E(!0);let t=e[e.length-2];return L(e=>[...e,JSON.parse(JSON.stringify(ee))]),et(t),J(null),setTimeout(()=>E(!1),0),e.slice(0,-1)})},children:(0,tx.jsx)(O,{})})}),(0,tx.jsx)(el,{title:"重做",children:(0,tx.jsx)("a",{className:`toolbar ${A.length>0?"active":""}`,onClick:()=>{L(e=>e.length?(E(!0),I(e=>[...e,JSON.parse(JSON.stringify(ee))]),et(e[e.length-1]),J(null),setTimeout(()=>E(!1),0),e.slice(0,-1)):e)},children:(0,tx.jsx)(k,{})})}),(0,tx.jsx)(W,{orientation:"vertical"}),(0,tx.jsx)(el,{title:"导入JSON",children:(0,tx.jsx)("a",{className:`toolbar ${A.length>0?"active":""}`,onClick:()=>{eo(!0)},children:(0,tx.jsx)(v,{})})})]}),(0,tx.jsxs)(er,{children:[(0,tx.jsx)(el,{title:"缩小",children:(0,tx.jsx)("a",{className:"toolbar",onClick:()=>T(parseFloat(Math.max(C-.1,.5).toFixed(1))),children:(0,tx.jsx)(z,{})})}),(0,tx.jsxs)("div",{style:{fontSize:12,color:"#999",userSelect:"none"},children:[(100*C).toFixed(0),"%"]}),(0,tx.jsx)(el,{title:"放大",children:(0,tx.jsx)("a",{className:"toolbar",onClick:()=>T(parseFloat(Math.min(C+.1,2).toFixed(1))),children:(0,tx.jsx)(P,{})})}),(0,tx.jsx)(el,{title:"重置缩放",children:(0,tx.jsx)("a",{className:"toolbar",onClick:()=>T(1),children:(0,tx.jsx)(na,{type:"icon-zoom-reset"})})}),(0,tx.jsx)(W,{orientation:"vertical"}),(0,tx.jsx)(el,{title:"切换左侧栏",children:(0,tx.jsx)("a",{className:`toolbar ${q?"active":""}`,onClick:()=>{X(e=>!e),setTimeout(()=>{var e,t;return null==(t=b.current)||null==(e=t.handleResize)?void 0:e.call(t)},0)},children:(0,tx.jsx)(na,{type:"icon-sider-l"})})}),(0,tx.jsx)(el,{title:"切换右侧栏",children:(0,tx.jsx)("a",{className:`toolbar ${$?"active":""}`,onClick:()=>{K(e=>!e),setTimeout(()=>{var e,t;return null==(t=b.current)||null==(e=t.handleResize)?void 0:e.call(t)},0)},children:(0,tx.jsx)(na,{type:"icon-sider-r"})})}),s]})]}),(0,tx.jsxs)(n5,{style:ec,children:[(0,tx.jsxs)("div",{className:"left",style:eh,children:[(0,tx.jsx)("div",{style:{padding:"22px 1px 22px 0",borderRight:"solid 1px #e8e8e8"},children:(0,tx.jsxs)(Q.Group,{value:H,onChange:e=>V(e.target.value),buttonStyle:"outline",style:{fontWeight:"normal",display:"inline-flex",flexDirection:"column",gap:14},className:"left-pane-tabs",children:[(0,tx.jsx)(Q.Button,{value:"component",children:(0,tx.jsx)(el,{title:"组件",placement:"right",children:(0,tx.jsx)(na,{type:"icon-puzzle"})})}),(0,tx.jsx)(Q.Button,{value:"layer",children:(0,tx.jsx)(el,{title:"图层",placement:"right",children:(0,tx.jsx)(na,{type:"icon-outline"})})}),!!d&&(0,tx.jsx)(Q.Button,{value:"dataset",children:(0,tx.jsx)(el,{title:"数据集",placement:"right",children:(0,tx.jsx)(na,{type:"icon-dataset"})})}),u&&(0,tx.jsx)(Q.Button,{value:"datasource",title:"数据源",children:(0,tx.jsx)(el,{title:"数据源",placement:"right",children:(0,tx.jsx)(na,{type:"icon-datasource"})})}),c&&(0,tx.jsx)(Q.Button,{value:"script",children:(0,tx.jsx)(el,{title:"脚本",placement:"right",children:(0,tx.jsx)(na,{type:"icon-js"})})}),(0,tx.jsx)(Q.Button,{value:"env",children:(0,tx.jsx)(el,{title:"环境变量",placement:"right",children:(0,tx.jsx)(na,{type:"icon-variable"})})}),(0,tx.jsx)(Q.Button,{value:"code",children:(0,tx.jsx)(el,{title:"源码",placement:"right",children:(0,tx.jsx)(na,{type:"icon-json"})})})]})}),(0,tx.jsxs)("div",{style:{flex:"1 1 auto",display:"flex",flexDirection:"column",width:"calc(100% - 47px)"},children:["component"===H&&(0,tx.jsx)(nW,{}),"layer"===H&&(0,tx.jsx)(nX,{}),u&&"datasource"===H&&(0,tx.jsx)(nG,{}),c&&"script"===H&&(0,tx.jsx)(n1,{}),"env"===H&&(0,tx.jsx)(n2,{}),"code"===H&&(0,tx.jsx)(nF,{}),!!d&&"dataset"===H&&(0,tx.jsx)(n4,{ref:S,renderNode:d()})]})]}),(0,tx.jsxs)("div",{className:"center",style:{flex:"1 1 auto"},children:[(0,tx.jsx)(nT,{title:"页面",extra:(0,tx.jsxs)(er,{children:[(0,tx.jsx)(R,{size:"small",type:en?"default":"primary",icon:en?(0,tx.jsx)(p,{}):(0,tx.jsx)(f,{}),onClick:()=>ei(!en)}),(0,tx.jsxs)(Q.Group,{value:B,onChange:e=>F(e.target.value),size:"small",buttonStyle:"outline",children:[(0,tx.jsx)(Q.Button,{value:"desktop",title:"桌面",children:(0,tx.jsx)(h,{})}),(0,tx.jsx)(Q.Button,{value:"mobile",title:"移动设备",children:(0,tx.jsx)(w,{})}),(0,tx.jsx)(Q.Button,{value:"tablet",title:"平板设备",children:(0,tx.jsx)(D,{})})]})]})}),(0,tx.jsx)("div",{className:["body beautified_scrollbar always",B].join(" "),children:(0,tx.jsx)("div",{style:{transform:`scale(${C})`,transformOrigin:"top center"},children:(0,tx.jsx)(nf,{ref:b,device:B})})})]}),(0,tx.jsxs)("div",{className:"right",style:ed,children:[(0,tx.jsxs)("div",{style:{flex:"1 1 auto",display:"flex",flexDirection:"column",width:"calc(100% - 47px)"},children:[(0,tx.jsx)(nD,{agentList:a,onEffect:ef,style:{display:"ai"===eg&&(null==y?void 0:y.ai)?void 0:"none"}}),"props"===eg&&(0,tx.jsx)(nZ,{datasourceEnable:u}),"cascade"===eg&&(null==Z?void 0:Z.cascadeIds)&&(0,tx.jsx)(nR,{})]}),(0,tx.jsx)("div",{style:{padding:"22px 0",borderLeft:"solid 1px #e8e8e8",display:"flex",flexDirection:"column",justifyContent:"space-between",alignItems:"center"},children:(0,tx.jsxs)(Q.Group,{value:eg,onChange:e=>U(e.target.value),buttonStyle:"outline",style:{fontWeight:"normal",display:"inline-flex",flexDirection:"column",gap:14},className:"right-pane-tabs",children:[(null==y?void 0:y.ai)&&(0,tx.jsx)(Q.Button,{value:"ai",children:(0,tx.jsx)(el,{title:"智能助理",placement:"right",children:(0,tx.jsx)(na,{type:"icon-assistant"})})}),(0,tx.jsx)(Q.Button,{value:"props",children:(0,tx.jsx)(el,{title:"属性",placement:"right",children:(0,tx.jsx)(na,{type:"icon-info"})})}),(null==Z?void 0:Z.cascadeIds)&&(0,tx.jsx)(Q.Button,{value:"cascade",children:(0,tx.jsx)(el,{title:"联动",placement:"right",children:(0,tx.jsx)(na,{type:"icon-cascade"})})})]})})]})]})]}),(0,tx.jsx)(n8,{open:ea,onOk:e=>{eo(!1),et(e)},onCancel:()=>eo(!1)}),(0,tx.jsx)(Y,{open:es,size:400,mask:!1,title:null,closable:!1,styles:{body:{padding:0}},onClose:()=>eu(!1),children:(0,tx.jsx)(nD,{agentList:a,headExtra:(0,tx.jsx)(R,{type:"link",icon:(0,tx.jsx)(l,{}),onClick:()=>eu(!1)}),onEffect:ef})})]})});var n6=((ez={}).STRING="STRING",ez.NUMBER="NUMBER",ez.BOOLEAN="BOOLEAN",ez.OBJECT="OBJECT",ez.ARRAY="ARRAY",ez);let n7=t(x)`
|
|
988
993
|
vertical-align: middle;
|
|
989
994
|
margin-left: 2px;
|
|
990
995
|
color: var(--ant-color-text-description);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import "./styles.css";
|
|
3
3
|
import { DatasetAddFunction, DatasetSelectorFunction, FetchType, PageSchema, PluginType } from "./typing";
|
|
4
|
+
type DatasetPanelComponent = React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<{
|
|
5
|
+
handleAdd: () => void;
|
|
6
|
+
}>>;
|
|
4
7
|
export type PageDesignerProps = {
|
|
5
8
|
pageId: string;
|
|
6
9
|
agentList?: any[];
|
|
@@ -8,9 +11,7 @@ export type PageDesignerProps = {
|
|
|
8
11
|
headerExtra?: React.ReactNode;
|
|
9
12
|
datasourceEnable?: boolean;
|
|
10
13
|
scriptEnable?: boolean;
|
|
11
|
-
datasetPanel?:
|
|
12
|
-
handleAdd: () => void;
|
|
13
|
-
}>>;
|
|
14
|
+
datasetPanel?: () => DatasetPanelComponent;
|
|
14
15
|
datasetSelector?: DatasetSelectorFunction;
|
|
15
16
|
datasetAdd?: DatasetAddFunction;
|
|
16
17
|
fetch?: FetchType;
|
|
@@ -417,7 +417,7 @@
|
|
|
417
417
|
.conversation-list li small {
|
|
418
418
|
white-space: nowrap;
|
|
419
419
|
}
|
|
420
|
-
`,tO=[],tA="bi-design",tP=e=>{let t,n,r,i,a,o,s,{agentList:l=tO,headExtra:u,style:c={},onEffect:h}=e,{pageId:d,schema:p,fetch:f,atItems:g,onRemoveAtItem:m,clearAtItems:v}=(0,ed.useContext)(em);if(!f)return null;let[y,x]=(0,ed.useState)(null),[_,b]=(0,ed.useState)([]),[w,S]=(0,ed.useState)([]),C=ep().useRef(null),T=()=>{setTimeout(()=>{C.current&&C.current.scrollToBottom()},100)},k=()=>{x(null),S([])},I=async e=>{tn.Modal.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=f.ai)?void 0:t.removeConversation(e)),b(t=>t.filter(t=>t.id!==e)),S(t=>t.filter(t=>t.conversationId!==e)),y===e&&k()}})},j=async e=>{var t,n,r;x(e),b(t=>t.map(t=>({...t,isActived:t.id===e}))),await (null==(n=f.ai)||null==(t=n.activateConversation)?void 0:t.call(n,e)),S(await (null==(r=f.ai)?void 0:r.messageList(e))||[]),T()},M=async e=>{var t;let
|
|
420
|
+
`,tO=[],tA="bi-design",tP=e=>{let t,n,r,i,a,o,s,{agentList:l=tO,headExtra:u,style:c={},onEffect:h}=e,{pageId:d,schema:p,fetch:f,atItems:g,onRemoveAtItem:m,clearAtItems:v}=(0,ed.useContext)(em);if(!f)return null;let[y,x]=(0,ed.useState)(null),[_,b]=(0,ed.useState)([]),[w,S]=(0,ed.useState)([]),C=ep().useRef(null),T=()=>{setTimeout(()=>{C.current&&C.current.scrollToBottom()},100)},k=()=>{x(null),S([])},I=async e=>{tn.Modal.confirm({title:"确认删除该对话吗?",okText:"确认",cancelText:"取消",onOk:async()=>{var t;await (null==(t=f.ai)?void 0:t.removeConversation(e)),b(t=>t.filter(t=>t.id!==e)),S(t=>t.filter(t=>t.conversationId!==e)),y===e&&k()}})},j=async e=>{var t,n,r;x(e),b(t=>t.map(t=>({...t,isActived:t.id===e}))),await (null==(n=f.ai)||null==(t=n.activateConversation)?void 0:t.call(n,e)),S(await (null==(r=f.ai)?void 0:r.messageList(e))||[]),T()},M=async e=>{var t,n,r;let i={id:ty(),question:e.message,createdAt:new Date().toISOString(),files:e.files||[],agents:e.agents||[],atItems:JSON.stringify(g),sending:!0};S(e=>[...e,i]),T();let a=!y;v();try{let{id:n,answer:r,createdAt:o,conversation:s}=await (null==(t=f.ai)?void 0:t.chat(tA,d,y,{...e,page:p,pageItems:g||[]}));x((null==s?void 0:s.id)||""),b(e=>[a?s||{}:null,...e].filter(e=>null!==e)),Object.assign(i,{id:n,answer:r,createdAt:o,conversationId:(null==s?void 0:s.id)||"",sending:!1}),r.effect&&(null==h||h(r.effect))}catch(t){let e=(null==t||null==(r=t.response)||null==(n=r.data)?void 0:n.message)||t.message||"未知错误";console.error(e),Object.assign(i,{sending:!1,error:e})}S(e=>[...e]),T()},D=async e=>{var t;await (null==(t=f.ai)?void 0:t.removeMessage(e)),S(t=>t.filter(t=>t.id!==e))},O=(t=new Date,n=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),(r=new Date(t)).setDate(t.getDate()-1),i=[],a=[],o=[],s=[],_.forEach(e=>{let l=new Date(e.createdAt);if(n(l,t))i.push(e);else if(n(l,r))a.push(e);else l.getFullYear()===t.getFullYear()&&l.getMonth()===t.getMonth()?o.push(e):s.push(e)}),[{title:"今天",items:i},{title:"昨天",items:a},{title:"本月内",items:o},{title:"很久以前",items:s}].filter(e=>e.items.length>0)),A=async()=>{try{var e,t;let n=await (null==(e=f.ai)?void 0:e.conversationList(tA,d));b(n||[]);let r=null==n?void 0:n.find(e=>e.isActived);if(r){x(r.id);let e=await (null==(t=f.ai)?void 0:t.messageList(r.id));S(e||[]),T()}}catch(e){console.error(e)}};return(0,ed.useEffect)(()=>{A()},[f]),(0,ed.useEffect)(()=>{T()},[]),(0,eh.jsxs)(tD,{style:c,children:[(0,eh.jsx)(tM,{title:"智能助理",extra:(0,eh.jsxs)(tn.Space,{children:[(0,eh.jsx)(tn.Tooltip,{title:"新对话",placement:"topRight",children:(0,eh.jsx)("a",{onClick:k,children:(0,eh.jsx)(tt,{type:"icon-chat-plus"})})}),(0,eh.jsx)(tn.Dropdown,{trigger:["click"],styles:{root:{boxShadow:"var(--ant-box-shadow-drawer-up)",backgroundColor:"#ffffff",borderRadius:"var(--ant-border-radius)"}},popupRender:()=>(0,eh.jsx)(tN,{children:O.map(e=>(0,eh.jsxs)("div",{className:"group",children:[(0,eh.jsx)("div",{className:"group-title",children:e.title}),(0,eh.jsx)("ul",{className:"group-list",children:e.items.map(e=>(0,eh.jsxs)("li",{className:e.isActived?"actived":"",children:[(0,eh.jsx)("a",{onClick:()=>j(e.id),children:e.name}),(0,eh.jsx)("small",{children:(0,eh.jsx)("a",{onClick:()=>I(e.id),children:(0,eh.jsx)(e7.DeleteOutlined,{})})})]},e.id))})]},e.title))}),placement:"topRight",children:(0,eh.jsx)("a",{children:(0,eh.jsx)(e7.HistoryOutlined,{})})}),u]}),style:{width:"initial"}}),(0,eh.jsxs)("div",{className:"body",children:[(0,eh.jsx)("div",{style:{flex:"1 1 auto",overflowY:"auto"},children:w.length?(0,eh.jsx)(tF,{ref:C,list:w,onDeleteMessage:D}):(0,eh.jsx)(tz,{})}),0===w.length&&_.length>0&&(0,eh.jsx)(tn.Card,{title:"历史记录",size:"small",variant:"borderless",styles:{header:{padding:0,border:"none"},body:{padding:0}},style:{padding:"12px 12px 0 12px"},children:(0,eh.jsx)("ul",{className:"conversation-list",children:_.slice(0,3).map(e=>(0,eh.jsxs)("li",{children:[(0,eh.jsxs)("a",{children:[(0,eh.jsx)(e7.MessageOutlined,{}),e.name]}),(0,eh.jsx)("small",{children:tx(e.createdAt)})]},e.id))})}),(0,eh.jsx)(tI,{agentList:l,style:{padding:12},atItems:g,onUploading:null==f?void 0:f.upload,onSubmit:M,onRemoveAtItem:m})]})]})},tR=eg().div`
|
|
421
421
|
flex: 1 1 auto;
|
|
422
422
|
display: flex;
|
|
423
423
|
align-items: center;
|
|
@@ -574,6 +574,11 @@
|
|
|
574
574
|
font-size: 13px;
|
|
575
575
|
line-height: 1.6;
|
|
576
576
|
white-space: pre-wrap;
|
|
577
|
+
|
|
578
|
+
&.error {
|
|
579
|
+
color: var(--ant-color-error-text);
|
|
580
|
+
padding: 10px 0;
|
|
581
|
+
}
|
|
577
582
|
}
|
|
578
583
|
.msg-meta {
|
|
579
584
|
display: flex;
|
|
@@ -632,7 +637,7 @@
|
|
|
632
637
|
}
|
|
633
638
|
}
|
|
634
639
|
}
|
|
635
|
-
`,tF=(0,ed.forwardRef)((e,t)=>{let{list:n,onDeleteMessage:r}=e,i=(0,ed.useRef)(null),a=()=>{setTimeout(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},100)};return(0,ed.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,eh.jsx)(tL,{className:"message-list beautified_scrollbar",ref:i,children:n.map(e=>{var t,n,i,a,o,s,l,u,c,h;return(0,eh.jsxs)("div",{className:"msg",children:[(0,eh.jsxs)("div",{className:"user-message",children:[(0,eh.jsx)("div",{className:"msg-header",children:(0,eh.jsx)("span",{children:tx(e.createdAt)})}),(0,eh.jsxs)("div",{className:"msg-section",children:[(0,eh.jsxs)(tn.Space,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,eh.jsx)(tn.Typography.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,eh.jsx)(tn.Popconfirm,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>r(e.id),children:(0,eh.jsx)(tn.Tooltip,{title:"删除",children:(0,eh.jsx)(tn.Button,{type:"link",size:"small",icon:(0,eh.jsx)(e7.DeleteOutlined,{})})})})]}),(0,eh.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(n=e.agents)?void 0:n.length)||(null==(i=e.atItems)?void 0:i.length)?(0,eh.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,eh.jsxs)(tn.Tag,{color:"processing",children:[(0,eh.jsx)(tt,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(o=e.agents)?void 0:o.map(e=>(0,eh.jsxs)(tn.Tag,{color:"blue",children:[(0,eh.jsx)(tt,{type:"icon-at"})," ",e.name]},e.id)),(e=>{try{if(e){if("object"==typeof e)return e;else if("string"==typeof e)return JSON.parse(e||"[]")}return[]}catch(e){return[]}})(e.atItems).map(e=>(0,eh.jsxs)(tn.Tag,{color:"blue",children:[(0,eh.jsx)(tt,{type:"icon-number"})," ",e.name]},e.id))]}):null]})]}),(0,eh.jsxs)("div",{className:"assistant-message",children:[(0,eh.jsx)("div",{className:"msg-header",children:(0,eh.jsxs)("span",{className:"msg-title",children:[(0,eh.jsx)(e7.RobotOutlined,{})," 智能助理"]})}),(0,eh.jsx)("div",{className:"msg-section",children:e.sending?(0,eh.jsx)(tn.Skeleton,{active:!0}):(0,eh.jsxs)(eh.Fragment,{children:[(0,eh.jsx)("div",{className:"msg-content",children:(null==(s=e.answer)?void 0:s.answer)||""}),!!(null==(u=e.answer)||null==(l=u.plans)?void 0:l.length)&&(0,eh.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,eh.jsx)("summary",{className:"msg-ai-meta-title",children:"PLANS:"}),(0,eh.jsx)("div",{className:"msg-ai-meta-list",children:e.answer.plans.map((e,t)=>(0,eh.jsx)(tn.Tooltip,{title:e.description,children:(0,eh.jsx)(tn.Tag,{color:"blue",children:e.name})},t))})]}),!!(null==(h=e.answer)||null==(c=h.extra)?void 0:c.length)&&(0,eh.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,eh.jsx)("summary",{className:"msg-ai-meta-title",children:"ACTIONS:"}),(0,eh.jsx)("div",{className:"msg-ai-meta-list vertical",children:e.answer.extra.map((e,t)=>(0,eh.jsxs)("div",{className:"msg-ai-meta-list-item",children:[(0,eh.jsx)(tn.Tag,{color:"gold",children:e.element}),(0,eh.jsx)("span",{children:e.action})]},t))})]})]})})]})]},e.id)})})}),tE=eg().div`
|
|
640
|
+
`,tF=(0,ed.forwardRef)((e,t)=>{let{list:n,onDeleteMessage:r}=e,i=(0,ed.useRef)(null),a=()=>{setTimeout(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},100)};return(0,ed.useImperativeHandle)(t,()=>({scrollToBottom:a})),(0,eh.jsx)(tL,{className:"message-list beautified_scrollbar",ref:i,children:n.map(e=>{var t,n,i,a,o,s,l,u,c,h;return(0,eh.jsxs)("div",{className:"msg",children:[(0,eh.jsxs)("div",{className:"user-message",children:[(0,eh.jsx)("div",{className:"msg-header",children:(0,eh.jsx)("span",{children:tx(e.createdAt)})}),(0,eh.jsxs)("div",{className:"msg-section",children:[(0,eh.jsxs)(tn.Space,{size:4,orientation:"vertical",className:"msg-tools",children:[(0,eh.jsx)(tn.Typography.Text,{copyable:{text:e.question,tooltips:"复制"}}),(0,eh.jsx)(tn.Popconfirm,{title:"确认删除吗?",okText:"确认",cancelText:"取消",onConfirm:()=>r(e.id),children:(0,eh.jsx)(tn.Tooltip,{title:"删除",children:(0,eh.jsx)(tn.Button,{type:"link",size:"small",icon:(0,eh.jsx)(e7.DeleteOutlined,{})})})})]}),(0,eh.jsx)("div",{className:"msg-content",children:e.question}),(null==(t=e.files)?void 0:t.length)||(null==(n=e.agents)?void 0:n.length)||(null==(i=e.atItems)?void 0:i.length)?(0,eh.jsxs)("div",{className:"msg-meta",children:[null==(a=e.files)?void 0:a.map(e=>(0,eh.jsxs)(tn.Tag,{color:"processing",children:[(0,eh.jsx)(tt,{type:"icon-paper-clip"})," ",e.name]},e.id)),null==(o=e.agents)?void 0:o.map(e=>(0,eh.jsxs)(tn.Tag,{color:"blue",children:[(0,eh.jsx)(tt,{type:"icon-at"})," ",e.name]},e.id)),(e=>{try{if(e){if("object"==typeof e)return e;else if("string"==typeof e)return JSON.parse(e||"[]")}return[]}catch(e){return[]}})(e.atItems).map(e=>(0,eh.jsxs)(tn.Tag,{color:"blue",children:[(0,eh.jsx)(tt,{type:"icon-number"})," ",e.name]},e.id))]}):null]})]}),(0,eh.jsxs)("div",{className:"assistant-message",children:[(0,eh.jsx)("div",{className:"msg-header",children:(0,eh.jsxs)("span",{className:"msg-title",children:[(0,eh.jsx)(e7.RobotOutlined,{})," 智能助理"]})}),(0,eh.jsx)("div",{className:"msg-section",children:e.sending?(0,eh.jsx)(tn.Skeleton,{active:!0}):(0,eh.jsxs)(eh.Fragment,{children:[e.error?(0,eh.jsxs)("div",{className:"msg-content error",children:["执行失败:",e.error]}):(0,eh.jsx)("div",{className:"msg-content",children:(null==(s=e.answer)?void 0:s.answer)||""}),!!(null==(u=e.answer)||null==(l=u.plans)?void 0:l.length)&&(0,eh.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,eh.jsx)("summary",{className:"msg-ai-meta-title",children:"PLANS:"}),(0,eh.jsx)("div",{className:"msg-ai-meta-list",children:e.answer.plans.map((e,t)=>(0,eh.jsx)(tn.Tooltip,{title:e.description,children:(0,eh.jsx)(tn.Tag,{color:"blue",children:e.name})},t))})]}),!!(null==(h=e.answer)||null==(c=h.extra)?void 0:c.length)&&(0,eh.jsxs)("details",{className:"msg-ai-meta",open:!0,children:[(0,eh.jsx)("summary",{className:"msg-ai-meta-title",children:"ACTIONS:"}),(0,eh.jsx)("div",{className:"msg-ai-meta-list vertical",children:e.answer.extra.map((e,t)=>(0,eh.jsxs)("div",{className:"msg-ai-meta-list-item",children:[(0,eh.jsx)(tn.Tag,{color:"gold",children:e.element}),(0,eh.jsx)("span",{children:e.action})]},t))})]})]})})]})]},e.id)})})}),tE=eg().div`
|
|
636
641
|
display: flex;
|
|
637
642
|
flex-direction: column;
|
|
638
643
|
height: 100%;
|
|
@@ -984,7 +989,7 @@
|
|
|
984
989
|
background: transparent;
|
|
985
990
|
}
|
|
986
991
|
}
|
|
987
|
-
`,t7=e=>{let{open:t,onCancel:n,onOk:r}=e,[i,a]=(0,ed.useState)(JSON.stringify({info:{},datasources:[],scripts:[],variables:[],items:[]}));return(0,eh.jsx)(tn.Modal,{title:"导入页面",open:t,width:800,onCancel:n,onOk:()=>null==r?void 0:r(JSON.parse(i)),okText:"导入",cancelText:"取消",styles:{body:{height:"calc(100vh - 250px)",overflow:"auto"}},children:(0,eh.jsx)("div",{className:"body",style:{flex:"1 1 auto",display:"flex",height:"100%"},children:(0,eh.jsx)(ta.Editor,{height:"100%",defaultLanguage:"json",value:i,options:{minimap:{enabled:!1}},onChange:e=>a(e||"")})})})},ne=ep().forwardRef((e,t)=>{var n;let r,{pageId:i,agentList:a=[],plugins:o=[],headerExtra:s,datasourceEnable:l=!0,scriptEnable:u=!0,datasetPanel:c,datasetSelector:h,datasetAdd:d,fetch:p,onSave:f,loading:g=!1}=e,m=(0,ed.useRef)(null),v=(0,ed.useRef)(null),[y,x]=(0,ed.useState)(1),[_,b]=(0,ed.useState)([]),[w,S]=(0,ed.useState)([]),[C,T]=(0,ed.useState)(!1),[k,I]=(0,ed.useState)("desktop"),[j,M]=(0,ed.useState)("component"),[D,O]=(0,ed.useState)((null==p?void 0:p.ai)?"ai":"props"),[A,P]=(0,ed.useState)(!0),[R,z]=(0,ed.useState)(!0),[N,L]=(0,ed.useState)(null),[F,E]=(0,ed.useState)({info:{},datasources:[],scripts:[],variables:[],items:[]}),[B,H]=(0,ed.useState)(!0),[V,W]=(0,ed.useState)(!1),[Y,G]=(0,ed.useState)(!1),U=(0,ed.useMemo)(()=>{let e=A?"250px":"",t=R?"400px":"";return{gridTemplateColumns:`${e} 1fr ${t}`}},[A,R]),q=(0,ed.useMemo)(()=>({display:A?"flex":"none"}),[A]),X=(0,ed.useMemo)(()=>({display:R?"flex":"none"}),[R]);n=[F],(r=(0,ed.useRef)()).current===JSON.stringify(n)&&r.current||(r.current=JSON.stringify(n),(()=>{C||(b(e=>e.length?[...e,JSON.parse(JSON.stringify(F))].slice(-50):[JSON.parse(JSON.stringify(F))]),S([]))})()),(0,ed.useImperativeHandle)(t,()=>({handleOpen(e){T(!0),$(e.items),E(e),b([JSON.parse(JSON.stringify(e))]),S([]),setTimeout(()=>T(!1),0)}}));let $=(e,t)=>{e&&e.forEach(e=>{e.id||(e.id=t||ty()),Array.isArray(e.children)?$(e.children):"object"==typeof e.children&&e.children&&Object.keys(e.children).forEach(t=>{Array.isArray(e.children[t])&&$(e.children[t],ty())})})},Z=e=>{var t,n,r;if((null==(t=e.datasets)?void 0:t.length)&&(null==v||null==(n=v.current)?void 0:n.reload)&&v.current.reload(),e.schema){let t=JSON.parse(JSON.stringify(e.schema));$(t.items),E(t)}else if(null==(r=e.pageItems)?void 0:r.length){let t=new Map;e.pageItems.forEach(e=>{t.has(e.targetId)||t.set(e.targetId,[]),t.get(e.targetId).push(e)});let n=JSON.parse(JSON.stringify(F)),r=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];e.forEach((n,i)=>{t.has(n.id)&&t.get(n.id).forEach(t=>{let{position:r,insertSlot:a,pageItem:s}=t;switch(r){case"before":e.splice(i,0,s);break;case"after":e.splice(i+1,0,s);break;case"replace":Object.keys(n).forEach(e=>{"id"!==e&&delete n[e]}),Object.assign(n,s);break;case"insert":var l,u,c;let h=o.find(e=>e.key===n.type);Array.isArray(null==h||null==(l=h.defaultOptions)?void 0:l.children)?n.children=[...n.children||[],s]:"object"==typeof(null==h||null==(u=h.defaultOptions)?void 0:u.children)&&a&&(n.children={...n.children||{},[a]:[...(null==(c=n.children)?void 0:c[a])||[],s]})}}),Array.isArray(n.children)?r(n.children):"object"==typeof n.children&&n.children&&Object.keys(n.children).forEach(e=>{Array.isArray(n.children[e])&&r(n.children[e])})})};r(n.items),E(n)}},K=(0,ed.useMemo)(()=>"cascade"!==D||(null==N?void 0:N.cascadeIds)?D:"props",[N,D]);return(0,eh.jsxs)(ev,{pageId:i,designable:B,plugins:o,schema:F,selectedItem:N,setSchema:E,setSelectedItem:L,datasetSelector:h,datasetAdd:d,fetch:p,children:[(0,eh.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,eh.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 24px",borderBottom:"solid 1px #e8e8e8"},children:[(0,eh.jsxs)(tn.Space,{children:[(0,eh.jsx)("span",{style:{fontSize:16,fontWeight:500},children:"创建数据报表"}),(0,eh.jsx)(tn.Divider,{orientation:"vertical"}),(0,eh.jsx)(tn.Tooltip,{title:"保存",children:(0,eh.jsx)(tn.Button,{type:"link",className:"toolbar",onClick:()=>{null==f||f(F)},loading:g,children:(0,eh.jsx)(e7.SaveOutlined,{})})}),(0,eh.jsx)(tn.Divider,{orientation:"vertical"}),(0,eh.jsx)(tn.Tooltip,{title:"撤销",children:(0,eh.jsx)("a",{className:`toolbar ${_.length>1?"active":""}`,onClick:()=>{b(e=>{if(e.length<=1)return e;T(!0);let t=e[e.length-2];return S(e=>[...e,JSON.parse(JSON.stringify(F))]),E(t),L(null),setTimeout(()=>T(!1),0),e.slice(0,-1)})},children:(0,eh.jsx)(e7.UndoOutlined,{})})}),(0,eh.jsx)(tn.Tooltip,{title:"重做",children:(0,eh.jsx)("a",{className:`toolbar ${w.length>0?"active":""}`,onClick:()=>{S(e=>e.length?(T(!0),b(e=>[...e,JSON.parse(JSON.stringify(F))]),E(e[e.length-1]),L(null),setTimeout(()=>T(!1),0),e.slice(0,-1)):e)},children:(0,eh.jsx)(e7.RedoOutlined,{})})}),(0,eh.jsx)(tn.Divider,{orientation:"vertical"}),(0,eh.jsx)(tn.Tooltip,{title:"导入JSON",children:(0,eh.jsx)("a",{className:`toolbar ${w.length>0?"active":""}`,onClick:()=>{W(!0)},children:(0,eh.jsx)(e7.ImportOutlined,{})})})]}),(0,eh.jsxs)(tn.Space,{children:[(0,eh.jsx)(tn.Tooltip,{title:"缩小",children:(0,eh.jsx)("a",{className:"toolbar",onClick:()=>x(parseFloat(Math.max(y-.1,.5).toFixed(1))),children:(0,eh.jsx)(e7.ZoomOutOutlined,{})})}),(0,eh.jsxs)("div",{style:{fontSize:12,color:"#999",userSelect:"none"},children:[(100*y).toFixed(0),"%"]}),(0,eh.jsx)(tn.Tooltip,{title:"放大",children:(0,eh.jsx)("a",{className:"toolbar",onClick:()=>x(parseFloat(Math.min(y+.1,2).toFixed(1))),children:(0,eh.jsx)(e7.ZoomInOutlined,{})})}),(0,eh.jsx)(tn.Tooltip,{title:"重置缩放",children:(0,eh.jsx)("a",{className:"toolbar",onClick:()=>x(1),children:(0,eh.jsx)(tt,{type:"icon-zoom-reset"})})}),(0,eh.jsx)(tn.Divider,{orientation:"vertical"}),(0,eh.jsx)(tn.Tooltip,{title:"切换左侧栏",children:(0,eh.jsx)("a",{className:`toolbar ${A?"active":""}`,onClick:()=>{P(e=>!e),setTimeout(()=>{var e,t;return null==(t=m.current)||null==(e=t.handleResize)?void 0:e.call(t)},0)},children:(0,eh.jsx)(tt,{type:"icon-sider-l"})})}),(0,eh.jsx)(tn.Tooltip,{title:"切换右侧栏",children:(0,eh.jsx)("a",{className:`toolbar ${R?"active":""}`,onClick:()=>{z(e=>!e),setTimeout(()=>{var e,t;return null==(t=m.current)||null==(e=t.handleResize)?void 0:e.call(t)},0)},children:(0,eh.jsx)(tt,{type:"icon-sider-r"})})}),s]})]}),(0,eh.jsxs)(t6,{style:U,children:[(0,eh.jsxs)("div",{className:"left",style:q,children:[(0,eh.jsx)("div",{style:{padding:"22px 1px 22px 0",borderRight:"solid 1px #e8e8e8"},children:(0,eh.jsxs)(tn.Radio.Group,{value:j,onChange:e=>M(e.target.value),buttonStyle:"outline",style:{fontWeight:"normal",display:"inline-flex",flexDirection:"column",gap:14},className:"left-pane-tabs",children:[(0,eh.jsx)(tn.Radio.Button,{value:"component",children:(0,eh.jsx)(tn.Tooltip,{title:"组件",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-puzzle"})})}),(0,eh.jsx)(tn.Radio.Button,{value:"layer",children:(0,eh.jsx)(tn.Tooltip,{title:"图层",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-outline"})})}),!!c&&(0,eh.jsx)(tn.Radio.Button,{value:"dataset",children:(0,eh.jsx)(tn.Tooltip,{title:"数据集",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-dataset"})})}),l&&(0,eh.jsx)(tn.Radio.Button,{value:"datasource",title:"数据源",children:(0,eh.jsx)(tn.Tooltip,{title:"数据源",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-datasource"})})}),u&&(0,eh.jsx)(tn.Radio.Button,{value:"script",children:(0,eh.jsx)(tn.Tooltip,{title:"脚本",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-js"})})}),(0,eh.jsx)(tn.Radio.Button,{value:"env",children:(0,eh.jsx)(tn.Tooltip,{title:"环境变量",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-variable"})})}),(0,eh.jsx)(tn.Radio.Button,{value:"code",children:(0,eh.jsx)(tn.Tooltip,{title:"源码",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-json"})})})]})}),(0,eh.jsxs)("div",{style:{flex:"1 1 auto",display:"flex",flexDirection:"column",width:"calc(100% - 47px)"},children:["component"===j&&(0,eh.jsx)(tU,{}),"layer"===j&&(0,eh.jsx)(tK,{}),l&&"datasource"===j&&(0,eh.jsx)(tX,{}),u&&"script"===j&&(0,eh.jsx)(t3,{}),"env"===j&&(0,eh.jsx)(t5,{}),"code"===j&&(0,eh.jsx)(tW,{}),!!c&&"dataset"===j&&(0,eh.jsx)(t8,{ref:v,renderNode:c})]})]}),(0,eh.jsxs)("div",{className:"center",style:{flex:"1 1 auto"},children:[(0,eh.jsx)(tM,{title:"页面",extra:(0,eh.jsxs)(tn.Space,{children:[(0,eh.jsx)(tn.Button,{size:"small",type:B?"default":"primary",icon:B?(0,eh.jsx)(e7.EyeInvisibleOutlined,{}):(0,eh.jsx)(e7.EyeOutlined,{}),onClick:()=>H(!B)}),(0,eh.jsxs)(tn.Radio.Group,{value:k,onChange:e=>I(e.target.value),size:"small",buttonStyle:"outline",children:[(0,eh.jsx)(tn.Radio.Button,{value:"desktop",title:"桌面",children:(0,eh.jsx)(e7.DesktopOutlined,{})}),(0,eh.jsx)(tn.Radio.Button,{value:"mobile",title:"移动设备",children:(0,eh.jsx)(e7.MobileOutlined,{})}),(0,eh.jsx)(tn.Radio.Button,{value:"tablet",title:"平板设备",children:(0,eh.jsx)(e7.TabletOutlined,{})})]})]})}),(0,eh.jsx)("div",{className:["body beautified_scrollbar always",k].join(" "),children:(0,eh.jsx)("div",{style:{transform:`scale(${y})`,transformOrigin:"top center"},children:(0,eh.jsx)(tg,{ref:m,device:k})})})]}),(0,eh.jsxs)("div",{className:"right",style:X,children:[(0,eh.jsxs)("div",{style:{flex:"1 1 auto",display:"flex",flexDirection:"column",width:"calc(100% - 47px)"},children:[(0,eh.jsx)(tP,{agentList:a,onEffect:Z,style:{display:"ai"===K&&(null==p?void 0:p.ai)?void 0:"none"}}),"props"===K&&(0,eh.jsx)(t1,{datasourceEnable:l}),"cascade"===K&&(null==N?void 0:N.cascadeIds)&&(0,eh.jsx)(tB,{})]}),(0,eh.jsx)("div",{style:{padding:"22px 0",borderLeft:"solid 1px #e8e8e8",display:"flex",flexDirection:"column",justifyContent:"space-between",alignItems:"center"},children:(0,eh.jsxs)(tn.Radio.Group,{value:K,onChange:e=>O(e.target.value),buttonStyle:"outline",style:{fontWeight:"normal",display:"inline-flex",flexDirection:"column",gap:14},className:"right-pane-tabs",children:[(null==p?void 0:p.ai)&&(0,eh.jsx)(tn.Radio.Button,{value:"ai",children:(0,eh.jsx)(tn.Tooltip,{title:"智能助理",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-assistant"})})}),(0,eh.jsx)(tn.Radio.Button,{value:"props",children:(0,eh.jsx)(tn.Tooltip,{title:"属性",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-info"})})}),(null==N?void 0:N.cascadeIds)&&(0,eh.jsx)(tn.Radio.Button,{value:"cascade",children:(0,eh.jsx)(tn.Tooltip,{title:"联动",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-cascade"})})})]})})]})]})]}),(0,eh.jsx)(t7,{open:V,onOk:e=>{W(!1),E(e)},onCancel:()=>W(!1)}),(0,eh.jsx)(tn.Drawer,{open:Y,size:400,mask:!1,title:null,closable:!1,styles:{body:{padding:0}},onClose:()=>G(!1),children:(0,eh.jsx)(tP,{agentList:a,headExtra:(0,eh.jsx)(tn.Button,{type:"link",icon:(0,eh.jsx)(e7.CloseOutlined,{}),onClick:()=>G(!1)}),onEffect:Z})})]})});var nt=((m={}).STRING="STRING",m.NUMBER="NUMBER",m.BOOLEAN="BOOLEAN",m.OBJECT="OBJECT",m.ARRAY="ARRAY",m);let nn=eg()(e7.InfoCircleOutlined)`
|
|
992
|
+
`,t7=e=>{let{open:t,onCancel:n,onOk:r}=e,[i,a]=(0,ed.useState)(JSON.stringify({info:{},datasources:[],scripts:[],variables:[],items:[]}));return(0,eh.jsx)(tn.Modal,{title:"导入页面",open:t,width:800,onCancel:n,onOk:()=>null==r?void 0:r(JSON.parse(i)),okText:"导入",cancelText:"取消",styles:{body:{height:"calc(100vh - 250px)",overflow:"auto"}},children:(0,eh.jsx)("div",{className:"body",style:{flex:"1 1 auto",display:"flex",height:"100%"},children:(0,eh.jsx)(ta.Editor,{height:"100%",defaultLanguage:"json",value:i,options:{minimap:{enabled:!1}},onChange:e=>a(e||"")})})})},ne=ep().forwardRef((e,t)=>{var n;let r,{pageId:i,agentList:a=[],plugins:o=[],headerExtra:s,datasourceEnable:l=!0,scriptEnable:u=!0,datasetPanel:c,datasetSelector:h,datasetAdd:d,fetch:p,onSave:f,loading:g=!1}=e,m=(0,ed.useRef)(null),v=(0,ed.useRef)(null),[y,x]=(0,ed.useState)(1),[_,b]=(0,ed.useState)([]),[w,S]=(0,ed.useState)([]),[C,T]=(0,ed.useState)(!1),[k,I]=(0,ed.useState)("desktop"),[j,M]=(0,ed.useState)("component"),[D,O]=(0,ed.useState)((null==p?void 0:p.ai)?"ai":"props"),[A,P]=(0,ed.useState)(!0),[R,z]=(0,ed.useState)(!0),[N,L]=(0,ed.useState)(null),[F,E]=(0,ed.useState)({info:{},datasources:[],scripts:[],variables:[],items:[]}),[B,H]=(0,ed.useState)(!0),[V,W]=(0,ed.useState)(!1),[Y,G]=(0,ed.useState)(!1),U=(0,ed.useMemo)(()=>{let e=A?"250px":"",t=R?"400px":"";return{gridTemplateColumns:`${e} 1fr ${t}`}},[A,R]),q=(0,ed.useMemo)(()=>({display:A?"flex":"none"}),[A]),X=(0,ed.useMemo)(()=>({display:R?"flex":"none"}),[R]);n=[F],(r=(0,ed.useRef)()).current===JSON.stringify(n)&&r.current||(r.current=JSON.stringify(n),(()=>{C||(b(e=>e.length?[...e,JSON.parse(JSON.stringify(F))].slice(-50):[JSON.parse(JSON.stringify(F))]),S([]))})()),(0,ed.useImperativeHandle)(t,()=>({handleOpen(e){T(!0),$(e.items),E(e),b([JSON.parse(JSON.stringify(e))]),S([]),setTimeout(()=>T(!1),0)}}));let $=(e,t)=>{e&&e.forEach(e=>{e.id||(e.id=t||ty()),Array.isArray(e.children)?$(e.children):"object"==typeof e.children&&e.children&&Object.keys(e.children).forEach(t=>{Array.isArray(e.children[t])&&$(e.children[t],ty())})})},Z=e=>{var t,n,r;if((null==(t=e.datasets)?void 0:t.length)&&(null==v||null==(n=v.current)?void 0:n.reload)&&v.current.reload(),e.schema){let t=JSON.parse(JSON.stringify(e.schema));$(t.items),E(t)}else if(null==(r=e.pageItems)?void 0:r.length){let t=new Map;e.pageItems.forEach(e=>{t.has(e.targetId)||t.set(e.targetId,[]),t.get(e.targetId).push(e)});let n=JSON.parse(JSON.stringify(F)),r=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];e.forEach((n,i)=>{t.has(n.id)&&t.get(n.id).forEach(t=>{let{position:r,insertSlot:a,pageItem:s}=t;switch(r){case"before":e.splice(i,0,s);break;case"after":e.splice(i+1,0,s);break;case"replace":Object.keys(n).forEach(e=>{"id"!==e&&delete n[e]}),Object.assign(n,s);break;case"insert":var l,u,c;let h=o.find(e=>e.key===n.type);Array.isArray(null==h||null==(l=h.defaultOptions)?void 0:l.children)?n.children=[...n.children||[],s]:"object"==typeof(null==h||null==(u=h.defaultOptions)?void 0:u.children)&&a&&(n.children={...n.children||{},[a]:[...(null==(c=n.children)?void 0:c[a])||[],s]})}}),Array.isArray(n.children)?r(n.children):"object"==typeof n.children&&n.children&&Object.keys(n.children).forEach(e=>{Array.isArray(n.children[e])&&r(n.children[e])})})};r(n.items),E(n)}},K=(0,ed.useMemo)(()=>"cascade"!==D||(null==N?void 0:N.cascadeIds)?D:"props",[N,D]);return(0,eh.jsxs)(ev,{pageId:i,designable:B,plugins:o,schema:F,selectedItem:N,setSchema:E,setSelectedItem:L,datasetSelector:h,datasetAdd:d,fetch:p,children:[(0,eh.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,eh.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 24px",borderBottom:"solid 1px #e8e8e8"},children:[(0,eh.jsxs)(tn.Space,{children:[(0,eh.jsx)("span",{style:{fontSize:16,fontWeight:500},children:"创建数据报表"}),(0,eh.jsx)(tn.Divider,{orientation:"vertical"}),(0,eh.jsx)(tn.Tooltip,{title:"保存",children:(0,eh.jsx)(tn.Button,{type:"link",className:"toolbar",onClick:()=>{null==f||f(F)},loading:g,children:(0,eh.jsx)(e7.SaveOutlined,{})})}),(0,eh.jsx)(tn.Divider,{orientation:"vertical"}),(0,eh.jsx)(tn.Tooltip,{title:"撤销",children:(0,eh.jsx)("a",{className:`toolbar ${_.length>1?"active":""}`,onClick:()=>{b(e=>{if(e.length<=1)return e;T(!0);let t=e[e.length-2];return S(e=>[...e,JSON.parse(JSON.stringify(F))]),E(t),L(null),setTimeout(()=>T(!1),0),e.slice(0,-1)})},children:(0,eh.jsx)(e7.UndoOutlined,{})})}),(0,eh.jsx)(tn.Tooltip,{title:"重做",children:(0,eh.jsx)("a",{className:`toolbar ${w.length>0?"active":""}`,onClick:()=>{S(e=>e.length?(T(!0),b(e=>[...e,JSON.parse(JSON.stringify(F))]),E(e[e.length-1]),L(null),setTimeout(()=>T(!1),0),e.slice(0,-1)):e)},children:(0,eh.jsx)(e7.RedoOutlined,{})})}),(0,eh.jsx)(tn.Divider,{orientation:"vertical"}),(0,eh.jsx)(tn.Tooltip,{title:"导入JSON",children:(0,eh.jsx)("a",{className:`toolbar ${w.length>0?"active":""}`,onClick:()=>{W(!0)},children:(0,eh.jsx)(e7.ImportOutlined,{})})})]}),(0,eh.jsxs)(tn.Space,{children:[(0,eh.jsx)(tn.Tooltip,{title:"缩小",children:(0,eh.jsx)("a",{className:"toolbar",onClick:()=>x(parseFloat(Math.max(y-.1,.5).toFixed(1))),children:(0,eh.jsx)(e7.ZoomOutOutlined,{})})}),(0,eh.jsxs)("div",{style:{fontSize:12,color:"#999",userSelect:"none"},children:[(100*y).toFixed(0),"%"]}),(0,eh.jsx)(tn.Tooltip,{title:"放大",children:(0,eh.jsx)("a",{className:"toolbar",onClick:()=>x(parseFloat(Math.min(y+.1,2).toFixed(1))),children:(0,eh.jsx)(e7.ZoomInOutlined,{})})}),(0,eh.jsx)(tn.Tooltip,{title:"重置缩放",children:(0,eh.jsx)("a",{className:"toolbar",onClick:()=>x(1),children:(0,eh.jsx)(tt,{type:"icon-zoom-reset"})})}),(0,eh.jsx)(tn.Divider,{orientation:"vertical"}),(0,eh.jsx)(tn.Tooltip,{title:"切换左侧栏",children:(0,eh.jsx)("a",{className:`toolbar ${A?"active":""}`,onClick:()=>{P(e=>!e),setTimeout(()=>{var e,t;return null==(t=m.current)||null==(e=t.handleResize)?void 0:e.call(t)},0)},children:(0,eh.jsx)(tt,{type:"icon-sider-l"})})}),(0,eh.jsx)(tn.Tooltip,{title:"切换右侧栏",children:(0,eh.jsx)("a",{className:`toolbar ${R?"active":""}`,onClick:()=>{z(e=>!e),setTimeout(()=>{var e,t;return null==(t=m.current)||null==(e=t.handleResize)?void 0:e.call(t)},0)},children:(0,eh.jsx)(tt,{type:"icon-sider-r"})})}),s]})]}),(0,eh.jsxs)(t6,{style:U,children:[(0,eh.jsxs)("div",{className:"left",style:q,children:[(0,eh.jsx)("div",{style:{padding:"22px 1px 22px 0",borderRight:"solid 1px #e8e8e8"},children:(0,eh.jsxs)(tn.Radio.Group,{value:j,onChange:e=>M(e.target.value),buttonStyle:"outline",style:{fontWeight:"normal",display:"inline-flex",flexDirection:"column",gap:14},className:"left-pane-tabs",children:[(0,eh.jsx)(tn.Radio.Button,{value:"component",children:(0,eh.jsx)(tn.Tooltip,{title:"组件",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-puzzle"})})}),(0,eh.jsx)(tn.Radio.Button,{value:"layer",children:(0,eh.jsx)(tn.Tooltip,{title:"图层",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-outline"})})}),!!c&&(0,eh.jsx)(tn.Radio.Button,{value:"dataset",children:(0,eh.jsx)(tn.Tooltip,{title:"数据集",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-dataset"})})}),l&&(0,eh.jsx)(tn.Radio.Button,{value:"datasource",title:"数据源",children:(0,eh.jsx)(tn.Tooltip,{title:"数据源",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-datasource"})})}),u&&(0,eh.jsx)(tn.Radio.Button,{value:"script",children:(0,eh.jsx)(tn.Tooltip,{title:"脚本",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-js"})})}),(0,eh.jsx)(tn.Radio.Button,{value:"env",children:(0,eh.jsx)(tn.Tooltip,{title:"环境变量",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-variable"})})}),(0,eh.jsx)(tn.Radio.Button,{value:"code",children:(0,eh.jsx)(tn.Tooltip,{title:"源码",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-json"})})})]})}),(0,eh.jsxs)("div",{style:{flex:"1 1 auto",display:"flex",flexDirection:"column",width:"calc(100% - 47px)"},children:["component"===j&&(0,eh.jsx)(tU,{}),"layer"===j&&(0,eh.jsx)(tK,{}),l&&"datasource"===j&&(0,eh.jsx)(tX,{}),u&&"script"===j&&(0,eh.jsx)(t3,{}),"env"===j&&(0,eh.jsx)(t5,{}),"code"===j&&(0,eh.jsx)(tW,{}),!!c&&"dataset"===j&&(0,eh.jsx)(t8,{ref:v,renderNode:c()})]})]}),(0,eh.jsxs)("div",{className:"center",style:{flex:"1 1 auto"},children:[(0,eh.jsx)(tM,{title:"页面",extra:(0,eh.jsxs)(tn.Space,{children:[(0,eh.jsx)(tn.Button,{size:"small",type:B?"default":"primary",icon:B?(0,eh.jsx)(e7.EyeInvisibleOutlined,{}):(0,eh.jsx)(e7.EyeOutlined,{}),onClick:()=>H(!B)}),(0,eh.jsxs)(tn.Radio.Group,{value:k,onChange:e=>I(e.target.value),size:"small",buttonStyle:"outline",children:[(0,eh.jsx)(tn.Radio.Button,{value:"desktop",title:"桌面",children:(0,eh.jsx)(e7.DesktopOutlined,{})}),(0,eh.jsx)(tn.Radio.Button,{value:"mobile",title:"移动设备",children:(0,eh.jsx)(e7.MobileOutlined,{})}),(0,eh.jsx)(tn.Radio.Button,{value:"tablet",title:"平板设备",children:(0,eh.jsx)(e7.TabletOutlined,{})})]})]})}),(0,eh.jsx)("div",{className:["body beautified_scrollbar always",k].join(" "),children:(0,eh.jsx)("div",{style:{transform:`scale(${y})`,transformOrigin:"top center"},children:(0,eh.jsx)(tg,{ref:m,device:k})})})]}),(0,eh.jsxs)("div",{className:"right",style:X,children:[(0,eh.jsxs)("div",{style:{flex:"1 1 auto",display:"flex",flexDirection:"column",width:"calc(100% - 47px)"},children:[(0,eh.jsx)(tP,{agentList:a,onEffect:Z,style:{display:"ai"===K&&(null==p?void 0:p.ai)?void 0:"none"}}),"props"===K&&(0,eh.jsx)(t1,{datasourceEnable:l}),"cascade"===K&&(null==N?void 0:N.cascadeIds)&&(0,eh.jsx)(tB,{})]}),(0,eh.jsx)("div",{style:{padding:"22px 0",borderLeft:"solid 1px #e8e8e8",display:"flex",flexDirection:"column",justifyContent:"space-between",alignItems:"center"},children:(0,eh.jsxs)(tn.Radio.Group,{value:K,onChange:e=>O(e.target.value),buttonStyle:"outline",style:{fontWeight:"normal",display:"inline-flex",flexDirection:"column",gap:14},className:"right-pane-tabs",children:[(null==p?void 0:p.ai)&&(0,eh.jsx)(tn.Radio.Button,{value:"ai",children:(0,eh.jsx)(tn.Tooltip,{title:"智能助理",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-assistant"})})}),(0,eh.jsx)(tn.Radio.Button,{value:"props",children:(0,eh.jsx)(tn.Tooltip,{title:"属性",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-info"})})}),(null==N?void 0:N.cascadeIds)&&(0,eh.jsx)(tn.Radio.Button,{value:"cascade",children:(0,eh.jsx)(tn.Tooltip,{title:"联动",placement:"right",children:(0,eh.jsx)(tt,{type:"icon-cascade"})})})]})})]})]})]}),(0,eh.jsx)(t7,{open:V,onOk:e=>{W(!1),E(e)},onCancel:()=>W(!1)}),(0,eh.jsx)(tn.Drawer,{open:Y,size:400,mask:!1,title:null,closable:!1,styles:{body:{padding:0}},onClose:()=>G(!1),children:(0,eh.jsx)(tP,{agentList:a,headExtra:(0,eh.jsx)(tn.Button,{type:"link",icon:(0,eh.jsx)(e7.CloseOutlined,{}),onClick:()=>G(!1)}),onEffect:Z})})]})});var nt=((m={}).STRING="STRING",m.NUMBER="NUMBER",m.BOOLEAN="BOOLEAN",m.OBJECT="OBJECT",m.ARRAY="ARRAY",m);let nn=eg()(e7.InfoCircleOutlined)`
|
|
988
993
|
vertical-align: middle;
|
|
989
994
|
margin-left: 2px;
|
|
990
995
|
color: var(--ant-color-text-description);
|
package/package.json
CHANGED
|
@@ -12,21 +12,8 @@ import {
|
|
|
12
12
|
ZoomInOutlined,
|
|
13
13
|
ZoomOutOutlined,
|
|
14
14
|
} from "@ant-design/icons";
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
Divider,
|
|
18
|
-
Drawer,
|
|
19
|
-
Modal,
|
|
20
|
-
Radio,
|
|
21
|
-
Space,
|
|
22
|
-
Tooltip
|
|
23
|
-
} from "antd";
|
|
24
|
-
import React, {
|
|
25
|
-
useImperativeHandle,
|
|
26
|
-
useMemo,
|
|
27
|
-
useRef,
|
|
28
|
-
useState
|
|
29
|
-
} from "react";
|
|
15
|
+
import { Button, Divider, Drawer, Modal, Radio, Space, Tooltip } from "antd";
|
|
16
|
+
import React, { useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
30
17
|
import styled from "styled-components";
|
|
31
18
|
import { IconFont } from "./icon/IconFont";
|
|
32
19
|
import { PageCanvas } from "./layout/PageCanvas";
|
|
@@ -58,6 +45,13 @@ import {
|
|
|
58
45
|
} from "./typing";
|
|
59
46
|
import { uuid } from "./utils";
|
|
60
47
|
|
|
48
|
+
type DatasetPanelComponent = React.ForwardRefExoticComponent<
|
|
49
|
+
Omit<any, "ref"> &
|
|
50
|
+
React.RefAttributes<{
|
|
51
|
+
handleAdd: () => void;
|
|
52
|
+
}>
|
|
53
|
+
>;
|
|
54
|
+
|
|
61
55
|
export type PageDesignerProps = {
|
|
62
56
|
pageId: string;
|
|
63
57
|
agentList?: any[];
|
|
@@ -65,12 +59,7 @@ export type PageDesignerProps = {
|
|
|
65
59
|
headerExtra?: React.ReactNode;
|
|
66
60
|
datasourceEnable?: boolean;
|
|
67
61
|
scriptEnable?: boolean;
|
|
68
|
-
datasetPanel?:
|
|
69
|
-
Omit<any, "ref"> &
|
|
70
|
-
React.RefAttributes<{
|
|
71
|
-
handleAdd: () => void;
|
|
72
|
-
}>
|
|
73
|
-
>;
|
|
62
|
+
datasetPanel?: () => DatasetPanelComponent;
|
|
74
63
|
datasetSelector?: DatasetSelectorFunction;
|
|
75
64
|
datasetAdd?: DatasetAddFunction;
|
|
76
65
|
fetch?: FetchType;
|
|
@@ -670,7 +659,7 @@ export const PageDesigner = React.forwardRef<any, PageDesignerProps>(
|
|
|
670
659
|
{!!datasetPanel && leftPanelActiveKey === "dataset" && (
|
|
671
660
|
<DatasetPanel
|
|
672
661
|
ref={datasetPanelRef}
|
|
673
|
-
renderNode={datasetPanel}
|
|
662
|
+
renderNode={datasetPanel()}
|
|
674
663
|
/>
|
|
675
664
|
)}
|
|
676
665
|
</div>
|
|
@@ -708,7 +697,10 @@ export const PageDesigner = React.forwardRef<any, PageDesignerProps>(
|
|
|
708
697
|
}
|
|
709
698
|
/>
|
|
710
699
|
<div
|
|
711
|
-
className={[
|
|
700
|
+
className={[
|
|
701
|
+
"body beautified_scrollbar always",
|
|
702
|
+
deviceType,
|
|
703
|
+
].join(" ")}
|
|
712
704
|
>
|
|
713
705
|
<div
|
|
714
706
|
style={{
|
|
@@ -716,10 +708,7 @@ export const PageDesigner = React.forwardRef<any, PageDesignerProps>(
|
|
|
716
708
|
transformOrigin: "top center",
|
|
717
709
|
}}
|
|
718
710
|
>
|
|
719
|
-
<PageCanvas
|
|
720
|
-
ref={pageCanvasRef}
|
|
721
|
-
device={deviceType}
|
|
722
|
-
/>
|
|
711
|
+
<PageCanvas ref={pageCanvasRef} device={deviceType} />
|
|
723
712
|
</div>
|
|
724
713
|
</div>
|
|
725
714
|
</div>
|
|
@@ -104,7 +104,9 @@ export const AiPanel: React.FC<AiPanelProps> = ({
|
|
|
104
104
|
const [conversationList, setConversationList] = useState<
|
|
105
105
|
ChatConversationType[]
|
|
106
106
|
>([]);
|
|
107
|
-
const [messageList, setMessageList] = useState<
|
|
107
|
+
const [messageList, setMessageList] = useState<
|
|
108
|
+
(ChatMessageType & { error?: string | null })[]
|
|
109
|
+
>([]);
|
|
108
110
|
const messageListRef = React.useRef<MessageListRef>(null);
|
|
109
111
|
|
|
110
112
|
const scrollToBottom = () => {
|
|
@@ -159,39 +161,48 @@ export const AiPanel: React.FC<AiPanelProps> = ({
|
|
|
159
161
|
agents: data.agents || [],
|
|
160
162
|
atItems: JSON.stringify(atItems),
|
|
161
163
|
sending: true,
|
|
162
|
-
} as ChatMessageType;
|
|
164
|
+
} as ChatMessageType & { error?: string | null };
|
|
163
165
|
setMessageList((list) => [...list, questionMessage]);
|
|
164
166
|
scrollToBottom();
|
|
165
167
|
|
|
166
168
|
const newConversation = !conversationId;
|
|
167
169
|
|
|
168
170
|
clearAtItems();
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
171
|
+
try {
|
|
172
|
+
const { id, answer, createdAt, conversation } = await fetch.ai?.chat(
|
|
173
|
+
BIZ_TYPE,
|
|
174
|
+
pageId,
|
|
175
|
+
conversationId,
|
|
176
|
+
{
|
|
177
|
+
...data,
|
|
178
|
+
page: schema,
|
|
179
|
+
pageItems: atItems || [],
|
|
180
|
+
},
|
|
181
|
+
)!;
|
|
182
|
+
setConversationId(conversation?.id || "");
|
|
183
|
+
setConversationList((list) =>
|
|
184
|
+
[
|
|
185
|
+
newConversation ? conversation || ({} as ChatConversationType) : null,
|
|
186
|
+
...list,
|
|
187
|
+
].filter((i) => i !== null),
|
|
188
|
+
);
|
|
189
|
+
Object.assign(questionMessage, {
|
|
190
|
+
id,
|
|
191
|
+
answer,
|
|
192
|
+
createdAt,
|
|
193
|
+
conversationId: conversation?.id || "",
|
|
194
|
+
sending: false,
|
|
195
|
+
});
|
|
196
|
+
if (answer.effect) {
|
|
197
|
+
onEffect?.(answer.effect);
|
|
198
|
+
}
|
|
199
|
+
} catch (error: any) {
|
|
200
|
+
const errorMessage = error?.response?.data?.message || error.message || "未知错误";
|
|
201
|
+
console.error(errorMessage);
|
|
202
|
+
Object.assign(questionMessage, {
|
|
203
|
+
sending: false,
|
|
204
|
+
error: errorMessage,
|
|
205
|
+
});
|
|
195
206
|
}
|
|
196
207
|
setMessageList((list) => [...list]);
|
|
197
208
|
scrollToBottom();
|
|
@@ -238,9 +249,7 @@ export const AiPanel: React.FC<AiPanelProps> = ({
|
|
|
238
249
|
const active = list?.find((i) => i.isActived);
|
|
239
250
|
if (active) {
|
|
240
251
|
setConversationId(active.id);
|
|
241
|
-
const messages = await fetch.ai?.messageList(
|
|
242
|
-
active.id,
|
|
243
|
-
);
|
|
252
|
+
const messages = await fetch.ai?.messageList(active.id);
|
|
244
253
|
setMessageList(messages || []);
|
|
245
254
|
scrollToBottom();
|
|
246
255
|
}
|
|
@@ -553,6 +562,11 @@ const MessageRoot = styled.div`
|
|
|
553
562
|
font-size: 13px;
|
|
554
563
|
line-height: 1.6;
|
|
555
564
|
white-space: pre-wrap;
|
|
565
|
+
|
|
566
|
+
&.error {
|
|
567
|
+
color: var(--ant-color-error-text);
|
|
568
|
+
padding: 10px 0;
|
|
569
|
+
}
|
|
556
570
|
}
|
|
557
571
|
.msg-meta {
|
|
558
572
|
display: flex;
|
|
@@ -619,7 +633,7 @@ type MessageListRef = {
|
|
|
619
633
|
|
|
620
634
|
const MessageList = forwardRef<
|
|
621
635
|
MessageListRef,
|
|
622
|
-
{ list: ChatMessageType[]; onDeleteMessage: (id: string) => void }
|
|
636
|
+
{ list: (ChatMessageType & { error?: string | null })[]; onDeleteMessage: (id: string) => void }
|
|
623
637
|
>(({ list, onDeleteMessage }, forwardRef) => {
|
|
624
638
|
const ref = useRef<HTMLDivElement>(null);
|
|
625
639
|
|
|
@@ -661,7 +675,9 @@ const MessageList = forwardRef<
|
|
|
661
675
|
</div>
|
|
662
676
|
<div className="msg-section">
|
|
663
677
|
<Space size={4} orientation="vertical" className="msg-tools">
|
|
664
|
-
<Typography.Text
|
|
678
|
+
<Typography.Text
|
|
679
|
+
copyable={{ text: msg.question, tooltips: "复制" }}
|
|
680
|
+
/>
|
|
665
681
|
<Popconfirm
|
|
666
682
|
title="确认删除吗?"
|
|
667
683
|
okText="确认"
|
|
@@ -681,7 +697,9 @@ const MessageList = forwardRef<
|
|
|
681
697
|
</Tooltip> */}
|
|
682
698
|
</Space>
|
|
683
699
|
<div className="msg-content">{msg.question}</div>
|
|
684
|
-
{msg.files?.length ||
|
|
700
|
+
{msg.files?.length ||
|
|
701
|
+
msg.agents?.length ||
|
|
702
|
+
msg.atItems?.length ? (
|
|
685
703
|
<div className="msg-meta">
|
|
686
704
|
{msg.files?.map((f) => (
|
|
687
705
|
<Tag key={f.id} color="processing">
|
|
@@ -721,7 +739,11 @@ const MessageList = forwardRef<
|
|
|
721
739
|
<Skeleton active />
|
|
722
740
|
) : (
|
|
723
741
|
<>
|
|
724
|
-
|
|
742
|
+
{msg.error ? (
|
|
743
|
+
<div className="msg-content error">执行失败:{msg.error}</div>
|
|
744
|
+
) : (
|
|
745
|
+
<div className="msg-content">{msg.answer?.answer || ""}</div>
|
|
746
|
+
)}
|
|
725
747
|
{!!msg.answer?.plans?.length && (
|
|
726
748
|
<details className="msg-ai-meta" open>
|
|
727
749
|
<summary className="msg-ai-meta-title">PLANS:</summary>
|
package/src/example.tsx
CHANGED