Skip to content

Commit c6189f2

Browse files
committed
refactor: slider
1 parent 7ce9066 commit c6189f2

File tree

7 files changed

+15
-9
lines changed

7 files changed

+15
-9
lines changed

example/pages/slider/index-ios.mpx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
createPage({
1818
data: {
19-
currentValue: false
19+
currentValue: 0
2020
},
2121
methods: {
2222
handleChange(e) {

example/pages/slider/slider-default.mpx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
createComponent({
1414
data: {
15-
currentValue: false
15+
currentValue: 0
1616
},
1717
methods: {
1818
handleChange(e) {

example/pages/slider/slider-min-max.mpx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
createComponent({
1717
data: {
18-
currentValue: false
18+
currentValue: 0
1919
},
2020
methods: {
2121
handleChange(e) {

example/pages/slider/slider-slot.mpx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
createComponent({
1717
data: {
18-
currentValue: false
18+
currentValue: 0
1919
},
2020
methods: {
2121
handleChange(e) {

example/pages/slider/slider-step.mpx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
createComponent({
1515
data: {
16-
currentValue: false
16+
currentValue: 0
1717
},
1818
methods: {
1919
handleChange(e) {

example/pages/slider/slider-value.mpx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
createComponent({
1515
data: {
16-
currentValue: false
16+
currentValue: 0
1717
},
1818
methods: {
1919
handleChange(e) {

packages/mpx-cube-ui/src/components/slider/slider.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MOUNTED } from '@mpxjs/core'
12
import { createComponent } from '../../common/helper/create-component'
23

34
const EVENT_CHANGE = 'change' // 完成一次拖动后触发的事件
@@ -117,6 +118,11 @@ createComponent({
117118
immediate: true
118119
}
119120
},
121+
[MOUNTED]() {
122+
this.getRect().then(res => {
123+
this.startDragRect = res
124+
})
125+
},
120126
computed: {
121127
sliderClass() {
122128
return {
@@ -183,7 +189,7 @@ createComponent({
183189
}
184190
},
185191
methods: {
186-
getOffsetX() {
192+
getRect() {
187193
return new Promise((resolve) => {
188194
this.createSelectorQuery()
189195
.select('.cube-slider-tab-area')
@@ -212,17 +218,17 @@ createComponent({
212218
}
213219
},
214220
async onClick(e) {
215-
const rect = await this.getOffsetX()
221+
const rect = await this.getRect()
216222
this.calcProgress(e.detail.x, rect)
217223
// 完成一次拖动后触发的事件
218224
// @arg event.detail = {value}
219225
this.triggerEvent(EVENT_CHANGE, { value: this.currentValue })
220226
},
221227
async startHandler(e) {
222-
this.startDragRect = await this.getOffsetX()
223228
if (__mpx_mode__ === 'web') {
224229
e && e.preventDefault()
225230
}
231+
this.startDragRect = await this.getRect()
226232
},
227233
moveHandler(e) {
228234
if (!this.startDragRect) {

0 commit comments

Comments
 (0)