From 2f95f4f8b3d9cd23a7a0a584c78c620c196b3360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Thu, 11 Mar 2021 15:36:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dinput,number=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E7=9A=84lazy=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/form/input.wc | 2 +- src/form/number.wc | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/form/input.wc b/src/form/input.wc index 4481b97..b77f2a3 100644 --- a/src/form/input.wc +++ b/src/form/input.wc @@ -472,7 +472,7 @@ export default class Input { // 键盘事件 this._handleSubmit = $.catch(this.__INPUT__, 'keydown', ev => { - let { passwd, minlength } = this.props + let { passwd, minlength, lazy } = this.props let val = this.value let now = Date.now() diff --git a/src/form/number.wc b/src/form/number.wc index b86409a..2c130c3 100644 --- a/src/form/number.wc +++ b/src/form/number.wc @@ -218,7 +218,8 @@ export default class Number { step: 1, autofocus: false, readonly: false, - disabled: false + disabled: false, + lazy: 0 } __init__() { @@ -330,8 +331,13 @@ export default class Number { } mounted() { + this.stamp = 0 + // 键盘事件 this._handleSubmit = $.catch(this.__INPUT__, 'keydown', ev => { + let now = Date.now() + let { lazy } = this.props + if (this.disabled || this.readOnly) { return } @@ -344,6 +350,14 @@ export default class Number { // 回车触发submit事件 if (ev.keyCode === 13) { ev.preventDefault() + + // 并发拦截 + if (lazy && now - this.stamp < lazy) { + return + } + + this.stamp = now + this.dispatchEvent( new CustomEvent('submit', { detail: this.value @@ -400,6 +414,10 @@ export default class Number { this._checkActionEnable() break + case 'lazy': + this.props.lazy = val >> 0 + break + case 'readonly': case 'disabled': var k = name