From 6206d7bda513ca59a1254238c86d2a6e35c5168d Mon Sep 17 00:00:00 2001 From: ShuaiKang Zhang Date: Thu, 19 Sep 2019 16:04:52 +0800 Subject: [PATCH] feat(Slider): add dragStart&dragEnd events (#2059) --- packages/slider/README.md | 2 ++ packages/slider/index.ts | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/slider/README.md b/packages/slider/README.md index d5ba58aa..79184952 100644 --- a/packages/slider/README.md +++ b/packages/slider/README.md @@ -104,6 +104,8 @@ Page({ |-----------|-----------|-----------| | bind:drag | 拖动进度条时触发 | event.detail.value: 当前进度 | | bind:change | 进度值改变后触发 | event.detail: 当前进度 | +| bind:drag-start | 开始拖动时触发 | - | +| bind:drag-end | 结束拖动时触发 | - | ### 外部样式类 diff --git a/packages/slider/index.ts b/packages/slider/index.ts index 0ede9116..ce768328 100644 --- a/packages/slider/index.ts +++ b/packages/slider/index.ts @@ -49,12 +49,19 @@ VantComponent({ this.touchStart(event); this.startValue = this.format(this.data.value); + this.dragStatus = 'start'; }, onTouchMove(event: Weapp.TouchEvent) { if (this.data.disabled) return; + if (this.dragStatus === 'start') { + this.$emit('drag-start'); + } + this.touchMove(event); + this.dragStatus = 'draging'; + this.getRect('.van-slider').then((rect: WechatMiniprogram.BoundingClientRectCallbackResult) => { const diff = this.deltaX / rect.width * 100; this.newValue = this.startValue + diff; @@ -64,7 +71,11 @@ VantComponent({ onTouchEnd() { if (this.data.disabled) return; - this.updateValue(this.newValue, true); + + if (this.dragStatus === 'draging') { + this.updateValue(this.newValue, true); + this.$emit('drag-end'); + } }, onClick(event: Weapp.TouchEvent) {