物管理前端
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
4.5 KiB

import{i as ne,e as J}from"./index-Csvj-veb.js";import{d as p}from"./dayjs.min-tKPc2Ebd.js";import{t as ae,c as oe,g as U,a as se,x as re,s as ie}from"./utils-BnHQDKCA.js";import{c as W}from"./cloneDeep-C6NKQlMO.js";import{d as le,Y as ce,t as de,Q as me,v as pe,p as fe,o as ue,b as Fe,k as ge}from"./index-bVOhw2NF.js";import"./_initCloneObject-K-Y0ueWp.js";import"./_baseEach-BwxcRWC6.js";import"./_getTag-BJ2nhJXz.js";import"./get-BuNGRF3A.js";import"./toString-eibgRg41.js";import"./_baseFor-mOzdmxoL.js";const ye=le({name:"EsBarLine",components:{},props:{options:{type:Object,default:()=>({})},datasets:{type:[Array,Object,String],default:()=>[]},eventData:{type:[String,Boolean,Number],default:""},element:{type:Object,default:()=>({})}},setup(f){const i=ce(null),S={day:{prev:"昨日",curr:"今日"},month:{prev:"上月",curr:"当月"},year:{prev:"去年",curr:"今年"}},z=(a,u)=>{const{grid:E,title:G,legend:K,tooltip:h,xAxis:x,yAxis:q,codeConfig:I,timeAxisFormatter:d,completeDatas:T,timeCompare:e,dataShowTypes:X,legendNameType:Z,renderMode:ee}=u,te=ae.bind({timeCompare:e,timeAxisFormatter:d}),N=document.querySelector(`.chart-${f.element.id}`);if(N){i.value||(i.value=ne(N,null,{renderer:ee}));const _=a.info,m=Array.isArray(a.values)?a.values:a,R=a.param;if(m&&_&&R){let v=[];T&&(v=oe(R,_,m));let l=[],F=[],t=[],B=null;if(m.length>0){const M=U(m,"thingCode");for(const k in M){const w=U(M[k],"attrKey"),Q=Object.keys(w).length;for(const Y in w){let o=w[Y];const O=se(_,k,Y,X,Z,o);if(F.push(O),!B){const c=o[0],s=o[o.length-1];c.ts>s.ts&&(o=o.reverse());const g=p(+c.ts),b=p(+s.ts),D=g.diff(b,"day"),A=g.diff(b,"month");B=re.bind({months:A,days:D,timeAxisFormatter:d,timeCompare:T&&e})}if(T&&v.length>0)if(e){const c=ie(v,e),s={},g=c.prev.map((r,V)=>{let n=null;if(e==="day"?n=p(r).format(d||"HH:mm"):e==="month"?n=p(r).format(d||"DD"):e==="year"&&(n=p(r).format(d||"MM")),!t.includes(n)){t.push(n),s[V]=!0;const y=o.find(j=>+j.ts===r);return y&&y.val||0}}),b=c.curr.map((r,V)=>{if(t.length===0){let n=null;if(e==="day"?n=p(r).format(d||"HH:mm"):e==="month"?n=p(r).format(d||"DD"):e==="year"&&(n=p(r).format(d||"MM")),!t.includes(n)){t.push(n);const y=o.find(j=>+j.ts===r);return y&&y.val||0}}else if(s[V]){const n=o.find(y=>+y.ts===r);return n&&n.val||0}});let D="",A="";Q>1?(D=`${O}(${S[e].prev})`,A=`${O}(${S[e].curr})`):Q===1&&(D=`${S[e].prev}`,A=`${S[e].curr}`),F.push(D),F.push(A),l.push({name:D,type:"line",data:g.filter(Boolean)}),l.push({name:A,type:"line",data:b.filter(Boolean)})}else{const c=v.map(s=>{t.push(s);const g=o.find(b=>+b.ts===s);return g&&g.val||0});l.push({name:O,type:"line",data:c})}else{const c=o.map(s=>(t.push(+s.ts),s.val));l.push({name:O,type:"line",data:c})}}}}else F=["测试图例"],t=[1,2,3,4,5,6,7,8],l=[{type:"line",name:"测试图例",data:[100,80,60,40,20,10,5,0]}];t=[...new Set(t)].sort();const H={...K,data:F.filter(Boolean)},C={...x,axisLabel:{...x.axisLabel,formatter:T&&e?null:B},nameLocation:"end",nameGap:5,nameTextStyle:{color:x.nameColor,verticalAlign:"top",lineHeight:28},data:t},$={grid:E,title:G,tooltip:{...h,formatter:te,borderColor:h.backgroundColor,textStyle:{...h.textStyle,align:"left"}},legend:H,xAxis:C,yAxis:q,series:l};$.series[0]&&($.series[0].type="bar"),$.color=["#4992FFFF","#7CFFB2FF","#FDDD60FF","#FF6E76FF","#58D9F9FF","#05C091FF"];const L=new Function("option","datas","instance","echarts",I)(W($),m,i.value,J);i.value.setOption(L)}else{const v=f.element.dataSource.legendConfig||[{dataField:"data1",legend:"legend1"},{dataField:"data2",legend:"legend2"}],l=[],F=[...new Set(m.map(L=>L.category))],t=[];for(const L of v){const{dataField:M,legend:k}=L;l.push(k),t.push({name:k,type:"line",data:m.map(w=>w[M])})}const B={...x,axisLabel:{...x.axisLabel},nameLocation:"end",nameGap:5,nameTextStyle:{color:x.nameColor,verticalAlign:"top",lineHeight:28},data:F},H={...K,data:l.filter(Boolean)},C={grid:E,title:G,tooltip:{...h,borderColor:h.backgroundColor,textStyle:{...h.textStyle,align:"left"}},legend:H,xAxis:B,yAxis:q,series:t};C.series[0]&&(C.series[0].type="bar"),C.color=["#4992FFFF","#7CFFB2FF","#FDDD60FF","#FF6E76FF","#58D9F9FF","#05C091FF"];const P=new Function("option","datas","instance","echarts",I)(W(C),m,i.value,J);i.value.setOption(P)}}};return de([()=>f.datasets,()=>f.options],([a,u])=>{a&&me(()=>{z(a,u)})},{immediate:!0,deep:!0}),pe(()=>{const a=new ResizeObserver(()=>{i.value.resize()}),u=document.querySelector(`.chart-${f.element.id}`);u&&a.observe(u)}),{myChart:i}}});function he(f,i,S,z,a,u){return ue(),Fe("div",{class:ge(`chart-${f.element.id}`),width:"100%",height:"100%"},null,2)}const we=fe(ye,[["render",he]]);export{we as default};