diff --git a/src/widget/intervalslider/__test__/intervalslider.test.js b/src/widget/intervalslider/__test__/intervalslider.test.js index 3b7b3618dd..363e5321fe 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 7b7e197acb..e8b09fcc41 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);