From 2d5c4a7fe5fa7c449b2b578f43838907deecbc89 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Wed, 8 May 2024 17:28:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(app):=20=E8=A7=A3=E5=86=B3=20iOS=20?= =?UTF-8?q?=E4=B8=8A=20input=20digit=20=E8=BE=93=E5=85=A5=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E5=B0=8F=E6=95=B0=E7=82=B9=E6=B8=85=E7=A9=BA=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=A1=86=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/view/components/input/index.vue | 50 ++++++++++++------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/core/view/components/input/index.vue b/src/core/view/components/input/index.vue index 848bc34855..7ba4a3a2d8 100644 --- a/src/core/view/components/input/index.vue +++ b/src/core/view/components/input/index.vue @@ -225,6 +225,23 @@ export default { input.blur() } }, + _resolveDigitDecimalPoint ($event) { + if ($event.data === '.') { + if (__PLATFORM__ === 'app-plus') { + if (this.cachedValue.slice(-1) === '.') { + this.valueSync = $event.target.value = this.cachedValue = this.cachedValue.slice(0, -1) + return false + } else if (this.cachedValue.includes('.')) { + this.valueSync = $event.target.value = this.cachedValue + return false + } + } + if (this.cachedValue) { + this.cachedValue += '.' + return false + } + } + }, _onInput ($event, force) { let outOfMaxlength = false @@ -263,36 +280,17 @@ export default { return } // 处理小数点 - if (this.cachedValue) { - if (this.cachedValue.indexOf('.') !== -1) { - // 删除到小数点时 - if ( - $event.data !== '.' && - $event.inputType === 'deleteContentBackward' - ) { - const dotIndex = this.cachedValue.indexOf('.') - this.cachedValue = - $event.target.value = - this.valueSync = - this.cachedValue.slice(0, dotIndex) - return this.$triggerInput($event, { - value: this.valueSync - }, force) - } - } else if ($event.data === '.') { - // 输入小数点时 - this.cachedValue += '.' - this.__clearCachedValue = () => { - this.cachedValue = this.valueSync = $event.target.value = this.cachedValue.slice(0, -1) - } - $event.target.addEventListener('blur', this.__clearCachedValue) - return false - } - } + const res = this._resolveDigitDecimalPoint($event) + if (typeof res === 'boolean') return res + this.cachedValue = this.valueSync = $event.target.value = this.cachedValue === '-' ? '' : this.cachedValue // 输入非法字符不触发 input 事件 return } else { + // 处理小数点 + const res = this._resolveDigitDecimalPoint($event) + if (typeof res === 'boolean') return res + this.cachedValue = this.valueSync } } -- GitLab