|
@@ -50,6 +50,7 @@
|
|
|
:selected-day="realSelectedDay"
|
|
|
:range="range"
|
|
|
:hide-header="index !== 0"
|
|
|
+ :first-day-of-week="realFirstDayOfWeek"
|
|
|
@pick="pickDay" />
|
|
|
</div>
|
|
|
</div>
|
|
@@ -62,6 +63,7 @@ import DateTable from './date-table';
|
|
|
import { validateRangeInOneMonth } from 'element-ui/src/utils/date-util';
|
|
|
|
|
|
const validTypes = ['prev-month', 'today', 'next-month'];
|
|
|
+const weekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
|
const oneDay = 86400000;
|
|
|
|
|
|
export default {
|
|
@@ -127,6 +129,17 @@ export default {
|
|
|
throw new Error('invalid val');
|
|
|
}
|
|
|
return val instanceof Date ? val : new Date(val);
|
|
|
+ },
|
|
|
+
|
|
|
+ rangeValidator(date, isStart) {
|
|
|
+ const firstDayOfWeek = this.realFirstDayOfWeek;
|
|
|
+ const expected = isStart ? firstDayOfWeek : (firstDayOfWeek === 0 ? 6 : firstDayOfWeek - 1);
|
|
|
+ const message = `${isStart ? 'start' : 'end'} of range should be ${weekDays[expected]}.`;
|
|
|
+ if (date.getDay() !== expected) {
|
|
|
+ console.warn('[ElementCalendar]', message, 'Invalid range will be ignored.');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -189,21 +202,9 @@ export default {
|
|
|
validatedRange() {
|
|
|
let range = this.range;
|
|
|
if (!range) return [];
|
|
|
- const expetedMap = {
|
|
|
- 0: {
|
|
|
- value: 1,
|
|
|
- message: 'start of range should be Monday.'
|
|
|
- },
|
|
|
- 1: {
|
|
|
- value: 0,
|
|
|
- message: 'end of range should be Sunday.'
|
|
|
- }
|
|
|
- };
|
|
|
range = range.reduce((prev, val, index) => {
|
|
|
const date = this.toDate(val);
|
|
|
- if (date.getDay() !== expetedMap[index].value) {
|
|
|
- console.warn('[ElementCalendar]', expetedMap[index].message, ' invalid range will be ignored');
|
|
|
- } else {
|
|
|
+ if (this.rangeValidator(date, index === 0)) {
|
|
|
prev = prev.concat(date);
|
|
|
}
|
|
|
return prev;
|
|
@@ -227,12 +228,23 @@ export default {
|
|
|
console.warn('[ElementCalendar]start time and end time interval must not exceed two months');
|
|
|
return [];
|
|
|
}
|
|
|
+ // 第一个月的时间范围
|
|
|
data.push([
|
|
|
start,
|
|
|
lastDay
|
|
|
]);
|
|
|
- let interval = startDay.getDay();
|
|
|
- interval = interval <= 1 ? Math.abs(interval - 1) : (8 - interval);
|
|
|
+ // 下一月的时间范围,需要计算一下该月的第一个周起始日
|
|
|
+ const firstDayOfWeek = this.realFirstDayOfWeek;
|
|
|
+ const nextMontFirstDay = startDay.getDay();
|
|
|
+ let interval = 0;
|
|
|
+ if (nextMontFirstDay !== firstDayOfWeek) {
|
|
|
+ if (firstDayOfWeek === 0) {
|
|
|
+ interval = 7 - nextMontFirstDay;
|
|
|
+ } else {
|
|
|
+ interval = firstDayOfWeek - nextMontFirstDay;
|
|
|
+ interval = interval > 0 ? interval : 7 + interval;
|
|
|
+ }
|
|
|
+ }
|
|
|
startDay = this.toDate(startDay.getTime() + interval * oneDay);
|
|
|
if (startDay.getDate() < end.getDate()) {
|
|
|
data.push([
|