9d844d53
梁灏
fixed Layout bug
|
1
2
|
<template>
<div :class="classes">
|
531cd165
梁灏
support DatePicke...
|
3
|
<div :class="[prefixCls+ '-list']" ref="hours">
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
4
5
|
<ul :class="[prefixCls + '-ul']">
<li :class="getCellCls(item)" v-for="item in hoursList" v-show="!item.hide" @click="handleClick('hours', item)">{{ formatTime(item.text) }}</li>
|
9d844d53
梁灏
fixed Layout bug
|
6
7
|
</ul>
</div>
|
531cd165
梁灏
support DatePicke...
|
8
|
<div :class="[prefixCls+ '-list']" ref="minutes">
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
9
10
|
<ul :class="[prefixCls + '-ul']">
<li :class="getCellCls(item)" v-for="item in minutesList" v-show="!item.hide" @click="handleClick('minutes', item)">{{ formatTime(item.text) }}</li>
|
36628aca
梁灏
update TimePicker
|
11
|
</ul>
|
9d844d53
梁灏
fixed Layout bug
|
12
|
</div>
|
531cd165
梁灏
support DatePicke...
|
13
|
<div :class="[prefixCls+ '-list']" v-show="showSeconds" ref="seconds">
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
14
15
|
<ul :class="[prefixCls + '-ul']">
<li :class="getCellCls(item)" v-for="item in secondsList" v-show="!item.hide" @click="handleClick('seconds', item)">{{ formatTime(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
|
default: 0
},
showSeconds: {
type: Boolean,
default: true
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
44
45
46
47
|
},
steps: {
type: Array,
default: () => []
|
9d844d53
梁灏
fixed Layout bug
|
48
49
50
51
|
}
},
data () {
return {
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
52
|
spinerSteps: [1, 1, 1].map((one, i) => Math.abs(this.steps[i]) || one),
|
af713093
梁灏
update TimePicker
|
53
54
|
prefixCls: prefixCls,
compiled: false
|
9d844d53
梁灏
fixed Layout bug
|
55
56
57
58
59
60
61
62
63
64
65
66
|
};
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-with-seconds`]: this.showSeconds
}
];
},
hoursList () {
|
36628aca
梁灏
update TimePicker
|
67
|
let hours = [];
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
68
|
const step = this.spinerSteps[0];
|
36628aca
梁灏
update TimePicker
|
69
|
const hour_tmpl = {
|
2d948738
梁灏
update TimePicker...
|
70
|
text: 0,
|
36628aca
梁灏
update TimePicker
|
71
72
73
74
75
|
selected: false,
disabled: false,
hide: false
};
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
76
|
for (let i = 0; i < 24; i += step) {
|
36628aca
梁灏
update TimePicker
|
77
78
79
|
const hour = deepCopy(hour_tmpl);
hour.text = i;
|
d70cad45
梁灏
update TimePicker
|
80
|
if (this.disabledHours.length && this.disabledHours.indexOf(i) > -1) {
|
36628aca
梁灏
update TimePicker
|
81
82
83
|
hour.disabled = true;
if (this.hideDisabledOptions) hour.hide = true;
}
|
2d948738
梁灏
update TimePicker...
|
84
|
if (this.hours === i) hour.selected = true;
|
36628aca
梁灏
update TimePicker
|
85
86
87
88
|
hours.push(hour);
}
return hours;
|
9d844d53
梁灏
fixed Layout bug
|
89
90
|
},
minutesList () {
|
36628aca
梁灏
update TimePicker
|
91
|
let minutes = [];
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
92
|
const step = this.spinerSteps[1];
|
36628aca
梁灏
update TimePicker
|
93
|
const minute_tmpl = {
|
2d948738
梁灏
update TimePicker...
|
94
|
text: 0,
|
36628aca
梁灏
update TimePicker
|
95
96
97
98
99
|
selected: false,
disabled: false,
hide: false
};
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
100
|
for (let i = 0; i < 60; i += step) {
|
36628aca
梁灏
update TimePicker
|
101
102
103
|
const minute = deepCopy(minute_tmpl);
minute.text = i;
|
d70cad45
梁灏
update TimePicker
|
104
|
if (this.disabledMinutes.length && this.disabledMinutes.indexOf(i) > -1) {
|
36628aca
梁灏
update TimePicker
|
105
106
107
|
minute.disabled = true;
if (this.hideDisabledOptions) minute.hide = true;
}
|
2d948738
梁灏
update TimePicker...
|
108
|
if (this.minutes === i) minute.selected = true;
|
36628aca
梁灏
update TimePicker
|
109
110
|
minutes.push(minute);
}
|
36628aca
梁灏
update TimePicker
|
111
|
return minutes;
|
9d844d53
梁灏
fixed Layout bug
|
112
113
|
},
secondsList () {
|
36628aca
梁灏
update TimePicker
|
114
|
let seconds = [];
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
115
|
const step = this.spinerSteps[2];
|
36628aca
梁灏
update TimePicker
|
116
|
const second_tmpl = {
|
2d948738
梁灏
update TimePicker...
|
117
|
text: 0,
|
36628aca
梁灏
update TimePicker
|
118
119
120
121
122
|
selected: false,
disabled: false,
hide: false
};
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
123
|
for (let i = 0; i < 60; i += step) {
|
36628aca
梁灏
update TimePicker
|
124
125
126
|
const second = deepCopy(second_tmpl);
second.text = i;
|
d70cad45
梁灏
update TimePicker
|
127
|
if (this.disabledSeconds.length && this.disabledSeconds.indexOf(i) > -1) {
|
36628aca
梁灏
update TimePicker
|
128
129
130
|
second.disabled = true;
if (this.hideDisabledOptions) second.hide = true;
}
|
2d948738
梁灏
update TimePicker...
|
131
|
if (this.seconds === i) second.selected = true;
|
36628aca
梁灏
update TimePicker
|
132
133
134
135
|
seconds.push(second);
}
return seconds;
|
9d844d53
梁灏
fixed Layout bug
|
136
137
138
|
}
},
methods: {
|
36628aca
梁灏
update TimePicker
|
139
140
141
142
143
144
145
146
|
getCellCls (cell) {
return [
`${prefixCls}-cell`,
{
[`${prefixCls}-cell-selected`]: cell.selected,
[`${prefixCls}-cell-disabled`]: cell.disabled
}
];
|
2d948738
梁灏
update TimePicker...
|
147
|
},
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
148
149
150
151
152
|
handleClick (type, cell) {
if (cell.disabled) return;
const data = {};
data[type] = cell.text;
this.$emit('on-change', data);
|
4db5926d
梁灏
fixed #153
|
153
|
this.$emit('on-pick-click');
|
91505561
梁灏
TimePicker
|
154
|
},
|
af713093
梁灏
update TimePicker
|
155
|
scroll (type, index) {
|
531cd165
梁灏
support DatePicke...
|
156
|
const from = this.$refs[type].scrollTop;
|
af713093
梁灏
update TimePicker
|
157
|
const to = 24 * this.getScrollIndex(type, index);
|
531cd165
梁灏
support DatePicke...
|
158
|
scrollTop(this.$refs[type], from, to, 500);
|
af713093
梁灏
update TimePicker
|
159
|
},
|
91505561
梁灏
TimePicker
|
160
161
162
163
164
165
166
167
168
169
170
171
|
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'];
|
91505561
梁灏
TimePicker
|
172
173
|
this.$nextTick(() => {
times.forEach(type => {
|
d5e44814
Sergio Crisostomo
remove Array.find...
|
174
|
this.$refs[type].scrollTop = 24 * this[`${type}List`].findIndex(obj => obj.text == this[type]);
|
91505561
梁灏
TimePicker
|
175
|
});
|
91505561
梁灏
TimePicker
|
176
|
});
|
b27687d3
梁灏
update TimePicker
|
177
178
179
|
},
formatTime (text) {
return text < 10 ? '0' + text : text;
|
36628aca
梁灏
update TimePicker
|
180
|
}
|
91505561
梁灏
TimePicker
|
181
|
},
|
af713093
梁灏
update TimePicker
|
182
183
184
|
watch: {
hours (val) {
if (!this.compiled) return;
|
7309b434
梁灏
InputNumber add `...
|
185
|
this.scroll('hours', this.hoursList.findIndex(obj => obj.text == val));
|
af713093
梁灏
update TimePicker
|
186
187
188
|
},
minutes (val) {
if (!this.compiled) return;
|
7309b434
梁灏
InputNumber add `...
|
189
|
this.scroll('minutes', this.minutesList.findIndex(obj => obj.text == val));
|
af713093
梁灏
update TimePicker
|
190
191
192
|
},
seconds (val) {
if (!this.compiled) return;
|
7309b434
梁灏
InputNumber add `...
|
193
|
this.scroll('seconds', this.secondsList.findIndex(obj => obj.text == val));
|
af713093
梁灏
update TimePicker
|
194
195
|
}
},
|
531cd165
梁灏
support DatePicke...
|
196
|
mounted () {
|
91505561
梁灏
TimePicker
|
197
|
this.updateScroll();
|
af713093
梁灏
update TimePicker
|
198
|
this.$nextTick(() => this.compiled = true);
|
9d844d53
梁灏
fixed Layout bug
|
199
200
|
}
};
|
9b376832
Sergio Crisostomo
Add feature: allo...
|
201
|
</script>
|