This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0
wcui/js/lib/datepicker/doui.datepicker.min.js

1 line
6.4 KiB
JavaScript

"use strict";define(["avalon","css!./doui.datepicker.min"],function(av){function getThisYearMonth(){var a=new Date;return[a.getFullYear(),a.getMonth()+1]}function getNumsOfYearMonth(a,e){return new Date(a,e,0).getDate()}function getDayByYearMonth(a,e,t){return t=t||1,new Date(a,e-1,t).getDay()}function numberFormat(a,e){if(a+="",a.length===e)return a;for(;a.length<e;)a="0"+a;return a}var parentVm=null;return av.component("do:datepicker",{$replace:!0,$template:'<div class="do-ui-datepicker do-fn-noselect"><input class="date-input" type="text" ms-duplex="dateVal" ms-on-focus="$focus" ms-click="$cancelBubble" ms-attr-disabled="disabled" ms-css-border-width="border" ms-css-border-radius="radius"><div class="calendar" ms-if="showCalendar" ms-click="$cancelBubble"><div class="calendar-hd">请选择日期</div><div class="calendar-contrl"><a href="javascript:;" ms-click="$turn(1, -1)" class="prev-year">{{btns.prevYear}}</a><a href="javascript:;" ms-click="$turn(0, -1)" class="prev-month">{{btns.prevMonth}}</a><a href="javascript:;" ms-click="$turn(0, 1)" class="next-month">{{btns.nextMonth}}</a><a href="javascript:;" ms-click="$turn(1, 1)" class="next-year">{{btns.nextYear}}</a><span class="date-display">{{calendar.year + \'-\' + calendar.month}}</span></div><ul class="calendar-table"><li class="tr tr-hd"><span class="td">日</span><span class="td">一</span><span class="td">二</span><span class="td">三</span><span class="td">四</span><span class="td">五</span><span class="td">六</span></li><li class="tr list do-fn-cl"><span class="td" ms-class="weeken:el.weeken" ms-class-1="{{el.disable ? \'disabled\' : \'do-st-hand\'}}" ms-class-2="selected:el.selected" ms-repeat="calendar.list" ms-click="$getDate(el.disable, el.day)">{{el.day}}</span></li></ul><div class="time-contrl" ms-if="showTime"><label class="hours"><input type="text" ms-duplex-time="calendar.hour" data-format="hour"></label><label class="minutes"><input type="text" ms-duplex-time="calendar.minute" data-format="minute"></label><label class="seconds"><input type="text" ms-duplex-time="calendar.second" data-format="second"></label><a href="javascript:;" class="now" ms-click="$now">现在</a></div><span class="calendar-tips" ms-if="tips">{{tips}}</span></div></div>',$construct:function(a,e,t){var n=av.mix(e,t),l=n.duplex.slice(0,n.duplex.indexOf("."));parentVm=av.vmodels[l],n.duplex=n.duplex.slice(n.duplex.indexOf(".")+1);var r=new Function("v","return v."+n.duplex)(parentVm);return n.showTime||n.format||(n.format="Y-m-d"),void 0===r&&(n.minDate?(r=n.minDate,n.format):a.maxDate&&(r=n.maxDate,n.format)),a.dateVal=r&&av.filters.date(r,n.format),a.calendar={list:[],year:av.filters.date(a.dateVal,"Y"),month:av.filters.date(a.dateVal,"m"),day:av.filters.date(a.dateVal,"d")||0,hour:av.filters.date(a.dateVal,"H")||0,minute:av.filters.date(a.dateVal,"i")||0,second:av.filters.date(a.dateVal,"s")||0,minYear:n.minDate&&av.filters.date(n.minDate,"Y")>>0,minMonth:n.minDate&&av.filters.date(n.minDate,"m")>>0,minDay:n.minDate&&av.filters.date(n.minDate,"d")>>0||1,maxYear:n.maxDate&&av.filters.date(n.maxDate,"Y")>>0,maxMonth:n.maxDate&&av.filters.date(n.maxDate,"m")>>0,maxDay:n.maxDate&&av.filters.date(n.maxDate,"d")>>0},delete n.minDate,delete n.maxDate,av.mix(a,n)},$init:function(vm,ele){function getCalendar(){var a=vm.calendar.year>>0,e=vm.calendar.month>>0,t=getNumsOfYearMonth(a,e),n=-getDayByYearMonth(a,e)+1,l=isLimited(a,e);vm.calendar.list.clear();for(var r=n;t>=r;r++){var s={weeken:!1,day:"",selected:!1,disable:!0};if(r>0){var d=getDayByYearMonth(a,e,r);s={weeken:0==d||6==d,day:r,selected:isSelected(r),disable:disabledDay(r,l)}}vm.calendar.list.push(s)}}function isLimited(a,e){var t={Y:vm.calendar.minYear,M:vm.calendar.minMonth,mY:vm.calendar.maxYear,mM:vm.calendar.maxMonth},n="";if(!t.Y&&!t.mY||!t.M&&!t.mM)return!1;if(!a)return!1;if(t.Y&&a<t.Y||t.mY&&a>t.mY)return!0;if(e){if(a===t.Y){if(t.M&&e<t.M)return!0;e==t.M&&(n+="-")}if(a===t.mY){if(t.mM&&e>t.mM)return!0;e==t.mM&&(n+="+")}}return n}function disabledDay(a,e){var t=vm.calendar.minDay,n=vm.calendar.maxDay;return"-"===e?t>a:"+"===e?n&&a>n:"-+"===e?t>a||n&&a>n:e}function isSelected(a){var e=vm.calendar.year>>0,t=vm.calendar.month>>0;return!(lastDate.year!==e||lastDate.month!==t||lastDate.day!==a)}function changeStyle(a){vm.calendar.list.forEach(function(e){e.selected=e.day!=a?!1:!0})}function updateTime(){var a=vm.calendar,e=a.year,t=a.month,n=a.day,l=a.hour,r=a.minute,s=a.second,d=e+"-"+t+"-"+n;vm.showTime&&(d+=" "+l+":"+r+":"+s),lastDate={year:e>>0,month:t>>0,day:n>>0},vm.dateVal=av.filters.date(d,vm.format)}var lastDate={year:vm.calendar.year>>0,month:vm.calendar.month>>0,day:vm.calendar.day>>0},timer;getCalendar(),vm.$turn=function(a,e){var t=vm.calendar.year>>0,n=vm.calendar.month>>0;return 1===a?t+=e:(n+=e,1>n&&(n=12,t--),n>12&&(n=1,t++)),isLimited(t,n)===!0?void(vm.tips="日期超出限制"):(vm.calendar.year=t,void(vm.calendar.month=numberFormat(n,2)))},vm.$getDate=function(a,e){a||(vm.calendar.day=e,changeStyle(e),updateTime(),vm.showCalendar=!1)},vm.$focus=function(){vm.showCalendar=!0},vm.$now=function(){var a=av.filters.date(null,"Y")>>0,e=av.filters.date(null,"m")>>0,t=av.filters.date(null,"d")>>0,n=isLimited(a,e),l=disabledDay(t,n);return l?void(vm.tips="今天超出了限制日期"):(vm.calendar.year=a,vm.calendar.month=e,vm.calendar.day=t,vm.calendar.hour=av.filters.date(null,"H"),vm.calendar.minute=av.filters.date(null,"i"),vm.calendar.second=av.filters.date(null,"s"),changeStyle(t),updateTime(),void(vm.showCalendar=!1))},vm.$watch("calendar.year",function(){getCalendar()}),vm.$watch("calendar.month",function(){getCalendar()}),vm.$watch("calendar.hour",function(a){vm.calendar.hour=a,updateTime()}),vm.$watch("calendar.minute",function(a){vm.calendar.minute=a,updateTime()}),vm.$watch("calendar.second",function(a){vm.calendar.second=a,updateTime()}),vm.$watch("showCalendar",function(v){!v&&vm.duplex&&(eval("parentVm."+vm.duplex+' = "'+vm.dateVal+'"'),vm.callback&&vm.callback(vm.dateVal))}),vm.$watch("tips",function(a){a&&(clearTimeout(timer),timer=setTimeout(function(){vm.tips=""},1500))}),document.addEventListener("click",function(){vm.showCalendar=!1})},showTime:!1,showCalendar:!1,disabled:!1,exclass:"",tips:"",duplex:"",format:"",dateVal:"",radius:0,border:1,btns:{prevYear:"<<",nextYear:">>",prevMonth:"<",nextMonth:">"},$focus:av.noop,$turn:av.noop,$getDate:av.noop,$now:av.noop,$cancelBubble:function(a){a.stopPropagation&&a.stopPropagation()||(a.cancelBubble=!0)},callback:null}),av});
wcui是一套基于`Web Components`的UI组件库, 宗旨是追求简单、实用、不花哨。
JavaScript 95.2%
CSS 4.8%