Skip to content

Commit fad244c

Browse files
committed
chore(release): Merge branch 'dev' into master
2 parents 0a95b9b + 7d0a5ef commit fad244c

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

src/components/calendar/CalendarCtrl.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,21 @@ const lunnarFestivals = {
4848
'腊月廿三': '小年'
4949
};
5050

51+
const dateRange = {
52+
preMinDate: new Date(1900, 1, 1),
53+
preMaxDate: new Date((new Date()).getFullYear() + 30, 11, 1),
54+
minDate: new Date(1900, 0, 1), // 闭
55+
maxDate: new Date((new Date()).getFullYear() + 31, 0, 1) // 开
56+
};
57+
58+
const MIN_YEAR = 1900;
59+
const MAX_YEAR = new Date().getFullYear() + 30;
60+
5161

5262
const yearList = (function() {
53-
const end = new Date().getFullYear() + 30,
54-
result = [];
63+
const result = [];
5564

56-
for (let i = 1900; i <= end; i += 1) {
65+
for (let i = MIN_YEAR; i <= MAX_YEAR; i += 1) {
5766
result.push(i + '');
5867
}
5968

@@ -99,10 +108,25 @@ export default class DatePickerCtrl {
99108
return this.DISPLAY_FORMAT[this.displayFormat] === 2;
100109
}
101110

111+
setLGButtonStatus() {
112+
if (this.parts.month === '0' && this.parts.year === MIN_YEAR + '') {
113+
this.disabledL = true;
114+
} else {
115+
this.disabledL = false;
116+
}
117+
118+
if (this.parts.month === '11' && this.parts.year === MAX_YEAR + '') {
119+
this.disabledG = true;
120+
} else {
121+
this.disabledG = false;
122+
}
123+
}
124+
102125
/**
103126
* 改变月份
104127
*/
105128
changeMonth() {
129+
this.setLGButtonStatus();
106130
this.value = new Date(new Date(this.value).setMonth(this.parts.month));
107131
}
108132

@@ -111,6 +135,7 @@ export default class DatePickerCtrl {
111135
* 改变年份
112136
*/
113137
changeYear() {
138+
this.setLGButtonStatus();
114139
this.value = new Date(new Date(this.value).setFullYear(this.parts.year));
115140
}
116141

@@ -273,7 +298,23 @@ export default class DatePickerCtrl {
273298
*/
274299
switchMonth(delta) {
275300
if (this.disableYear || this.disableMonth) return;
276-
this.value = new Date(new Date(this.value).setMonth(this.value.getMonth() + delta));
301+
const newDate = new Date(new Date(this.value).setMonth(this.value.getMonth() + delta));
302+
303+
if (newDate < dateRange.preMinDate) {
304+
this.disabledL = true;
305+
} else {
306+
this.disabledL = false;
307+
}
308+
309+
if (newDate >= dateRange.preMaxDate) {
310+
this.disabledG = true;
311+
} else {
312+
this.disabledG = false;
313+
}
314+
315+
if (newDate >= dateRange.minDate && newDate < dateRange.maxDate) {
316+
this.value = newDate;
317+
}
277318
};
278319

279320

src/components/calendar/calendar.tpl.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div class="calendar" ng-click="ctrl.preventDefault($event)">
22
<div class="calendar-header" ng-hide="ctrl.hideMonth()">
3-
<span class="calendar-prev iconfont icon-rightarrow" ng-style="{'visibility': ctrl.hideYear() ? 'hidden' : 'inherit'}" ng-click="ctrl.switchMonth(-1)"></span><select ng-model="ctrl.parts.month"
3+
<span class="calendar-prev iconfont icon-rightarrow" ng-style="{'visibility': ctrl.hideYear() ? 'hidden' : 'inherit', 'cursor': ctrl.disabledL ? 'not-allowed' : 'pointer'}" ng-click="ctrl.switchMonth(-1)"></span><select ng-model="ctrl.parts.month"
44
ng-options="index as month for (index, month) in ctrl.months" ng-disabled="ctrl.disableMonth" ng-hide="ctrl.hideMonth()"
55
ng-change="ctrl.changeMonth()"></select><select ng-model="ctrl.parts.year"
66
ng-options="year for year in ctrl.years" ng-disabled="ctrl.disableYear" ng-hide="ctrl.hideYear()"
7-
ng-change="ctrl.changeYear()"></select><span class="calendar-next iconfont icon-rightarrow" ng-style="{'visibility': ctrl.hideYear() ? 'hidden' : 'inherit'}" ng-click="ctrl.switchMonth(1)"></span>
7+
ng-change="ctrl.changeYear()"></select><span class="calendar-next iconfont icon-rightarrow" ng-style="{'visibility': ctrl.hideYear() ? 'hidden' : 'inherit', 'cursor': ctrl.disabledG ? 'not-allowed' : 'pointer'}" ng-click="ctrl.switchMonth(1)"></span>
88
</div>
99

1010
<ul class="calendar-week-title">

src/components/date-picker/_date-picker.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ $normal-color: #c9c9c9;
4949
&.disabledInput .date-picker-input {
5050
background: #fff;
5151
color: #3d3d3d;
52+
pointer-events: none;
5253
}
5354

5455
.date-picker-input-year {

0 commit comments

Comments
 (0)