2 lines
7.4 KiB
JavaScript
2 lines
7.4 KiB
JavaScript
import{b9 as y,d9 as ve,m as me,v as he,aa as c,cf as g,ad as l,b2 as s,ac as x,ab as fe,u as I,ae as n,I as b,bb as k,aR as L,bp as u,aT as d,ai as ge,a2 as ye}from"../jse/index-index-NearNHEt.js";import{b as W,f as pe}from"./data-DcmDNjV_.js";import{a as _e}from"./index-BE_nvmAp.js";import{ac as be}from"./bootstrap-LRVGLqq_.js";let M=null;const O=y([]),G=y(!1);function ke(){return M||(M=_e({isActive:!0}).then(p=>{var v;const N=Array.isArray(p)?p:(v=p==null?void 0:p.list)!=null?v:[];O.value=ve(N,"id","parentId")}).catch(()=>{O.value=[],M=null}).finally(()=>{G.value=!0}),M)}const Te={class:"gantt-area-wrapper"},Ce={key:0,class:"gantt-empty"},Se={key:1,class:"gantt-empty"},Me={key:2,class:"gantt-container"},xe={class:"gantt-toolbar"},Ie={class:"time-presets"},Ne=["onClick"],$e={class:"toolbar-zoom"},Ae=["disabled"],we={class:"zoom-label"},ze=["disabled"],De={class:"gantt-main"},He={class:"gantt-left"},Le={class:"gantt-left-body"},Oe=["onClick"],Pe={key:1,class:"gantt-toggle-placeholder"},Ye={class:"gantt-label-text"},Be={class:"gantt-right-body"},je=["onClick","onMouseenter"],Ee={key:2,class:"gantt-no-data-line"},Fe={key:3,class:"gantt-legend"},Re={class:"gantt-tooltip-title"},Ue={class:"gantt-tooltip-sub"},Ve={class:"gantt-tooltip-sub"},We={class:"gantt-tooltip-sub"},Ge=me({__name:"trajectory-gantt-area",props:{date:{},loading:{type:Boolean},records:{}},emits:["select"],setup(p,{emit:N}){const v=p,q=N,X=O,Z=G;he(()=>{ke()});const m=y("auto"),$=y(6),A=y(24),P=c(()=>{if(v.records.length===0)return[6,24];let e=24,t=0;for(const r of v.records){const h=g(r.enterTime),f=r.leaveTime?g(r.leaveTime):g();e=Math.min(e,h.hour());const T=f.minute()>0?f.hour()+1:f.hour();t=Math.max(t,T)}const a=Math.max(0,e-1),o=Math.min(24,Math.max(t+1,a+4));return[a,o]}),C=c(()=>m.value==="full"?0:m.value==="custom"?$.value:P.value[0]),J=c(()=>m.value==="full"?24:m.value==="custom"?A.value:P.value[1]),S=c(()=>J.value-C.value),Y=c(()=>Array.from({length:S.value},(e,t)=>C.value+t)),K=[{label:"自适应",value:"auto"},{label:"全天",value:"full"},{label:"上午",start:6,end:12},{label:"下午",start:12,end:18},{label:"工作时段",start:8,end:18}];function Q(e){"value"in e?m.value=e.value:(m.value="custom",$.value=e.start,A.value=e.end)}function ee(e){return"value"in e?m.value===e.value:m.value==="custom"&&$.value===e.start&&A.value===e.end}const w=[1,2,4,8,16],_=y(0),z=c(()=>w[_.value]);function te(){_.value<w.length-1&&_.value++}function ae(){_.value>0&&_.value--}const B=c(()=>`${z.value*100}%`),j=c(()=>{const e=new Map;for(const t of v.records)e.has(t.areaId)||e.set(t.areaId,[]),e.get(t.areaId).push(t);for(const t of e.values())t.sort((a,o)=>a.enterTime.localeCompare(o.enterTime));return e}),ne=c(()=>{const e=new Set;for(const t of j.value.keys())e.add(t);return e}),D=y(new Set);function se(e){const t=D.value;t.has(e)?t.delete(e):t.add(e)}function E(e){return e.id!==null&&e.id!==void 0&&ne.value.has(e.id)?!0:e.children?e.children.some(t=>E(t)):!1}const H=c(()=>{const e=[];function t(a,o){for(const r of a){const h=r.id,f=E(r);if(!f)continue;const T=r.areaType||"FUNCTION",V=!!(r.children&&r.children.length>0),ue=T==="FUNCTION"?j.value.get(h)||[]:[],de=r.areaName;e.push({key:`node_${h}`,areaId:h,type:T,label:de,depth:o,hasChildren:V,hasData:f,records:ue}),V&&!D.value.has(h)&&t(r.children,o+1)}}return t(X.value,0),e});function F(e){const t=g(e),a=t.hour()*60+t.minute()-C.value*60;return Math.max(0,Math.min(100,a/(S.value*60)*100))}function le(e){const t=F(e.enterTime),a=e.leaveTime||g().format("YYYY-MM-DD HH:mm:ss"),r=F(a)-t,h=.8/z.value,f=Math.max(r,h),T=e.nickname||e.deviceName;return{left:`${t}%`,width:`${f}%`,backgroundColor:W(T)}}const R=c(()=>{const e=g();if(e.format("YYYY-MM-DD")!==v.date)return-1;const a=(e.hour()*60+e.minute()-C.value*60)/(S.value*60)*100;return a>=0&&a<=100?a:-1}),i=y({visible:!1,x:0,y:0,record:null});function oe(e,t){i.value={visible:!0,x:e.clientX,y:e.clientY,record:t}}function re(){i.value.visible=!1}function ie(e){q("select",e)}function ce(e){var o;const t=e.target,a=(o=t.closest(".gantt-main"))==null?void 0:o.querySelector(".gantt-left-body");a&&(a.scrollTop=t.scrollTop)}const U=c(()=>{const e=new Set;for(const t of v.records)e.add(t.nickname||t.deviceName);return[...e].map(t=>({name:t,color:W(t)}))});return(e,t)=>(s(),l("div",Te,[I(Z)?H.value.length===0?(s(),l("div",Se,[...t[1]||(t[1]=[n("span",{style:{color:"#8c8c8c"}},"暂无区域数据",-1)])])):(s(),l("div",Me,[n("div",xe,[t[2]||(t[2]=n("span",{class:"toolbar-label"},"时段",-1)),n("div",Ie,[(s(),l(b,null,k(K,a=>n("button",{key:a.label,class:L(["preset-btn",{active:ee(a)}]),onClick:o=>Q(a)},u(a.label),11,Ne)),64))]),n("div",$e,[n("button",{class:"zoom-btn",disabled:_.value<=0,title:"缩小",onClick:ae}," − ",8,Ae),n("span",we,u(z.value)+"x",1),n("button",{class:"zoom-btn",disabled:_.value>=w.length-1,title:"放大",onClick:te}," + ",8,ze)])]),n("div",De,[n("div",He,[t[3]||(t[3]=n("div",{class:"gantt-label-col gantt-header-label"},"区域",-1)),n("div",Le,[(s(!0),l(b,null,k(H.value,a=>(s(),l("div",{key:a.key,class:L(["gantt-row-label",[`gantt-row--${a.type.toLowerCase()}`,{"gantt-row--inactive":!a.hasData}]])},[n("div",{class:"gantt-label-inner",style:d({paddingLeft:`${a.depth*16+8}px`})},[a.hasChildren?(s(),l("span",{key:0,class:"gantt-toggle",onClick:o=>se(a.areaId)},u(D.value.has(a.areaId)?"▶":"▼"),9,Oe)):(s(),l("span",Pe)),n("span",Ye,u(a.label),1)],4)],2))),128))])]),n("div",{class:"gantt-right",onScroll:ce},[n("div",{class:"gantt-timeline-header",style:d({width:B.value})},[(s(!0),l(b,null,k(Y.value,a=>(s(),l("div",{key:a,class:"gantt-hour-cell",style:d({width:`${100/S.value}%`})},u(String(a).padStart(2,"0"))+":00 ",5))),128))],4),n("div",Be,[(s(!0),l(b,null,k(H.value,a=>(s(),l("div",{key:a.key,class:L(["gantt-row-timeline",[`gantt-row--${a.type.toLowerCase()}`,{"gantt-row--inactive":!a.hasData}]]),style:d({width:B.value})},[(s(!0),l(b,null,k(Y.value,o=>(s(),l("div",{key:o,class:"gantt-grid-line",style:d({left:`${(o-C.value)/S.value*100}%`})},null,4))),128)),R.value>=0?(s(),l("div",{key:0,class:"gantt-now-line",style:d({left:`${R.value}%`})},null,4)):x("",!0),a.type==="FUNCTION"&&a.records.length>0?(s(!0),l(b,{key:1},k(a.records,o=>(s(),l("div",{key:o.id,class:"gantt-bar",style:d(le(o)),onClick:r=>ie(o),onMouseenter:r=>oe(r,o),onMouseleave:re},null,44,je))),128)):a.type==="FUNCTION"&&a.records.length===0?(s(),l("div",Ee)):x("",!0)],6))),128))])],32)])])):(s(),l("div",Ce,[...t[0]||(t[0]=[n("span",{style:{color:"#8c8c8c"}},"加载区域结构...",-1)])])),U.value.length>0?(s(),l("div",Fe,[t[4]||(t[4]=n("span",{class:"legend-title"},"人员:",-1)),(s(!0),l(b,null,k(U.value,a=>(s(),l("span",{key:a.name,class:"legend-item"},[n("span",{class:"legend-dot",style:d({backgroundColor:a.color})},null,4),ge(" "+u(a.name),1)]))),128))])):x("",!0),(s(),fe(ye,{to:"body"},[i.value.visible&&i.value.record?(s(),l("div",{key:0,class:"gantt-tooltip",style:d({left:`${i.value.x+12}px`,top:`${i.value.y-10}px`})},[n("div",Re,u(i.value.record.nickname||i.value.record.deviceName),1),n("div",Ue,u(i.value.record.areaName),1),n("div",Ve,u(I(g)(i.value.record.enterTime).format("HH:mm:ss"))+" → "+u(i.value.record.leaveTime?I(g)(i.value.record.leaveTime).format("HH:mm:ss"):"至今"),1),n("div",We," 停留 "+u(i.value.record.durationSeconds?I(pe)(i.value.record.durationSeconds):"进行中"),1)],4)):x("",!0)]))]))}}),qe=be(Ge,[["__scopeId","data-v-b465948b"]]),Qe=Object.freeze(Object.defineProperty({__proto__:null,default:qe},Symbol.toStringTag,{value:"Module"}));export{qe as T,ke as e,Qe as t};
|