diff --git a/.gitignore b/.gitignore
index 219fb81..0d09221 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
node_modules/
npm-debug.log
yarn-error.log
+package-lock.json
diff --git a/README.md b/README.md
index 8abd9e0..60ecfba 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,13 @@ export default {
return {
time1: '',
time2: '',
+ shortcuts: [
+ {
+ text: 'Today',
+ start: new Date(),
+ end: new Date()
+ }
+ ]
}
}
}
@@ -32,19 +39,36 @@ export default {
-
-
+
+
```
## Attributes
-| Prop | Type | Default | Description |
-|-------------|---------------|------------|--------------------------------|
-| range | Boolean | false | if true, the type is daterange |
-| format | String | yyyy-MM-dd | Date formatting string |
-| lang | String | zh | Translation (en/zh/es/fr) |
-| placeholder | String | | input placeholder text |
-| width | String/Number | 210 | input size |
+| Prop | Type | Default | Description |
+|-------------------|---------------|-------------|---------------------------------------------------|
+| range | Boolean | false | if true, the type is daterange |
+| format | String | yyyy-MM-dd | Date formatting string |
+| lang | String | zh | Translation (en/zh/es/fs) |
+| placeholder | String | | input placeholder text |
+| width | String/Number | 210 | input size |
+| disabled-days | Array | [] | Days in YYYY-MM-DD format to disable |
+| not-before | String | '' | Disable all dates before date in YYY-MM-DD format |
+| not-after | String | '' | Disable all dates after date in YYY-MM-DD format |
+| shortcuts | Boolean/Array | true | the shortcuts for the range picker |
+| first-day-of-week | Number | 7 | set the first day of week (1-7) |
+
+## shortcuts
+* true - show the default shortcuts
+* false - hide the shortcuts
+* Object[] - custom shortcuts, [{text, start, end}]
+
+| Prop | Type | Description |
+|-----------------|---------------|------------------------|
+| text | String | Text |
+| start | Date | Start Date |
+| end | Date | End Date |
+
diff --git a/datepicker/calendar-panel.vue b/datepicker/calendar-panel.vue
index d0f0888..e3df7cd 100644
--- a/datepicker/calendar-panel.vue
+++ b/datepicker/calendar-panel.vue
@@ -4,7 +4,7 @@
«
‹
»
- ›
+ ›
{{months[currentMonth]}}
{{currentYear}}
@@ -17,10 +17,7 @@
- | {{cell.day}} |
+ {{cell.day}} |
@@ -45,7 +42,6 @@ export default {
data () {
const translation = this.$parent.translation
return {
- days: translation.days,
months: translation.months,
dates: [],
now: new Date(), // calendar-header 显示的时间, 用于切换日历
@@ -54,6 +50,11 @@ export default {
}
},
computed: {
+ days () {
+ const days = this.$parent.translation.days
+ const firstday = +this.$parent.firstDayOfWeek
+ return days.concat(days).slice(firstday, firstday + 7)
+ },
currentYear () {
return this.now.getFullYear()
},
@@ -88,7 +89,7 @@ export default {
function getCalendar (time, firstday, length, classes) {
return Array.apply(null, { length }).map((v, i) => { // eslint-disable-line
let day = firstday + i
- const date = new Date(time.getFullYear(), time.getMonth(), day)
+ const date = new Date(time.getFullYear(), time.getMonth(), day, 0, 0, 0)
return {
title: date.toLocaleDateString(),
date,
@@ -97,9 +98,10 @@ export default {
}
})
}
+ const firstDayOfWeek = this.$parent.firstDayOfWeek
const time = new Date(this.now)
time.setDate(0) // 把时间切换到上个月最后一天
- const lastMonthLength = time.getDay() + 1 // time.getDay() 0是星期天, 1是星期一 ...
+ const lastMonthLength = (time.getDay() + 7 - firstDayOfWeek) % 7 + 1 // time.getDay() 0是星期天, 1是星期一 ...
const lastMonthfirst = time.getDate() - (lastMonthLength - 1)
const lastMonth = getCalendar(time, lastMonthfirst, lastMonthLength, 'lastMonth')
@@ -129,11 +131,18 @@ export default {
const endTime = this.endAt ? new Date(this.endAt).setHours(0, 0, 0, 0) : 0
const today = new Date().setHours(0, 0, 0, 0)
+ if (this.$parent.disabledDays.some(v => +new Date(v) === +cell.date) ||
+ (this.$parent.notBefore !== '' && cell.date.getTime() < (new Date(this.$parent.notBefore)).getTime()) ||
+ (this.$parent.notAfter !== '' && cell.date.getTime() > (new Date(this.$parent.notAfter)).getTime())) {
+ return 'disabled'
+ }
+
classes.push(cell.classes)
if (cellTime === today) {
classes.push('today')
}
+
// range classes
if (cellTime === curTime) {
classes.push('current')
@@ -210,11 +219,9 @@ export default {
}
}
}
-
diff --git a/datepicker/index.vue b/datepicker/index.vue
index 0e0fe5d..9295db1 100644
--- a/datepicker/index.vue
+++ b/datepicker/index.vue
@@ -20,14 +20,22 @@
ref="calendar"
v-show="showPopup">
-
+
-
@@ -57,7 +65,28 @@ export default {
type: String,
default: 'zh'
},
- value: null
+ value: null,
+ shortcuts: {
+ type: [Boolean, Array],
+ default: true
+ },
+ disabledDays: {
+ type: Array,
+ default: function () { return [] }
+ },
+ notBefore: {
+ type: String,
+ default: ''
+ },
+ notAfter: {
+ type: String,
+ default: ''
+ },
+ firstDayOfWeek: {
+ default: 7,
+ type: Number,
+ validator: val => val >= 1 && val <= 7
+ }
},
data () {
return {
@@ -87,7 +116,6 @@ export default {
showPopup (val) {
if (val) {
this.$nextTick(this.displayPopup)
- // this.displayPopup()
}
}
},
@@ -109,9 +137,6 @@ export default {
}
},
methods: {
- selectDate (date) {
-
- },
closePopup () {
this.showPopup = false
},
@@ -176,26 +201,32 @@ export default {
this.$emit('input', [range.start, range.end])
},
initRanges () {
- this.ranges = [{
- text: '未来7天',
- start: new Date(),
- end: new Date(Date.now() + 3600 * 1000 * 24 * 7)
- }, {
- text: '未来30天',
- start: new Date(),
- end: new Date(Date.now() + 3600 * 1000 * 24 * 30)
- }, {
- text: '最近7天',
- start: new Date(Date.now() - 3600 * 1000 * 24 * 7),
- end: new Date()
- }, {
- text: '最近30天',
- start: new Date(Date.now() - 3600 * 1000 * 24 * 30),
- end: new Date()
- }]
- this.ranges.forEach((v, i) => {
- v.text = this.translation.pickers[i]
- })
+ if (Array.isArray(this.shortcuts)) {
+ this.ranges = this.shortcuts
+ } else if (this.shortcuts) {
+ this.ranges = [{
+ text: '未来7天',
+ start: new Date(),
+ end: new Date(Date.now() + 3600 * 1000 * 24 * 7)
+ }, {
+ text: '未来30天',
+ start: new Date(),
+ end: new Date(Date.now() + 3600 * 1000 * 24 * 30)
+ }, {
+ text: '最近7天',
+ start: new Date(Date.now() - 3600 * 1000 * 24 * 7),
+ end: new Date()
+ }, {
+ text: '最近30天',
+ start: new Date(Date.now() - 3600 * 1000 * 24 * 30),
+ end: new Date()
+ }]
+ this.ranges.forEach((v, i) => {
+ v.text = this.translation.pickers[i]
+ })
+ } else {
+ this.ranges = []
+ }
},
displayPopup () {
const dw = document.documentElement.clientWidth
diff --git a/demo/App.vue b/demo/App.vue
new file mode 100644
index 0000000..54c80a0
--- /dev/null
+++ b/demo/App.vue
@@ -0,0 +1,38 @@
+
+
+
+ default:
+
+
+
+ range:
+
+
+
+
+
+
+
+
diff --git a/demo/main.js b/demo/main.js
new file mode 100644
index 0000000..bfc71bd
--- /dev/null
+++ b/demo/main.js
@@ -0,0 +1,7 @@
+import Vue from 'vue'
+import App from './App.vue'
+
+new Vue({ // eslint-disable-line
+ el: '#app',
+ render: h => h(App)
+})
diff --git a/dist/build.js b/dist/build.js
new file mode 100644
index 0000000..dfc7570
--- /dev/null
+++ b/dist/build.js
@@ -0,0 +1,6 @@
+!function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},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=6)}([function(t,e){t.exports=function(){var t=[];return t.toString=function(){for(var t=[],e=0;en.parts.length&&(r.parts.length=n.parts.length)}else{for(var i=[],o=0;o-1)return t.splice(n,1)}}function p(t,e){return qn.call(t,e)}function h(t){var e=Object.create(null);return function(n){return e[n]||(e[n]=t(n))}}function v(t,e){function n(n){var r=arguments.length;return r?r>1?t.apply(e,arguments):t.call(e,n):t.call(e)}return n._length=t.length,n}function m(t,e){e=e||0;for(var n=t.length-e,r=new Array(n);n--;)r[n]=t[n+e];return r}function g(t,e){for(var n in e)t[n]=e[n];return t}function y(t){for(var e={},n=0;n=0&&Rr[n].id>t.id;)n--;Rr.splice(Math.max(n,zr)+1,0,t)}else Rr.push(t);Yr||(Yr=!0,xr(At))}}function Dt(t){qr.clear(),St(t,qr)}function St(t,e){var n,r,o=Array.isArray(t);if((o||i(t))&&Object.isExtensible(t)){if(t.__ob__){var a=t.__ob__.dep.id;if(e.has(a))return;e.add(a)}if(o)for(n=t.length;n--;)St(t[n],e);else for(r=Object.keys(t),n=r.length;n--;)St(t[r[n]],e)}}function Et(t,e,n){Qr.get=function(){return this[e][n]},Qr.set=function(t){this[e][n]=t},Object.defineProperty(t,n,Qr)}function Pt(t){t._watchers=[];var e=t.$options;e.props&&Mt(t,e.props),e.methods&&Lt(t,e.methods),e.data?jt(t):M(t._data={},!0),e.computed&&Nt(t,e.computed),e.watch&&Rt(t,e.watch)}function Mt(t,e){var n=t.$options.propsData||{},r=t._props={},o=t.$options._propKeys=[],a=!t.$parent;Sr.shouldConvert=a;for(var i in e)!function(a){o.push(a);var i=z(a,e,n,t);j(r,a,i),a in t||Et(t,"_props",a)}(i);Sr.shouldConvert=!0}function jt(t){var e=t.$options.data;e=t._data="function"==typeof e?Tt(e,t):e||{},s(e)||(e={});for(var n=Object.keys(e),r=t.$options.props,o=n.length;o--;)r&&p(r,n[o])||A(n[o])||Et(t,"_data",n[o]);M(e,!0)}function Tt(t,e){try{return t.call(e)}catch(t){return $(t,e,"data()"),{}}}function Nt(t,e){var n=t._computedWatchers=Object.create(null);for(var r in e){var o=e[r],a="function"==typeof o?o:o.get;n[r]=new Jr(t,a,_,Wr),r in t||It(t,r,o)}}function It(t,e,n){"function"==typeof n?(Qr.get=Vt(e),Qr.set=_):(Qr.get=n.get?!1!==n.cache?Vt(e):n.get:_,Qr.set=n.set?n.set:_),Object.defineProperty(t,e,Qr)}function Vt(t){return function(){var e=this._computedWatchers&&this._computedWatchers[t];if(e)return e.dirty&&e.evaluate(),Cr.target&&e.depend(),e.value}}function Lt(t,e){t.$options.props;for(var n in e)t[n]=null==e[n]?_:v(e[n],t)}function Rt(t,e){for(var n in e){var r=e[n];if(Array.isArray(r))for(var o=0;o=0||n.indexOf(t[o])<0)&&r.push(t[o]);return r}return t}function he(t){this._init(t)}function ve(t){t.use=function(t){if(!t.installed){var e=m(arguments,1);return e.unshift(this),"function"==typeof t.install?t.install.apply(t,e):"function"==typeof t&&t.apply(null,e),t.installed=!0,this}}}function me(t){t.mixin=function(t){this.options=Y(this.options,t)}}function ge(t){t.cid=0;var e=1;t.extend=function(t){t=t||{};var n=this,r=n.cid,o=t._Ctor||(t._Ctor={});if(o[r])return o[r];var a=t.name||n.options.name,i=function(t){this._init(t)};return i.prototype=Object.create(n.prototype),i.prototype.constructor=i,i.cid=e++,i.options=Y(n.options,t),i.super=n,i.options.props&&ye(i),i.options.computed&&_e(i),i.extend=n.extend,i.mixin=n.mixin,i.use=n.use,tr.forEach(function(t){i[t]=n[t]}),a&&(i.options.components[a]=i),i.superOptions=n.options,i.extendOptions=t,i.sealedOptions=g({},i.options),o[r]=i,i}}function ye(t){var e=t.options.props;for(var n in e)Et(t.prototype,"_props",n)}function _e(t){var e=t.options.computed;for(var n in e)It(t.prototype,n,e[n])}function be(t){tr.forEach(function(e){t[e]=function(t,n){return n?("component"===e&&s(n)&&(n.name=n.name||t,n=this.options._base.extend(n)),"directive"===e&&"function"==typeof n&&(n={bind:n,update:n}),this.options[e+"s"][t]=n,n):this.options[e+"s"][t]}})}function we(t){return t&&(t.Ctor.options.name||t.tag)}function xe(t,e){return"string"==typeof t?t.split(",").indexOf(e)>-1:!!c(t)&&t.test(e)}function Ae(t,e,n){for(var r in t){var o=t[r];if(o){var a=we(o.componentOptions);a&&!n(a)&&(o!==e&&Ce(o),t[r]=null)}}}function Ce(t){t&&t.componentInstance.$destroy()}function ke(t){for(var e=t.data,n=t,o=t;r(o.componentInstance);)o=o.componentInstance._vnode,o.data&&(e=$e(o.data,e));for(;r(n=n.parent);)n.data&&(e=$e(e,n.data));return Oe(e)}function $e(t,e){return{staticClass:De(t.staticClass,e.staticClass),class:r(t.class)?[t.class,e.class]:e.class}}function Oe(t){var e=t.class,n=t.staticClass;return r(n)||r(e)?De(n,Se(e)):""}function De(t,e){return t?e?t+" "+e:t:e||""}function Se(t){if(n(t))return"";if("string"==typeof t)return t;var e="";if(Array.isArray(t)){for(var o,a=0,s=t.length;a-1?bo[t]=e.constructor===window.HTMLUnknownElement||e.constructor===window.HTMLElement:bo[t]=/HTMLUnknownElement/.test(e.toString())}function Me(t){if("string"==typeof t){var e=document.querySelector(t);return e||document.createElement("div")}return t}function je(t,e){var n=document.createElement(t);return"select"!==t?n:(e.data&&e.data.attrs&&void 0!==e.data.attrs.multiple&&n.setAttribute("multiple","multiple"),n)}function Te(t,e){return document.createElementNS(mo[t],e)}function Ne(t){return document.createTextNode(t)}function Ie(t){return document.createComment(t)}function Ve(t,e,n){t.insertBefore(e,n)}function Le(t,e){t.removeChild(e)}function Re(t,e){t.appendChild(e)}function Be(t){return t.parentNode}function Ue(t){return t.nextSibling}function Ye(t){return t.tagName}function Fe(t,e){t.textContent=e}function ze(t,e,n){t.setAttribute(e,n)}function He(t,e){var n=t.data.ref;if(n){var r=t.context,o=t.componentInstance||t.elm,a=r.$refs;e?Array.isArray(a[n])?f(a[n],o):a[n]===o&&(a[n]=void 0):t.data.refInFor?Array.isArray(a[n])&&a[n].indexOf(o)<0?a[n].push(o):a[n]=[o]:a[n]=o}}function Je(t,e){return t.key===e.key&&t.tag===e.tag&&t.isComment===e.isComment&&r(t.data)===r(e.data)&&qe(t,e)}function qe(t,e){if("input"!==t.tag)return!0;var n;return(r(n=t.data)&&r(n=n.attrs)&&n.type)===(r(n=e.data)&&r(n=n.attrs)&&n.type)}function Qe(t,e,n){var o,a,i={};for(o=e;o<=n;++o)a=t[o].key,r(a)&&(i[a]=o);return i}function We(t,e){(t.data.directives||e.data.directives)&&Ke(t,e)}function Ke(t,e){var n,r,o,a=t===Ao,i=e===Ao,s=Ge(t.data.directives,t.context),c=Ge(e.data.directives,e.context),u=[],l=[];for(n in c)r=s[n],o=c[n],r?(o.oldValue=r.value,Xe(o,"update",e,t),o.def&&o.def.componentUpdated&&l.push(o)):(Xe(o,"bind",e,t),o.def&&o.def.inserted&&u.push(o));if(u.length){var d=function(){for(var n=0;n-1?e.split(/\s+/).forEach(function(e){return t.classList.add(e)}):t.classList.add(e);else{var n=" "+(t.getAttribute("class")||"")+" ";n.indexOf(" "+e+" ")<0&&t.setAttribute("class",(n+e).trim())}}function gn(t,e){if(e&&(e=e.trim()))if(t.classList)e.indexOf(" ")>-1?e.split(/\s+/).forEach(function(e){return t.classList.remove(e)}):t.classList.remove(e);else{for(var n=" "+(t.getAttribute("class")||"")+" ",r=" "+e+" ";n.indexOf(r)>=0;)n=n.replace(r," ");t.setAttribute("class",n.trim())}}function yn(t){if(t){if("object"==typeof t){var e={};return!1!==t.css&&g(e,Uo(t.name||"v")),g(e,t),e}return"string"==typeof t?Uo(t):void 0}}function _n(t){Wo(function(){Wo(t)})}function bn(t,e){(t._transitionClasses||(t._transitionClasses=[])).push(e),mn(t,e)}function wn(t,e){t._transitionClasses&&f(t._transitionClasses,e),gn(t,e)}function xn(t,e,n){var r=An(t,e),o=r.type,a=r.timeout,i=r.propCount;if(!o)return n();var s=o===Fo?Jo:Qo,c=0,u=function(){t.removeEventListener(s,l),n()},l=function(e){e.target===t&&++c>=i&&u()};setTimeout(function(){c0&&(n=Fo,l=i,d=a.length):e===zo?u>0&&(n=zo,l=u,d=c.length):(l=Math.max(i,u),n=l>0?i>u?Fo:zo:null,d=n?n===Fo?a.length:c.length:0),{type:n,timeout:l,propCount:d,hasTransform:n===Fo&&Ko.test(r[Ho+"Property"])}}function Cn(t,e){for(;t.length1}function En(t,e){!0!==e.data.show&&$n(e)}function Pn(t,e,n){var r=e.value,o=t.multiple;if(!o||Array.isArray(r)){for(var a,i,s=0,c=t.options.length;s-1,i.selected!==a&&(i.selected=a);else if(b(jn(i),r))return void(t.selectedIndex!==s&&(t.selectedIndex=s));o||(t.selectedIndex=-1)}}function Mn(t,e){for(var n=0,r=e.length;n0,dr=cr&&cr.indexOf("edge/")>0,fr=cr&&cr.indexOf("android")>0,pr=cr&&/iphone|ipad|ipod|ios/.test(cr),hr=cr&&/chrome\/\d+/.test(cr)&&!dr,vr=!1;if(sr)try{var mr={};Object.defineProperty(mr,"passive",{get:function(){vr=!0}}),window.addEventListener("test-passive",null,mr)}catch(t){}var gr,yr,_r=function(){return void 0===gr&&(gr=!sr&&void 0!==t&&"server"===t.process.env.VUE_ENV),gr},br=sr&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,wr="undefined"!=typeof Symbol&&O(Symbol)&&"undefined"!=typeof Reflect&&O(Reflect.ownKeys),xr=function(){function t(){r=!1;var t=n.slice(0);n.length=0;for(var e=0;e1?m(n):n;for(var r=m(arguments,1),o=0,a=n.length;o1&&(e[n[0].trim()]=n[1].trim())}}),e}),No=/^--/,Io=/\s*!important$/,Vo=function(t,e,n){if(No.test(e))t.style.setProperty(e,n);else if(Io.test(n))t.style.setProperty(e,n.replace(Io,""),"important");else{var r=Ro(e);if(Array.isArray(n))for(var o=0,a=n.length;oh?(d=n(o[g+1])?null:o[g+1].elm,y(t,d,o,p,g,a)):p>g&&b(t,e,f,h)}function A(t,e,a,i){if(t!==e){if(o(e.isStatic)&&o(t.isStatic)&&e.key===t.key&&(o(e.isCloned)||o(e.isOnce)))return e.elm=t.elm,void(e.componentInstance=t.componentInstance);var s,c=e.data;r(c)&&r(s=c.hook)&&r(s=s.prepatch)&&s(t,e);var u=e.elm=t.elm,l=t.children,d=e.children;if(r(c)&&v(e)){for(s=0;snew Date(this.notAfter).getTime()?"disabled":(e.push(t.classes),n===i&&e.push("today"),n===r?e.push("current"):o?na?e.push("disabled"):r&&n>=r&&e.push("inrange")),e.join(" "))},showMonths:function(){"months"===this.currentPanel?this.currentPanel="date":this.currentPanel="months"},showYears:function(){if("years"===this.currentPanel)this.currentPanel="date";else{for(var t=10*Math.floor(this.now.getFullYear()/10),e=[],n=0;n<10;n++)e.push(t+n);this.years=e,this.currentPanel="years"}},changeYear:function(t){if("years"===this.currentPanel)this.years=this.years.map(function(e){return e+10*t});else{var e=new Date(this.now);e.setFullYear(e.getFullYear()+t),this.now=e}},changeMonth:function(t){var e=new Date(this.now);e.setMonth(e.getMonth()+t),this.now=e},selectDate:function(t){-1===this.getClasses(t).indexOf("disabled")&&(this.$emit("input",t.date),this.$emit("select"))},selectYear:function(t){var e=new Date(this.now);e.setFullYear(t),this.now=e,this.currentPanel="months"},selectMonth:function(t){var e=new Date(this.now);e.setMonth(t),this.now=e,this.currentPanel="date"}}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(13),o=n.n(r),a=n(5);e.default={components:{CalendarPanel:o.a},props:{format:{type:String,default:"yyyy-MM-dd"},range:{type:Boolean,default:!1},width:{type:[String,Number],default:210},placeholder:String,lang:{type:String,default:"zh"},value:null,disabledDays:{type:Array,default:function(){return[]}},showYearNav:{type:Boolean,default:!0},notBefore:{type:String,default:""},notAfter:{type:String,default:""}},data:function(){return{showPopup:!1,showCloseIcon:!1,currentValue:this.value,position:null,ranges:[]}},watch:{value:{handler:function(t){this.range?this.currentValue=this.isValidRange(t)?t:[void 0,void 0]:this.currentValue=this.isValidDate(t)?t:void 0},immediate:!0},currentValue:function(t){(!this.range&&t||this.range&&t[0]&&t[1])&&this.$emit("input",t)},showPopup:function(t){t&&this.$nextTick(this.displayPopup)}},computed:{translation:function(){return a.a[this.lang]||a.a.en},innerPlaceholder:function(){return this.placeholder||(this.range?this.translation.placeholder.dateRange:this.translation.placeholder.date)},text:function(){return!this.range&&this.currentValue?this.stringify(this.currentValue):this.range&&this.currentValue[0]&&this.currentValue[1]?this.stringify(this.currentValue[0])+" ~ "+this.stringify(this.currentValue[1]):""}},methods:{selectDate:function(t){},closePopup:function(){this.showPopup=!1},togglePopup:function(){this.showPopup?(this.$refs.input.blur(),this.showPopup=!1):(this.$refs.input.focus(),this.showPopup=!0)},hoverIcon:function(t){"mouseenter"===t.type&&this.text&&(this.showCloseIcon=!0),"mouseleave"===t.type&&(this.showCloseIcon=!1)},clickIcon:function(){this.showCloseIcon?this.$emit("input",""):this.togglePopup()},formatDate:function(t,e){var n={"M+":t.getMonth()+1,"[Dd]+":t.getDate(),"[Hh]+":t.getHours(),"m+":t.getMinutes(),"s+":t.getSeconds(),"q+":Math.floor((t.getMonth()+3)/3),S:t.getMilliseconds()},r=e.replace(/[Yy]+/g,function(e){return(""+t.getFullYear()).slice(4-e.length)});return Object.keys(n).forEach(function(t){r=r.replace(new RegExp(t),function(e){var r=""+n[t];return 1===e.length?r:("00"+r).slice(r.length)})}),r},stringify:function(t){return this.formatDate(new Date(t),this.format)},isValidDate:function(t){return!!new Date(t).getTime()},isValidRange:function(t){return Array.isArray(t)&&2===t.length&&this.isValidDate(t[0])&&this.isValidDate(t[1])},selectRange:function(t){this.$emit("input",[t.start,t.end])},initRanges:function(){var t=this;this.ranges=[{text:"未来7天",start:new Date,end:new Date(Date.now()+6048e5)},{text:"未来30天",start:new Date,end:new Date(Date.now()+2592e6)},{text:"最近7天",start:new Date(Date.now()-6048e5),end:new Date},{text:"最近30天",start:new Date(Date.now()-2592e6),end:new Date}],this.ranges.forEach(function(e,n){e.text=t.translation.pickers[n]})},displayPopup:function(){var t=document.documentElement.clientWidth,e=document.documentElement.clientHeight,n=this.$el.getBoundingClientRect(),r=this.$refs.calendar.getBoundingClientRect();this.position={},t-n.lefta[data-v-3d611c10]:hover{color:#1284e7}.calendar__prev-icon[data-v-3d611c10]{float:left}.calendar__next-icon[data-v-3d611c10]{float:right}.calendar-table[data-v-3d611c10]{width:100%;font-size:12px;table-layout:fixed;border-collapse:collapse;border-spacing:0}.calendar-table td[data-v-3d611c10],.calendar-table th[data-v-3d611c10]{width:32px;height:32px;text-align:center}.calendar-table td[data-v-3d611c10]{cursor:pointer}.calendar-month>a[data-v-3d611c10]:hover,.calendar-table td.inrange[data-v-3d611c10],.calendar-table td[data-v-3d611c10]:hover,.calendar-year>a[data-v-3d611c10]:hover{background-color:#eaf8fe}.calendar-month>a.current[data-v-3d611c10],.calendar-table td.current[data-v-3d611c10],.calendar-year>a.current[data-v-3d611c10]{color:#fff;background-color:#1284e7}.calendar-table td.disabled[data-v-3d611c10]{cursor:not-allowed;color:#ccc;background-color:#f3f3f3}.lastMonth[data-v-3d611c10],.nextMonth[data-v-3d611c10]{color:#ddd}.today[data-v-3d611c10]{color:#20a0ff}.calendar-month[data-v-3d611c10],.calendar-year[data-v-3d611c10]{width:100%;height:224px;padding:7px 0;text-align:center}.calendar-year>a[data-v-3d611c10]{display:inline-block;width:40%;margin:1px 5%;line-height:40px}.calendar-month>a[data-v-3d611c10]{display:inline-block;width:30%;line-height:40px;margin:8px 1.5%}",""])},function(t,e,n){e=t.exports=n(0)(),e.push([t.i,".demo{float:left;margin:250px}.label{margin-right:1em}",""])},function(t,e,n){e=t.exports=n(0)(),e.push([t.i,'.datepicker[data-v-6bba66df]{position:relative;display:inline-block;color:#73879c;font:14px/1.5 Helvetica Neue,Helvetica,Arial,Microsoft Yahei,sans-serif}.datepicker [data-v-6bba66df]{box-sizing:border-box}.datepicker-popup[data-v-6bba66df]{position:absolute;width:250px;margin-top:1px;margin-bottom:1px;border:1px solid #d9d9d9;background-color:#fff;box-shadow:0 6px 12px rgba(0,0,0,.175);z-index:1000}.range[data-v-6bba66df]{width:496px}.input[data-v-6bba66df]{display:inline-block;width:100%;height:34px;padding:6px 30px 6px 10px;font-size:14px;line-height:1.4;color:#555;background-color:#fff;border:1px solid #ccc;border-radius:4px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075)}.input-icon[data-v-6bba66df]{top:0;right:0;position:absolute;width:30px;height:100%;color:#888;text-align:center;font-style:normal}.input-icon[data-v-6bba66df]:after{content:"";display:inline-block;width:0;height:100%;vertical-align:middle}.input-icon__calendar[data-v-6bba66df]{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA00lEQVQ4T72SzQ2CQBCF54UGKIES6EAswQq0BS/A3PQ0hAt0oKVQgiVYAkcuZMwSMOyCyRKNe9uf+d6b2Qf6csGtL8sy7vu+Zebn/E5EoiAIwjRNH/PzBUBEGiJqmPniAMw+YeZkFSAiJwA3j45aVT0wsxGitwOjDGDnASBVvU4OLQARRURk9e4CAcSqWn8CLHp3Ae6MXAe/B4yzUeMkz/P9ZgdFUQzFIwD/B4yKgwMTos0OtvzCHcDRJ0gAzlmW1VYSq6oKu66LfQBTjC2AT+Hamxcml5IRpPq3VQAAAABJRU5ErkJggg==);background-position:50%;background-repeat:no-repeat}.input-icon__close[data-v-6bba66df]:before{content:"\\2716";vertical-align:middle}.datepicker-top[data-v-6bba66df]{margin:0 12px;line-height:34px;border-bottom:1px solid rgba(0,0,0,.05)}.datepicker-top>span[data-v-6bba66df]{white-space:nowrap;cursor:pointer}.datepicker-top>span[data-v-6bba66df]:hover{color:#1284e7}.datepicker-top>span[data-v-6bba66df]:after{content:"|";margin:0 10px;color:#48576a}',""])},function(t,e,n){n(18);var r=n(1)(n(7),n(15),"data-v-3d611c10",null);t.exports=r.exports},function(t,e,n){n(20);var r=n(1)(n(8),n(17),"data-v-6bba66df",null);t.exports=r.exports},function(t,e){t.exports={render:function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"calendar"},[n("div",{staticClass:"calendar-header"},[n("a",{directives:[{name:"show",rawName:"v-show",value:t.showYearNav,expression:"showYearNav"}],staticClass:"calendar__prev-icon",on:{click:function(e){t.changeYear(-1)}}},[t._v("«")]),t._v(" "),n("a",{directives:[{name:"show",rawName:"v-show",value:"date"===t.currentPanel,expression:"currentPanel === 'date'"}],staticClass:"calendar__prev-icon",on:{click:function(e){t.changeMonth(-1)}}},[t._v("‹")]),t._v(" "),n("a",{directives:[{name:"show",rawName:"v-show",value:t.showYearNav,expression:"showYearNav"}],staticClass:"calendar__next-icon",on:{click:function(e){t.changeYear(1)}}},[t._v("»")]),t._v(" "),n("a",{directives:[{name:"show",rawName:"v-show",value:"date"===t.currentPanel,expression:"currentPanel === 'date'"}],staticClass:"calendar__next-icon",on:{click:function(e){t.changeMonth(1)}}},[t._v("›")]),t._v(" "),n("a",{on:{click:t.showMonths}},[t._v(t._s(t.months[t.currentMonth]))]),t._v(" "),n("a",{on:{click:t.showYears}},[t._v(t._s(t.currentYear))])]),t._v(" "),n("div",{staticClass:"calendar-content"},[n("table",{directives:[{name:"show",rawName:"v-show",value:"date"===t.currentPanel,expression:"currentPanel === 'date'"}],staticClass:"calendar-table"},[n("thead",[n("tr",t._l(t.days,function(e){return n("th",[t._v(t._s(e))])}))]),t._v(" "),n("tbody",t._l(t.dates,function(e){return n("tr",t._l(e,function(e){return n("td",{class:t.getClasses(e),attrs:{title:e.title},on:{click:function(n){t.selectDate(e)}}},[t._v(t._s(e.day))])}))}))]),t._v(" "),n("div",{directives:[{name:"show",rawName:"v-show",value:"years"===t.currentPanel,expression:"currentPanel === 'years'"}],staticClass:"calendar-year"},t._l(t.years,function(e){return n("a",{class:{current:t.currentYear===e},on:{click:function(n){t.selectYear(e)}}},[t._v(t._s(e))])})),t._v(" "),n("div",{directives:[{name:"show",rawName:"v-show",value:"months"===t.currentPanel,expression:"currentPanel === 'months'"}],staticClass:"calendar-month"},t._l(t.months,function(e,r){return n("a",{class:{current:t.currentMonth===r},on:{click:function(e){t.selectMonth(r)}}},[t._v(t._s(e))])}))])])},staticRenderFns:[]}},function(t,e){t.exports={render:function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{attrs:{id:"app"}},[n("div",{staticClass:"demo"},[n("span",{staticClass:"label"},[t._v("default:")]),t._v(" "),n("date-picker",{attrs:{lang:"en"},model:{value:t.value1,callback:function(e){t.value1=e},expression:"value1"}})],1),t._v(" "),n("div",{staticClass:"demo"},[n("span",{staticClass:"label"},[t._v("range:")]),t._v(" "),n("date-picker",{attrs:{range:"",lang:"zh"},model:{value:t.value2,callback:function(e){t.value2=e},expression:"value2"}})],1)])},staticRenderFns:[]}},function(t,e){t.exports={render:function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{directives:[{name:"clickoutside",rawName:"v-clickoutside",value:t.closePopup,expression:"closePopup"}],staticClass:"datepicker",style:{width:t.width+"px","min-width":t.range?"210px":"140px"}},[n("input",{ref:"input",staticClass:"input",attrs:{readonly:"",placeholder:t.innerPlaceholder},domProps:{value:t.text},on:{click:t.togglePopup,mousedown:function(t){t.preventDefault()}}}),t._v(" "),n("i",{staticClass:"input-icon",class:t.showCloseIcon?"input-icon__close":"input-icon__calendar",on:{mouseenter:t.hoverIcon,mouseleave:t.hoverIcon,click:t.clickIcon}}),t._v(" "),n("div",{directives:[{name:"show",rawName:"v-show",value:t.showPopup,expression:"showPopup"}],ref:"calendar",staticClass:"datepicker-popup",class:{range:t.range},style:t.position},[t.range?[n("div",{staticClass:"datepicker-top"},t._l(t.ranges,function(e){return n("span",{on:{click:function(n){t.selectRange(e)}}},[t._v(t._s(e.text))])})),t._v(" "),n("calendar-panel",{staticStyle:{width:"50%","box-shadow":"1px 0 rgba(0, 0, 0, .1)"},attrs:{"end-at":t.currentValue[1],show:t.showPopup,disabledDays:t.disabledDays,showYearNav:t.showYearNav,notBefore:t.notBefore,notAfter:t.notAfter},model:{value:t.currentValue[0],callback:function(e){var n=t.currentValue;Array.isArray(n)?n.splice(0,1,e):t.currentValue[0]=e},expression:"currentValue[0]"}}),t._v(" "),n("calendar-panel",{staticStyle:{width:"50%"},attrs:{"start-at":t.currentValue[0],show:t.showPopup,disabledDays:t.disabledDays,showYearNav:t.showYearNav,notBefore:t.notBefore,notAfter:t.notAfter},model:{value:t.currentValue[1],callback:function(e){var n=t.currentValue;Array.isArray(n)?n.splice(1,1,e):t.currentValue[1]=e},expression:"currentValue[1]"}})]:[n("calendar-panel",{attrs:{show:t.showPopup,disabledDays:t.disabledDays,showYearNav:t.showYearNav,notBefore:t.notBefore,notAfter:t.notAfter},on:{select:function(e){t.showPopup=!1}},model:{value:t.currentValue,callback:function(e){t.currentValue=e},expression:"currentValue"}})]],2)])},staticRenderFns:[]}},function(t,e,n){var r=n(10);"string"==typeof r&&(r=[[t.i,r,""]]),r.locals&&(t.exports=r.locals);n(2)("1b4d20bb",r,!0)},function(t,e,n){var r=n(11);"string"==typeof r&&(r=[[t.i,r,""]]),r.locals&&(t.exports=r.locals);n(2)("6c008236",r,!0)},function(t,e,n){var r=n(12);"string"==typeof r&&(r=[[t.i,r,""]]),r.locals&&(t.exports=r.locals);n(2)("592f1982",r,!0)},function(t,e){t.exports=function(t,e){for(var n=[],r={},o=0;o
+
+
+
+ vue2-datepicker
+
+
+
+
+
+
diff --git a/package.json b/package.json
index 39bb1ac..fb2bee5 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "vue2-datepicker",
"description": "A Datepicker Component For Vue2",
"main": "datepicker/index.vue",
- "version": "1.2.1",
+ "version": "1.5.0",
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
diff --git a/webpack.config.js b/webpack.config.js
new file mode 100644
index 0000000..a94ae79
--- /dev/null
+++ b/webpack.config.js
@@ -0,0 +1,71 @@
+var path = require('path')
+var webpack = require('webpack')
+
+module.exports = {
+ entry: './demo/main.js',
+ output: {
+ path: path.resolve(__dirname, './dist'),
+ publicPath: '/dist/',
+ filename: 'build.js'
+ },
+ module: {
+ rules: [
+ {
+ test: /\.vue$/,
+ loader: 'vue-loader',
+ options: {
+ loaders: {
+ }
+ // other vue-loader options go here
+ }
+ },
+ {
+ test: /\.js$/,
+ loader: 'babel-loader',
+ exclude: /node_modules/
+ },
+ {
+ test: /\.(png|jpg|gif|svg)$/,
+ loader: 'file-loader',
+ options: {
+ name: '[name].[ext]?[hash]'
+ }
+ }
+ ]
+ },
+ resolve: {
+ alias: {
+ // 'vue$': 'vue/dist/vue.esm.js'
+ }
+ },
+ devServer: {
+ historyApiFallback: true,
+ noInfo: true,
+ port: 9000
+ },
+ performance: {
+ hints: false
+ },
+ devtool: '#eval-source-map'
+}
+
+if (process.env.NODE_ENV === 'production') {
+ module.exports.devtool = '#source-map'
+ // http://vue-loader.vuejs.org/en/workflow/production.html
+ module.exports.plugins = (module.exports.plugins || []).concat([
+ new webpack.DefinePlugin({
+ 'process.env': {
+ NODE_ENV: '"production"'
+ }
+ }),
+ new webpack.optimize.UglifyJsPlugin({
+ sourceMap: false,
+ compress: {
+ warnings: false
+ }
+ }),
+ new webpack.LoaderOptionsPlugin({
+ minimize: true
+ })
+ ])
+}