quarkd
Version:
Mobile UI Components built on Web Components.
2 lines (1 loc) • 15.8 kB
JavaScript
import{_ as t,a as e}from"../typeof.js";import{_ as n,a as i,b as r,c as o,P as a,H as u,d as s,N as c,B as l}from"../index2.js";import{_ as h}from"../defineProperty.js";import{_ as m}from"../slicedToArray.js";import"../picker/index.js";import"../index4.js";import{Local as p}from"../locale/index.js";import"../unsupportedIterableToArray.js";import"../core.esm.js";import"../wheel.esm.js";import"../popup/index.js";import"../bodyScrollLock.esm.js";import"../index22.js";import"../button/index.js";import"../loading/index.js";import"../util.js";var f=":host {\n width: 100%;\n display: block;\n}\n\n:host .quark-date-picker-header {\n position: relative;\n height: 14.93333vw;\n width: 100%;\n padding: 0 4.26667vw;\n background-color: white;\n display: flex;\n justify-content: space-between;\n align-items: center;\n}\n\n:host .quark-date-picker-title {\n color: var(--picker-title-color, #242729);\n font-weight: var(--picker-title-font-weight, 500);\n font-family: var(--picker-title-font-family, PingFangSC-Medium, PingFang SC);\n text-align: center;\n font-size: var(--picker-title-font-size, 4.8vw);\n}\n\n:host .quark-date-picker-close-btn {\n color: #969799;\n font-size: 3.73333vw;\n}\n\n:host .quark-date-picker-confirm-btn {\n font-size: 3.73333vw;\n color: #0088ff;\n}\n",d=function(t,e){return 32-new Date(t,e-1,32).getDate()},y=function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n=t+"";n.length<e;)n="0"+n;return n},v=function(t,e,n){return Math.min(Math.max(t,e),n)},k=function(t,e){if(t<0)return[];for(var n=Array(t),i=-1;++i<t;)n[i]=e(i);return n},g=function(t){return"[object Date]"===Object.prototype.toString.call(t)&&!Number.isNaN(t.getTime())};function x(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,o=n(t);if(e){var a=n(this).constructor;r=Reflect.construct(o,arguments,a)}else r=o.apply(this,arguments);return i(this,r)}}var b=(new Date).getFullYear(),D=function(n){r(s,u);var i=x(s);function s(){var e;t(this,s);for(var n=arguments.length,r=new Array(n),u=0;u<n;u++)r[u]=arguments[u];return e=i.call.apply(i,[this].concat(r)),h(o(e),"open",!1),h(o(e),"value",""),h(o(e),"type","datetime"),h(o(e),"title",""),h(o(e),"mindate",""),h(o(e),"maxdate",""),h(o(e),"showtoolbar",!1),h(o(e),"confirmbuttontext",""),h(o(e),"cancelbuttontext",""),h(o(e),"forbidmaskclick",!1),h(o(e),"pickerRef",a()),h(o(e),"originColumns",[]),h(o(e),"columns",[]),h(o(e),"currentDate",null),h(o(e),"innerMinDate",new Date(b-10,0,1)),h(o(e),"innerMaxDate",new Date(b+10,0,1)),h(o(e),"formatter",(function(t,e){return e})),h(o(e),"filter",(function(t,e){return e})),h(o(e),"getBoundary",(function(t,n){var i,r="max"===t?e.innerMaxDate:e.innerMinDate,o=r.getFullYear(),a=1,u=1,s=0,c=0;return"max"===t&&(a=12,u=d(n.getFullYear(),n.getMonth()+1),s=23,c=59),n.getFullYear()===o&&(a=r.getMonth()+1,n.getMonth()+1===a&&(u=r.getDate(),n.getDate()===u&&(s=r.getHours(),n.getHours()===s&&(c=r.getMinutes())))),h(i={},"".concat(t,"Year"),o),h(i,"".concat(t,"Month"),a),h(i,"".concat(t,"Date"),u),h(i,"".concat(t,"Hour"),s),h(i,"".concat(t,"Minute"),c),i})),h(o(e),"onClose",(function(){e.$emit("close")})),h(o(e),"onConfirm",(function(){e.$emit("confirm",{detail:{value:e.currentDate}})})),h(o(e),"onChange",(function(t){var n=t.detail;e.updateInnerValue(n),e.setColumns()})),e}return e(s,[{key:"formatValue",value:function(t){if(g(t)){var e=v(t.getTime(),this.innerMinDate.getTime(),this.innerMaxDate.getTime());return new Date(e)}}},{key:"calcRanges",value:function(){var t=this.getBoundary("max",this.currentDate||this.innerMinDate),e=t.maxYear,n=t.maxDate,i=t.maxMonth,r=t.maxHour,o=t.maxMinute,a=this.getBoundary("min",this.currentDate||this.innerMinDate),u=a.minYear,s=a.minDate,c=[{type:"year",range:[u,e]},{type:"month",range:[a.minMonth,i]},{type:"day",range:[s,n]},{type:"hour",range:[a.minHour,r]},{type:"minute",range:[a.minMinute,o]}];switch(this.type){case"date":c=c.slice(0,3);break;case"year-month":c=c.slice(0,2);break;case"month-day":c=c.slice(1,3);break;case"datehour":c=c.slice(0,4)}return c}},{key:"setColumns",value:function(){var t=this,e=this.calcRanges();if(this.originColumns=e.map((function(e){var n=e.type,i=e.range,r=k(i[1]-i[0]+1,(function(t){return y(i[0]+t)}));return t.filter&&(r=t.filter(n,r)),{defaultIndex:0,type:n,values:r}})),this.currentDate){var n=[];n=[this.currentDate.getFullYear(),this.currentDate.getMonth()+1,this.currentDate.getDate(),this.currentDate.getHours(),this.currentDate.getMinutes()],"month-day"===this.type&&(n=n.slice(1)),this.originColumns.forEach((function(t,e){var i=t.values.indexOf(y("".concat(n[e])));t.defaultIndex=i>0?i:0}))}this.columns=this.originColumns.map((function(e){var n=e.type,i=e.defaultIndex,r=e.values;return{type:n,defaultIndex:i,values:r.map((function(e){return t.formatter(n,e)}))}})),this.pickerRef.current&&this.pickerRef.current.setColumns(this.columns)}},{key:"updateInnerValue",value:function(t){var e,n,i,r=this,o=t.value.map((function(t){return t.index})),a=m(o,5),u=a[0],s=a[1],c=a[2],l=a[3],h=a[4],p=function(t,e){return function(t){if(!t)return 0;for(;Number.isNaN(parseInt(t,10));){if(!(t.length>1))return 0;t=t.slice(1)}return parseInt(t,10)}(r.originColumns.find((function(e){return e.type===t})).values[e])};if("month-day"===this.type){var f=m(o,2),y=f[0],v=f[1];e=(this.currentDate||this.innerMinDate).getFullYear(),n=p("month",y),i=p("day",v)}else e=p("year",u),n=p("month",s),i="year-month"===this.type?1:p("day",c);var k=d(e,n);i=i>k?k:i;var g=0,x=0;"datehour"===this.type?g=p("hour",l):"datetime"===this.type&&(g=p("hour",l),x=p("minute",h));var b=new Date(e,n-1,i,g,x);this.currentDate=this.formatValue(b),this.$emit("change",{detail:{value:this.currentDate}})}},{key:"componentDidMount",value:function(){this.mindate&&(this.innerMinDate=new Date(this.mindate)),this.maxdate&&(this.innerMaxDate=new Date(this.maxdate)),this.value?this.currentDate=this.formatValue(new Date(this.value)):this.currentDate=this.innerMinDate,this.setColumns()}},{key:"getValues",value:function(){return this.pickerRef.current.getValues()}},{key:"setValue",value:function(t){if(!g(t))throw new Error("请传入正确格式的value");this.currentDate=this.formatValue(t),this.setColumns()}},{key:"setFormatter",value:function(t){this.formatter=t,this.setColumns()}},{key:"setFilter",value:function(t){this.filter=t,this.setColumns()}},{key:"render",value:function(){return u.h("quark-picker",{ref:this.pickerRef,title:this.title,bottomhidden:this.showtoolbar,open:this.open,forbidmaskclick:this.forbidmaskclick,onclose:this.onClose,onchange:this.onChange,onconfirm:this.onConfirm},this.showtoolbar&&u.h("div",{slot:"header",class:"quark-date-picker-header"},u.h("span",{class:"quark-date-picker-close-btn",onclick:this.onClose},this.cancelbuttontext),u.h("span",{class:"quark-date-picker-title"},this.title),u.h("span",{class:"quark-date-picker-confirm-btn",onclick:this.onConfirm},this.confirmbuttontext)))}}]),s}();s([c({type:Boolean})],D.prototype,"open",void 0),s([c({type:String})],D.prototype,"value",void 0),s([c({type:String})],D.prototype,"type",void 0),s([c({type:String})],D.prototype,"title",void 0),s([c({type:String})],D.prototype,"mindate",void 0),s([c({type:String})],D.prototype,"maxdate",void 0),s([c({type:Boolean})],D.prototype,"showtoolbar",void 0),s([c({type:String})],D.prototype,"confirmbuttontext",void 0),s([c({type:String})],D.prototype,"cancelbuttontext",void 0),s([c({type:Boolean})],D.prototype,"forbidmaskclick",void 0);D=s([l({tag:"quark-date-picker",style:f})],D);function C(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,o=n(t);if(e){var a=n(this).constructor;r=Reflect.construct(o,arguments,a)}else r=o.apply(this,arguments);return i(this,r)}}var w=function(n){r(s,u);var i=C(s);function s(){var e;t(this,s);for(var n=arguments.length,r=new Array(n),u=0;u<n;u++)r[u]=arguments[u];return e=i.call.apply(i,[this].concat(r)),h(o(e),"open",!1),h(o(e),"type","time"),h(o(e),"title",""),h(o(e),"minhour",0),h(o(e),"maxhour",23),h(o(e),"minminute",0),h(o(e),"maxminute",59),h(o(e),"showtoolbar",!1),h(o(e),"confirmbuttontext",""),h(o(e),"cancelbuttontext",""),h(o(e),"forbidmaskclick",!1),h(o(e),"pickerRef",a()),h(o(e),"originColumns",[]),h(o(e),"columns",[]),h(o(e),"currentTime",null),h(o(e),"formatter",(function(t,e){return e})),h(o(e),"filter",(function(t,e){return e})),h(o(e),"onClose",(function(){e.$emit("close")})),h(o(e),"confirm",(function(){e.$emit("confirm",{detail:{value:e.currentTime}})})),h(o(e),"onChange",(function(t){var n=t.detail;e.updateInnerValue(n)})),e}return e(s,[{key:"formatValue",value:function(t){t||(t="".concat(y(this.minhour),":").concat(y(this.minminute)));var e=t.split(":"),n=m(e,2),i=n[0],r=n[1];return i=y(v(+i,+this.minhour,+this.maxhour)),r=y(v(+r,+this.minminute,this.maxminute)),"".concat(i,":").concat(r)}},{key:"calcRanges",value:function(){return[{type:"hour",range:[+this.minhour,+this.maxhour]},{type:"minute",range:[+this.minminute,+this.maxminute]}]}},{key:"setColumns",value:function(){var t=this,e=this.calcRanges(),n=this.currentTime.split(":"),i=m(n,2),r=i[0],o=i[1],a=function(t,e){var n=t.indexOf(e);return n>-1?n:0};this.originColumns=e.map((function(e){var n=e.type,i=e.range,u=k(i[1]-i[0]+1,(function(t){return y(i[0]+t)}));return t.filter&&(u=t.filter(n,u)),{defaultIndex:a(u,"hour"===n?r:o),type:n,values:u}})),this.columns=this.originColumns.map((function(e){var n=e.type,i=e.defaultIndex,r=e.values;return{type:n,defaultIndex:i,values:r.map((function(e){return t.formatter(n,e)}))}})),this.pickerRef.current.setColumns(this.columns)}},{key:"updateInnerValue",value:function(t){var e=t.value.map((function(t){return parseInt(t.value,10)})),n=m(e,2),i=n[0],r=n[1];this.currentTime=this.formatValue("".concat(i,":").concat(r)),this.$emit("change",{detail:{value:this.currentTime}}),this.setColumns()}},{key:"componentDidMount",value:function(){this.currentTime=this.formatValue(this.value),this.setColumns()}},{key:"getValues",value:function(){return this.pickerRef.current.getValues()}},{key:"setValue",value:function(t){this.currentTime=this.formatValue(t),this.setColumns()}},{key:"setFormatter",value:function(t){this.formatter=t,this.setColumns()}},{key:"setFilter",value:function(t){this.filter=t,this.setColumns()}},{key:"render",value:function(){return u.h("quark-picker",{ref:this.pickerRef,title:this.title,bottomhidden:this.showtoolbar,open:this.open,forbidmaskclick:this.forbidmaskclick,onclose:this.onClose,onchange:this.onChange,onconfirm:this.confirm,part:"root"},this.showtoolbar&&u.h("div",{slot:"header",class:"quark-date-picker-header",part:"header"},u.h("span",{class:"quark-date-picker-close-btn",part:"close-btn",onclick:this.onClose},this.cancelbuttontext),u.h("span",{class:"quark-date-picker-title",part:"title"},this.title),u.h("span",{class:"quark-date-picker-confirm-btn",part:"confirm-btn",onclick:this.confirm},this.confirmbuttontext)))}}]),s}();s([c({type:Boolean})],w.prototype,"open",void 0),s([c({type:String})],w.prototype,"value",void 0),s([c({type:String})],w.prototype,"type",void 0),s([c({type:String})],w.prototype,"title",void 0),s([c({type:Number})],w.prototype,"minhour",void 0),s([c({type:Number})],w.prototype,"maxhour",void 0),s([c({type:Number})],w.prototype,"minminute",void 0),s([c({type:Number})],w.prototype,"maxminute",void 0),s([c({type:Boolean})],w.prototype,"showtoolbar",void 0),s([c({type:String})],w.prototype,"confirmbuttontext",void 0),s([c({type:String})],w.prototype,"cancelbuttontext",void 0),s([c({type:Boolean})],w.prototype,"forbidmaskclick",void 0);w=s([l({tag:"quark-time-picker",style:f})],w);function R(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,o=n(t);if(e){var a=n(this).constructor;r=Reflect.construct(o,arguments,a)}else r=o.apply(this,arguments);return i(this,r)}}var M=function(n){r(s,u);var i=R(s);function s(){var e;t(this,s);for(var n=arguments.length,r=new Array(n),u=0;u<n;u++)r[u]=arguments[u];return e=i.call.apply(i,[this].concat(r)),h(o(e),"open",!1),h(o(e),"title",""),h(o(e),"type","datetime"),h(o(e),"mindate",""),h(o(e),"maxdate",""),h(o(e),"minhour",0),h(o(e),"maxhour",23),h(o(e),"minminute",0),h(o(e),"maxminute",59),h(o(e),"showtoolbar",!1),h(o(e),"confirmbuttontext",p.current.confirm),h(o(e),"cancelbuttontext",p.current.cancel),h(o(e),"forbidmaskclick",!1),h(o(e),"datePickerRef",a()),h(o(e),"timePickerRef",a()),h(o(e),"onClose",(function(){e.$emit("close")})),h(o(e),"onConfirm",(function(t){var n=t.detail;e.$emit("confirm",{detail:n})})),h(o(e),"onChange",(function(t){var n=t.detail;e.$emit("change",{detail:n})})),e}return e(s,[{key:"componentDidMount",value:function(){}},{key:"getValues",value:function(){var t,e;return"time"===this.type?null===(t=this.timePickerRef.current)||void 0===t?void 0:t.getValues():null===(e=this.datePickerRef.current)||void 0===e?void 0:e.getValues()}},{key:"setValue",value:function(t){var e,n;"time"===this.type?null===(e=this.timePickerRef.current)||void 0===e||e.setValue(t):null===(n=this.datePickerRef.current)||void 0===n||n.setValue(new Date(t))}},{key:"setFormatter",value:function(t){var e,n;"time"===this.type?null===(e=this.timePickerRef.current)||void 0===e||e.setFormatter(t):null===(n=this.datePickerRef.current)||void 0===n||n.setFormatter(t)}},{key:"setFilter",value:function(t){var e,n;"time"===this.type?null===(e=this.timePickerRef.current)||void 0===e||e.setFilter(t):null===(n=this.datePickerRef.current)||void 0===n||n.setFilter(t)}},{key:"render",value:function(){return"time"===this.type?u.h("quark-time-picker",{ref:this.timePickerRef,value:this.value,title:this.title,open:this.open,type:this.type,minhour:this.minhour,maxhour:this.maxhour,minminute:this.minminute,maxminute:this.maxminute,showtoolbar:this.showtoolbar,confirmbuttontext:this.confirmbuttontext,cancelbuttontext:this.cancelbuttontext,forbidmaskclick:this.forbidmaskclick,onclose:this.onClose,onchange:this.onChange,onconfirm:this.onConfirm,part:"root"},u.h("slot",null)):u.h("quark-date-picker",{ref:this.datePickerRef,value:this.value,title:this.title,open:this.open,type:this.type,maxdate:this.maxdate,mindate:this.mindate,showtoolbar:this.showtoolbar,confirmbuttontext:this.confirmbuttontext,cancelbuttontext:this.cancelbuttontext,forbidmaskclick:this.forbidmaskclick,onclose:this.onClose,onchange:this.onChange,onconfirm:this.onConfirm,part:"root"},u.h("slot",null))}}]),s}();s([c({type:Boolean})],M.prototype,"open",void 0),s([c()],M.prototype,"value",void 0),s([c({type:String})],M.prototype,"title",void 0),s([c({type:String})],M.prototype,"type",void 0),s([c({type:String})],M.prototype,"mindate",void 0),s([c({type:String})],M.prototype,"maxdate",void 0),s([c({type:Number})],M.prototype,"minhour",void 0),s([c({type:Number})],M.prototype,"maxhour",void 0),s([c({type:Number})],M.prototype,"minminute",void 0),s([c({type:Number})],M.prototype,"maxminute",void 0),s([c({type:Boolean})],M.prototype,"showtoolbar",void 0),s([c({type:String})],M.prototype,"confirmbuttontext",void 0),s([c({type:String})],M.prototype,"cancelbuttontext",void 0),s([c({type:Boolean})],M.prototype,"forbidmaskclick",void 0);var V=M=s([l({tag:"quark-datetime-picker",style:f})],M);export{V as default};