UNPKG

vuejs-mobile-datepicker

Version:
2 lines 16.8 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("vuejs-mobile-datepicker",[],e):"object"==typeof exports?exports["vuejs-mobile-datepicker"]=e():t["vuejs-mobile-datepicker"]=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="/dist/",e(e.s=1)}([function(t,e,n){"use strict";e.a={name:"MobileDatepicker",props:{showPickerModel:{type:Boolean,default:!1},defaultDate:{type:Date,default:function(){return new Date}},startDate:{type:Date,default:function(){return new Date("1900-1-1")}},endDate:{type:Date,default:function(){return new Date}},disableDate:{type:Function},markWeekend:{type:Boolean,default:!1},language:{type:String,default:"zh"}},created:function(){this.showPickerModel&&this.defaultDate&&this.initDate(this.defaultDate)},data:function(){return{weeks:["日","一","二","三","四","五","六"],enMonth:["January","February","March","April","May","June","July","August","September","October","November","December"],enShortWeeks:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],days:[],years:[],monthLastDay:[31,28,31,30,31,30,31,31,30,31,30,31],year:null,currentYear:null,month:null,currentMonth:null,day:null,currentDay:null,week:null,changeContentFlag:!1}},watch:{showPickerModel:function(t,e){t&&(this.defaultDate>=this.startDate&&this.defaultDate<=this.endDate?this.initDate(this.defaultDate):this.$emit("cancel"))}},computed:{isEnglish:function(){return"en"==this.language},currentDateText:function(){return this.isEnglish?this.enMonth[this.currentMonth]?this.enShortWeeks[this.weeks.indexOf(this.week)]+", "+this.enMonth[this.currentMonth].substring(0,3)+" "+this.currentDay:this.enShortWeeks[this.weeks.indexOf(this.week)]+", ":this.currentMonth+1+"月"+this.currentDay+"日周"+this.week},currentMonthText:function(){return this.isEnglish?this.enMonth[this.month]+" "+this.year:this.year+"年"+(this.month+1)+"月"}},methods:{handleCancel:function(){this.changeContentFlag=!1,this.$emit("cancel")},handleConfirm:function(){this.changeContentFlag=!1,this.$emit("confirm",this.currentYear+"-"+(this.currentMonth+1)+"-"+this.currentDay)},initDate:function(t){this.currentYear=this.year=t.getFullYear(),this.currentMonth=this.month=t.getMonth(),this.currentDay=this.day=t.getDate(),this.week=this.weeks[t.getDay()],this.years=[];for(var e=0;e<=this.endDate.getFullYear()-this.startDate.getFullYear();e++)this.years.push(Number(this.startDate.getFullYear())+e);this.updateDate(this.year,this.month)},updateDate:function(t,e){this.monthLastDay[1]=28,(t%4==0&&t%100!=0||t%400==0)&&(this.monthLastDay[1]=29);var n=new Date(t,e,1).getDay();this.days=[];for(var i=0;i<n;i++)this.days.push(0);for(var r=1;r<=this.monthLastDay[e];r++)this.days.push(r)},preMonth:function(){0==this.month?(this.year=this.year-1,this.month=11):this.month--,this.updateDate(this.year,this.month)},nextMonth:function(){11==this.month?(this.year=this.year+1,this.month=0):this.month++,this.updateDate(this.year,this.month)},handleClickDay:function(t){if(!(this.startDate>new Date(this.year,this.month,t)||this.endDate<new Date(this.year,this.month,t)||0==t||"function"==typeof this.disableDate&&this.disableDate(this.year+"-"+(this.month+1)+"-"+t))){this.currentYear=this.year,this.currentMonth=this.month,this.currentDay=this.day=t;var e=new Date(this.currentYear,this.currentMonth,this.currentDay);this.week=this.weeks[e.getDay()]}},handleClickYear:function(t){if(new Date(t,this.month,this.day)<this.startDate)this.year=this.currentYear=this.startDate.getFullYear(),this.month=this.currentMonth=this.startDate.getMonth(),this.day=this.currentDay=this.startDate.getDate(),this.week=this.weeks[this.startDate.getDay()];else if(new Date(t,this.month,this.day)>this.endDate)this.year=this.currentYear=this.endDate.getFullYear(),this.month=this.currentMonth=this.endDate.getMonth(),this.day=this.currentDay=this.endDate.getDate(),this.week=this.weeks[this.endDate.getDay()];else{if("function"==typeof this.disableDate&&this.disableDate(t+"-"+(this.currentMonth+1)+"-"+this.day))return this.year=t,this.updateDate(this.year,this.month),void(this.changeContentFlag=!1);if((t%4!=0||t%100==0)&&t%400!=0&&1==this.currentMonth&&29==this.currentDay)return this.year=t,this.updateDate(this.year,this.month),void(this.changeContentFlag=!1);this.year=this.currentYear=t,this.month=this.currentMonth,this.day=this.currentDay;var e=new Date(this.year,this.month,this.day);this.week=this.weeks[e.getDay()]}this.updateDate(this.year,this.month),this.changeContentFlag=!1},showDatePicker:function(){this.changeContentFlag&&(this.changeContentFlag=!1)},showYearPicker:function(){var t=this;if(!this.changeContentFlag){this.changeContentFlag=!0;var e=void 0;this.$nextTick(function(){e=(t.currentYear-t.startDate.getFullYear()-3)*t.$refs.mdp_year_list.firstElementChild.offsetHeight,e=e<0?0:e,t.$refs.mdp_year_list.scrollTop=e})}},activeDay:function(t){return t==this.currentDay&&this.month==this.currentMonth&&!this.dayIsDisable(t)},dayIsDisable:function(t){return 0!=t&&(this.startDate-new Date(this.year+"-"+(this.month+1)+"-"+t)>0||new Date(this.year+"-"+(this.month+1)+"-"+t)-this.endDate>0||!(!this.disableDate||"function"!=typeof this.disableDate||!this.disableDate(this.year+"-"+(this.month+1)+"-"+t)))},dayIsWeekend:function(t){return t%7==0||t%7==6}}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=n(2);i.a.install=function(t){t.component("MobileDatePicker",i.a)},"undefined"!=typeof window&&window.Vue&&window.Vue.use(i.a),e.default=i.a},function(t,e,n){"use strict";function i(t){n(3)}var r=n(0),a=n(9),s=n(8),o=i,h=s(r.a,a.a,!1,o,null,null);e.a=h.exports},function(t,e,n){var i=n(4);"string"==typeof i&&(i=[[t.i,i,""]]),i.locals&&(t.exports=i.locals);n(6)("48c1e764",i,!0,{})},function(t,e,n){e=t.exports=n(5)(!1),e.push([t.i,"@media (min-width:240px){html{font-size:32px}}@media (min-width:320px){html{font-size:42.66667px}}@media (min-width:360px){html{font-size:48px}}@media (min-width:375px){html{font-size:50px}}@media (min-width:384px){html{font-size:51.2px}}@media (min-width:411px){html{font-size:54.8px}}@media (min-width:414px){html{font-size:55.2px}}@media (min-width:424px){html{font-size:56.53333px}}@media (min-width:480px){html{font-size:64px}}@media (min-width:540px){html{font-size:72px}}@media (min-width:640px){html{font-size:85.33333px}}@media (min-width:720px){html{font-size:96px}}@media (min-width:750px){html{font-size:100px}}@media (min-width:768px){html{font-size:102.4px}}@media (min-width:800px){html{font-size:106.66667px}}@media (min-width:980px){html{font-size:130.66667px}}@media (min-width:1024px){html{font-size:136.53333px}}@media (min-width:1080px){html{font-size:144px}}@media (min-width:1152px){html{font-size:153.6px}}@media (min-width:1366px){html{font-size:182.13333px}}@media (min-width:1440px){html{font-size:192px}}@media (min-width:2160px){html{font-size:288px}}html{font-family:font-apple-system,system-ui,BlinkMacSystemFont,Helvetica Neue,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Arial,sans-serif}*{margin:0;padding:0}ol,ul{list-style:none}#mobile-datepicker{position:fixed;top:0;left:0;bottom:0;width:100%;height:100%;background-color:rgba(0,0,0,.5);display:flex;justify-content:center;align-items:center}.mdp_container{width:80%;height:10rem;background-color:#fff}.mdp_header{height:2rem;background-color:#dd2727;box-sizing:border-box;color:#eee;padding:.4rem .6rem;font-size:0}.mdp_current_year{font-size:.3125rem;display:inline-block}.mdp_current_date{font-size:.6125rem;display:inline-block}.mdp_current_date.active,.mdp_current_year.active{color:#fff}.mdp_content{width:100%;height:6.8rem;background:#fff}.mdp_date_content{width:100%;height:100%;box-sizing:border-box;padding:0 .6rem .4rem}.mdp_switch_month{display:flex;justify-content:space-between;align-items:center;height:1.2rem;font-weight:500;font-size:.3125rem}.mdp_arrow_action{display:flex;justify-content:center;align-items:center;min-height:.6rem;min-width:.6rem}.mdp_arrow{display:inline-block;width:.16rem;height:.16rem;border-top:.04rem solid #000;border-left:.04rem solid #000}.mdp_left{transform:rotate(-45deg)}.mdp_right{transform:rotate(135deg)}.mdp_arrow_hide{visibility:hidden}.mdp_weeks{width:100%;font-size:.25rem;color:#888}.mdp_week,.mdp_weeks{display:flex;align-items:center}.mdp_week{width:14.2%;height:.8rem;justify-content:center}.mdp_week.mark{color:#dd2727}.mdp_pick_day{font-size:.25rem;width:100%;flex-wrap:wrap}.mdp_day,.mdp_pick_day{display:flex;align-items:center}.mdp_day{width:14.2%;height:.8rem;justify-content:center}.mdp_day.mdp_day_disable{background-color:#f5f7fa;cursor:not-allowed;color:#c0c4cc!important}.mdp_day.mark{color:#dd2727}.mdp_day.active{width:14.2%;background-color:#dd2727;border-radius:50%;color:#fff}.mdp_year_content{width:100%;height:100%;display:flex;justify-content:center;align-items:center;border-bottom:.02rem solid #eee}.mdp_year_content ul{width:100%;height:100%;overflow:scroll;font-size:.3125rem}.mdp_year_content ul li{padding:.4rem 0;height:1rem;box-sizing:border-box;display:flex;justify-content:center;align-items:center}.mdp_year_content ul li.active{font-size:.465rem;color:#dd2727}.mdp_operate_button{margin:0 .6rem;height:1.2rem;display:flex;justify-content:flex-end;align-items:center}.mdp_button{border:none;outline:none;color:#dd2727;background-color:#fff;font-weight:500;font-size:.275rem}.mdp_cancel_button{margin-right:.6rem}",""])},function(t,e){function n(t,e){var n=t[1]||"",r=t[3];if(!r)return n;if(e&&"function"==typeof btoa){var a=i(r);return[n].concat(r.sources.map(function(t){return"/*# sourceURL="+r.sourceRoot+t+" */"})).concat([a]).join("\n")}return[n].join("\n")}function i(t){return"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(t))))+" */"}t.exports=function(t){var e=[];return e.toString=function(){return this.map(function(e){var i=n(e,t);return e[2]?"@media "+e[2]+"{"+i+"}":i}).join("")},e.i=function(t,n){"string"==typeof t&&(t=[[null,t,""]]);for(var i={},r=0;r<this.length;r++){var a=this[r][0];"number"==typeof a&&(i[a]=!0)}for(r=0;r<t.length;r++){var s=t[r];"number"==typeof s[0]&&i[s[0]]||(n&&!s[2]?s[2]=n:n&&(s[2]="("+s[2]+") and ("+n+")"),e.push(s))}},e}},function(t,e,n){function i(t){for(var e=0;e<t.length;e++){var n=t[e],i=c[n.id];if(i){i.refs++;for(var r=0;r<i.parts.length;r++)i.parts[r](n.parts[r]);for(;r<n.parts.length;r++)i.parts.push(a(n.parts[r]));i.parts.length>n.parts.length&&(i.parts.length=n.parts.length)}else{for(var s=[],r=0;r<n.parts.length;r++)s.push(a(n.parts[r]));c[n.id]={id:n.id,refs:1,parts:s}}}}function r(){var t=document.createElement("style");return t.type="text/css",l.appendChild(t),t}function a(t){var e,n,i=document.querySelector("style["+g+'~="'+t.id+'"]');if(i){if(p)return f;i.parentNode.removeChild(i)}if(_){var a=m++;i=u||(u=r()),e=s.bind(null,i,a,!1),n=s.bind(null,i,a,!0)}else i=r(),e=o.bind(null,i),n=function(){i.parentNode.removeChild(i)};return e(t),function(i){if(i){if(i.css===t.css&&i.media===t.media&&i.sourceMap===t.sourceMap)return;e(t=i)}else n()}}function s(t,e,n,i){var r=n?"":i.css;if(t.styleSheet)t.styleSheet.cssText=v(e,r);else{var a=document.createTextNode(r),s=t.childNodes;s[e]&&t.removeChild(s[e]),s.length?t.insertBefore(a,s[e]):t.appendChild(a)}}function o(t,e){var n=e.css,i=e.media,r=e.sourceMap;if(i&&t.setAttribute("media",i),y.ssrId&&t.setAttribute(g,e.id),r&&(n+="\n/*# sourceURL="+r.sources[0]+" */",n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */"),t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}var h="undefined"!=typeof document;if("undefined"!=typeof DEBUG&&DEBUG&&!h)throw new Error("vue-style-loader cannot be used in a non-browser environment. Use { target: 'node' } in your Webpack config to indicate a server-rendering environment.");var d=n(7),c={},l=h&&(document.head||document.getElementsByTagName("head")[0]),u=null,m=0,p=!1,f=function(){},y=null,g="data-vue-ssr-id",_="undefined"!=typeof navigator&&/msie [6-9]\b/.test(navigator.userAgent.toLowerCase());t.exports=function(t,e,n,r){p=n,y=r||{};var a=d(t,e);return i(a),function(e){for(var n=[],r=0;r<a.length;r++){var s=a[r],o=c[s.id];o.refs--,n.push(o)}e?(a=d(t,e),i(a)):a=[];for(var r=0;r<n.length;r++){var o=n[r];if(0===o.refs){for(var h=0;h<o.parts.length;h++)o.parts[h]();delete c[o.id]}}}};var v=function(){var t=[];return function(e,n){return t[e]=n,t.filter(Boolean).join("\n")}}()},function(t,e){t.exports=function(t,e){for(var n=[],i={},r=0;r<e.length;r++){var a=e[r],s=a[0],o=a[1],h=a[2],d=a[3],c={id:t+":"+r,css:o,media:h,sourceMap:d};i[s]?i[s].parts.push(c):n.push(i[s]={id:s,parts:[c]})}return n}},function(t,e){t.exports=function(t,e,n,i,r,a){var s,o=t=t||{},h=typeof t.default;"object"!==h&&"function"!==h||(s=t,o=t.default);var d="function"==typeof o?o.options:o;e&&(d.render=e.render,d.staticRenderFns=e.staticRenderFns,d._compiled=!0),n&&(d.functional=!0),r&&(d._scopeId=r);var c;if(a?(c=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),i&&i.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(a)},d._ssrRegister=c):i&&(c=i),c){var l=d.functional,u=l?d.render:d.beforeCreate;l?(d._injectStyles=c,d.render=function(t,e){return c.call(e),u(t,e)}):d.beforeCreate=u?[].concat(u,c):[c]}return{esModule:s,exports:o,options:d}}},function(t,e,n){"use strict";var i=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{directives:[{name:"show",rawName:"v-show",value:t.showPickerModel,expression:"showPickerModel"}],attrs:{id:"mobile-datepicker"},on:{click:function(e){return e.target!==e.currentTarget?null:t.handleCancel(e)}}},[n("div",{staticClass:"mdp_container"},[n("div",{staticClass:"mdp_header"},[n("div",{staticClass:"mdp_current_year",class:{active:t.changeContentFlag},on:{click:function(e){return t.showYearPicker()}}},[t._v(t._s(t.currentYear)+t._s(t.isEnglish?"":"年"))]),t._v(" "),n("br"),t._v(" "),n("div",{staticClass:"mdp_current_date",class:{active:!t.changeContentFlag},on:{click:function(e){return t.showDatePicker()}}},[t._v(t._s(t.currentDateText))])]),t._v(" "),n("div",{staticClass:"mdp_content"},[n("div",{directives:[{name:"show",rawName:"v-show",value:!t.changeContentFlag,expression:"!changeContentFlag"}],staticClass:"mdp_date_content"},[n("div",{staticClass:"mdp_switch_month"},[n("span",{staticClass:"mdp_arrow_action",class:{mdp_arrow_hide:t.startDate-new Date(t.year,t.month,1)>=0},on:{click:t.preMonth}},[n("span",{staticClass:"mdp_left mdp_arrow"})]),t._v(" "),n("span",{staticClass:"mdp_current_month"},[t._v(t._s(t.currentMonthText))]),t._v(" "),n("span",{staticClass:"mdp_arrow_action",class:{mdp_arrow_hide:t.endDate-new Date(t.year,t.month+1,1)<=0},on:{click:t.nextMonth}},[n("span",{staticClass:"mdp_right mdp_arrow"})])]),t._v(" "),n("div",{staticClass:"mdp_weeks"},t._l(t.isEnglish?t.enShortWeeks:t.weeks,function(e,i){return n("span",{key:i,staticClass:"mdp_week",class:{mark:t.markWeekend&&(0==i||6==i)}},[t._v(t._s(t.isEnglish?e[0]:e))])}),0),t._v(" "),n("div",{staticClass:"mdp_pick_day"},t._l(t.days,function(e,i){return n("span",{key:i,staticClass:"mdp_day",class:{active:t.activeDay(e),mdp_day_disable:t.dayIsDisable(e),mark:t.markWeekend&&t.dayIsWeekend(i)},on:{click:function(n){return t.handleClickDay(e)}}},[t._v(t._s(e||" "))])}),0)]),t._v(" "),n("div",{directives:[{name:"show",rawName:"v-show",value:t.changeContentFlag,expression:"changeContentFlag"}],staticClass:"mdp_year_content"},[n("ul",{ref:"mdp_year_list"},t._l(t.years,function(e,i){return n("li",{key:i,class:{active:e==t.currentYear},on:{click:function(n){return t.handleClickYear(e)}}},[t._v(t._s(e))])}),0)])]),t._v(" "),n("div",{staticClass:"mdp_operate_button"},[n("button",{staticClass:"mdp_cancel_button mdp_button",on:{click:t.handleCancel}},[t._v(t._s(t.isEnglish?"CANCEL":"取消"))]),t._v(" "),n("button",{staticClass:"mdp_sure_button mdp_button",on:{click:t.handleConfirm}},[t._v(t._s(t.isEnglish?"OK":"确认"))])])])])},r=[],a={render:i,staticRenderFns:r};e.a=a}])}); //# sourceMappingURL=vuejs-mobile-datepicker.js.map