2 lines
10 KiB
JavaScript
2 lines
10 KiB
JavaScript
!function(){"use strict";class e{constructor(e){}parseTime(e,t=""){if(0===arguments.length)return null;const s=t||"{y}-{m}-{d} {h}:{i}:{s}.{M}";let i;"object"==typeof e?i=e:(10===(""+e).length&&(e=1e3*parseInt(e)),i=new Date(e));const a={y:i.getFullYear(),m:i.getMonth()+1,d:i.getDate(),h:i.getHours(),i:i.getMinutes(),s:i.getSeconds(),M:i.getMilliseconds(),a:i.getDay()};return s.replace(/{(y|m|d|h|i|s|M|a)+}/g,((e,t)=>{let s=a[t];if("a"===t)return["一","二","三","四","五","六","日"][s-1];if(e.length>0&&s<10&&(s="0"+s),"M"===t){let e="";for(let t=0;t<3-(""+s).length;t++)e+="0";s=e+s}return s||0}))}timeToStamp(e){return new Date(e).getTime()}moveHalf(){let e=this.getDomElement(".timeline-ticMain"),t=this.getDomElement(".timeline-ticLabel");for(let s=0;s<e.length;s++){let i=e[s].offsetLeft-t[s].offsetWidth/2;t[s].style.left=i+"px"}}getDomElement(e,t=null){let s=".ts-zyl "+e,i=document.querySelectorAll(s);return null==t?i:i[t]}}const t={STOP:0,PLAY:1,PAUSE:2},s={EDITING:0,PLAYING:1},i=[".Grid",".Chart"];var a=Object.freeze({__proto__:null,editorMode:s,hideByMode:i,timeStatus:t});class l extends e{constructor(e={}){super(),this.timer1=null,this.timer=null,this._status=t.STOP,this.timestampFunctions={1732783188e3:function(){console.log("在时间戳 1732783188000 执行的函数")},1732783198e3:function(){console.log("在时间戳 1732783588000 执行的函数")},1732784588e3:function(){console.log("在时间戳 1732784588000 执行的函数")}}}makeLabel(e,t=""){return this.parseTime(e,t)}animation(e,t,s=()=>{console.log("滴答")}){let{multiplier:i,startTimestamp:a,endTimestamp:l,currentTimestamp:n}=e;console.log(s);let c=Date.now(),r=0,o=0;s(),this.timer1=setInterval(function e(){return setTimeout((()=>{s()}),1e3/i),e}(),1e3/i),this.timer=setInterval((()=>{let e=Date.now();r=(e-c)*i;let s=n+=r;for(let t=0;t<(e-c)*i;t++)o+=1;c=e,t(s,r,o)}),1)}stopAnimation(){clearInterval(this.timer1),clearInterval(this.timer)}get status(){return this._status}set status(e){this._status=e}}class n extends e{constructor(t={scales:{}}){var i;super(),console.log(t),this._editorMode=t.editorMode||s.EDITING,this._tasks=t.tasks||[],this._startTimestamp=t.startTimestamp||(new Date).getTime(),this._endTimestamp=t.endTimestamp||this.getTotalTime(),this._currentTimestamp=t.currentTimestamp||this._startTimestamp,this._multiplier=t.multiplier||1,this._panelWidth=t.panelWidth||1,this.columns=t.columns||[{name:"name",label:"名称",width:"100%"},{name:"start_time",label:"开始时间",width:"120px",align:"center"},{name:"duration",label:"持续时间",width:"70px",align:"center"}],t.hasOwnProperty("scales")||(t.scales={}),this._scales={cursorLeft:t.scales.cursorLeft||0,scrollLeft:t.scales.scrollLeft||0,scrollTop:t.scales.scrollTop||0,fullWidth:t.scales.fullWidth,fullHeight:t.scales.fullHeight,scaleHeight:t.scales.scaleHeight||30,cellHeight:t.scales.cellHeight||38,preMains:t.scales.preMains||this.getPreMains(),preMainIndex:t.scales.preMainIndex||8,gridWidth:t.scales.gridWidth||400,distanceOfTicTinyRange:[7,8,9,10,11,12,13],distanceOfTicTiny:7,ticTiny:0,originOffset:0,numOfSubRange:[4,5,6,10],numOfSubIndex:2,distanceOfTicSub:42,ticSub:0,numOfSub:6,originSubOffset:0,numOfMain:5,distanceOfTicMain:210,ticMain:0,originMainOffset:0,timeLabels:[],productTinySub:30,preSecondPx:0},this.scales=new Proxy(this._scales,(i=this,{set:(t,s,a,l)=>(t[s]=a,"numOfSubIndex"==s&&(t.numOfSub=t.numOfSubRange[t.numOfSubIndex]),"distanceOfTicTiny"==s&&(t.distanceOfTicSub=t.distanceOfTicTiny*t.numOfSub,t.distanceOfTicMain=t.distanceOfTicSub*t.numOfMain,t.preSecondPx=t.distanceOfTicMain/t.preMains[t.preMainIndex],i.setCurrentStamp(t)),"scrollLeft"==s&&((new e).getDomElement(".Chart",0).scrollLeft=t.scrollLeft,i.setCurrentStamp(t)),"cursorLeft"==s&&i.setCurrentStamp(t),"ticMain"==s&&(t.timeLabels=t.timeLabels.slice(0,t.ticMain)),"fullWidth"==s&&(i.getDomElement(".TimeScale",0).style.width=t.fullWidth+"px"),!0)}))}init(){let e=Math.floor(this.getDomElement(".TimeScale",0).getBoundingClientRect().width);this.panelWidth=e,this.getDomElement(".TimeScale",0).style.width=e+"px",console.log("store init"),this.updateTimeLineRightRest();let t=this.getMinTimeOfPanel();this.getTotalTime()<t&&(this.scales.fullWidth=this.panelWidth)}updateTimeLineRightRest(){let e=this.scales.cellHeight*this.tasks.length,t=this.getDomElement(".Chart",0).offsetHeight;console.log("updateTimeLineRightRest",e,t);let s=(this.getTotalTime()-this.startTimestamp)/1e3*this.scales.preSecondPx;s>this.panelWidth?this.scales.fullWidth=s:e>t&&(this.scales.fullWidth=this.panelWidth-20),this.getDomElement(".TimeScale",0).style.width=this.panelWidth+"px"}getMinTimeOfPanel(){return console.log(":",this.startTimestamp),console.log(this.panelWidth),console.log(this.scales.preSecondPx),this.startTimestamp+3e3*parseInt(this.panelWidth/this.scales.preSecondPx)}getTotalTime(){let e=this._startTimestamp;if(this._tasks.length){let t;t=this._tasks.map((e=>e.end_time)),e=Math.max(...t)}return e}getPreMains(){let e=[15];for(let t=0;t<20;t++)e.push(2*e[t]);return e}locate(e){let t=!e.tagName&&e.target?e.target:e;for(;t;){if(t.getAttribute&&t.getAttribute("data-task"))return t;t=t.parentNode}return null}getTaskById(e){return this.tasks.find((t=>t.ID==e))}getTaskByProperty(e,t="ID"){return this.tasks.filter((s=>s[t]==e))}getTaskInStamp(){return this.tasks.filter((e=>this.currentTimestamp>e.start_time&&this.currentTimestamp<=e.end_time))}setCurrentStamp(e){if(this.editorMode==s.EDITING){let{cursorLeft:t,preSecondPx:s,scrollLeft:i}=e,a=Math.round(t/s*1e3),l=Math.round(i/s*1e3);this.currentTimestamp=this.startTimestamp+a+l}}setCursorLeft(e){if(this.editorMode==s.PLAYING){let t,s=(e-this.startTimestamp)/1e3*this.scales.preSecondPx-this.scales.scrollLeft,i=s;this.panelWidth-s<=5&&(i=this.panelWidth-5,t=s-i,this.scales.scrollLeft=t),this.scales.cursorLeft=i}}changeUI(e){console.log("changeUI",e),i.forEach((t=>{this.getDomElement(t,0).style.display=e==s.EDITING?t.indexOf("Grid")>-1?"flex":"block":"none"})),this.getDomElement(".layoutBoxs",0).style.height=e==s.EDITING?"230px":"30px";let t=this.getDomElement(".TLContainer",0).getBoundingClientRect().width;console.log("width",t);let a=e==s.PLAYING?t:this.scales.fullWidth;this.panelWidth=a,this.getDomElement(".TimeScale",0).style.width=a+"px"}dealData(e="start_time",t=[]){let s=new Map;for(let i=0;i<this.tasks.length;i++){let a=null;if(0==t.length)a=this.tasks[i];else{let e={};t.forEach((t=>{e[t]=this.tasks[i][t]})),a=e}s.set(this.tasks[i][e]+""+this.tasks[i].ID,a)}return s}get startTimestamp(){return this._startTimestamp}set startTimestamp(e){this._startTimestamp=e}set currentTimestamp(e){this._currentTimestamp=e,this.editorMode==s.PLAYING&&this.setCursorLeft(e)}get currentTimestamp(){return this._currentTimestamp}set multiplier(e){this._multiplier=e}get multiplier(){return this._multiplier}set endTimestamp(e){this._endTimestamp=e}get endTimestamp(){return this._endTimestamp}set panelWidth(e){this._panelWidth=e}get panelWidth(){return this._panelWidth}set tasks(e){this._tasks=e,this.updateTimeLineRightRest()}get tasks(){return this._tasks}set editorMode(e){this._editorMode=e}get editorMode(){return this._editorMode}}!function(){window.EventsNameMap=new Map;["changeAction","changeStamp","changeStampUp","changeStampEventBox","openEventBox","initEvent","openEventDetail"].forEach((e=>{window.EventsNameMap.set(e,new Event(e))}))}(),window.TSTY={init:e=>{let t=new n(e);t.scales.fullHeight=t.tasks.length*t.scales.cellHeight,t.scales.preSecondPx=t.scales.distanceOfTicMain/t.scales.preMains[t.scales.preMainIndex];let s=e=>{t.scales.ticTiny=Math.ceil(t.panelWidth/t.scales.distanceOfTicTiny),t.scales.distanceOfTicSub=t.scales.numOfSub*t.scales.distanceOfTicTiny,t.scales.ticSub=Math.ceil(t.panelWidth/t.scales.distanceOfTicSub),t.scales.numOfMain=t.scales.productTinySub/t.scales.numOfSub,t.scales.distanceOfTicMain=t.scales.numOfMain*t.scales.distanceOfTicSub,t.scales.ticMain=Math.ceil(t.panelWidth/t.scales.distanceOfTicMain);let s=(t.endTimestamp-t.startTimestamp)/1e3*t.scales.preSecondPx;t.scales.fullWidth=s<t.panelWidth?t.panelWidth:s,console.log("事件渲染宽度",s),console.log("事件渲染宽度",t.panelWidth),i(e)},i=e=>{let s=-1*t.scales.scrollLeft;t.scales.originOffset=s%t.scales.distanceOfTicTiny,t.scales.originSubOffset=s%t.scales.distanceOfTicSub,t.scales.originMainOffset=s%t.scales.distanceOfTicMain,e((()=>{t.moveHalf()}))},c=e=>{let s=Math.floor(e.left/t.scales.distanceOfTicMain),i=t.scales.ticMain+s+1,a=[];for(let e=0;e<i;e++){let s=t.scales.preMains[t.scales.preMainIndex];a.push(t.startTimestamp+e*s*1e3)}a.splice(0,s),t.scales.timeLabels=a};return{store:t,clock:new l(e),initAction:()=>(console.log("initAction",t),e=>{console.log("action的参数",e);const{action:a,obj:l,cb:n}=e;switch(a){case"wheel-timeLine":const{num:a}=e;let r=t.scales.preMainIndex-a;if(r>t.scales.preMains.length-1)r=t.scales.preMains.length-1;else if(r<0)r=0;else{let e=t.scales.distanceOfTicTiny+a,s=Math.max(...t.scales.distanceOfTicTinyRange),i=Math.min(...t.scales.distanceOfTicTinyRange);e>s?e=i:e<i&&(e=s);let l=t.scales.numOfSubIndex+a;l>t.scales.numOfSubRange.length-1?l=0:l<0&&(l=t.scales.numOfSubRange.length-1),t.scales.preMainIndex=r,t.scales.distanceOfTicTiny=e,t.scales.numOfSubIndex=l,console.log("newPreMainIndex",r)}s(n),c({left:t.scales.scrollLeft}),t.updateTimeLineRightRest();break;case"scroll-chart":t.scales.scrollTop=l.top,t.scales.scrollLeft=l.left,c(l),0!=l.deltaX&&i(l.cb),0!=l.deltaY&&(document.getElementsByClassName("gridBody")[0].scrollTop=l.top);break;case"update-task-time":let o=t.getTaskById(l.id);switch(l.mode){case"content":o.start_time+=1e3*l.time,o.end_time=o.start_time+1e3*o.duration,t.updateTimeLineRightRest();break;case"next":o.duration+=l.time,o.end_time=o.start_time+1e3*o.duration;break;case"pre":o.start_time+=1e3*l.time,o.duration-=l.time}break;case"del-task":t.tasks=t.tasks.filter((e=>e.ID!==l.id)),t.scales.fullHeight=t.tasks.length*t.scales.cellHeight;break;case"add-task":t.tasks.push(l);let h=(t.getTotalTime()-t.startTimestamp)/1e3*t.scales.preSecondPx;t.scales.fullWidth=Math.max(h,t.panelWidth),t.scales.fullHeight=t.tasks.length*t.scales.cellHeight}}),renderLine:s,renderLabel:c,...a}},get VERSION(){return"1.0.0"},Util:e}}();
|