From 5b1e863066b4162420b73de75a0a8db4e69f1214 Mon Sep 17 00:00:00 2001 From: aisen Date: Mon, 1 Dec 2025 14:41:53 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8Dinput=20=E4=B8=BA?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=A1=86=E6=97=B6=E6=B2=A1=E6=9C=89=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tuniao-ui/components/tn-input/tn-input.vue | 61 +++++++++++++--------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/tuniao-ui/components/tn-input/tn-input.vue b/tuniao-ui/components/tn-input/tn-input.vue index 6387eef..2d1f513 100644 --- a/tuniao-ui/components/tn-input/tn-input.vue +++ b/tuniao-ui/components/tn-input/tn-input.vue @@ -45,7 +45,7 @@ v-if="type === 'select'" class="tn-input__text" > - {{defaultValue == undefined || defaultValue == '' ? placeholder : defaultValue }} + {{defaultValue == undefined || defaultValue == '' ? placeholder : defaultValue }} { - // 头条小程序由于自身bug,导致中文下,每按下一个键(尚未完成输入),都会触发一次@input,导致错误,这里进行判断处理 - // #ifdef MP-TOUTIAO - if (this.$tn.string.trim(value) === this.lastValue) return - this.lastValue = value - // #endif - - // 发送当前的值到form-item进行校验 - this.dispatch('tn-form-item','on-form-change', value) - }, 40) - },this.blockTime), + handleInput:()=>{}, /** * blur事件 */ @@ -407,7 +386,35 @@ inputClick() { this.$emit('click') } - } + }, + mounted() { + let that = this; + that.handleInput = debounceFun(function(event){ + let value = event.detail.value + // 是否需要去掉空格 + try { + if (that.trim) value = that.$tn.string.trim(value) + }catch (e){ + } + // 原生事件 + that.$emit('input', value) + // model赋值 + that.defaultValue = value + // 过一个生命周期再发送事件给tn-form-item,否则this.$emit('input')更新了父组件的值,但是微信小程序上 + // 尚未更新到tn-form-item,导致获取的值为空,从而校验混论 + // 这里不能延时时间太短,或者使用this.$nextTick,否则在头条上,会造成混乱 + setTimeout(() => { + // 头条小程序由于自身bug,导致中文下,每按下一个键(尚未完成输入),都会触发一次@input,导致错误,这里进行判断处理 + // #ifdef MP-TOUTIAO + if (that.$tn.string.trim(value) === that.lastValue) return + that.lastValue = value + // #endif + + // 发送当前的值到form-item进行校验 + that.dispatch('tn-form-item','on-form-change', value) + }, 40) + },that.blockTime); + }, } @@ -417,7 +424,11 @@ flex-direction: row; position: relative; flex: 1; - + + &__placeholder{ + color: $tn-font-sub-color; + } + &__input { font-size: 28rpx; color: $tn-font-color;