From 1f227a9d9d688ee562c851f0c889565f5e0bb9ea Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 24 Nov 2023 11:52:07 +0800 Subject: [PATCH] =?UTF-8?q?slider=E7=BB=84=E4=BB=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E9=99=90=E5=88=B6=E9=80=BB=E8=BE=91,=20?= =?UTF-8?q?=E5=B9=B6=E7=A7=BB=E5=85=A5=E8=A1=A8=E5=8D=95=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/form/index.js | 1 + src/{slider/index.js => form/slider.js} | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) rename src/{slider/index.js => form/slider.js} (96%) diff --git a/src/form/index.js b/src/form/index.js index 77f2e3e..acc2971 100644 --- a/src/form/index.js +++ b/src/form/index.js @@ -9,3 +9,4 @@ import './select.js' import './star.js' import './switch.js' import './textarea.js' +import './slider.js' diff --git a/src/slider/index.js b/src/form/slider.js similarity index 96% rename from src/slider/index.js rename to src/form/slider.js index 1d43a5c..4edca1c 100644 --- a/src/slider/index.js +++ b/src/form/slider.js @@ -38,8 +38,8 @@ class Slider extends Component { } }, vertical: false, - range: false, - disabled: false + disabled: false, + lazy: 'num!0' } #len = 100 @@ -48,6 +48,8 @@ class Slider extends Component { #value = 0 // 内部的值, 固定使用 0-100范围的值 #decimal = 0 //小数位 + #stamp = 0 + static styles = [ css` :host { @@ -241,8 +243,9 @@ class Slider extends Component { #seek(ev) { let { clientWidth: w, clientHeight: h } = ev.target - let { min, max, step } = this + let { min, max, step, lazy } = this let val = 0 + let now = Date.now() if (this.vertical) { val = (h - ev.y) / h @@ -253,7 +256,14 @@ class Slider extends Component { val += min this.value = this.#fix(val) + + // 并发拦截 + if (lazy > 0 && now - this.#stamp < lazy) { + return + } + this.#stamp = now this.$emit('input') + this.$emit('change') } #mousedown(ev) {