update Slider

This commit is contained in:
梁灏 2017-04-07 09:38:55 +08:00
parent bb1a3c38b4
commit 2f8104a321

View file

@ -360,18 +360,21 @@
} }
}, },
changeFirstPosition (newPos) { changeFirstPosition (newPos) {
if (newPos >= 0 && (newPos <= this.secondPosition)) { if (newPos < 0) {
const lengthPerStep = 100 / ((this.max - this.min) / this.step); newPos = 0;
const steps = Math.round(newPos / lengthPerStep); } else if (newPos > this.secondPosition) {
newPos = this.secondPosition;
}
const lengthPerStep = 100 / ((this.max - this.min) / this.step);
const steps = Math.round(newPos / lengthPerStep);
this.currentValue = [Math.round(steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min), this.currentValue[1]]; this.currentValue = [Math.round(steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min), this.currentValue[1]];
this.setFirstPosition(this.currentValue[0]); this.setFirstPosition(this.currentValue[0]);
if (!this.firstDragging) { if (!this.firstDragging) {
if (this.currentValue[0] !== this.oldFirstValue) { if (this.currentValue[0] !== this.oldFirstValue) {
this.$emit('on-change', this.currentValue); this.$emit('on-change', this.currentValue);
this.dispatch('FormItem', 'on-form-change', this.currentValue); this.dispatch('FormItem', 'on-form-change', this.currentValue);
this.oldFirstValue = this.currentValue[0]; this.oldFirstValue = this.currentValue[0];
}
} }
} }
}, },
@ -410,18 +413,21 @@
} }
}, },
changeSecondPosition (newPos) { changeSecondPosition (newPos) {
if (newPos >= this.firstPosition && (newPos <= 100)) { if (newPos > 100) {
const lengthPerStep = 100 / ((this.max - this.min) / this.step); newPos = 100;
const steps = Math.round(newPos / lengthPerStep); } else if (newPos < this.firstPosition) {
newPos = this.firstPosition;
}
const lengthPerStep = 100 / ((this.max - this.min) / this.step);
const steps = Math.round(newPos / lengthPerStep);
this.currentValue = [this.currentValue[0], Math.round(steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min)]; this.currentValue = [this.currentValue[0], Math.round(steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min)];
this.setSecondPosition(this.currentValue[1]); this.setSecondPosition(this.currentValue[1]);
if (!this.secondDragging) { if (!this.secondDragging) {
if (this.currentValue[1] !== this.oldSecondValue) { if (this.currentValue[1] !== this.oldSecondValue) {
this.$emit('on-change', this.currentValue); this.$emit('on-change', this.currentValue);
this.dispatch('FormItem', 'on-form-change', this.currentValue); this.dispatch('FormItem', 'on-form-change', this.currentValue);
this.oldSecondValue = this.currentValue[1]; this.oldSecondValue = this.currentValue[1];
}
} }
} }
}, },