效果图
dom结构---总秒数188
javascript
<div class="popover">
<div style="display: flex;align-items: center;">时间点:
<el-time-picker
value-format="mm:ss"
format="mm:ss"
:picker-options="{
selectableRange: '00:00:00 - 00:59:59'
}"
:disabled-hours="disabledHours"
:disabled-minutes="disabledMinutes"
:disabled-seconds="disabledSeconds"
style="width: 100px;margin-left: 8px;"
v-model="state.selectTime.time"
popper-class="noneMinute"
placeholder="请选择"
/>
<el-button @click="closeImage" style="margin-left: 8px;" size="small">取消</el-button>
<el-button @click="sureBtn" style="margin-left: 2px;" type="primary" size="small">确定</el-button>
</div>
</div>
事件
javascript
const state = reactive({
selectTime: {
time: '00:00' as any
},
meta_data_duration: 188 as any,
minutes: null as any
});
// 数据处理
const makeRange = (start: number, end: number) => {
const result: number[] = []
for (let i = start; i <= end; i++) {
result.push(i)
}
return result
}
// 小时
const disabledHours = () => {
return makeRange(0, 23)
}
// 分钟
const disabledMinutes = () => {
const val = state.meta_data_duration
const min = parseInt(val % 3600 / 60)
state.minutes = min
return makeRange(min, 59)
}
// 秒数
const disabledSeconds = (hour: number, minute: number) => {
const val = state.meta_data_duration
const sec = parseInt(val % 3600 % 60)
if (state.minutes === minute + 1) {
return makeRange(sec, 59)
}
}
只显示分秒,隐藏小时,
javascript
// 作用全局,为避免影响到其他页面样式,所以外层写一个单独的类名用于区分
<style lang="scss">
// 隐藏小时的代码
.noneMinute {
.el-scrollbar:nth-of-type(1) {
display: none !important;
}
//调整样式
.el-time-spinner {
width: 150%;
white-space: nowrap;
}
}
</style>