iview/src/components/date-picker/base/time-spinner.vue

139 lines
4.2 KiB
Vue
Raw Normal View History

2016-12-26 14:50:39 +08:00
<template>
<div :class="classes">
<div :class="[prefixCls+ '-wrapper']">
<ul :class="[prefixCls + '-list']">
2016-12-26 15:57:12 +08:00
<li :class="getCellCls(item)" v-for="item in hoursList" v-show="!item.hide">{{ item.text }}</li>
2016-12-26 14:50:39 +08:00
</ul>
</div>
<div :class="[prefixCls+ '-wrapper']">
2016-12-26 15:57:12 +08:00
<ul :class="[prefixCls + '-list']">
<li :class="getCellCls(item)" v-for="item in minutesList" v-show="!item.hide">{{ item.text }}</li>
</ul>
2016-12-26 14:50:39 +08:00
</div>
<div :class="[prefixCls+ '-wrapper']" v-show="showSeconds">
2016-12-26 15:57:12 +08:00
<ul :class="[prefixCls + '-list']">
<li :class="getCellCls(item)" v-for="item in secondsList" v-show="!item.hide">{{ item.text }}</li>
</ul>
2016-12-26 14:50:39 +08:00
</div>
</div>
</template>
<script>
2016-12-26 15:57:12 +08:00
import Options from '../time-mixins';
import { deepCopy } from '../../../utils/assist';
2016-12-26 14:50:39 +08:00
const prefixCls = 'ivu-time-picker-cells';
export default {
2016-12-26 15:57:12 +08:00
mixins: [Options],
2016-12-26 14:50:39 +08:00
props: {
hours: {
type: Number,
default: 0
},
minutes: {
type: Number,
default: 0
},
seconds: {
type: Number,
default: 0
},
showSeconds: {
type: Boolean,
default: true
}
},
data () {
return {
prefixCls: prefixCls
};
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-with-seconds`]: this.showSeconds
}
];
},
hoursList () {
2016-12-26 15:57:12 +08:00
let hours = [];
const hour_tmpl = {
text: '',
selected: false,
disabled: false,
hide: false
};
for (let i = 0; i < 24; i++) {
const hour = deepCopy(hour_tmpl);
hour.text = i;
if (this.disabledHours && this.disabledHours.indexOf(i) > -1) {
hour.disabled = true;
if (this.hideDisabledOptions) hour.hide = true;
}
hours.push(hour);
}
return hours;
2016-12-26 14:50:39 +08:00
},
minutesList () {
2016-12-26 15:57:12 +08:00
let minutes = [];
const minute_tmpl = {
text: '',
selected: false,
disabled: false,
hide: false
};
for (let i = 0; i < 60; i++) {
const minute = deepCopy(minute_tmpl);
minute.text = i;
if (this.disabledMinutes && this.disabledMinutes.indexOf(i) > -1) {
minute.disabled = true;
if (this.hideDisabledOptions) minute.hide = true;
}
minutes.push(minute);
}
return minutes;
2016-12-26 14:50:39 +08:00
},
secondsList () {
2016-12-26 15:57:12 +08:00
let seconds = [];
const second_tmpl = {
text: '',
selected: false,
disabled: false,
hide: false
};
for (let i = 0; i < 60; i++) {
const second = deepCopy(second_tmpl);
second.text = i;
if (this.disabledSeconds && this.disabledSeconds.indexOf(i) > -1) {
second.disabled = true;
if (this.hideDisabledOptions) second.hide = true;
}
seconds.push(second);
}
return seconds;
2016-12-26 14:50:39 +08:00
}
},
methods: {
2016-12-26 15:57:12 +08:00
getCellCls (cell) {
return [
`${prefixCls}-cell`,
{
[`${prefixCls}-cell-selected`]: cell.selected,
[`${prefixCls}-cell-disabled`]: cell.disabled
}
];
}
2016-12-26 14:50:39 +08:00
}
};
</script>