From fc411565b9c4e358b3c06f35ec81bea97f6fc8d3 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 21 Aug 2022 17:00:10 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20NumInput?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/share/NumInput.vue | 48 +++++++++++++++++++++------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/client/components/share/NumInput.vue b/client/components/share/NumInput.vue index c0aab0a..57d309a 100644 --- a/client/components/share/NumInput.vue +++ b/client/components/share/NumInput.vue @@ -14,7 +14,7 @@ :class="(validate(modelValue - step) ? '' : 'disable')" :name="minusIcon" class="button" - @click="minus" + @click="onClick('minus')" @mousedown.prevent.stop="onMouseDown($event, 'minus')" @mouseup.prevent.stop="onMouseUp" @mouseout.prevent.stop="onMouseUp" @@ -29,7 +29,7 @@ :class="(validate(modelValue + step) ? '' : 'disable')" :name="plusIcon" class="button" - @click="plus" + @click="onClick('plus')" @mousedown.prevent.stop="onMouseDown($event, 'plus')" @mouseup.prevent.stop="onMouseUp" @mouseout.prevent.stop="onMouseUp" @@ -109,23 +109,42 @@ class NumInput { this.filteredValue = newValue; } + onClick(way) { + if (this.clickRepeat) + return; + + if (way == 'plus') { + this.plus(); + } else { + this.minus(); + } + } + onMouseDown(event, way) { this.startClickRepeat = true; this.clickRepeat = false; if (event.button == 0) { (async() => { - await utils.sleep(300); - if (this.startClickRepeat) { - this.clickRepeat = true; - while (this.clickRepeat) { - if (way == 'plus') { - this.plus(); - } else { - this.minus(); + if (this.inRepeatFunc) + return; + + this.inRepeatFunc = true; + try { + await utils.sleep(300); + if (this.startClickRepeat) { + this.clickRepeat = true; + while (this.clickRepeat) { + if (way == 'plus') { + this.plus(); + } else { + this.minus(); + } + await utils.sleep(200); } - await utils.sleep(50); } + } finally { + this.inRepeatFunc = false; } })(); } @@ -135,7 +154,12 @@ class NumInput { if (this.inTouch) return; this.startClickRepeat = false; - this.clickRepeat = false; + if (this.clickRepeat) { + (async() => { + await utils.sleep(50); + this.clickRepeat = false; + })(); + } } onTouchStart(event, way) {