From 3b71312aac4ab4f838ca2bd321174b72dd0f206a Mon Sep 17 00:00:00 2001 From: "bin.yang" Date: Mon, 2 Apr 2018 11:18:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=20slider=E7=BB=84=E4=BB=B6=20step=E4=B8=BA?= =?UTF-8?q?=E5=B0=8F=E6=95=B0=E6=97=B6=E5=9B=9E=E4=B8=8D=E5=88=B0100?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/slider/slider.vue | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/slider/slider.vue b/src/components/slider/slider.vue index 0c2f9e9e..891823c8 100644 --- a/src/components/slider/slider.vue +++ b/src/components/slider/slider.vue @@ -326,12 +326,11 @@ const index = type === 'min' ? 0 : 1; if (type === 'min') newPos = this.checkLimits([newPos, this.maxPosition])[0]; else newPos = this.checkLimits([this.minPosition, newPos])[1]; - - const modulus = newPos % this.step; + + const modulus = this.handleDecimal(newPos,this.step) const value = this.currentValue; value[index] = newPos - modulus; this.currentValue = [...value]; - if (!this.dragging) { if (this.currentValue[index] !== this.oldValue[index]) { this.emitChange(); @@ -339,7 +338,18 @@ } } }, - + handleDecimal(pos,step){ + if(step<1){ + let sl = step.toString(), + multiple = 1, + m = 0; + try { + m += sl.split('.')[1].length; + } catch (e) {} + multiple = Math.pow(10,m); + return (pos * multiple) % (step * multiple) / multiple; + }else return pos % step; + }, emitChange(){ const value = this.range ? this.exportValue : this.exportValue[0]; this.$emit('on-change', value); From cd07742407fb30c443a23c4158ddad4e8d4505d9 Mon Sep 17 00:00:00 2001 From: "bin.yang" Date: Mon, 2 Apr 2018 11:24:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=20slider=E7=BB=84=E4=BB=B6=20step=E4=B8=BA?= =?UTF-8?q?=E5=B0=8F=E6=95=B0=E6=97=B6=E5=9B=9E=E4=B8=8D=E5=88=B0100?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/slider/slider.vue | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/slider/slider.vue b/src/components/slider/slider.vue index 891823c8..ec91eebc 100644 --- a/src/components/slider/slider.vue +++ b/src/components/slider/slider.vue @@ -327,7 +327,7 @@ if (type === 'min') newPos = this.checkLimits([newPos, this.maxPosition])[0]; else newPos = this.checkLimits([this.minPosition, newPos])[1]; - const modulus = this.handleDecimal(newPos,this.step) + const modulus = this.handleDecimal(newPos,this.step); const value = this.currentValue; value[index] = newPos - modulus; this.currentValue = [...value]; @@ -342,10 +342,12 @@ if(step<1){ let sl = step.toString(), multiple = 1, - m = 0; + m; try { - m += sl.split('.')[1].length; - } catch (e) {} + m = sl.split('.')[1].length; + } catch (e){ + m = 0; + } multiple = Math.pow(10,m); return (pos * multiple) % (step * multiple) / multiple; }else return pos % step;