Add week numbers
This commit is contained in:
parent
ac231c9ab4
commit
e55ba7a249
7 changed files with 65 additions and 71 deletions
|
@ -165,6 +165,8 @@
|
||||||
<br>
|
<br>
|
||||||
<Date-picker type="date" multiple style="width: 200px"></Date-picker> | Single date, multiple
|
<Date-picker type="date" multiple style="width: 200px"></Date-picker> | Single date, multiple
|
||||||
<br>
|
<br>
|
||||||
|
<Date-picker type="date" multiple style="width: 200px" show-week-numbers></Date-picker> | Single date, multiple, show week numbers
|
||||||
|
<br>
|
||||||
<Date-picker type="date" format="yyyy-MM-dd HH:mm" placeholder="选择日期和时间(不含秒)" style="width: 200px"></Date-picker> | Single date, format MM-dd HH:mm
|
<Date-picker type="date" format="yyyy-MM-dd HH:mm" placeholder="选择日期和时间(不含秒)" style="width: 200px"></Date-picker> | Single date, format MM-dd HH:mm
|
||||||
<br>
|
<br>
|
||||||
<Date-picker type="datetime" :start-date="minDate" v-model="singleDate" placeholder="选择日期和时间" style="width: 200px"></Date-picker> | Single datetime, date object, start date
|
<Date-picker type="datetime" :start-date="minDate" v-model="singleDate" placeholder="选择日期和时间" style="width: 200px"></Date-picker> | Single datetime, date object, start date
|
||||||
|
|
|
@ -7,18 +7,19 @@
|
||||||
</div>
|
</div>
|
||||||
<span
|
<span
|
||||||
:class="getCellCls(cell)"
|
:class="getCellCls(cell)"
|
||||||
v-for="cell in readCells"
|
v-for="(cell, i) in readCells"
|
||||||
|
:key="String(cell.date) + i"
|
||||||
@click="handleClick(cell)"
|
@click="handleClick(cell)"
|
||||||
@mouseenter="handleMouseMove(cell)"
|
@mouseenter="handleMouseMove(cell)"
|
||||||
>
|
>
|
||||||
<em>{{ cell.text }}</em>
|
<em>{{ cell.desc }}</em>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { getFirstDayOfMonth, getDayCountOfMonth, clearHours, isInRange } from '../util';
|
import { clearHours, isInRange } from '../util';
|
||||||
import { deepCopy } from '../../../utils/assist';
|
|
||||||
import Locale from '../../../mixins/locale';
|
import Locale from '../../../mixins/locale';
|
||||||
|
import jsCalendar from 'js-calendar';
|
||||||
|
|
||||||
import mixin from './mixin';
|
import mixin from './mixin';
|
||||||
import prefixCls from './prefixCls';
|
import prefixCls from './prefixCls';
|
||||||
|
@ -29,16 +30,25 @@
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
/* more props in mixin */
|
/* more props in mixin */
|
||||||
|
showWeekNumbers: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
|
const weekStartDay = Number(this.t('i.datepicker.weekStartDay'));
|
||||||
return {
|
return {
|
||||||
prefixCls: prefixCls,
|
prefixCls: prefixCls,
|
||||||
|
calendar: new jsCalendar.Generator({onlyDays: !this.showWeekNumbers, weekStart: weekStartDay})
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
classes () {
|
classes () {
|
||||||
return [
|
return [
|
||||||
`${prefixCls}`
|
`${prefixCls}`,
|
||||||
|
{
|
||||||
|
[`${prefixCls}-show-week-numbers`]: this.showWeekNumbers
|
||||||
|
}
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
headerDays () {
|
headerDays () {
|
||||||
|
@ -47,76 +57,32 @@
|
||||||
return this.t('i.datepicker.weeks.' + item);
|
return this.t('i.datepicker.weeks.' + item);
|
||||||
});
|
});
|
||||||
const weekDays = translatedDays.splice(weekStartDay, 7 - weekStartDay).concat(translatedDays.splice(0, weekStartDay));
|
const weekDays = translatedDays.splice(weekStartDay, 7 - weekStartDay).concat(translatedDays.splice(0, weekStartDay));
|
||||||
return weekDays;
|
return this.showWeekNumbers ? [''].concat(weekDays) : weekDays;
|
||||||
},
|
},
|
||||||
readCells () {
|
readCells () {
|
||||||
const tableYear = this.tableDate.getFullYear();
|
const tableYear = this.tableDate.getFullYear();
|
||||||
const tableMonth = this.tableDate.getMonth();
|
const tableMonth = this.tableDate.getMonth();
|
||||||
const date = new Date(tableYear, tableMonth, 1);
|
|
||||||
const weekStartDay = Number(this.t('i.datepicker.weekStartDay'));
|
|
||||||
const day = (getFirstDayOfMonth(date) || 7) - weekStartDay; // day of first day
|
|
||||||
const today = clearHours(new Date()); // timestamp of today
|
const today = clearHours(new Date()); // timestamp of today
|
||||||
const selectedDays = this.dates.filter(Boolean).map(clearHours); // timestamp of selected days
|
const selectedDays = this.dates.filter(Boolean).map(clearHours); // timestamp of selected days
|
||||||
const [minDay, maxDay] = this.dates.map(clearHours);
|
const [minDay, maxDay] = this.dates.map(clearHours);
|
||||||
const rangeStart = this.rangeState.from && clearHours(this.rangeState.from);
|
const rangeStart = this.rangeState.from && clearHours(this.rangeState.from);
|
||||||
const rangeEnd = this.rangeState.to && clearHours(this.rangeState.to);
|
const rangeEnd = this.rangeState.to && clearHours(this.rangeState.to);
|
||||||
|
|
||||||
const dateCountOfMonth = getDayCountOfMonth(date.getFullYear(), date.getMonth());
|
const isRange = this.selectionMode === 'range';
|
||||||
const dateCountOfLastMonth = getDayCountOfMonth(date.getFullYear(), (date.getMonth() === 0 ? 11 : date.getMonth() - 1));
|
const disabledTestFn = typeof this.disabledDate === 'function' && this.disabledDate;
|
||||||
|
|
||||||
const disabledDate = this.disabledDate;
|
return this.calendar(tableYear, tableMonth, (cell) => {
|
||||||
|
const time = cell.date && clearHours(cell.date);
|
||||||
let cells = [];
|
return {
|
||||||
const cell_tmpl = {
|
...cell,
|
||||||
text: '',
|
type: time === today ? 'today' : cell.type,
|
||||||
type: '',
|
selected: selectedDays.includes(time),
|
||||||
date: null,
|
disabled: (cell.date && disabledTestFn) && disabledTestFn(new Date(time)),
|
||||||
selected: false,
|
range: isRange && isInRange(time, rangeStart, rangeEnd),
|
||||||
disabled: false,
|
start: isRange && time === minDay,
|
||||||
range: false,
|
end: isRange && time === maxDay
|
||||||
start: false,
|
};
|
||||||
end: false
|
}).cells.slice(8);
|
||||||
};
|
|
||||||
if (day !== 7) {
|
|
||||||
for (let i = 0; i < day; i++) {
|
|
||||||
const cell = deepCopy(cell_tmpl);
|
|
||||||
cell.type = 'prev-month';
|
|
||||||
cell.text = dateCountOfLastMonth - (day - 1) + i;
|
|
||||||
cell.date = new Date(tableYear, tableMonth - 1, cell.text);
|
|
||||||
const time = clearHours(cell.date);
|
|
||||||
cell.disabled = typeof disabledDate === 'function' && disabledDate(new Date(time));
|
|
||||||
cells.push(cell);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 1; i <= dateCountOfMonth; i++) {
|
|
||||||
const cell = deepCopy(cell_tmpl);
|
|
||||||
cell.text = i;
|
|
||||||
cell.date = new Date(tableYear, tableMonth, cell.text);
|
|
||||||
const time = clearHours(cell.date);
|
|
||||||
cell.type = time === today ? 'today' : 'normal';
|
|
||||||
cell.selected = selectedDays.includes(time);
|
|
||||||
cell.disabled = typeof disabledDate === 'function' && disabledDate(new Date(time));
|
|
||||||
if (this.selectionMode === 'range'){
|
|
||||||
cell.range = isInRange(time, rangeStart, rangeEnd);
|
|
||||||
cell.start = time === minDay;
|
|
||||||
cell.end = time === maxDay;
|
|
||||||
}
|
|
||||||
cells.push(cell);
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextMonthCount = 42 - cells.length;
|
|
||||||
for (let i = 1; i <= nextMonthCount; i++) {
|
|
||||||
const cell = deepCopy(cell_tmpl);
|
|
||||||
cell.type = 'next-month';
|
|
||||||
cell.text = i;
|
|
||||||
cell.date = new Date(tableYear, tableMonth + 1, cell.text);
|
|
||||||
const time = clearHours(cell.date);
|
|
||||||
cell.disabled = typeof disabledDate === 'function' && disabledDate(new Date(time));
|
|
||||||
cells.push(cell);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cells;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -127,8 +93,9 @@
|
||||||
[`${prefixCls}-cell-selected`]: cell.selected || cell.start || cell.end,
|
[`${prefixCls}-cell-selected`]: cell.selected || cell.start || cell.end,
|
||||||
[`${prefixCls}-cell-disabled`]: cell.disabled,
|
[`${prefixCls}-cell-disabled`]: cell.disabled,
|
||||||
[`${prefixCls}-cell-today`]: cell.type === 'today',
|
[`${prefixCls}-cell-today`]: cell.type === 'today',
|
||||||
[`${prefixCls}-cell-prev-month`]: cell.type === 'prev-month',
|
[`${prefixCls}-cell-prev-month`]: cell.type === 'prevMonth',
|
||||||
[`${prefixCls}-cell-next-month`]: cell.type === 'next-month',
|
[`${prefixCls}-cell-next-month`]: cell.type === 'nextMonth',
|
||||||
|
[`${prefixCls}-cell-week-label`]: cell.type === 'weekLabel',
|
||||||
[`${prefixCls}-cell-range`]: cell.range && !cell.start && !cell.end
|
[`${prefixCls}-cell-range`]: cell.range && !cell.start && !cell.end
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -36,6 +36,10 @@ export default {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => [initTimeDate(), initTimeDate()]
|
default: () => [initTimeDate(), initTimeDate()]
|
||||||
},
|
},
|
||||||
|
showWeekNumbers: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
startDate: {
|
startDate: {
|
||||||
type: Date
|
type: Date
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
selection-mode="range"
|
selection-mode="range"
|
||||||
:disabled-date="disabledDate"
|
:disabled-date="disabledDate"
|
||||||
:range-state="rangeState"
|
:range-state="rangeState"
|
||||||
|
:show-week-numbers="showWeekNumbers"
|
||||||
:value="dates"
|
:value="dates"
|
||||||
@on-change-range="handleChangeRange"
|
@on-change-range="handleChangeRange"
|
||||||
@on-pick="handleRangePick"
|
@on-pick="handleRangePick"
|
||||||
|
@ -75,6 +76,7 @@
|
||||||
selection-mode="range"
|
selection-mode="range"
|
||||||
:range-state="rangeState"
|
:range-state="rangeState"
|
||||||
:disabled-date="disabledDate"
|
:disabled-date="disabledDate"
|
||||||
|
:show-week-numbers="showWeekNumbers"
|
||||||
:value="dates"
|
:value="dates"
|
||||||
@on-change-range="handleChangeRange"
|
@on-change-range="handleChangeRange"
|
||||||
@on-pick="handleRangePick"
|
@on-pick="handleRangePick"
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
ref="pickerTable"
|
ref="pickerTable"
|
||||||
v-if="currentView !== 'time'"
|
v-if="currentView !== 'time'"
|
||||||
:table-date="panelDate"
|
:table-date="panelDate"
|
||||||
|
:show-week-numbers="showWeekNumbers"
|
||||||
:value="dates"
|
:value="dates"
|
||||||
:selection-mode="selectionMode"
|
:selection-mode="selectionMode"
|
||||||
:disabled-date="disabledDate"
|
:disabled-date="disabledDate"
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
@on-click="handleIconClick"
|
@on-click="handleIconClick"
|
||||||
@mouseenter.native="handleInputMouseenter"
|
@mouseenter.native="handleInputMouseenter"
|
||||||
@mouseleave.native="handleInputMouseleave"
|
@mouseleave.native="handleInputMouseleave"
|
||||||
:icon="iconType"></i-input>
|
|
||||||
|
:icon="iconType"
|
||||||
|
></i-input>
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
<transition :name="transition">
|
<transition :name="transition">
|
||||||
|
@ -41,6 +43,7 @@
|
||||||
:value="internalValue"
|
:value="internalValue"
|
||||||
:start-date="startDate"
|
:start-date="startDate"
|
||||||
:split-panels="splitPanels"
|
:split-panels="splitPanels"
|
||||||
|
:show-week-numbers="showWeekNumbers"
|
||||||
|
|
||||||
v-bind="ownPickerProps"
|
v-bind="ownPickerProps"
|
||||||
|
|
||||||
|
@ -210,6 +213,10 @@
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
|
showWeekNumbers: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
startDate: {
|
startDate: {
|
||||||
type: Date
|
type: Date
|
||||||
},
|
},
|
||||||
|
@ -423,8 +430,7 @@
|
||||||
onPickSuccess(){
|
onPickSuccess(){
|
||||||
this.visible = false;
|
this.visible = false;
|
||||||
this.$emit('on-ok');
|
this.$emit('on-ok');
|
||||||
}
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
visible (state) {
|
visible (state) {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
@picker-prefix-cls: ~"@{css-prefix}picker";
|
@picker-prefix-cls: ~"@{css-prefix}picker";
|
||||||
|
|
||||||
@date-picker-cells-width: 196px;
|
@date-picker-cells-width: 196px;
|
||||||
|
@date-picker-cells-width-with-weeknumbers: 226px;
|
||||||
|
|
||||||
.@{date-picker-prefix-cls} {
|
.@{date-picker-prefix-cls} {
|
||||||
//position: relative;
|
//position: relative;
|
||||||
|
@ -64,15 +65,17 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
span&-disabled,span&-disabled:hover{
|
span&-week-label,span&-week-label:hover,span&-disabled,span&-disabled:hover{
|
||||||
cursor: @cursor-disabled;
|
cursor: @cursor-disabled;
|
||||||
background: @btn-disable-bg;
|
|
||||||
color: @btn-disable-color;
|
color: @btn-disable-color;
|
||||||
em{
|
em{
|
||||||
color: inherit;
|
color: inherit;
|
||||||
background: inherit;
|
background: inherit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
span&-disabled,span&-disabled:hover{
|
||||||
|
background: @btn-disable-bg;
|
||||||
|
}
|
||||||
&-today{
|
&-today{
|
||||||
em {
|
em {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
@ -132,6 +135,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-cells-show-week-numbers {
|
||||||
|
width: @date-picker-cells-width-with-weeknumbers;
|
||||||
|
}
|
||||||
|
|
||||||
&-cells-year,&-cells-month{
|
&-cells-year,&-cells-month{
|
||||||
margin-top: 14px;
|
margin-top: 14px;
|
||||||
span{
|
span{
|
||||||
|
@ -190,7 +197,12 @@
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.@{picker-prefix-cls}-cells-show-week-numbers {
|
||||||
|
min-width: (@date-picker-cells-width-with-weeknumbers + 20) * 2;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&-transfer{
|
&-transfer{
|
||||||
z-index: @zindex-transfer;
|
z-index: @zindex-transfer;
|
||||||
max-height: none;
|
max-height: none;
|
||||||
|
|
Loading…
Add table
Reference in a new issue