From fccccff983901fcef01a81e898cca4c0018ac1cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sun, 31 Mar 2024 22:02:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20`input-number`=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84=20`lay-precision`=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=80=BC=E4=B8=BA=20`0`=20=E6=97=B6=E7=9A=84=E5=8F=96?= =?UTF-8?q?=E6=95=B4=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/form.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/form.js b/src/modules/form.js index 9a4613fe..2047d24a 100644 --- a/src/modules/form.js +++ b/src/modules/form.js @@ -201,13 +201,19 @@ layui.define(['lay', 'layer', 'util'], function(exports){ precision = precision >= 0 ? precision : Math.max(decimals(step), decimals(rawValue)); - if(!noAction){ + // 初始化赋值 + if (!noAction) { // 初始渲染时只处理数字精度 - if(!isInit){ + if (!isInit) { if(value <= min) value = min; if(value >= max) value = max; } - if(precision) value = value.toFixed(precision); + // 若 `lay-precision` 为 0, 则表示只保留整数 + if (precision === 0) { + value = parseInt(value); + } else if(precision > 0) { // 小数位精度 + value = value.toFixed(precision); + } elem.val(value); }