Selaa lähdekoodia

fix: fix slider #1043 (#1093)

* fix: fix slider #1043

* fix: lint slider foundation

Co-authored-by: pointhalo <[email protected]>
代强 3 vuotta sitten
vanhempi
sitoutus
012e91bb08
1 muutettua tiedostoa jossa 15 lisäystä ja 8 poistoa
  1. 15 8
      packages/semi-foundation/slider/foundation.ts

+ 15 - 8
packages/semi-foundation/slider/foundation.ts

@@ -386,15 +386,22 @@ export default class SliderFoundation extends BaseFoundation<SliderAdapter> {
      * @memberof SliderFoundation
      */
     outPutValue = (inputValue: SliderProps['value']) => {
+        const checkHowManyDecimals = (num:number)=>{
+            const reg = /^\d+(\.\d+)?$/;
+            if (reg.test(String(num))){
+                return num.toString().split('.')[1]?.length ?? 0;
+            }
+            return 0;
+        };
         const step = this._adapter.getProp('step');
-        let transWay = Math.round;
-        if (step < 1 && step >= 0.1) {
-            transWay = value => Math.round(value * 10) / 10;
-        } else if (step < 0.1 && step >= 0.01) {
-            transWay = value => Math.round(value * 100) / 100;
-        } else if (step < 0.01 && step >= 0.001) {
-            transWay = value => Math.round(value * 1000) / 1000;
-        }
+        const transWay = (()=>{
+            const decimals = checkHowManyDecimals(step);
+            const multipler = Math.pow(10, decimals);
+            return (value: number)=>{
+                return Math.round(value * multipler) / multipler;
+            };
+        })();
+        
         if (Array.isArray(inputValue)) {
             return [transWay(inputValue[0]), transWay(inputValue[1])];
         } else {