From 60d46f82ef88e781742107e36a3c9f59cc90c129 Mon Sep 17 00:00:00 2001 From: haibiao_gu Date: Fri, 7 Nov 2025 14:36:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(cl-input):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E8=BE=93=E5=85=A5=E7=B2=BE=E5=BA=A6=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 precision 属性用于控制数字类型输入框的小数位数 - 实现输入值的精度校验与格式化逻辑 - 添加超出精度限制时的样式提示 - 支持深色模式下的精度超限颜色适配 - 在 demo 页面中增加精度控制示例 --- pages/demo/form/input.uvue | 12 ++++++ .../cool-ui/components/cl-input/cl-input.uvue | 40 ++++++++++++++++++- .../cool-ui/components/cl-input/props.ts | 1 + 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/pages/demo/form/input.uvue b/pages/demo/form/input.uvue index a82b279..ac2bb79 100644 --- a/pages/demo/form/input.uvue +++ b/pages/demo/form/input.uvue @@ -59,6 +59,16 @@ + + 当 type 为 number 时,可设置 precision 属性来保留精度 + + + + + + + + (2); + function toAlert() { ui.showToast({ message: "Hello" diff --git a/uni_modules/cool-ui/components/cl-input/cl-input.uvue b/uni_modules/cool-ui/components/cl-input/cl-input.uvue index 5f0037b..04fd0eb 100644 --- a/uni_modules/cool-ui/components/cl-input/cl-input.uvue +++ b/uni_modules/cool-ui/components/cl-input/cl-input.uvue @@ -8,7 +8,7 @@ 'cl-input--border': border, 'cl-input--focus': isFocus, 'cl-input--disabled': isDisabled, - 'cl-input--error': isError + 'cl-input--error': isError, } ]" @tap="onTap" @@ -28,7 +28,8 @@ :class="[ { 'is-disabled': isDisabled, - 'is-dark': isDark + 'is-dark': isDark, + 'is-exceed': isExceed }, ptClassName ]" @@ -189,6 +190,11 @@ const props = defineProps({ holdKeyboard: { type: Boolean, default: false + }, + // 保留精度 + precision: { + type: Number, + default: 0 } }); @@ -256,6 +262,17 @@ const showClear = computed(() => { // 是否显示密码 const isPassword = ref(props.password); +// 是否超出限制 +const isExceed = computed(() => { + // 检查数字精度是否超出限制 + if (props.type == "number" && props.precision >= 0 && value.value != "") { + const parts = value.value.split("."); + return parts.length > 1 && parts[1].length > props.precision; + } else { + return false; + } +}); + // 切换密码显示状态 function showPassword() { isPassword.value = !isPassword.value; @@ -271,6 +288,17 @@ function onFocus(e: UniInputFocusEvent) { function onBlur(e: UniInputBlurEvent) { emit("blur", e); + // 处理数字精度 + if (props.type == "number" && props.precision > 0 && value.value != "") { + const numValue = parseFloat(value.value); + if (!isNaN(numValue)) { + const formattedValue = numValue.toFixed(props.precision); + value.value = formattedValue; + emit("update:modelValue", formattedValue); + emit("change", formattedValue); + } + } + setTimeout(() => { isFocus.value = false; }, 0); @@ -367,6 +395,14 @@ defineExpose({ &.is-dark { @apply text-white; } + + &.is-exceed { + @apply text-red-500; + } + + &.is-exceed.is-dark { + @apply text-red-400; + } } &__icon { diff --git a/uni_modules/cool-ui/components/cl-input/props.ts b/uni_modules/cool-ui/components/cl-input/props.ts index a75909b..f5e5909 100644 --- a/uni_modules/cool-ui/components/cl-input/props.ts +++ b/uni_modules/cool-ui/components/cl-input/props.ts @@ -29,4 +29,5 @@ export type ClInputProps = { adjustPosition?: boolean; maxlength?: number; holdKeyboard?: boolean; + precision?: number; }; From a49a38c5f97498a8a56a754752e8085c2ea83e8e Mon Sep 17 00:00:00 2001 From: icssoa <615206459@qq.com> Date: Sun, 9 Nov 2025 23:28:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=B0=86=20precision=20=E7=9A=84=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E7=B1=BB=E5=9E=8B=E7=94=B1=20number=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E4=B8=BA=20digit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/demo/form/input.uvue | 12 +++++++----- .../cool-ui/components/cl-input/cl-input.uvue | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pages/demo/form/input.uvue b/pages/demo/form/input.uvue index ac2bb79..5d253d2 100644 --- a/pages/demo/form/input.uvue +++ b/pages/demo/form/input.uvue @@ -60,13 +60,15 @@ - 当 type 为 number 时,可设置 precision 属性来保留精度 + 当 type 为 digit 时,可设置 precision 属性来保留精度 - - - + - + + + + + diff --git a/uni_modules/cool-ui/components/cl-input/cl-input.uvue b/uni_modules/cool-ui/components/cl-input/cl-input.uvue index 04fd0eb..7c8cfb0 100644 --- a/uni_modules/cool-ui/components/cl-input/cl-input.uvue +++ b/uni_modules/cool-ui/components/cl-input/cl-input.uvue @@ -23,6 +23,7 @@ > + = 0 && value.value != "") { + if (props.type == "digit" && props.precision >= 0 && value.value != "") { const parts = value.value.split("."); return parts.length > 1 && parts[1].length > props.precision; } else { @@ -289,7 +290,7 @@ function onBlur(e: UniInputBlurEvent) { emit("blur", e); // 处理数字精度 - if (props.type == "number" && props.precision > 0 && value.value != "") { + if (props.type == "digit" && props.precision > 0 && value.value != "") { const numValue = parseFloat(value.value); if (!isNaN(numValue)) { const formattedValue = numValue.toFixed(props.precision); From b74a63fac19c421c8f8a2ef752a9c2f33036458f Mon Sep 17 00:00:00 2001 From: icssoa <615206459@qq.com> Date: Sun, 9 Nov 2025 23:28:47 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E6=83=85=E5=86=B5=E4=B8=8B=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?=E9=AB=98=E5=BA=A6=E4=B8=8D=E4=B8=80=E8=87=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cool-ui/components/cl-input-number/cl-input-number.uvue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/uni_modules/cool-ui/components/cl-input-number/cl-input-number.uvue b/uni_modules/cool-ui/components/cl-input-number/cl-input-number.uvue index 527d874..ea13c7d 100644 --- a/uni_modules/cool-ui/components/cl-input-number/cl-input-number.uvue +++ b/uni_modules/cool-ui/components/cl-input-number/cl-input-number.uvue @@ -7,6 +7,9 @@ }, pt.className ]" + :style="{ + height: parseRpx(size!) + }" >