Commit 2f8104a3212dd42d4d9b07b3e98816a7c4ee65d3
1 parent
bb1a3c38
update Slider
Showing
1 changed file
with
28 additions
and
22 deletions
Show diff stats
src/components/slider/slider.vue
@@ -360,18 +360,21 @@ | @@ -360,18 +360,21 @@ | ||
360 | } | 360 | } |
361 | }, | 361 | }, |
362 | changeFirstPosition (newPos) { | 362 | changeFirstPosition (newPos) { |
363 | - if (newPos >= 0 && (newPos <= this.secondPosition)) { | ||
364 | - const lengthPerStep = 100 / ((this.max - this.min) / this.step); | ||
365 | - const steps = Math.round(newPos / lengthPerStep); | 363 | + if (newPos < 0) { |
364 | + newPos = 0; | ||
365 | + } else if (newPos > this.secondPosition) { | ||
366 | + newPos = this.secondPosition; | ||
367 | + } | ||
368 | + const lengthPerStep = 100 / ((this.max - this.min) / this.step); | ||
369 | + const steps = Math.round(newPos / lengthPerStep); | ||
366 | 370 | ||
367 | - this.currentValue = [Math.round(steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min), this.currentValue[1]]; | ||
368 | - this.setFirstPosition(this.currentValue[0]); | ||
369 | - if (!this.firstDragging) { | ||
370 | - if (this.currentValue[0] !== this.oldFirstValue) { | ||
371 | - this.$emit('on-change', this.currentValue); | ||
372 | - this.dispatch('FormItem', 'on-form-change', this.currentValue); | ||
373 | - this.oldFirstValue = this.currentValue[0]; | ||
374 | - } | 371 | + this.currentValue = [Math.round(steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min), this.currentValue[1]]; |
372 | + this.setFirstPosition(this.currentValue[0]); | ||
373 | + if (!this.firstDragging) { | ||
374 | + if (this.currentValue[0] !== this.oldFirstValue) { | ||
375 | + this.$emit('on-change', this.currentValue); | ||
376 | + this.dispatch('FormItem', 'on-form-change', this.currentValue); | ||
377 | + this.oldFirstValue = this.currentValue[0]; | ||
375 | } | 378 | } |
376 | } | 379 | } |
377 | }, | 380 | }, |
@@ -410,18 +413,21 @@ | @@ -410,18 +413,21 @@ | ||
410 | } | 413 | } |
411 | }, | 414 | }, |
412 | changeSecondPosition (newPos) { | 415 | changeSecondPosition (newPos) { |
413 | - if (newPos >= this.firstPosition && (newPos <= 100)) { | ||
414 | - const lengthPerStep = 100 / ((this.max - this.min) / this.step); | ||
415 | - const steps = Math.round(newPos / lengthPerStep); | 416 | + if (newPos > 100) { |
417 | + newPos = 100; | ||
418 | + } else if (newPos < this.firstPosition) { | ||
419 | + newPos = this.firstPosition; | ||
420 | + } | ||
421 | + const lengthPerStep = 100 / ((this.max - this.min) / this.step); | ||
422 | + const steps = Math.round(newPos / lengthPerStep); | ||
416 | 423 | ||
417 | - this.currentValue = [this.currentValue[0], Math.round(steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min)]; | ||
418 | - this.setSecondPosition(this.currentValue[1]); | ||
419 | - if (!this.secondDragging) { | ||
420 | - if (this.currentValue[1] !== this.oldSecondValue) { | ||
421 | - this.$emit('on-change', this.currentValue); | ||
422 | - this.dispatch('FormItem', 'on-form-change', this.currentValue); | ||
423 | - this.oldSecondValue = this.currentValue[1]; | ||
424 | - } | 424 | + this.currentValue = [this.currentValue[0], Math.round(steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min)]; |
425 | + this.setSecondPosition(this.currentValue[1]); | ||
426 | + if (!this.secondDragging) { | ||
427 | + if (this.currentValue[1] !== this.oldSecondValue) { | ||
428 | + this.$emit('on-change', this.currentValue); | ||
429 | + this.dispatch('FormItem', 'on-form-change', this.currentValue); | ||
430 | + this.oldSecondValue = this.currentValue[1]; | ||
425 | } | 431 | } |
426 | } | 432 | } |
427 | }, | 433 | }, |