From 27ccdcc8b97746bc1d073613c9b4bbd4f1a8f2fd Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Fri, 29 Mar 2024 19:58:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20input=20=E5=9C=A8=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E5=B0=8F=E6=95=B0=E7=82=B9=E6=97=B6=E4=B8=8D=E4=B8=8A=E5=B1=8F?= =?UTF-8?q?=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uni-components/src/vue/input/index.tsx | 66 +++++++++++-------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/packages/uni-components/src/vue/input/index.tsx b/packages/uni-components/src/vue/input/index.tsx index 3b4146758c..e00406a4d8 100644 --- a/packages/uni-components/src/vue/input/index.tsx +++ b/packages/uni-components/src/vue/input/index.tsx @@ -86,30 +86,32 @@ export default /*#__PURE__*/ defineBuiltInComponent({ input.removeEventListener('blur', resetCache) resetCache = null } - //ios 16之后number类型连续输入3个小数点后会自动删除数字 - if ( - plus.os.version && - plus.os.name === 'iOS' && - parseFloat(plus.os.version) >= 16.0 - ) { - if (cache.value && !state.value && !input.value) { - pointCount = pointCount >= 2 ? pointCount : pointCount + 1 - if (cache.value.includes('.')) { - input.value = cache.value - return true - } - return false - } + if (__PLATFORM__ === 'app') { + //ios 16之后number类型连续输入3个小数点后会自动删除数字 if ( - cache.value.includes('.') && - state.value == cache.value.slice(0, -1) && - pointCount >= 2 + plus.os.version && + plus.os.name === 'iOS' && + parseFloat(plus.os.version) >= 16.0 ) { - state.value = input.value = cache.value - return true + if (cache.value && !state.value && !input.value) { + pointCount = pointCount >= 2 ? pointCount : pointCount + 1 + if (cache.value.includes('.')) { + input.value = cache.value + return true + } + return false + } + if ( + cache.value.includes('.') && + state.value == cache.value.slice(0, -1) && + pointCount >= 2 + ) { + state.value = input.value = cache.value + return true + } } + pointCount = 0 } - pointCount = 0 if (input.validity && !input.validity.valid) { if ( ((!cache.value || !input.value) && @@ -126,12 +128,9 @@ export default /*#__PURE__*/ defineBuiltInComponent({ return false } // 处理小数点 - if (cache.value) { - if ((event as InputEvent).data === '.') { - // 输入小数点时 - cache.value += '.' - return false - } + if (cache.value && (event as InputEvent).data === '.') { + cache.value += '.' + return false } cache.value = state.value = @@ -140,6 +139,11 @@ export default /*#__PURE__*/ defineBuiltInComponent({ // 输入非法字符不触发 input 事件 return false } else { + // 处理在 chrome 中输入 . 不上屏的问题 + if (cache.value && (event as InputEvent).data === '.') { + cache.value += '.' + return false + } cache.value = input.value } @@ -157,7 +161,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({ () => state.value, (value) => { if (props.type === 'number' && !(cache.value === '-' && value === '')) { - cache.value = value + cache.value = value.toString() } } ) @@ -242,7 +246,13 @@ export default /*#__PURE__*/ defineBuiltInComponent({