zxl
7 分钟以前 2f5150337fa53d7c5ea2fb19f3c5a259e37c8765
1
2
"use strict";class y{constructor({selected:t,startDate:e,endDate:i,range:l}={}){this.date=this.getDateObj(new Date),this.selected=t||[],this.startDate=e,this.endDate=i,this.range=l,this.cleanMultipleStatus(),this.weeks={},this.lastHover=!1}setDate(t){const e=this.getDateObj(t);this.getWeeks(e.fullDate)}cleanMultipleStatus(){this.multipleStatus={before:"",after:"",data:[]}}setStartDate(t){this.startDate=t}setEndDate(t){this.endDate=t}getPreMonthObj(t){t=g(t),t=new Date(t);const e=t.getMonth();t.setMonth(e-1);const i=t.getMonth();return e!==0&&i-e===0&&t.setMonth(i-1),this.getDateObj(t)}getNextMonthObj(t){t=g(t),t=new Date(t);const e=t.getMonth();t.setMonth(e+1);const i=t.getMonth();return i-e>1&&t.setMonth(i-1),this.getDateObj(t)}getDateObj(t){return t=g(t),t=new Date(t),{fullDate:S(t),year:t.getFullYear(),month:o(t.getMonth()+1),date:o(t.getDate()),day:t.getDay()}}getPreMonthDays(t,e){const i=[];for(let l=t-1;l>=0;l--){const a=e.month-1;i.push({date:new Date(e.year,a,-l).getDate(),month:a,disable:!0})}return i}getCurrentMonthDays(t,e){const i=[],l=this.date.fullDate;for(let a=1;a<=t;a++){const n=`${e.year}-${e.month}-${o(a)}`,c=l===n,m=this.selected&&this.selected.find(r=>{if(this.dateEqual(n,r.date))return r});this.startDate&&h(this.startDate,n),this.endDate&&h(n,this.endDate);let D=this.multipleStatus.data,u=-1;this.range&&D&&(u=D.findIndex(r=>this.dateEqual(r,n)));const f=u!==-1;i.push({fullDate:n,year:e.year,date:a,multiple:this.range?f:!1,beforeMultiple:this.isLogicBefore(n,this.multipleStatus.before,this.multipleStatus.after),afterMultiple:this.isLogicAfter(n,this.multipleStatus.before,this.multipleStatus.after),month:e.month,disable:this.startDate&&!h(this.startDate,n)||this.endDate&&!h(n,this.endDate),isToday:c,userChecked:!1,extraInfo:m})}return i}_getNextMonthDays(t,e){const i=[],l=e.month+1;for(let a=1;a<=t;a++)i.push({date:a,month:l,disable:!0});return i}getInfo(t){t||(t=new Date);const e=this.calendar.find(i=>i.fullDate===this.getDateObj(t).fullDate);return e||this.getDateObj(t)}dateEqual(t,e){return t=new Date(g(t)),e=new Date(g(e)),t.valueOf()===e.valueOf()}isLogicBefore(t,e,i){let l=e;return e&&i&&(l=h(e,i)?e:i),this.dateEqual(l,t)}isLogicAfter(t,e,i){let l=i;return e&&i&&(l=h(e,i)?i:e),this.dateEqual(l,t)}geDateAll(t,e){var i=[],l=t.split("-"),a=e.split("-"),n=new Date;n.setFullYear(l[0],l[1]-1,l[2]);var c=new Date;c.setFullYear(a[0],a[1]-1,a[2]);for(var m=n.getTime()-24*60*60*1e3,D=c.getTime()-24*60*60*1e3,u=m;u<=D;)u=u+24*60*60*1e3,i.push(this.getDateObj(new Date(parseInt(u))).fullDate);return i}setMultiple(t){if(!this.range)return;let{before:e,after:i}=this.multipleStatus;if(e&&i){if(!this.lastHover){this.lastHover=!0;return}this.multipleStatus.before=t,this.multipleStatus.after="",this.multipleStatus.data=[],this.multipleStatus.fulldate="",this.lastHover=!1}else e?(this.multipleStatus.after=t,h(this.multipleStatus.before,this.multipleStatus.after)?this.multipleStatus.data=this.geDateAll(this.multipleStatus.before,this.multipleStatus.after):this.multipleStatus.data=this.geDateAll(this.multipleStatus.after,this.multipleStatus.before),this.lastHover=!0):(this.multipleStatus.before=t,this.multipleStatus.after=void 0,this.lastHover=!1);this.getWeeks(t)}setHoverMultiple(t){if(!this.range||this.lastHover)return;const{before:e}=this.multipleStatus;e?(this.multipleStatus.after=t,h(this.multipleStatus.before,this.multipleStatus.after)?this.multipleStatus.data=this.geDateAll(this.multipleStatus.before,this.multipleStatus.after):this.multipleStatus.data=this.geDateAll(this.multipleStatus.after,this.multipleStatus.before)):this.multipleStatus.before=t,this.getWeeks(t)}setDefaultMultiple(t,e){this.multipleStatus.before=t,this.multipleStatus.after=e,t&&e&&(h(t,e)?(this.multipleStatus.data=this.geDateAll(t,e),this.getWeeks(e)):(this.multipleStatus.data=this.geDateAll(e,t),this.getWeeks(t)))}getWeeks(t){const{year:e,month:i}=this.getDateObj(t),l=new Date(e,i-1,1).getDay(),a=this.getPreMonthDays(l,this.getDateObj(t)),n=new Date(e,i,0).getDate(),c=this.getCurrentMonthDays(n,this.getDateObj(t)),m=42-l-n,D=this._getNextMonthDays(m,this.getDateObj(t)),u=[...a,...c,...D],f=new Array(6);for(let r=0;r<u.length;r++){const p=Math.floor(r/7);f[p]||(f[p]=new Array(7)),f[p][r%7]=u[r]}this.calendar=u,this.weeks=f}}function w(s,t){return`${S(s)} ${M(s,t)}`}function S(s){s=g(s),s=new Date(s);const t=s.getFullYear(),e=s.getMonth()+1,i=s.getDate();return`${t}-${o(e)}-${o(i)}`}function M(s,t){s=g(s),s=new Date(s);const e=s.getHours(),i=s.getMinutes(),l=s.getSeconds();return t?`${o(e)}:${o(i)}`:`${o(e)}:${o(i)}:${o(l)}`}function o(s){return s<10&&(s=`0${s}`),s}function b(s){return s?"00:00":"00:00:00"}function h(s,t){return s=new Date(g(typeof s=="string"?s.trim():s)),t=new Date(g(typeof t=="string"?t.trim():t)),s<=t}function d(s){const t=/((19|20)\d{2})(-|\/)\d{1,2}(-|\/)\d{1,2}/g;return s.match(t)}const A=/^\d{4}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])( [0-5]?[0-9]:[0-5]?[0-9](:[0-5]?[0-9])?)?$/;function g(s){return typeof s=="string"&&A.test(s)&&(s=s.replace(/-/g,"/")),s}exports.Calendar=y;exports.checkDate=d;exports.dateCompare=h;exports.fixIosDateFormat=g;exports.getDate=S;exports.getDateTime=w;exports.getDefaultSecond=b;exports.getTime=M;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uni-datetime-picker/components/uni-datetime-picker/util.js.map