You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
28 KiB
1 lines
28 KiB
import{d as ve,s as H,v as ue,o as me,b as he,p as we,q as de,ag as ee,Q as be,G as ye,D as Ce,t as oe,a8 as fe,c as I,W as Ee,ah as V,ai as Se,ac as ke,H as Y,aj as ae}from"./index-bVOhw2NF.js";import{u as J,a as xe}from"./helpers-CjmtV6uB.js";import{i as Ae,d as K,m as Fe,c as Be,u as Te,b as $e,g as Ie}from"./common-CalHcBJp.js";import{u as P,a as pe}from"./editor-ouq_SSv2.js";import{_ as Me,s as te}from"./http-D9Asdp-z.js";import"./dayjs.min-tKPc2Ebd.js";import"./toggleHighContrast-BiNrcRtm.js";const Ne=["accept"],De=ve({__name:"Upload",props:{option:{type:Object,required:!0}},setup(l,{expose:h}){const s=l,m={json:".json",image:"image/*"},w={option:s.option},t=H();function r(g){w.option=g;let u=m[g.resultType];g.accept&&(u=g.accept),t.value.setAttribute("accept",u),t.value.click()}async function a(g){if(!w.option||!w.option.onChange)return;const{resultType:u,onChange:o}=w.option;let c=g;const e=g.target.files[0];["json","text"].includes(u)?c=await d(e):u==="image"&&(c=await d(e,u)),o(c,e),t.value.value=""}function d(g,u="text"){return new Promise(o=>{const c=new FileReader;c.addEventListener("load",e=>{const n=e.target.result||"{}";o(n)}),u==="text"?c.readAsText(g):c.readAsDataURL(g)})}return ue(()=>{r(s.option)}),h({open:r}),(g,u)=>{var o;return me(),he("input",{ref_key:"inpurRef",ref:t,type:"file",accept:(o=w.option)==null?void 0:o.accept,class:"es-upload",onChange:a},null,40,Ne)}}}),Pe=we(De,[["__scopeId","data-v-35abe14c"]]),B=P();function Re(l){return ye(Me,{vShow:l.loading,description:"正在加载svg 看板",style:"position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 9999"})}function Ve(){const l=H(!1);function h(u){const o=window.atob(u),c=o.length,e=new Uint8Array(c);for(let n=0;n<c;n++)e[n]=o.charCodeAt(n);return e.buffer}const s=async u=>await new Blob([h(u)]).text();function m(u,o,c){const e=document.getElementById(u),n=document.getElementById(`editable-text-${u}`);e&&n&&(e.innerHTML=n.innerHTML,e.classList.remove("hidden"),n.remove(),o&&n.removeEventListener("focus",o),c&&n.removeEventListener("blur",c))}function w(){B.data.svgBoard&&B.data.svgBoard.textNodes&&B.data.svgBoard.textNodes.forEach(u=>{u.selected&&(u.selected=!1,m(u.id,"",""))})}function t(u,o,c,e){const n=B.data.container.scaleRatio/100,i=document.createElement("div");i.innerHTML=u,i.setAttribute("contenteditable","true"),i.setAttribute("class","editable-text-content"),i.setAttribute("id",`editable-text-${o}`),i.setAttribute("style",`top: ${e/n}px; left: ${c/n}px;position: absolute; z-index: 10000; color: #00ffff; border: 1px dashed #00ffff; outline: none; width: max-content;`);function p(b){var f;const S=b.target.id.split("-").pop(),k=B.data.elements.find(v=>v.id===S);if(k){const v=["0","1","2","3","4","5","6","7","8","9",".","-"],C=(f=b.target.textContent)==null?void 0:f.trim().split(" ");C==null||C.forEach(y=>{y.split("").every(A=>!!v.includes(A))&&window.$triggerChangeValue(k.props.datasets,y,k)})}}function E(){var S,k;const b=(S=B.data.svgBoard)==null?void 0:S.textNodes.find(f=>f.id===o);b&&(B.data.elements.forEach(f=>{f.selected&&(f.selected=!1)}),(k=B.data.svgBoard)==null||k.textNodes.forEach(f=>{f.selected&&(f.selected=!1,m(f.id,E,p))}),b.selected=!0,B.current=b)}return i.addEventListener("focus",E),i.addEventListener("blur",p),i}function r(u){var e;u.stopPropagation();const o=u.target;o.style.outline="none";const c=o.firstChild;if((c==null?void 0:c.nodeType)===3){const n=["0","1","2","3","4","5","6","7","8","9",".","-"],i=(e=c==null?void 0:c.textContent)==null?void 0:e.trim().split(" ");i==null||i.forEach(p=>{var b,S;if(p.split("").every(k=>!!n.includes(k))){const{x:k,y:f}=o.getBoundingClientRect(),v=document.querySelector(".es-canvas")||document.querySelector(".es-editor"),C=v==null?void 0:v.getBoundingClientRect().x,y=v==null?void 0:v.getBoundingClientRect().y,x=document.getElementById(o.id),A=t((x==null?void 0:x.textContent)||"",o.id,C?k-C:k,y?f-y:f);if(setTimeout(()=>{o.classList.add("hidden"),setTimeout(()=>{v==null||v.appendChild(A),A.focus()},0)},100),!((b=B.data.svgBoard)==null?void 0:b.textNodes.find(M=>M.id===o.id))){const M=Ae({name:"es-text",nameCn:o.getAttribute("name")||"",dataMap:!1,isRemote:!1});M.id=o.id,M.props.options={isSvgText:!0,text:p},(S=B.data.svgBoard)==null||S.textNodes.push(M);const N=Ce(M);oe(()=>N.props.datasets,(D,G)=>{D&&D!==G&&a(o.id,D)},{deep:!0}),oe(()=>N.props.options.text,(D,G)=>{D&&D!==G&&a(`editable-text-${o.id}`,D)})}}})}}function a(u,o){var E;const c=((E=document.getElementById(u))==null?void 0:E.textContent)||"";let e="";const n=c.trim().split(" "),i=["0","1","2","3","4","5","6","7","8","9",".","-"];n==null||n.forEach(b=>{b.split("").every(k=>!!i.includes(k))?e+=` ${o}`:e+=` ${b}`});const p=document.getElementById(u);p&&(p.textContent=e.trim())}const d=u=>{var n;const o=de(Re,{loading:!0}),c=document.querySelector(".es-layout-main")||document.querySelector(".es-preview-body");ee(o,c),s((n=B.data.svgBoard)==null?void 0:n.document).then(i=>{const p=document.getElementById(u);p&&(p.innerHTML=i,be(()=>{const E=document.getElementById(u),b=E==null?void 0:E.querySelector("svg");b&&(b.style.left="0px",b.style.top="0px",b==null||b.setAttribute("width",`${B.data.container.style.width}px`),b==null||b.setAttribute("height",`${B.data.container.style.height}px`),l.value=!0)})),setTimeout(()=>{if(B.data.svgBoard){const E=document.getElementById(u),b=E==null?void 0:E.querySelectorAll("text");b==null||b.forEach(S=>{S.style.cursor="pointer",S.addEventListener("focus",r)}),ee(null,c)}},0)});const e=document.querySelector(".es-canvas")||document.querySelector(".es-editor");e==null||e.addEventListener("click",i=>{i.target.nodeName==="text"||i.target.className==="editable-text-content"||w()})};function g(u){const o=document.getElementById(u);if(o){const c=o==null?void 0:o.querySelectorAll("text");c==null||c.forEach(e=>{const n=e.firstChild;(n==null?void 0:n.nodeType)===3&&e.removeEventListener("focus",r)}),o.innerHTML="",l.value=!1}}return{svgVisible:l,initSvgBoard:d,getSvgElement:s,removeSvgBoard:g,blurOldTextHandler:w,updateText:a}}const He=fe("contextMenu",{state:()=>({show:!1,clientX:0,clientY:0,items:[],onClick:()=>{}})}),Le={"ctrl+x":"cut","ctrl+c":"copy","ctrl+v":"paste",Delete:"remove","ctrl+a":"selectAll","ctrl+d":"duplicate","ctrl+g":"group","ctrl+shift+G":"ungroup","ctrl+l":"lock","ctrl+shift+L":"lock","ctrl+shift+H":"hide","ctrl+i":"insertPicture",ArrowUp:"translateUp",ArrowDown:"translateDown",ArrowLeft:"translateLeft",ArrowRight:"translateRight"},$=P(),O=pe(),se=He(),Oe=Ve(),R=I(()=>$.data.container.scaleRatio/100);function it(l,h){const s=I(()=>{var e;return((e=h.value)==null?void 0:e.getBoundingClientRect())||{}});let m=null,w=null;const t=e=>e?l.value.elements.findIndex(n=>n.id===e.id):-1,r=(e,n)=>{[l.value.elements[e],l.value.elements[n]]=[l.value.elements[n],l.value.elements[e]]},a=e=>{e&&l.value.elements.push(e)};let d=0;const g={remove(){l.value.elements=l.value.elements.filter(e=>!e.selected).filter(Boolean),$.current={}},cut(e){w=e,g.remove(e)},copy(e){d=0,w=e},duplicate(e){e.selected=!1;const n=K(e);n.id=J(),n.component==="es-group"&&n.props.elements.forEach(i=>{i.id=J()}),n.left+=10,n.top+=10,a(n)},hide(e){const n=l.value.elements.find(i=>i.id===e.id);n&&(n.visible=!1)},top(e){const n=t(e),[i]=l.value.elements.splice(n,1);l.value.elements.push(i)},bottom(e){const n=t(e),[i]=l.value.elements.splice(n,1);l.value.elements.unshift(i)},align(e,n){const i=l.value.elements.filter(v=>v.selected);if(i.length<2)return;const[p,E]=i.reduce(([v,C],y)=>[Math.min(v,y.left),Math.min(C,y.top)],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]),[b,S]=i.reduce(([v,C],y)=>[Math.max(v,y.left+y.width),Math.max(C,y.top+y.height)],[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY]),k=(p+b)/2,f=(E+S)/2;switch(n){case"left":i.forEach(v=>v.left=p);break;case"right":i.forEach(v=>v.left=b-v.width);break;case"top":i.forEach(v=>v.top=E);break;case"bottom":i.forEach(v=>v.top=S-v.height);break;case"verticalCenter":i.forEach(v=>{v.left=k-v.width/2});break;case"horizontalCenter":i.forEach(v=>{v.top=f-v.height/2});break}},group(){var i;const e=((i=h.value)==null?void 0:i.getBoundingClientRect())||{},n=l.value.elements.find(p=>p.component==="es-line");if(n&&n.selected)return window.$popmessage({type:"warn",str:"连线不可以编组"});l.value.elements=Fe(l.value.elements,e,R.value)},ungroup(){var n;const e=((n=h.value)==null?void 0:n.getBoundingClientRect())||{};l.value.elements=Be(l.value.elements,e,R.value)},paste(e,n,i){if(!w)return;w.selected=!1;const p=K(w);p.id=J(),!n&&!i?(p.left+=++d*10,p.top+=++d*10):(p.left=(n-s.value.left)/R.value,p.top=(i-s.value.top)/R.value),a(p)},selectAll(){setTimeout(()=>{l.value.elements.forEach(e=>e.selected=!0)},0)},lock(e){const n=t(e);l.value.elements[n].disabled=!0},unlock(e){const n=t(e);l.value.elements[n].disabled=!1},moveUp(e){const n=t(e);n>=l.value.elements.length-1||r(n,n+1)},moveDown(e){const n=t(e);n<=0||r(n,n-1)},translateUp(e){e.top-=1},translateDown(e){e.top+=1},translateLeft(e){e.left-=1},translateRight(e){e.left+=1},insertPicture(e,n,i){ce({resultType:"image",onChange(p){const b={id:Te(),component:"img",name:"图片",isHovered:!1,selected:!1,editable:!0,thumbnail:"",disabled:!1,visible:!0,dataSource:{...$e("static"),data:p},interactions:[],related:[],basicEvents:[],advancedEvents:[],...Ie(),class:"no-img-maxw",props:{src:p,width:200,datasets:"",eventData:"",onLoadOnce(S){if(b.props.loaded)return;const{naturalHeight:k,naturalWidth:f}=S.target,v=$.data.elements.find(y=>y.id===b.id);let C=200/f;C>1&&(C=1),v.width=f*C,v.height=k*C,b.props.loaded=!0}}};b.left=(n-s.value.left)/R.value,b.top=(i-s.value.top)/R.value,$.data.elements.push(b)}})},importSvg(){ce({resultType:"image",onChange(e){const n=O.pages.findIndex(b=>b.activePage),i=O.pages[n];if(i.data.svgBoard)return window.$popmessage({type:"warning",message:"只能导入一个svg看板"});const E={document:e.split(",")[1],textNodes:[]};i.data.svgBoard=E,$.data.svgBoard=E}})},deleteSvgBoard(){const e=O.pages.findIndex(p=>p.activePage),n=O.pages[e],i=n.data.svgBoard;i&&(i.document=void 0,i.textNodes=void 0),delete n.data.svgBoard,delete $.data.svgBoard,Oe.removeSvgBoard(`${$.pageName}-svg-board`)}},u=(e,n)=>{e.preventDefault();const{clientX:i,clientY:p}=e;m=K(n);const E=l.value.elements.filter(f=>f.selected),b=[{action:"remove",label:"删除",shortCut:"Delete"},{action:"cut",label:"剪切",shortCut:"Ctrl+X"},{action:"copy",label:"复制",shortCut:"Ctrl+C"},{action:"duplicate",label:"创建副本",shortCut:""},{action:"hide",label:"隐藏",shortCut:""},{action:"top",label:"置顶",shortCut:""},{action:"bottom",label:"置底",shortCut:""},{action:"moveUp",label:"上移一层",shortCut:"Up ↑"},{action:"moveDown",label:"下移一层",shortCut:"Down ↓"}];!n.group&&E.length>1?(b.push({action:"group",label:"创建分组",shortCut:"Ctrl+G"}),b.push({action:"align",label:"对齐",shortCut:">"})):n.group&&b.push({action:"ungroup",label:"解除分组",shortCut:"Ctrl+Shift+G"});const S=m.disabled,k={action:"lock",label:"锁定",shortCut:"Ctrl+L"};S||b.push(k),Object.assign(se,{show:!0,clientX:i,clientY:p,items:S?[{action:"unlock",label:"解锁",shortCut:"Ctrl+Shift+L"}]:b,onClick:({action:f},v)=>{g[f]&&g[f](m,v)}})},o=e=>{e.preventDefault();const{clientX:n,clientY:i}=e;Object.assign(se,{show:!0,clientX:n,clientY:i,items:[{action:"paste",label:"粘贴",shortCut:"Ctrl+V"},{action:"insertPicture",label:"插入图片",shortCut:"Ctrl+I"},{action:$.data.svgBoard?"deleteSvgBoard":"importSvg",label:$.data.svgBoard?"删除svg看板":"导入svg看板",shortCut:""},{action:"selectAll",label:"全选",shortCut:"Ctrl+A"}],onClick:({action:p})=>{p==="paste"?g.paste(m,n,i):p==="selectAll"&&g[p]?g[p](m):p==="insertPicture"&&g[p]||p==="importSvg"&&g[p]?g[p](m,n,i):p==="deleteSvgBoard"&&g[p]&&g[p](m)}})},c=e=>{var k;const{ctrlKey:n,shiftKey:i,key:p}=e,E=[];n&&E.push("ctrl"),i&&E.push("shift"),E.push(p);const b=E.join("+"),S=Le[b];if(g[S]){const f=e.target;if(f.nodeName==="INPUT"||f.nodeName==="TEXTAREA"||f.className==="inputarea monaco-mouse-cursor-text"){const C=e.target;if(C.className==="val-widget"){C.blur();const y=C.closest(".es-text"),x=(k=y==null?void 0:y.parentNode)==null?void 0:k.id;if(x){const A=l.value.elements.find(F=>F.id===x);A&&g[S](A)}}}else e.preventDefault(),m=l.value.elements.find(C=>C.selected)||null,g[S](m)}};return ue(()=>{window.addEventListener("keydown",c)}),Ee(()=>{window.removeEventListener("keydown",c)}),{actions:g,editorRect:s,onContextmenu:u,onEditorContextMenu:o}}let X;const z="es-editor-container-1996";function qe(){if(!X&&!document.querySelector(`#${z}`)){const l=document.createElement("div");l.id=z,X=l,document.body.appendChild(l)}return{container:X,selector:z}}const _e=fe("ruler",()=>{const l=H(-20),h=H(-20),s=H(-20),m=H(-20);return{initScrollX:l,initScrollY:h,scrollX:s,scrollY:m,reset:()=>{s.value=-20,m.value=-20,l.value=-20,h.value=-20}}});function Ue(){const l=_e(),h=P(),s=I(()=>{var w;return((w=h.data.container)==null?void 0:w.scaleRatio)||100});function m(){var r,a;const w=(r=document.querySelector(".es-editor-container"))==null?void 0:r.getBoundingClientRect(),t=(a=document.querySelector(".es-canvas"))==null?void 0:a.getBoundingClientRect();if(w&&t){const d=w.left-t.left,g=w.top-t.top;l.scrollX=d/(s.value/100)+20/(s.value/100),l.scrollY=g/(s.value/100)+20/(s.value/100)}}return setTimeout(()=>{const w=document.querySelector(".edit-screens");V(w,"scroll",m),w&&(w.scrollTo({left:3840/2-w.offsetWidth/2,top:2160/2-w.offsetHeight/2}),setTimeout(m,100))},0),{scrollHandler:m}}const re=P(),{scrollHandler:je}=Ue(),We=Se(()=>{je()},200,{maxWait:500});function lt(l){const h=document.querySelector(l),s=I({get(){return re.data.container.scaleRatio/100},set(t){re.data.container.scaleRatio=+(t*100).toFixed(0)}});function m(t){if(!t.ctrlKey)return;let r=!0;r=t.wheelDelta?t.wheelDelta<0:t.detail>0;let a;return r?(a=s.value-.05,a<.5&&(a=.5)):(a=s.value+.05,a>1&&(a=1)),s.value=a,t.preventDefault&&t.preventDefault(),We(),!1}V(h,"mousewheel",m),V(h,"DOMMouseScroll",m),V(document,"mousewheel",t=>{const r=window.event;(t.wheelDelta&&r.ctrlKey||t.detail)&&r.preventDefault()},{capture:!1,passive:!1});let w=!1;V(document,"mousedown",t=>{t.target&&t.target.closest(l)?w=!0:w=!1}),V(document.body,"keydown",t=>{(window.event||event).code==="Space"&&w&&(t.preventDefault?t.preventDefault():window.event.returnValue=!1)})}const Ge=P(),q=I(()=>Ge.data.container.style);function ct(l,h,s){l.forEach((m,w)=>{let t=m.groupStyle.left,r=m.groupStyle.top;switch(h){case"left":t=0;break;case"right":t=(s.width-m.width)/s.width;break;case"top":r=0;break;case"bottom":r=(s.height-m.height)/s.height;break;case"horizontalCenter":t=(s.width/2-m.width/2)/s.width;break;case"verticalCenter":r=(s.height/2-m.height/2)/s.height;break}l[w].groupStyle={...l[w].groupStyle,left:`${t*100}%`,top:`${r*100}%`}})}function ut(l,h){l.forEach(s=>{switch(h){case"left":s.left=0;break;case"right":s.left=q.value.width-s.width;break;case"top":s.top=0;break;case"bottom":s.top=q.value.height-s.height;break;case"horizontalCenter":s.left=q.value.width/2-s.width/2;break;case"verticalCenter":s.top=q.value.height/2-s.height/2;break}})}function Q(){return l=>{if(l){let h="";const s=l||[{val:""}];return s[0]?h=s[0].val:h=s[0]===void 0?"":s[0],h}else return""}}function ge(){return l=>{const{deviceAttrs:h,calcRules:s,uniquePoint:m,values:w,deviceIdCodeMap:t}=l,r=[];if(s&&s.length>0&&h&&h.length>0){const a=[],d={},g={},u=h.map(o=>{const c=t[o.devices];return d[o.num]=[],g[`${c}-${o.dataPoint}`]=o.num,a.push({...o,deviceCode:c}),o.num});return w.forEach(o=>{const c=g[`${o.thingCode}-${o.attrKey}`];c&&d[c].push({...o})}),s.forEach(o=>{const c=a.find(e=>e.num===o.resultAttr);if(c)d[c.num].forEach((e,n)=>{let i=o.formular;u.forEach(b=>{if(i.includes(b)){const S=d[b][n].val;i=i.replace(b,S)}});const E=new Function("",`return ${i}`)();e.val=E});else if(u.length>0){const e=d[u[0]].map((n,i)=>{let p=o.formular;u.forEach(S=>{if(p.includes(S)){const k=d[S][i].val;p=p.replace(S,k)}});const b=new Function("",`return ${p}`)();return{thingCode:o.resultAttr,attrKey:o.resultAttr,ts:n.ts,val:b}});d[o.resultAttr]=e}}),m&&u.includes(m)?r.push(...d[m]):Object.values(d).forEach(o=>{r.push(...o)}),r}}}function Ye(){function l(){return t=>{var S,k,f;const{dataSource:r}=this.element,{isTesting:a}=this;if(!r.SuperApiConfig)return;const{devices:d,dataPoint:g,enableDataHandle:u,deviceAttrs:o,calcRules:c,uniquePoint:e}=r.SuperApiConfig;if(!g)return;const n=((S=t.data)==null?void 0:S.result.info)||{},i=((k=t.data)==null?void 0:k.result.values)||[];let p="";const E={},b=Object.keys(n).filter(v=>d.includes(n[v].entityId)?(E[n[v].entityId]=v,!0):!1);if(g.length>0){const v=i.filter(C=>b.includes(C.thingCode)&&g.includes(C.attrKey));if(u?p=ge()({deviceAttrs:o,calcRules:c,uniquePoint:e,values:v,deviceIdCodeMap:E}):p=v,!r.filterFunction)a?(this.element.dataSource.data=Q()(p),this.element.props.datasets=Q()(p)):this.element.props.datasets=Q()(p);else{const C=new Function("data",r.filterFunction),y=r.filterFunction==="return result"?{info:(f=t.data)==null?void 0:f.result.info,values:p}:C(p);a?(this.element.dataSource.data=y,this.element.props.datasets=y):this.element.props.datasets=y}}}}const h={};function s(t,r,a,d=!1){h[t]||(h[t]={}),h[t]&&(h[t][r.id]||(h[t][r.id]={}),h[t][r.id]=a.bind({apiId:t,element:r,isTesting:d}))}function m(t,r){for(const a in t){const d=t[a];typeof d=="function"&&d(r)}}function w(t){if(h[t])return;const r=window.isDeveloping?"192.168.8.91:8080":window.location.host,a=localStorage.getItem("v1@CacheToken"),g=JSON.parse(a||"{}").token||sessionStorage.getItem("token")||"",u=`ws://${r}/thing/websocket?token=${g}&apiId=${t}`,o=new WebSocket(u);o.onopen=function(){h[t]||(h[t]={})},o.onmessage=function(c){if(!c.data)return;const e=JSON.parse(c.data);for(const n in h)if(n===t){const i=h[n];m(i,e),Object.keys(i).length===0&&setTimeout(()=>{m(h[n],e)},1e3)}},o.onclose=function(c){h[t]=0,c.wasClean},o.onerror=function(){h[t]=0}}return{bindSocket:s,startSocket:w,dataResolve:l}}window.totalDeviceInfos={};window.totalApiParams={};const j=P(),ne=I({get(){return j.data.globals.variables},set(l){j.data.globals.variables=l}});function _(l,h){return typeof l>"u"||l.length===0?[]:(Array.isArray(l)||window.$popmessage({type:"warn",str:"请确保过滤后的数据格式为数组"}),l.map(s=>{const m={};return h.forEach(w=>{const{sourceField:t,mapField:r,checked:a}=w;s[r]&&(a===!0||a===void 0)&&(m[t]=s[r])}),m}))}function L(l,h){const s=/\{([^{}]+)\}/,m=s.exec(l),w=s.exec(h);let t=l,r=h;if(m){t=m[1];const a=ne.value.find(d=>d.name===t);a&&(t=a.type==="static"?a.value||a.defaultValue:a.value||a.routeDefaultVal)}if(w){r=w[1];const a=ne.value.find(d=>d.name===d);a&&(r=a.type==="static"?a.value||a.defaultValue:a.value||a.routeDefaultVal)}return{k:t,v:r}}function Je(l){const h=/\$\{([^}]*)\}/g;let s;const m=[];for(;(s=h.exec(l))!==null;)m.push(s[1]);let w=l;return m.forEach(t=>{const r=ne.value.find(d=>d.name===t);let a="";r&&(a=r.type==="static"?r.value||r.defaultValue:r.value||r.routeDefaultVal),w=w.replace(`\${${t}}`,a)}),w}function Ke(){return(l,h,s)=>{var p,E,b,S,k;const{dataSource:m}=h;if(!m.SuperApiConfig)return;const{devices:w,dataPoint:t,enableDataHandle:r,deviceAttrs:a,calcRules:d,uniquePoint:g}=m.SuperApiConfig;if(!t)return;const u=((p=l.data)==null?void 0:p.result.info)||{},o=m.SuperApiConfig.dataSource;o&&(window.totalDeviceInfos[o]||(window.totalDeviceInfos[o]=u),window.totalApiParams[o]||(window.totalApiParams[o]=((E=l.data)==null?void 0:E.param)||{}));const c=((b=l.data)==null?void 0:b.result.values)||[];let e="";const n={},i=Object.keys(u).filter(f=>w.includes(u[f].entityId)?(n[u[f].entityId]=f,!0):!1);if(t.length>0){const f=c.filter(v=>i.includes(v.thingCode)&&t.includes(v.attrKey));if(r?e=ge()({deviceAttrs:a,calcRules:d,uniquePoint:g,values:f,deviceIdCodeMap:n}):e=f,!m.filterFunction)s&&(h.dataSource.data=JSON.stringify(e,null,2)),h.props.datasets=e;else{const v=new Function("data",m.filterFunction),C=m.filterFunction==="return result"?{info:(S=l.data)==null?void 0:S.result.info,values:e,param:(k=l.data)==null?void 0:k.param}:v(e);s&&(h.dataSource.data=JSON.stringify(C,null,2)),h.props.datasets=C}}}}const{bindSocket:Xe,dataResolve:ze}=Ye();function Qe(){const l=(s,m,w)=>{if(w&&s.SuperApiConfig){const f=s==null?void 0:s.SuperApiConfig;if(f.dataSource&&f.type==="socket")return Xe(f.dataSource,m,ze(),w)}const t=s.envConfig.service||window.location.origin;if(!t)return window.$popmessage({str:"请先配置服务地址!",type:"warn"});const a=s.envConfig.header.filter(f=>f.k&&f.value).reduce((f,v)=>{const{k:C,v:y}=L(v.k,v.value);return f[C]=y,f},{}),d=s.api.method,g=s.api.url;if(!g)return window.$popmessage({str:"请先配置API地址!",type:"warn"});const o=s.api.params.filter(f=>f.k&&f.value).reduce((f,v)=>{const{k:C,v:y}=L(v.k,v.value);return f[C]=y,f},{}),c=s.api.body,n=s.api.header.filter(f=>f.k&&f.value).reduce((f,v)=>{const{k:C,v:y}=L(v.k,v.value);return f[C]=y,f},{}),i=s.api.bodyType,p=c.none,E=c["form-data"],b=c["x-www-form-urlencoded"],S=c.json,k=c.raw;if(d==="GET")te.get(`${t}${g}`,o,{...a,...n}).then(f=>{var v;try{if(s.apiType==="globalApi")j.data.elements.filter(y=>y.dataSource.id===s.id).forEach(y=>{let F=new Function("data","res",y.dataSource.filterFunction)(f.data,f);y.dataSource.dataMapping&&(F=_(F,y.dataSource.dataMapping)),y.props.datasets=F,w&&(y.dataSource.data=JSON.stringify(F,null,2))});else if(s.apiType==="superApi"&&((v=s.SuperApiConfig)==null?void 0:v.type)==="history")Ke()(f,m,w);else{let x=new Function("data","res",s.filterFunction)(f.data,f);s.dataMapping&&(x=_(x,s.dataMapping)),m.props.datasets=x,w&&(m.dataSource.data=JSON.stringify(x,null,2))}}catch(C){window.$popmessage({str:C.toString(),type:"warn"})}});else{let f={},v="application/json";if(i==="form-data")f=new FormData,v="multipart/form-data",E.forEach(y=>{const{k:x,v:A}=L(y.k,y.value);f.append(x,A)});else if(i==="x-www-form-urlencoded"){v="application/x-www-form-urlencoded";const y=new URLSearchParams;b.forEach(x=>{const{k:A,v:F}=L(x.k,x.value);y.append(A,F.toString())}),f=y}else i==="json"?f=JSON.parse(Je(S)||"{}"):i==="raw"?f=JSON.stringify(k||""):f=p;const C={...a,...n,"Content-Type":v};te[d](g,f,{headers:C}).then(y=>{try{if(s.apiType==="globalApi")j.data.elements.filter(A=>A.dataSource.id===s.id).forEach(A=>{let N=new Function("data","res",A.dataSource.filterFunction)(y.data,y);A.dataSource.dataMapping&&(N=_(N,A.dataSource.dataMapping)),A.props.datasets=N,w&&(A.dataSource.data=JSON.stringify(N,null,2))});else{let F=new Function("data","res",s.filterFunction)(y.data,y);s.dataMapping&&(F=_(F,s.dataMapping)),m.props.datasets=F,w&&(m.dataSource.data=JSON.stringify(F,null,2))}}catch(x){window.$popmessage({str:x.toString(),type:"warn"})}})}};return{intervalFn:(s,m,w)=>{const{interval:t,intervalUnit:r}=s.envConfig,{interval:a,intervalUnit:d}=s.api;t||a?ke(()=>{l(s,m,w)},+r||+d):l(s,m,w)}}}const W=P(),ie=pe(),T=I(()=>W.data.elements),Ze=I({get(){return W.data.globals.variables},set(l){W.data.globals.variables=l}}),le=I(()=>W.data.globals.apis),{intervalFn:Z}=Qe();function dt(){const l=(t,r)=>{const a=T.value.find(d=>t.targetId.includes(d.id));if(a){r!==void 0&&(a.visible=r);const{animationEnabled:d,animationOptions:g}=t.targetProps;a.animationEnabled=d,a.animationOptions=g}},h={show:()=>t=>{l(t,!0)},hide:()=>t=>{l(t,!1)},animate:()=>t=>{l(t)},filter:()=>t=>{const r=T.value.find(a=>t.targetId.includes(a.id));if(r&&r.style){const a=t.targetProps;a.enabled?r.style.filter=`saturate(${a.saturate/100}) contrast(${a.contrast/100}) hue-rotate(${a["hue-rotate"]}deg) brightness(${a.brightness/100}) blur(${a.blur/100}px)`:r.style.filter="none"}},pageSwitch:()=>t=>{const{pageName:r,delay:a}=t.targetProps;setTimeout(()=>{ie.$state.forEach(d=>{d.pageName===r?d.activePage=!0:d.activePage=!1}),ie.toggle()},+a)},jumpToBigScreen:()=>t=>{const{bigscreenUrl:r,delay:a,params:d}=t.targetProps,g=d.map(u=>u.key&&u.value?`${u.key}=${u.value}`:"").filter(Boolean).join("&");setTimeout(()=>{window.location.href=`${r}${g?`?${g}`:""}`},a)},jumpToNewUrl:()=>t=>{const{newUrl:r,delay:a,openNewTab:d}=t.targetProps;setTimeout(()=>{let g=r;r.includes("http")||(g=`http://${g}`),d?window.open(g,"_blank"," "):window.location.href=g},a)},requestData:()=>(t,r,a)=>{const{delay:d,globalVariablesUpdate:g}=t.targetProps,u=T.value.find(o=>t.targetId.includes(o.id));if(u)try{let o=null;if(u.dataSource.apiType==="globalApi"){const e=le.value.find(n=>n.id===u.dataSource.id);e&&(o={...Y(e),filterFunction:u.dataSource.filterFunction})}else o=u.dataSource;new Function("globalVariables","dataset","eventData","components",g)(Ze,r,a,T.value),setTimeout(()=>{Z(o,u)},+d)}catch(o){console.error(o)}},transform:()=>t=>{const r=T.value.find(a=>t.targetId.includes(a.id));r&&xe(t,r)},updateStyles:()=>t=>{const r=T.value.find(a=>t.targetId.includes(a.id));r&&Object.assign(r.props.options,{...t.targetProps})},dispatchCommand:()=>(t,r,a,d)=>{const{method:g,url:u,command:o,device:c,params:e,delay:n,enable:i}=t.targetProps;if(i===!1)return;const E=new Function("deviceInfo","command","event",e)(c,o,a);setTimeout(()=>{te[g](u,E).then(b=>{b.code!==0?ae({str:b.message,type:"warning"}):ae({str:"指令下发成功",type:"success"})})},+n)},transferData:()=>(t,r,a,d)=>{const g=new Function("datasets","eventData","components","component",t.targetProps.params);try{g(r,a,T.value,d)}catch{}}},s=t=>(r,a,d)=>{if(!d)return;d.interactions.filter(o=>o.eventType===t).forEach(o=>{const c=new Function("dataset","eventData",o.triggerCondtion);try{c(r,a)!==!1&&o.action.forEach(n=>{h[n.type]()(n,r,a,d)})}catch{}});const u=d.basicEvents.find(o=>o.type===t);if(u){const o=new Function("mouseEvent","components","component",u.functionBody);try{o(a,T.value,d)}catch{}}t==="change"&&d.related.forEach(o=>{if(!o.triggerEvent||!o.bindApi)return;const c=T.value.find(e=>e.dataSource.id===o.bindApi);if(c){const{dataSource:e}=c;if(e.apiType==="globalApi"){const n=le.value.find(i=>i.id===e.id);if(n){const i=Y(n);i.api.params=o.relatedApiParams.params.map(p=>p.value==="[changeValue]"?{key:p.key,value:a}:null).filter(Boolean),i.api.header=o.relatedApiParams.header.map(p=>p.value==="[changeValue]"?{key:p.key,value:a}:null).filter(Boolean),Z({...i,filterFunction:e.filterFunction},c)}}else{const n=Y(c.dataSource);n.api.params=o.relatedApiParams.params.map(i=>i.value==="[changeValue]"?{key:i.key,value:a}:null).filter(Boolean),n.api.header=o.relatedApiParams.header.map(i=>i.value==="[changeValue]"?{key:i.key,value:a}:null).filter(Boolean),Z(c.dataSource,c)}}})},m={click:s("click"),dblclick:s("dblclick"),mouseenter:s("mouseenter"),mouseleave:s("mouseleave"),change:s("change")};return window.$triggerChangeValue=m.change,window.$postIframeMessage=(t,r,a)=>{var u;const d=document.getElementById(t);if(!d)return;((u=d.querySelector(".iframe-container iframe"))==null?void 0:u.contentWindow).postMessage({type:r,data:a})},{...m,...{vnodeMounted:(t,r,a,d)=>{var u;const g=a.advancedEvents.find(o=>o.type==="vnodeMounted");if(g){const o=new Function("mouseEvent","components","component",g.functionBody);if(a.isRemote){const c=document.getElementById(a.id);if(!c)return;const e=(u=c.querySelector(".iframe-container iframe"))==null?void 0:u.contentWindow;if(!e)return;const n=o.bind(e);try{n(r,T.value,a)}catch{}}else{const c=o.bind(d.component.ctx.myChart||d.component.ctx);try{c(r,T.value,a)}catch{}}}},vnodeBeforeMount:(t,r,a,d)=>{var u;const g=a.advancedEvents.find(o=>o.type==="vnodeBeforeMount");if(g){const o=new Function("mouseEvent","components","component",g.functionBody);if(a.isRemote){const c=document.getElementById(a.id);if(!c)return;const e=(u=c.querySelector(".iframe-container iframe"))==null?void 0:u.contentWindow;if(!e)return;const n=o.bind(e);try{n(r,T.value,a)}catch{}}else{const c=o.bind(d.component.ctx.myChart||d.component.ctx);try{c(r,T.value,a)}catch{}}}}}}}let U=null;function ce(l){if(U){const{open:h}=U.component.exposed;h(l)}else{const{container:h}=qe(),s=document.createElement("div");U=de(Pe,{option:l}),ee(U,s),h.appendChild(s.firstElementChild)}}export{ce as $,ut as a,ct as b,Ue as c,_e as d,He as e,Ve as f,Ye as g,Qe as h,it as i,dt as j,lt as k,qe as u};
|