mirror of https://github.com/ElemeFE/element
Calendar: add first-day-of-week attribute (#16047)
parent
4069f37ef0
commit
e2303b85a4
|
@ -54,9 +54,10 @@ Display date.
|
||||||
|
|
||||||
### Attributes
|
### Attributes
|
||||||
| Attribute | Description | Type | Accepted Values | Default |
|
| Attribute | Description | Type | Accepted Values | Default |
|
||||||
|-----------------|-------------- |---------- |---------------------- |--------- |
|
|-----------------|------------------- |---------- |---------------------- |--------- |
|
||||||
| value / v-model | binding value | Date/string/number | — | — |
|
| value / v-model | binding value | Date/string/number | — | — |
|
||||||
| range | time range, including start time and end time. Start time must be Monday, end time must be Sunday, the time span cannot exceed two months | Array | — | — |
|
| range | time range, including start time and end time. Start time must be Monday, end time must be Sunday, the time span cannot exceed two months | Array | — | — |
|
||||||
|
| first-day-of-week | fisrt day of week| Number | 1 to 7 | 1 |
|
||||||
|
|
||||||
### dateCell scoped slot 参数
|
### dateCell scoped slot 参数
|
||||||
| Attribute | Description | Type | Accepted Values | Default |
|
| Attribute | Description | Type | Accepted Values | Default |
|
||||||
|
|
|
@ -55,9 +55,10 @@ Muestra fechas.
|
||||||
|
|
||||||
### Atributos
|
### Atributos
|
||||||
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto |
|
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto |
|
||||||
|-----------------|-------------- |---------- |---------------------- |--------- |
|
|-----------------|------------------- |---------- |---------------------- |------------ |
|
||||||
| value / v-model | valor vinculante | Date/string/number | — | — |
|
| value / v-model | valor vinculante | Date/string/number | — | — |
|
||||||
| range | rango de tiempo, incluyendo el tiempo de inicio y el tiempo final. El tiempo de inicio debe ser el lunes, el tiempo final debe ser el domingo, el período no puede exceder los dos meses. | Array | — | — |
|
| range | rango de tiempo, incluyendo el tiempo de inicio y el tiempo final. El tiempo de inicio debe ser el lunes, el tiempo final debe ser el domingo, el período no puede exceder los dos meses. | Array | — | — |
|
||||||
|
| first-day-of-week | fisrt day of week| Number | 1 to 7 | 1 |
|
||||||
|
|
||||||
### dateCell scoped slot
|
### dateCell scoped slot
|
||||||
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto |
|
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto |
|
||||||
|
|
|
@ -55,9 +55,10 @@ Affiche un calendrier.
|
||||||
### Attributs
|
### Attributs
|
||||||
|
|
||||||
| Attribut | Description | Type | Valeurs acceptées | Défaut |
|
| Attribut | Description | Type | Valeurs acceptées | Défaut |
|
||||||
|-----------------|-------------- |---------- |---------------------- |--------- |
|
|------------------ |-------------- |---------- |---------------------- |--------- |
|
||||||
| value / v-model | Valeur liée. | Date/string/number | — | — |
|
| value / v-model | Valeur liée. | Date/string/number | — | — |
|
||||||
| range | Intervalle de dates, début et fin inclus. Le début doit être un lundi et la fin un dimanche, l'intervalle ne pouvant excéder deux mois. | Array | — | — |
|
| range | Intervalle de dates, début et fin inclus. Le début doit être un lundi et la fin un dimanche, l'intervalle ne pouvant excéder deux mois. | Array | — | — |
|
||||||
|
| first-day-of-week | fisrt day of week| Number | 1 to 7 | 1 |
|
||||||
|
|
||||||
### Slot dateCell
|
### Slot dateCell
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
|-----------------|-------------- |---------- |------------ |-------- |
|
|-----------------|-------------- |---------- |------------ |-------- |
|
||||||
| value / v-model | 绑定值 | Date/string/number | — | — |
|
| value / v-model | 绑定值 | Date/string/number | — | — |
|
||||||
| range | 时间范围,包括开始时间与结束时间。开始时间必须是周一,结束时间必须是周日,且时间跨度不能超过两个月。 | Array | — | — |
|
| range | 时间范围,包括开始时间与结束时间。开始时间必须是周一,结束时间必须是周日,且时间跨度不能超过两个月。 | Array | — | — |
|
||||||
|
| first-day-of-week | 周起始日 | Number | 1 到 7 | 1 |
|
||||||
|
|
||||||
### dateCell scoped slot 参数
|
### dateCell scoped slot 参数
|
||||||
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<script>
|
<script>
|
||||||
import fecha from 'element-ui/src/utils/date';
|
import fecha from 'element-ui/src/utils/date';
|
||||||
import { range as rangeArr, getFirstDayOfMonth, getPrevMonthLastDays, getMonthDays, getI18nSettings, validateRangeInOneMonth } from 'element-ui/src/utils/date-util';
|
import { range as rangeArr, getFirstDayOfMonth, getPrevMonthLastDays, getMonthDays, getI18nSettings, validateRangeInOneMonth } from 'element-ui/src/utils/date-util';
|
||||||
export default {
|
|
||||||
|
|
||||||
|
const WEEK_DAYS = getI18nSettings().dayNames;
|
||||||
|
export default {
|
||||||
props: {
|
props: {
|
||||||
selectedDay: String, // formated date yyyy-MM-dd
|
selectedDay: String, // formated date yyyy-MM-dd
|
||||||
range: {
|
range: {
|
||||||
|
@ -14,7 +15,8 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
date: Date,
|
date: Date,
|
||||||
hideHeader: Boolean
|
hideHeader: Boolean,
|
||||||
|
firstDayOfWeek: Number
|
||||||
},
|
},
|
||||||
|
|
||||||
inject: ['elCalendar'],
|
inject: ['elCalendar'],
|
||||||
|
@ -119,7 +121,8 @@ export default {
|
||||||
const date = this.date;
|
const date = this.date;
|
||||||
let firstDay = getFirstDayOfMonth(date);
|
let firstDay = getFirstDayOfMonth(date);
|
||||||
firstDay = firstDay === 0 ? 7 : firstDay;
|
firstDay = firstDay === 0 ? 7 : firstDay;
|
||||||
const prevMonthDays = getPrevMonthLastDays(date, firstDay - 1).map(day => ({
|
const firstDayOfWeek = typeof this.firstDayOfWeek === 'number' ? this.firstDayOfWeek : 1;
|
||||||
|
const prevMonthDays = getPrevMonthLastDays(date, firstDay - firstDayOfWeek).map(day => ({
|
||||||
text: day,
|
text: day,
|
||||||
type: 'prev'
|
type: 'prev'
|
||||||
}));
|
}));
|
||||||
|
@ -135,20 +138,22 @@ export default {
|
||||||
days = days.concat(nextMonthDays);
|
days = days.concat(nextMonthDays);
|
||||||
}
|
}
|
||||||
return this.toNestedArr(days);
|
return this.toNestedArr(days);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
weekDays() {
|
||||||
const dayNames = getI18nSettings().dayNames;
|
const start = this.firstDayOfWeek;
|
||||||
return {
|
if (typeof start !== 'number' || start === 0) {
|
||||||
DAYS: dayNames.slice(1).concat(dayNames[0])
|
return WEEK_DAYS.slice();
|
||||||
};
|
} else {
|
||||||
|
return WEEK_DAYS.slice(start).concat(WEEK_DAYS.slice(0, start));
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const thead = this.hideHeader ? null : (<thead>
|
const thead = this.hideHeader ? null : (<thead>
|
||||||
{
|
{
|
||||||
this.DAYS.map(day => <th key={day}>{ day }</th>)
|
this.weekDays.map(day => <th key={day}>{ day }</th>)
|
||||||
}
|
}
|
||||||
</thead>);
|
</thead>);
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
<date-table
|
<date-table
|
||||||
:date="date"
|
:date="date"
|
||||||
:selected-day="realSelectedDay"
|
:selected-day="realSelectedDay"
|
||||||
|
:first-day-of-week="realFirstDayOfWeek"
|
||||||
@pick="pickDay" />
|
@pick="pickDay" />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
@ -86,6 +87,10 @@ export default {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
firstDayOfWeek: {
|
||||||
|
type: Number,
|
||||||
|
default: 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -238,6 +243,13 @@ export default {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
|
},
|
||||||
|
|
||||||
|
realFirstDayOfWeek() {
|
||||||
|
if (this.firstDayOfWeek < 1 || this.firstDayOfWeek > 6) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return Math.floor(this.firstDayOfWeek);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -66,5 +66,24 @@ describe('Calendar', () => {
|
||||||
expect(/2019.*5/.test(titleEl.innerText)).to.be.true;
|
expect(/2019.*5/.test(titleEl.innerText)).to.be.true;
|
||||||
expect(cell.classList.contains('is-selected')).to.be.true;
|
expect(cell.classList.contains('is-selected')).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('firstDayOfWeek', async() => {
|
||||||
|
vm = createVue({
|
||||||
|
template: `
|
||||||
|
<el-calendar v-model="value" :first-day-of-week="0"></el-calendar>
|
||||||
|
`,
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
value: new Date('2019-04-01')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
const head = vm.$el.querySelector('.el-calendar-table thead');
|
||||||
|
expect(head.firstElementChild.innerText).to.be.equal('日');
|
||||||
|
expect(head.lastElementChild.innerText).to.be.equal('六');
|
||||||
|
const firstRow = vm.$el.querySelector('.el-calendar-table__row');
|
||||||
|
expect(firstRow.firstElementChild.innerText).to.be.equal('31');
|
||||||
|
expect(firstRow.lastElementChild.innerText).to.be.equal('6');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -9,4 +9,7 @@ export declare class ElCalendar extends ElementUIComponent {
|
||||||
|
|
||||||
/** Specify the display range of the calendar */
|
/** Specify the display range of the calendar */
|
||||||
range: DateType[]
|
range: DateType[]
|
||||||
|
|
||||||
|
/** First day of week */
|
||||||
|
firstDayOfWeek: number
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue