DatePicker: Add calculation of select range position

pull/21258/head
Aex 2021-08-23 16:23:55 +00:00 committed by GitHub
parent a87ce4b282
commit 028d8e5a40
3 changed files with 30 additions and 9 deletions

View File

@ -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;
}, },

View File

@ -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>

View File

@ -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">