zxl
5 天以前 874e9cce3b2f9b6649ab72047d98e4244a345b3c
1
2
"use strict";const i=require("../../../../common/vendor.js"),f=require("./i18n/index.js"),r=require("./util.js"),D=()=>"./calendar.js",T=()=>"./time-picker.js",R={name:"UniDatetimePicker",options:{virtualHost:!0},components:{Calendar:D,TimePicker:T},data(){return{isRange:!1,hasTime:!1,displayValue:"",inputDate:"",calendarDate:"",pickerTime:"",calendarRange:{startDate:"",startTime:"",endDate:"",endTime:""},displayRangeValue:{startDate:"",endDate:""},tempRange:{startDate:"",startTime:"",endDate:"",endTime:""},startMultipleStatus:{before:"",after:"",data:[],fulldate:""},endMultipleStatus:{before:"",after:"",data:[],fulldate:""},pickerVisible:!1,pickerPositionStyle:null,isEmitValue:!1,isPhone:!1,isFirstShow:!0,i18nT:()=>{}}},props:{type:{type:String,default:"datetime"},value:{type:[String,Number,Array,Date],default:""},modelValue:{type:[String,Number,Array,Date],default:""},start:{type:[Number,String],default:""},end:{type:[Number,String],default:""},returnType:{type:String,default:"string"},placeholder:{type:String,default:""},startPlaceholder:{type:String,default:""},endPlaceholder:{type:String,default:""},rangeSeparator:{type:String,default:"-"},border:{type:[Boolean],default:!0},disabled:{type:[Boolean],default:!1},clearIcon:{type:[Boolean],default:!0},hideSecond:{type:[Boolean],default:!1},defaultValue:{type:[String,Object,Array],default:""}},watch:{type:{immediate:!0,handler(e){this.hasTime=e.indexOf("time")!==-1,this.isRange=e.indexOf("range")!==-1}},modelValue:{immediate:!0,handler(e){if(this.isEmitValue){this.isEmitValue=!1;return}this.initPicker(e)}},start:{immediate:!0,handler(e){e&&(this.calendarRange.startDate=r.getDate(e),this.hasTime&&(this.calendarRange.startTime=r.getTime(e)))}},end:{immediate:!0,handler(e){e&&(this.calendarRange.endDate=r.getDate(e),this.hasTime&&(this.calendarRange.endTime=r.getTime(e,this.hideSecond)))}}},computed:{timepickerStartTime(){return(this.isRange?this.tempRange.startDate:this.inputDate)===this.calendarRange.startDate?this.calendarRange.startTime:""},timepickerEndTime(){return(this.isRange?this.tempRange.endDate:this.inputDate)===this.calendarRange.endDate?this.calendarRange.endTime:""},mobileCalendarTime(){const e={start:this.tempRange.startTime,end:this.tempRange.endTime};return this.isRange?e:this.pickerTime},mobSelectableTime(){return{start:this.calendarRange.startTime,end:this.calendarRange.endTime}},datePopupWidth(){return this.isRange?653:301},singlePlaceholderText(){return this.placeholder||(this.type==="date"?this.selectDateText:this.selectDateTimeText)},startPlaceholderText(){return this.startPlaceholder||this.startDateText},endPlaceholderText(){return this.endPlaceholder||this.endDateText},selectDateText(){return this.i18nT("uni-datetime-picker.selectDate")},selectDateTimeText(){return this.i18nT("uni-datetime-picker.selectDateTime")},selectTimeText(){return this.i18nT("uni-datetime-picker.selectTime")},startDateText(){return this.startPlaceholder||this.i18nT("uni-datetime-picker.startDate")},startTimeText(){return this.i18nT("uni-datetime-picker.startTime")},endDateText(){return this.endPlaceholder||this.i18nT("uni-datetime-picker.endDate")},endTimeText(){return this.i18nT("uni-datetime-picker.endTime")},okText(){return this.i18nT("uni-datetime-picker.ok")},clearText(){return this.i18nT("uni-datetime-picker.clear")},showClearIcon(){return this.clearIcon&&!this.disabled&&(this.displayValue||this.displayRangeValue.startDate&&this.displayRangeValue.endDate)}},created(){this.initI18nT(),this.platform()},methods:{initI18nT(){const e=i.initVueI18n(f.i18nMessages);this.i18nT=e.t},initPicker(e){if(!e&&!this.defaultValue||Array.isArray(e)&&!e.length){this.$nextTick(()=>{this.clear(!1)});return}if(!Array.isArray(e)&&!this.isRange)e?(this.displayValue=this.inputDate=this.calendarDate=r.getDate(e),this.hasTime&&(this.pickerTime=r.getTime(e,this.hideSecond),this.displayValue=`${this.displayValue} ${this.pickerTime}`)):this.defaultValue&&(this.inputDate=this.calendarDate=r.getDate(this.defaultValue),this.hasTime&&(this.pickerTime=r.getTime(this.defaultValue,this.hideSecond)));else{const[a,h]=e;if(!a&&!h)return;const l=r.getDate(a),t=r.getTime(a,this.hideSecond),s=r.getDate(h),n=r.getTime(h,this.hideSecond),d=l,g=s;this.displayRangeValue.startDate=this.tempRange.startDate=d,this.displayRangeValue.endDate=this.tempRange.endDate=g,this.hasTime&&(this.displayRangeValue.startDate=`${l} ${t}`,this.displayRangeValue.endDate=`${s} ${n}`,this.tempRange.startTime=t,this.tempRange.endTime=n);const m={before:l,after:s};this.startMultipleStatus=Object.assign({},this.startMultipleStatus,m,{which:"right"}),this.endMultipleStatus=Object.assign({},this.endMultipleStatus,m,{which:"left"})}},updateLeftCale(e){const a=this.$refs.left;a.cale.setHoverMultiple(e.after),a.setDate(this.$refs.left.nowDate.fullDate)},updateRightCale(e){const a=this.$refs.right;a.cale.setHoverMultiple(e.after),a.setDate(this.$refs.right.nowDate.fullDate)},platform(){if(typeof navigator<"u"){this.isPhone=navigator.userAgent.toLowerCase().indexOf("mobile")!==-1;return}const{windowWidth:e}=i.index.getWindowInfo();this.isPhone=e<=500,this.windowWidth=e},show(){if(this.$emit("show"),this.disabled)return;if(this.platform(),this.isPhone){setTimeout(()=>{this.$refs.mobile.open()},0);return}this.pickerPositionStyle={top:"10px"},i.index.createSelectorQuery().in(this).select(".uni-date-editor").boundingClientRect(a=>{this.windowWidth-a.left<this.datePopupWidth&&(this.pickerPositionStyle.right=0)}).exec(),setTimeout(()=>{if(this.pickerVisible=!this.pickerVisible,!this.isPhone&&this.isRange&&this.isFirstShow){this.isFirstShow=!1;const{startDate:a,endDate:h}=this.calendarRange;a&&h?this.diffDate(a,h)<30&&this.$refs.right.changeMonth("pre"):this.isPhone&&(this.$refs.right.cale.lastHover=!1)}},50)},close(){setTimeout(()=>{this.pickerVisible=!1,this.$emit("maskClick",this.value),this.$refs.mobile&&this.$refs.mobile.close()},20)},setEmit(e){(this.returnType==="timestamp"||this.returnType==="date")&&(Array.isArray(e)?(this.hasTime||(e[0]=e[0]+" 00:00:00",e[1]=e[1]+" 00:00:00"),e[0]=this.createTimestamp(e[0]),e[1]=this.createTimestamp(e[1]),this.returnType==="date"&&(e[0]=new Date(e[0]),e[1]=new Date(e[1]))):(this.hasTime||(e=e+" 00:00:00"),e=this.createTimestamp(e),this.returnType==="date"&&(e=new Date(e)))),this.$emit("update:modelValue",e),this.$emit("input",e),this.$emit("change",e),this.isEmitValue=!0},createTimestamp(e){return e=r.fixIosDateFormat(e),Date.parse(new Date(e))},singleChange(e){this.calendarDate=this.inputDate=e.fulldate,!this.hasTime&&this.confirmSingleChange()},confirmSingleChange(){if(!r.checkDate(this.inputDate)){const n=new Date;this.calendarDate=this.inputDate=r.getDate(n),this.pickerTime=r.getTime(n,this.hideSecond)}let e=!1,a,h;if(this.start){let n=this.start;typeof this.start=="number"&&(n=r.getDateTime(this.start,this.hideSecond)),[a,h]=n.split(" "),this.start&&!r.dateCompare(a,this.inputDate)&&(e=!0,this.inputDate=a)}let l=!1,t,s;if(this.end){let n=this.end;typeof this.end=="number"&&(n=r.getDateTime(this.end,this.hideSecond)),[t,s]=n.split(" "),this.end&&!r.dateCompare(this.inputDate,t)&&(l=!0,this.inputDate=t)}this.hasTime?(e&&(this.pickerTime=h||r.getDefaultSecond(this.hideSecond)),l&&(this.pickerTime=s||r.getDefaultSecond(this.hideSecond)),this.pickerTime||(this.pickerTime=r.getTime(Date.now(),this.hideSecond)),this.displayValue=`${this.inputDate} ${this.pickerTime}`):this.displayValue=this.inputDate,this.setEmit(this.displayValue),this.pickerVisible=!1},leftChange(e){const{before:a,after:h}=e.range;this.rangeChange(a,h);const l={before:e.range.before,after:e.range.after,data:e.range.data,fulldate:e.fulldate};this.startMultipleStatus=Object.assign({},this.startMultipleStatus,l),this.$emit("calendarClick",e)},rightChange(e){const{before:a,after:h}=e.range;this.rangeChange(a,h);const l={before:e.range.before,after:e.range.after,data:e.range.data,fulldate:e.fulldate};this.endMultipleStatus=Object.assign({},this.endMultipleStatus,l),this.$emit("calendarClick",e)},mobileChange(e){if(this.isRange){const{before:a,after:h}=e.range;if(!a)return;if(this.handleStartAndEnd(a,h,!0),this.hasTime){const{startTime:l,endTime:t}=e.timeRange;this.tempRange.startTime=l,this.tempRange.endTime=t}this.confirmRangeChange()}else this.hasTime?this.displayValue=e.fulldate+" "+e.time:this.displayValue=e.fulldate,this.setEmit(this.displayValue),this.calendarDate=this.displayValue;this.$refs.mobile.close()},rangeChange(e,a){e&&a&&(this.handleStartAndEnd(e,a,!0),!this.hasTime&&this.confirmRangeChange())},confirmRangeChange(){if(!this.tempRange.startDate||!this.tempRange.endDate){this.pickerVisible=!1;return}r.checkDate(this.tempRange.startDate)||(this.tempRange.startDate=r.getDate(Date.now())),r.checkDate(this.tempRange.endDate)||(this.tempRange.endDate=r.getDate(Date.now()));let e,a,h=!1,l=!1,t,s,n=this.tempRange.startDate,d=this.tempRange.endDate;if(this.hasTime&&(n=`${this.tempRange.startDate} ${this.tempRange.startTime}`,d=`${this.tempRange.endDate} ${this.tempRange.endTime}`),this.start){let c=this.start;typeof this.start=="number"&&(c=r.getDateTime(this.start,this.hideSecond)),[t,s]=c.split(" "),this.start&&!r.dateCompare(this.start,n)&&(h=!0,this.tempRange.startDate=t),this.start&&!r.dateCompare(this.start,d)&&(l=!0,this.tempRange.endDate=t)}let g=!1,m=!1,u,o;if(this.end){let c=this.end;typeof this.end=="number"&&(c=r.getDateTime(this.end,this.hideSecond)),[u,o]=c.split(" "),this.end&&!r.dateCompare(n,this.end)&&(g=!0,this.tempRange.startDate=u),this.end&&!r.dateCompare(d,this.end)&&(m=!0,this.tempRange.endDate=u)}this.hasTime?(h?this.tempRange.startTime=s||r.getDefaultSecond(this.hideSecond):g&&(this.tempRange.startTime=o||r.getDefaultSecond(this.hideSecond)),this.tempRange.startTime||(this.tempRange.startTime=r.getTime(Date.now(),this.hideSecond)),l?this.tempRange.endTime=s||r.getDefaultSecond(this.hideSecond):m&&(this.tempRange.endTime=o||r.getDefaultSecond(this.hideSecond)),this.tempRange.endTime||(this.tempRange.endTime=r.getTime(Date.now(),this.hideSecond)),e=this.displayRangeValue.startDate=`${this.tempRange.startDate} ${this.tempRange.startTime}`,a=this.displayRangeValue.endDate=`${this.tempRange.endDate} ${this.tempRange.endTime}`):(e=this.displayRangeValue.startDate=this.tempRange.startDate,a=this.displayRangeValue.endDate=this.tempRange.endDate),r.dateCompare(e,a)||([e,a]=[a,e]),this.displayRangeValue.startDate=e,this.displayRangeValue.endDate=a;const p=[e,a];this.setEmit(p),this.pickerVisible=!1},handleStartAndEnd(e,a,h=!1){if(!e)return;a||(a=e);const l=h?"tempRange":"range",t=r.dateCompare(e,a);this[l].startDate=t?e:a,this[l].endDate=t?a:e},dateCompare(e,a){return e=new Date(e.replace("-","/").replace("-","/")),a=new Date(a.replace("-","/").replace("-","/")),e<=a},diffDate(e,a){e=new Date(e.replace("-","/").replace("-","/")),a=new Date(a.replace("-","/").replace("-","/"));const h=(a-e)/(24*60*60*1e3);return Math.abs(h)},clear(e=!0){this.isRange?(this.displayRangeValue.startDate="",this.displayRangeValue.endDate="",this.tempRange.startDate="",this.tempRange.startTime="",this.tempRange.endDate="",this.tempRange.endTime="",this.isPhone?this.$refs.mobile&&this.$refs.mobile.clearCalender():(this.$refs.left&&this.$refs.left.clearCalender(),this.$refs.right&&this.$refs.right.clearCalender(),this.$refs.right&&this.$refs.right.changeMonth("next")),e&&(this.$emit("change",[]),this.$emit("input",[]),this.$emit("update:modelValue",[]))):(this.displayValue="",this.inputDate="",this.pickerTime="",this.isPhone?this.$refs.mobile&&this.$refs.mobile.clearCalender():this.$refs.pcSingle&&this.$refs.pcSingle.clearCalender(),e&&(this.$emit("change",""),this.$emit("input",""),this.$emit("update:modelValue","")))},calendarClick(e){this.$emit("calendarClick",e)}}};if(!Array){const e=i.resolveComponent("uni-icons"),a=i.resolveComponent("time-picker"),h=i.resolveComponent("Calendar");(e+a+h)()}const S=()=>"../../../uni-icons/components/uni-icons/uni-icons.js";Math||S();function y(e,a,h,l,t,s){return i.e({a:!t.isRange},t.isRange?{d:i.p({type:"calendar",color:"#c0c4cc",size:"22"}),e:i.t(t.displayRangeValue.startDate||s.startPlaceholderText),f:i.t(h.rangeSeparator),g:i.t(t.displayRangeValue.endDate||s.endPlaceholderText)}:{b:i.p({type:"calendar",color:"#c0c4cc",size:"22"}),c:i.t(t.displayValue||s.singlePlaceholderText)},{h:s.showClearIcon},s.showClearIcon?{i:i.p({type:"clear",color:"#c0c4cc",size:"22"}),j:i.o((...n)=>s.clear&&s.clear(...n))}:{},{k:h.disabled?1:"",l:h.border?1:"",m:i.o((...n)=>s.show&&s.show(...n)),n:t.pickerVisible,o:i.o((...n)=>s.close&&s.close(...n)),p:!t.isPhone},t.isPhone?{}:i.e({q:!t.isRange},t.isRange?i.e({J:t.hasTime},t.hasTime?{K:s.startDateText,L:t.tempRange.startDate,M:i.o(n=>t.tempRange.startDate=n.detail.value),N:s.startTimeText,O:!t.tempRange.startDate,P:t.tempRange.startTime,Q:i.o(n=>t.tempRange.startTime=n.detail.value),R:i.o(n=>t.tempRange.startTime=n),S:i.p({type:"time",start:s.timepickerStartTime,border:!1,disabled:!t.tempRange.startDate,hideSecond:h.hideSecond,modelValue:t.tempRange.startTime}),T:i.p({type:"arrowthinright",color:"#999"}),U:s.endDateText,V:t.tempRange.endDate,W:i.o(n=>t.tempRange.endDate=n.detail.value),X:s.endTimeText,Y:!t.tempRange.endDate,Z:t.tempRange.endTime,aa:i.o(n=>t.tempRange.endTime=n.detail.value),ab:i.o(n=>t.tempRange.endTime=n),ac:i.p({type:"time",end:s.timepickerEndTime,border:!1,disabled:!t.tempRange.endDate,hideSecond:h.hideSecond,modelValue:t.tempRange.endTime})}:{},{ad:i.sr("left","3b65f7cc-8"),ae:i.o(s.leftChange),af:i.o(s.updateRightCale),ag:i.p({showMonth:!1,"start-date":t.calendarRange.startDate,"end-date":t.calendarRange.endDate,range:!0,pleStatus:t.endMultipleStatus}),ah:i.sr("right","3b65f7cc-9"),ai:i.o(s.rightChange),aj:i.o(s.updateLeftCale),ak:i.p({showMonth:!1,"start-date":t.calendarRange.startDate,"end-date":t.calendarRange.endDate,range:!0,pleStatus:t.startMultipleStatus}),al:t.hasTime},t.hasTime?{am:i.t(s.clearText),an:i.o((...n)=>s.clear&&s.clear(...n)),ao:i.t(s.okText),ap:i.o((...n)=>s.confirmRangeChange&&s.confirmRangeChange(...n))}:{},{aq:i.s(t.pickerPositionStyle)}):i.e({r:t.hasTime},t.hasTime?{s:s.selectDateText,t:t.inputDate,v:i.o(n=>t.inputDate=n.detail.value),w:s.selectTimeText,x:!t.inputDate,y:t.pickerTime,z:i.o(n=>t.pickerTime=n.detail.value),A:i.o(n=>t.pickerTime=n),B:i.p({type:"time",border:!1,disabled:!t.inputDate,start:s.timepickerStartTime,end:s.timepickerEndTime,hideSecond:h.hideSecond,modelValue:t.pickerTime})}:{},{C:i.sr("pcSingle","3b65f7cc-4"),D:i.o(s.singleChange),E:i.p({showMonth:!1,"start-date":t.calendarRange.startDate,"end-date":t.calendarRange.endDate,date:t.calendarDate,"default-value":h.defaultValue}),F:t.hasTime},t.hasTime?{G:i.t(s.okText),H:i.o((...n)=>s.confirmSingleChange&&s.confirmSingleChange(...n))}:{},{I:i.s(t.pickerPositionStyle)}),{ar:t.pickerVisible}),{as:t.isPhone},t.isPhone?{at:i.sr("mobile","3b65f7cc-10"),av:i.o(s.mobileChange),aw:i.o(s.close),ax:i.o(s.calendarClick),ay:i.p({clearDate:!1,date:t.calendarDate,defTime:s.mobileCalendarTime,"start-date":t.calendarRange.startDate,"end-date":t.calendarRange.endDate,selectableTimes:s.mobSelectableTime,startPlaceholder:h.startPlaceholder,endPlaceholder:h.endPlaceholder,"default-value":h.defaultValue,pleStatus:t.endMultipleStatus,showMonth:!1,range:t.isRange,hasTime:t.hasTime,insert:!1,hideSecond:h.hideSecond})}:{})}const k=i._export_sfc(R,[["render",y]]);wx.createComponent(k);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.js.map