Commit 915055614b5f6ab4758eb2b322f962c1a6894548
1 parent
d70cad45
TimePicker
TimePicker
Showing
1 changed file
with
24 additions
and
11 deletions
Show diff stats
src/components/date-picker/base/time-spinner.vue
| @@ -156,20 +156,33 @@ | @@ -156,20 +156,33 @@ | ||
| 156 | this.$emit('on-change', data); | 156 | this.$emit('on-change', data); |
| 157 | 157 | ||
| 158 | const from = this.$els[type].scrollTop; | 158 | const from = this.$els[type].scrollTop; |
| 159 | - | ||
| 160 | - let index = cell.text; | ||
| 161 | - const Type = firstUpperCase(type); | ||
| 162 | - const disabled = this[`disabled${Type}`]; | ||
| 163 | - if (disabled.length && this.hideDisabledOptions) { | ||
| 164 | - let _count = 0; | ||
| 165 | - disabled.forEach(item => item <= index ? _count++ : ''); | ||
| 166 | - index -= _count; | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | - const to = 24 * index; | 159 | + const to = 24 * this.getScrollIndex(type, cell.text); |
| 170 | scrollTop(this.$els[type], from, to, 500); | 160 | scrollTop(this.$els[type], from, to, 500); |
| 171 | } | 161 | } |
| 162 | + }, | ||
| 163 | + getScrollIndex (type, index) { | ||
| 164 | + const Type = firstUpperCase(type); | ||
| 165 | + const disabled = this[`disabled${Type}`]; | ||
| 166 | + if (disabled.length && this.hideDisabledOptions) { | ||
| 167 | + let _count = 0; | ||
| 168 | + disabled.forEach(item => item <= index ? _count++ : ''); | ||
| 169 | + index -= _count; | ||
| 170 | + } | ||
| 171 | + return index; | ||
| 172 | + }, | ||
| 173 | + updateScroll () { | ||
| 174 | + const times = ['hours', 'minutes', 'seconds']; | ||
| 175 | + times.forEach(type => this.$els[type].style.overflow = 'hidden'); | ||
| 176 | + this.$nextTick(() => { | ||
| 177 | + times.forEach(type => { | ||
| 178 | + this.$els[type].scrollTop = 24 * this.getScrollIndex(type, this[type]); | ||
| 179 | + }); | ||
| 180 | + this.$nextTick(() => times.forEach(type => this.$els[type].style.overflow = 'auto')); | ||
| 181 | + }); | ||
| 172 | } | 182 | } |
| 183 | + }, | ||
| 184 | + compiled () { | ||
| 185 | + this.updateScroll(); | ||
| 173 | } | 186 | } |
| 174 | }; | 187 | }; |
| 175 | </script> | 188 | </script> |
| 176 | \ No newline at end of file | 189 | \ No newline at end of file |