9d844d53
梁灏
fixed Layout bug
|
1
2
|
<template>
<div :class="classes">
|
2d948738
梁灏
update TimePicker...
|
3
4
5
|
<div :class="[prefixCls+ '-list']" v-el:hours>
<ul @click="handleClickHours">
<li :class="getCellCls(item)" v-for="item in hoursList" v-show="!item.hide" :index="$index">{{ item.text < 10 ? '0' + item.text : item.text }}</li>
|
9d844d53
梁灏
fixed Layout bug
|
6
7
|
</ul>
</div>
|
2d948738
梁灏
update TimePicker...
|
8
9
10
|
<div :class="[prefixCls+ '-list']" v-el:minutes>
<ul @click="handleClickMinutes">
<li :class="getCellCls(item)" v-for="item in minutesList" v-show="!item.hide" :index="$index">{{ item.text < 10 ? '0' + item.text : item.text }}</li>
|
36628aca
梁灏
update TimePicker
|
11
|
</ul>
|
9d844d53
梁灏
fixed Layout bug
|
12
|
</div>
|
2d948738
梁灏
update TimePicker...
|
13
14
15
|
<div :class="[prefixCls+ '-list']" v-show="showSeconds" v-el:seconds>
<ul @click="handleClickSeconds">
<li :class="getCellCls(item)" v-for="item in secondsList" v-show="!item.hide" :index="$index">{{ item.text < 10 ? '0' + item.text : item.text }}</li>
|
36628aca
梁灏
update TimePicker
|
16
|
</ul>
|
9d844d53
梁灏
fixed Layout bug
|
17
18
19
20
|
</div>
</div>
</template>
<script>
|
36628aca
梁灏
update TimePicker
|
21
|
import Options from '../time-mixins';
|
d70cad45
梁灏
update TimePicker
|
22
|
import { deepCopy, scrollTop, firstUpperCase } from '../../../utils/assist';
|
36628aca
梁灏
update TimePicker
|
23
|
|
9d844d53
梁灏
fixed Layout bug
|
24
25
26
|
const prefixCls = 'ivu-time-picker-cells';
export default {
|
36628aca
梁灏
update TimePicker
|
27
|
mixins: [Options],
|
9d844d53
梁灏
fixed Layout bug
|
28
29
|
props: {
hours: {
|
2dbbd7de
梁灏
update TimePicker
|
30
|
type: [Number, String],
|
9d844d53
梁灏
fixed Layout bug
|
31
32
33
|
default: 0
},
minutes: {
|
2dbbd7de
梁灏
update TimePicker
|
34
|
type: [Number, String],
|
9d844d53
梁灏
fixed Layout bug
|
35
36
37
|
default: 0
},
seconds: {
|
2dbbd7de
梁灏
update TimePicker
|
38
|
type: [Number, String],
|
9d844d53
梁灏
fixed Layout bug
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
default: 0
},
showSeconds: {
type: Boolean,
default: true
}
},
data () {
return {
prefixCls: prefixCls
};
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-with-seconds`]: this.showSeconds
}
];
},
hoursList () {
|
36628aca
梁灏
update TimePicker
|
61
62
|
let hours = [];
const hour_tmpl = {
|
2d948738
梁灏
update TimePicker...
|
63
|
text: 0,
|
36628aca
梁灏
update TimePicker
|
64
65
66
67
68
69
70
71
72
|
selected: false,
disabled: false,
hide: false
};
for (let i = 0; i < 24; i++) {
const hour = deepCopy(hour_tmpl);
hour.text = i;
|
d70cad45
梁灏
update TimePicker
|
73
|
if (this.disabledHours.length && this.disabledHours.indexOf(i) > -1) {
|
36628aca
梁灏
update TimePicker
|
74
75
76
|
hour.disabled = true;
if (this.hideDisabledOptions) hour.hide = true;
}
|
2d948738
梁灏
update TimePicker...
|
77
|
if (this.hours === i) hour.selected = true;
|
36628aca
梁灏
update TimePicker
|
78
79
80
81
|
hours.push(hour);
}
return hours;
|
9d844d53
梁灏
fixed Layout bug
|
82
83
|
},
minutesList () {
|
36628aca
梁灏
update TimePicker
|
84
85
|
let minutes = [];
const minute_tmpl = {
|
2d948738
梁灏
update TimePicker...
|
86
|
text: 0,
|
36628aca
梁灏
update TimePicker
|
87
88
89
90
91
92
93
94
95
|
selected: false,
disabled: false,
hide: false
};
for (let i = 0; i < 60; i++) {
const minute = deepCopy(minute_tmpl);
minute.text = i;
|
d70cad45
梁灏
update TimePicker
|
96
|
if (this.disabledMinutes.length && this.disabledMinutes.indexOf(i) > -1) {
|
36628aca
梁灏
update TimePicker
|
97
98
99
|
minute.disabled = true;
if (this.hideDisabledOptions) minute.hide = true;
}
|
2d948738
梁灏
update TimePicker...
|
100
|
if (this.minutes === i) minute.selected = true;
|
36628aca
梁灏
update TimePicker
|
101
102
103
104
|
minutes.push(minute);
}
return minutes;
|
9d844d53
梁灏
fixed Layout bug
|
105
106
|
},
secondsList () {
|
36628aca
梁灏
update TimePicker
|
107
108
|
let seconds = [];
const second_tmpl = {
|
2d948738
梁灏
update TimePicker...
|
109
|
text: 0,
|
36628aca
梁灏
update TimePicker
|
110
111
112
113
114
115
116
117
118
|
selected: false,
disabled: false,
hide: false
};
for (let i = 0; i < 60; i++) {
const second = deepCopy(second_tmpl);
second.text = i;
|
d70cad45
梁灏
update TimePicker
|
119
|
if (this.disabledSeconds.length && this.disabledSeconds.indexOf(i) > -1) {
|
36628aca
梁灏
update TimePicker
|
120
121
122
|
second.disabled = true;
if (this.hideDisabledOptions) second.hide = true;
}
|
2d948738
梁灏
update TimePicker...
|
123
|
if (this.seconds === i) second.selected = true;
|
36628aca
梁灏
update TimePicker
|
124
125
126
127
|
seconds.push(second);
}
return seconds;
|
9d844d53
梁灏
fixed Layout bug
|
128
129
130
|
}
},
methods: {
|
36628aca
梁灏
update TimePicker
|
131
132
133
134
135
136
137
138
|
getCellCls (cell) {
return [
`${prefixCls}-cell`,
{
[`${prefixCls}-cell-selected`]: cell.selected,
[`${prefixCls}-cell-disabled`]: cell.disabled
}
];
|
2d948738
梁灏
update TimePicker...
|
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
},
handleClickHours (event) {
this.handleClick('hours', event);
},
handleClickMinutes (event) {
this.handleClick('minutes', event);
},
handleClickSeconds (event) {
this.handleClick('seconds', event);
},
handleClick (type, event) {
const target = event.target;
if (target.tagName === 'LI') {
const cell = this[`${type}List`][parseInt(event.target.getAttribute('index'))];
if (cell.disabled) return;
const data = {};
data[type] = cell.text;
this.$emit('on-change', data);
const from = this.$els[type].scrollTop;
|
91505561
梁灏
TimePicker
|
159
|
const to = 24 * this.getScrollIndex(type, cell.text);
|
2d948738
梁灏
update TimePicker...
|
160
161
|
scrollTop(this.$els[type], from, to, 500);
}
|
91505561
梁灏
TimePicker
|
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
},
getScrollIndex (type, index) {
const Type = firstUpperCase(type);
const disabled = this[`disabled${Type}`];
if (disabled.length && this.hideDisabledOptions) {
let _count = 0;
disabled.forEach(item => item <= index ? _count++ : '');
index -= _count;
}
return index;
},
updateScroll () {
const times = ['hours', 'minutes', 'seconds'];
times.forEach(type => this.$els[type].style.overflow = 'hidden');
this.$nextTick(() => {
times.forEach(type => {
this.$els[type].scrollTop = 24 * this.getScrollIndex(type, this[type]);
});
this.$nextTick(() => times.forEach(type => this.$els[type].style.overflow = 'auto'));
});
|
36628aca
梁灏
update TimePicker
|
182
|
}
|
91505561
梁灏
TimePicker
|
183
184
185
|
},
compiled () {
this.updateScroll();
|
9d844d53
梁灏
fixed Layout bug
|
186
187
188
|
}
};
</script>
|