mirror of https://github.com/ElemeFE/element
DatePicker: Add calculation of select range position
parent
a87ce4b282
commit
028d8e5a40
|
@ -120,6 +120,7 @@
|
||||||
default: true
|
default: true
|
||||||
},
|
},
|
||||||
arrowControl: Boolean,
|
arrowControl: Boolean,
|
||||||
|
format: String,
|
||||||
amPmMode: {
|
amPmMode: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '' // 'a': am/pm; 'A': AM/PM
|
default: '' // 'a': am/pm; 'A': AM/PM
|
||||||
|
@ -206,13 +207,30 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
calculateSelectRangePostion(type) {
|
||||||
|
const reg = /[Hhms]/g;
|
||||||
|
const postion = { start: -1, end: -1 };
|
||||||
|
const maskTypeMap = { H: 'hours', h: 'hours', m: 'minutes', s: 'seconds' };
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const match = reg.exec(this.format);
|
||||||
|
if (!match) break;
|
||||||
|
const { 0: mask, index } = match;
|
||||||
|
if (maskTypeMap[mask] === type) {
|
||||||
|
if (postion.start === -1) {
|
||||||
|
postion.start = postion.end = index;
|
||||||
|
} else {
|
||||||
|
postion.end = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return postion;
|
||||||
|
},
|
||||||
|
|
||||||
emitSelectRange(type) {
|
emitSelectRange(type) {
|
||||||
if (type === 'hours') {
|
const { start, end } = this.calculateSelectRangePostion(type);
|
||||||
this.$emit('select-range', 0, 2);
|
if (start > -1) {
|
||||||
} else if (type === 'minutes') {
|
this.$emit('select-range', start, end + 1);
|
||||||
this.$emit('select-range', 3, 5);
|
|
||||||
} else if (type === 'seconds') {
|
|
||||||
this.$emit('select-range', 6, 8);
|
|
||||||
}
|
}
|
||||||
this.currentScrollbar = type;
|
this.currentScrollbar = type;
|
||||||
},
|
},
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
@change="handleMinChange"
|
@change="handleMinChange"
|
||||||
:arrow-control="arrowControl"
|
:arrow-control="arrowControl"
|
||||||
@select-range="setMinSelectionRange"
|
@select-range="setMinSelectionRange"
|
||||||
:date="minDate">
|
:date="minDate"
|
||||||
|
:format="format">
|
||||||
</time-spinner>
|
</time-spinner>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -35,7 +36,8 @@
|
||||||
@change="handleMaxChange"
|
@change="handleMaxChange"
|
||||||
:arrow-control="arrowControl"
|
:arrow-control="arrowControl"
|
||||||
@select-range="setMaxSelectionRange"
|
@select-range="setMaxSelectionRange"
|
||||||
:date="maxDate">
|
:date="maxDate"
|
||||||
|
:format="format">
|
||||||
</time-spinner>
|
</time-spinner>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
:show-seconds="showSeconds"
|
:show-seconds="showSeconds"
|
||||||
:am-pm-mode="amPmMode"
|
:am-pm-mode="amPmMode"
|
||||||
@select-range="setSelectionRange"
|
@select-range="setSelectionRange"
|
||||||
:date="date">
|
:date="date"
|
||||||
|
:format="format">
|
||||||
</time-spinner>
|
</time-spinner>
|
||||||
</div>
|
</div>
|
||||||
<div class="el-time-panel__footer">
|
<div class="el-time-panel__footer">
|
||||||
|
|
Loading…
Reference in New Issue