Skip to content

Commit bea7a49

Browse files
author
xuqingkai
committed
feat: ✨ Slider 支持钉钉小程序
1 parent 924c65b commit bea7a49

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

src/uni_modules/wot-design-uni/components/wd-slider/wd-slider.vue

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
11
<template>
2-
<view :class="rootClass">
3-
<view :class="`wd-slider__label-min ${customMinClass}`" v-if="!hideMinMax">
4-
{{ minValue }}
5-
</view>
6-
<view class="wd-slider__bar-wrapper" :style="barWrapperStyle">
7-
<view class="wd-slider__bar" :style="barCustomStyle"></view>
8-
<!-- 左边 -->
9-
<view
10-
class="wd-slider__button-wrapper"
11-
:style="buttonLeftStyle"
12-
@touchstart="onTouchStart"
13-
@touchmove="onTouchMove"
14-
@touchend="onTouchEnd"
15-
@touchcancel="onTouchEnd"
16-
>
17-
<view class="wd-slider__label" v-if="!hideLabel">
18-
{{ leftNewValue }}
19-
</view>
20-
<view class="wd-slider__button" />
2+
<view :class="rootClass" :id="sliderId">
3+
<!-- #ifdef MP-DINGTALK -->
4+
<view :id="sliderId" style="flex: 1" :class="rootClass">
5+
<!-- #endif -->
6+
<view :class="`wd-slider__label-min ${customMinClass}`" v-if="!hideMinMax">
7+
{{ minValue }}
218
</view>
22-
<!-- 右边 -->
23-
<view
24-
v-if="showRight"
25-
class="wd-slider__button-wrapper"
26-
:style="buttonRightStyle"
27-
@touchstart="onTouchStartRight"
28-
@touchmove="onTouchMoveRight"
29-
@touchend="onTouchEndRight"
30-
@touchcancel="onTouchEndRight"
31-
>
32-
<view class="wd-slider__label" v-if="!hideLabel">
33-
{{ rightNewValue }}
9+
<view class="wd-slider__bar-wrapper" :style="barWrapperStyle">
10+
<view class="wd-slider__bar" :style="barCustomStyle"></view>
11+
<!-- 左边 -->
12+
<view
13+
class="wd-slider__button-wrapper"
14+
:style="buttonLeftStyle"
15+
@touchstart="onTouchStart"
16+
@touchmove="onTouchMove"
17+
@touchend="onTouchEnd"
18+
@touchcancel="onTouchEnd"
19+
>
20+
<view class="wd-slider__label" v-if="!hideLabel">
21+
{{ leftNewValue }}
22+
</view>
23+
<view class="wd-slider__button" />
24+
</view>
25+
<!-- 右边 -->
26+
<view
27+
v-if="showRight"
28+
class="wd-slider__button-wrapper"
29+
:style="buttonRightStyle"
30+
@touchstart="onTouchStartRight"
31+
@touchmove="onTouchMoveRight"
32+
@touchend="onTouchEndRight"
33+
@touchcancel="onTouchEndRight"
34+
>
35+
<view class="wd-slider__label" v-if="!hideLabel">
36+
{{ rightNewValue }}
37+
</view>
38+
<view class="wd-slider__button" />
3439
</view>
35-
<view class="wd-slider__button" />
3640
</view>
41+
<view :class="`wd-slider__label-max ${customMaxClass}`" v-if="!hideMinMax">
42+
{{ maxValue }}
43+
</view>
44+
<!-- #ifdef MP-DINGTALK -->
3745
</view>
38-
<view :class="`wd-slider__label-max ${customMaxClass}`" v-if="!hideMinMax">
39-
{{ maxValue }}
40-
</view>
46+
<!-- #endif -->
4147
</view>
4248
</template>
4349

@@ -54,7 +60,7 @@ export default {
5460

5561
<script lang="ts" setup>
5662
import { computed, getCurrentInstance, onMounted, ref } from 'vue'
57-
import { getRect, isArray, isDef } from '../common/util'
63+
import { getRect, isArray, isDef, uuid } from '../common/util'
5864
import { useTouch } from '../composables/useTouch'
5965
import { watch } from 'vue'
6066
@@ -94,11 +100,11 @@ const rightSlider = {
94100
deltaX: 0,
95101
newValue: 0
96102
}
103+
const sliderId = ref<string>(`sliderId${uuid()}`)
97104
98105
const touchLeft = useTouch()
99106
const touchRight = useTouch()
100107
101-
const $slider = '.wd-slider'
102108
const showRight = ref<boolean>(false)
103109
const barStyle = ref<string>('width: 0; height: 3px')
104110
const barHeight = ref<string>('3px')
@@ -222,7 +228,7 @@ const buttonRightStyle = computed(() => {
222228
})
223229
224230
onMounted(() => {
225-
getRect($slider, false, proxy).then((data: any) => {
231+
getRect(`#${sliderId.value}`, false, proxy).then((data: any) => {
226232
// trackWidth: 轨道全长
227233
trackWidth.value = data.width
228234
// trackLeft: 轨道距离左侧的距离

0 commit comments

Comments
 (0)