From 7161a07914614dfef075ced5891fc14aa1dbeb36 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Mon, 11 May 2020 12:33:46 +0800 Subject: [PATCH] =?UTF-8?q?BI-65178=20fix:=20=E6=9C=80=E5=A4=A7=E6=9C=80?= =?UTF-8?q?=E5=B0=8F=E5=80=BC=E7=9B=B8=E5=B7=AE=E9=87=8F=E7=BA=A7=E5=A4=A7?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4=E7=AB=AF=E7=82=B9=E5=80=BC?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__test__/intervalslider.test.js | 45 +++++++++++++++++++ src/widget/intervalslider/intervalslider.js | 7 +++ 2 files changed, 52 insertions(+) diff --git a/src/widget/intervalslider/__test__/intervalslider.test.js b/src/widget/intervalslider/__test__/intervalslider.test.js index 3b7b3618d..363e5321f 100644 --- a/src/widget/intervalslider/__test__/intervalslider.test.js +++ b/src/widget/intervalslider/__test__/intervalslider.test.js @@ -61,4 +61,49 @@ describe("intervalSlider", function () { intervalSliderLabel.destroy(); }); + /** + * test_author_windy + */ + it("测试拖拽", function () { + var intervalSliderLabel = BI.Test.createWidget({ + type: "bi.interval_slider", + width: 300, + unit: "px", + cls: "layout-bg-white" + }); + intervalSliderLabel.setMinAndMax({ + min: 0, + max: 120 + }); + intervalSliderLabel.setValue({ + min: 10, + max: 120 + }); + intervalSliderLabel.reset(); + intervalSliderLabel.populate(); + expect(intervalSliderLabel.getValue()).eql({ + min: "", + max: "" + }); + intervalSliderLabel.destroy(); + }); + + /** + * test_author_windy + */ + it("BI-65178", function () { + var intervalSliderLabel = BI.Test.createWidget({ + type: "bi.interval_slider", + width: 300, + unit: "px", + cls: "layout-bg-white" + }); + intervalSliderLabel.setMinAndMax({ + min: -2, + max: 237939882 + }); + expect(intervalSliderLabel._getValueByPercent(0)).to.equal(-2); + expect(intervalSliderLabel._getValueByPercent(100)).to.equal(237939882); + intervalSliderLabel.destroy(); + }); }); \ No newline at end of file diff --git a/src/widget/intervalslider/intervalslider.js b/src/widget/intervalslider/intervalslider.js index 7b7e197ac..e8b09fcc4 100644 --- a/src/widget/intervalslider/intervalslider.js +++ b/src/widget/intervalslider/intervalslider.js @@ -397,7 +397,14 @@ BI.IntervalSlider = BI.inherit(BI.Single, { }, // 其中取max-min后保留4为有效数字后的值的小数位数为最终value的精度 + // 端点处的值有可能因为min,max相差量级很大(precision很大)而丢失精度,此时直接返回端点值即可 _getValueByPercent: function (percent) {// return (((max-min)*percent)/100+min) + if (percent === 0) { + return this.min; + } + if (percent === 100) { + return this.max; + } var sub = this.calculation.accurateSubtraction(this.max, this.min); var mul = this.calculation.accurateMultiplication(sub, percent); var div = this.calculation.accurateDivisionTenExponent(mul, 2);