cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
2 lines (1 loc) • 7.59 kB
JavaScript
;Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e=require("vue");require("./index.vue_vue_type_style_index_0_lang.js");var t=require("../../_virtual/plugin-vue_export-helper.js");const r=e.defineComponent({name:"CoTimeCalendar",props:{src:{type:String},width:{type:String},height:{type:String},type:{type:String,default:"multicolour"},dataType:{type:String,default:"zhCN"},fontFamily:String,headerColor:String,headerSize:Number,headerLetter:Number,contentColor:String,contentSize:Number,headerBgColor:String,bgColor:String},setup(t){const r=e.ref(["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]),a=e.ref(["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]),n=e.ref(!0),o=e.ref(),l=e.ref(),i=e.ref(),u=e.ref(),d=e.ref(),s=e.ref(),c=e.ref(),h=e.ref(),v=e.ref(),m=e.ref(),f=e.ref();(()=>{const e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t=e.length;let r="";for(let a=0;a<6;a++){r+=e[Math.floor(Math.random()*t)]}f.value=r})();function p(e){this.headerDom=e.headerDom;var t=this;t.divId=e.RenderID?e.RenderID:"",t.DaysOfWeek=e.DaysOfWeek?e.DaysOfWeek:a.value,t.Months=e.Months?e.Months:r.value;var n=new Date;t.CurrentMonth=n.getMonth(),t.CurrentYear=n.getFullYear();var o=e.Format;t.f="string"==typeof o?o.charAt(0).toUpperCase():"M",t.enMonths=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}p.prototype.nextMonth=function(){11==this.CurrentMonth?(this.CurrentMonth=0,this.CurrentYear=this.CurrentYear+1):this.CurrentMonth=this.CurrentMonth+1,this.divId='[data-active="false"] .render',this.showCurrent()},p.prototype.prevMonth=function(){0==this.CurrentMonth?(this.CurrentMonth=11,this.CurrentYear=this.CurrentYear-1):this.CurrentMonth=this.CurrentMonth-1,this.divId='[data-active="false"] .render',this.showCurrent()},p.prototype.previousYear=function(){this.CurrentYear=this.CurrentYear-1,this.showCurrent()},p.prototype.nextYear=function(){this.CurrentYear=this.CurrentYear+1,this.showCurrent()},p.prototype.showCurrent=function(){this.Calendar(this.CurrentYear,this.CurrentMonth)},p.prototype.checkActive=function(){let e=this;1==s.value.getAttribute("class").includes("active")?s.value.setAttribute("class","months"):s.value.setAttribute("class","months active"),"true"==v.value.getAttribute("data-active")?(v.value.setAttribute("data-active",!1),m.value.setAttribute("data-active",!0)):(v.value.setAttribute("data-active",!0),m.value.setAttribute("data-active",!1)),setTimeout((function(){e.headerDom.setAttribute("class","calendar-header active")}),200),i.value.setAttribute("data-theme",this.enMonths[document.querySelector(`.calendar${f.value} [data-active="true"] .render`).getAttribute("data-month")].toLowerCase())},p.prototype.Calendar=function(e,t){var r,a,n;"number"==typeof e&&(this.CurrentYear=e),"number"==typeof e&&(this.CurrentMonth=t);var o=(new Date).getDate(),i=(new Date).getMonth(),u=(new Date).getFullYear(),s=new Date(e,t,1).getDay(),c=new Date(e,t+1,0).getDate(),h=0==t?new Date(e-1,11,0).getDate():new Date(e,t,0).getDate(),v="<span>"+this.Months[t]+" "+e+"</span>",m='<div class="table">';m+='<div class="row head">';for(var p=0;p<7;p++)m+='<div class="cell">'+this.DaysOfWeek[p]+"</div>";m+="</div>";for(var y,g=n="M"==this.f?1:0==s?-5:2,C=(p=0,0);C<6;C++){m+='<div class="row">';for(var M=0;M<7;M++)(y=p+n-s)<1?m+='<div class="cell disable">'+(h-s+g++)+"</div>":y>c?m+='<div class="cell disable">'+g+++"</div>":(m+='<div class="cell'+(o==y&&this.CurrentMonth==i&&this.CurrentYear==u?" active":"")+'"><span>'+y+"</span></div>",g=1),p%7==6&&y>=c&&(C=10),p++;m+="</div>"}m+="</div>",d.value.innerHTML=v,document.querySelector(`.calendar${f.value} ${this.divId}`).innerHTML=m,null==(r=document.querySelector(`.calendar${f.value} ${this.divId}`))||r.setAttribute("data-date",this.enMonths[t]+" - "+e),null==(a=document.querySelector(`.calendar${f.value} ${this.divId}`))||a.setAttribute("data-month",t),l.value=u+"-"+i+"-"+o};const y=()=>{"zhCN"===t.dataType?(r.value=["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],a.value=["日","一","二","三","四","五","六"]):"en"===t.dataType?(r.value=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],a.value=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]):"zhTW"===t.dataType&&(r.value=["壹月","貳月","叁月","肆月","伍月","陆月","柒月","捌月","玖月","拾月","拾壹月","拾贰月"],a.value=["日","壹","貳","叁","肆","伍","陆"]),clearInterval(o.value);var e=new p({RenderID:".render-a",Format:"M",headerDom:u.value});e.showCurrent(),e.checkActive();var n=[c.value,h.value];for(let t=0;t<n.length;t++)n[t].onclick=function(){var t,r,a,n;if(u.value.setAttribute("class","calendar-header"),"true"==s.value.getAttribute("data-loading"))return u.value.setAttribute("class","calendar-header active"),!1;s.value.setAttribute("data-loading","true"),(null==(t=this.getAttribute("data-action"))?void 0:t.includes("prev"))?(e.prevMonth(),n="left"):(e.nextMonth(),n="right"),e.checkActive(),s.value.setAttribute("data-flow",n),null==(r=document.querySelector(`.calendar${f.value} .month[data-active="true"]`))||r.addEventListener("webkitTransitionEnd",(function(){s.value.removeAttribute("data-loading")})),null==(a=document.querySelector(`.calendar${f.value} .month[data-active="true"]`))||a.addEventListener("transitionend",(function(){s.value.removeAttribute("data-loading")}))};o.value=setInterval((()=>{let e=(new Date).getDate(),t=(new Date).getMonth();(new Date).getFullYear()+"-"+t+"-"+e!==l.value&&g()}),1e3)},g=()=>{"multicolour"===t.type&&(n.value=!1,e.nextTick((()=>{n.value=!0,e.nextTick((()=>{y()}))})))};return e.watch((()=>[t.dataType]),(()=>{g()}),{deep:!0}),e.onMounted((()=>{y()})),e.onUnmounted((()=>{clearInterval(o.value)})),{timeId:f,calendarDom:i,calendarHDom:u,monthYear:d,monthsDom:s,prevMonth:c,nextMonth:h,monthA:v,monthB:m,multicolourShow:n,RESET_VIEW:()=>{},...e.toRefs(t)}}}),a={class:"calendar-header",ref:"calendarHDom"},n={"data-action":"prev-month",href:"javascript:void(0)",ref:"prevMonth"},o=[e.createElementVNode("i",null,null,-1)],l={"data-action":"next-month",href:"javascript:void(0)",ref:"nextMonth"},i=[e.createElementVNode("i",null,null,-1)],u=[e.createElementVNode("div",{class:"render render-a"},null,-1)],d=[e.createElementVNode("div",{class:"render render-b"},null,-1)];var s=t.default(r,[["render",function(t,r,s,c,h,v){return e.openBlock(),e.createElementBlock("div",{class:"co-time-calendar",style:e.normalizeStyle({width:t.width||"100%",height:t.height||"100%"})},[t.multicolourShow?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(`calendar calendar${t.timeId}`),ref:"calendarDom",style:e.normalizeStyle({fontFamily:t.fontFamily})},[e.createElementVNode("div",a,[e.createElementVNode("a",n,o,512),e.createElementVNode("div",{class:"text",ref:"monthYear",style:e.normalizeStyle({color:t.headerColor,fontSize:t.headerSize+"px",letterSpacing:t.headerLetter+"px",backgroundColor:t.headerBgColor})},null,4),e.createElementVNode("a",l,i,512)],512),e.createElementVNode("div",{class:"months",ref:"monthsDom","data-flow":"left",style:e.normalizeStyle({color:t.contentColor,fontSize:t.contentSize+"px"})},[e.createElementVNode("div",{class:"month month-a",ref:"monthA",style:e.normalizeStyle({backgroundColor:t.bgColor})},u,4),e.createElementVNode("div",{class:"month month-b",ref:"monthB",style:e.normalizeStyle({backgroundColor:t.bgColor})},d,4)],4)],6)):e.createCommentVNode("",!0)],4)}]]);exports.default=s;