File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
src/uni_modules/wot-design-uni/components/wd-slider Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ watch(
102102 } else {
103103 maxValue .value = newValue // 更新最大值
104104 }
105+ calcBarPercent ()
105106 },
106107 { immediate: true }
107108)
@@ -116,6 +117,7 @@ watch(
116117 } else {
117118 minValue .value = newValue // 更新最小值
118119 }
120+ calcBarPercent ()
119121 },
120122 { immediate: true }
121123)
@@ -328,6 +330,16 @@ function formatPercent(value: number) {
328330 const percentage = ((value - minValue .value ) / (maxValue .value - minValue .value )) * 100
329331 return percentage
330332}
333+ // 计算滑块位置和进度长度
334+ function calcBarPercent() {
335+ const { modelValue } = props
336+ let value = ! isArray (modelValue ) ? format (modelValue ) : leftBarPercent .value < rightBarPercent .value ? format (modelValue [0 ]) : format (modelValue [1 ])
337+ value = format (value )
338+ // 把 value 转换成百分比
339+ const percent = formatPercent (value )
340+ leftBarPercent .value = percent
341+ barStyle .value = ` width: ${percent }%; height: ${barHeight .value }; `
342+ }
331343 </script >
332344<style lang="scss" scoped>
333345@import ' ./index.scss' ;
You can’t perform that action at this time.
0 commit comments