Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
b7195628
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
719
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b7195628
编写于
12月 08, 2020
作者:
2
23700113@qq.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 修复slider组件step设置为小数时精度丢失,问题:112749
上级
aec26a6c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
90 addition
and
19 deletion
+90
-19
src/core/view/components/slider/index.vue
src/core/view/components/slider/index.vue
+90
-19
未找到文件。
src/core/view/components/slider/index.vue
浏览文件 @
b7195628
...
@@ -2,33 +2,33 @@
...
@@ -2,33 +2,33 @@
<uni-slider
<uni-slider
ref=
"uni-slider"
ref=
"uni-slider"
v-on=
"$listeners"
v-on=
"$listeners"
@
click=
"_onClick"
@
click=
"_onClick"
>
>
<div
class=
"uni-slider-wrapper"
>
<div
class=
"uni-slider-wrapper"
>
<div
class=
"uni-slider-tap-area"
>
<div
class=
"uni-slider-tap-area"
>
<div
<div
:style=
"setBgColor"
:style=
"setBgColor"
class=
"uni-slider-handle-wrapper"
class=
"uni-slider-handle-wrapper"
>
>
<div
<div
ref=
"uni-slider-handle"
ref=
"uni-slider-handle"
:style=
"setBlockBg"
:style=
"setBlockBg"
class=
"uni-slider-handle"
class=
"uni-slider-handle"
/>
/>
<div
<div
:style=
"setBlockStyle"
:style=
"setBlockStyle"
class=
"uni-slider-thumb"
class=
"uni-slider-thumb"
/>
/>
<div
<div
:style=
"setActiveColor"
:style=
"setActiveColor"
class=
"uni-slider-track"
class=
"uni-slider-track"
/>
/>
</div>
</div>
</div>
</div>
<span
<span
v-show=
"showValue"
v-show=
"showValue"
ref=
"uni-slider-value"
ref=
"uni-slider-value"
class=
"uni-slider-value"
class=
"uni-slider-value"
>
{{
sliderValue
}}
</span>
>
{{
sliderValue
}}
</span>
</div>
</div>
<slot
/>
<slot
/>
...
@@ -40,6 +40,78 @@ import {
...
@@ -40,6 +40,78 @@ import {
listeners
listeners
}
from
'
uni-mixins
'
}
from
'
uni-mixins
'
import
touchtrack
from
'
uni-mixins/touchtrack
'
import
touchtrack
from
'
uni-mixins/touchtrack
'
// 处理js计算小数时的精度问题
var
computeController
=
{
add
:
function
(
arg
)
{
var
r1
,
r2
,
m
try
{
// 获得小数位数
r1
=
this
.
toString
().
split
(
'
.
'
)[
1
].
length
}
catch
(
e
)
{
r1
=
0
}
try
{
// 获得小数位数
r2
=
arg
.
toString
().
split
(
'
.
'
)[
1
].
length
}
catch
(
e
)
{
r2
=
0
}
m
=
Math
.
pow
(
10
,
Math
.
max
(
r1
,
r2
))
return
(
this
*
m
+
arg
*
m
)
/
m
},
sub
:
function
(
arg
)
{
return
this
.
add
(
-
arg
)
},
mul
:
function
(
arg
)
{
var
m
=
0
;
var
s1
=
this
.
toString
();
var
s2
=
arg
.
toString
()
try
{
// 获得小数位数
m
+=
s1
.
split
(
'
.
'
)[
1
].
length
}
catch
(
e
)
{
}
try
{
// 获得小数位数
m
+=
s2
.
split
(
'
.
'
)[
1
].
length
}
catch
(
e
)
{
}
// 转为十进制计算后,要除以两个数的共同小数位数
return
Number
(
s1
.
replace
(
'
.
'
,
''
))
*
Number
(
s2
.
replace
(
'
.
'
,
''
))
/
Math
.
pow
(
10
,
m
)
},
div
:
function
(
arg
)
{
var
t1
=
0
;
var
t2
=
0
;
var
r1
;
var
r2
try
{
// 获得小数位数
t1
=
this
.
toString
().
split
(
'
.
'
)[
1
].
length
}
catch
(
e
)
{
}
try
{
// 获得小数位数
t2
=
arg
.
toString
().
split
(
'
.
'
)[
1
].
length
}
catch
(
e
)
{
}
r1
=
Number
(
this
.
toString
().
replace
(
'
.
'
,
''
))
r2
=
Number
(
arg
.
toString
().
replace
(
'
.
'
,
''
))
// 转为十进制计算后,要乘以除数与被除数小数位数的差
return
(
r1
/
r2
)
*
Math
.
pow
(
10
,
t2
-
t1
)
},
mod
:
function
(
arg
)
{
var
t1
=
0
;
var
t2
=
0
;
var
r1
;
var
r2
try
{
t1
=
this
.
toString
().
split
(
'
.
'
)[
1
].
length
}
catch
(
e
)
{
}
try
{
t2
=
arg
.
toString
().
split
(
'
.
'
)[
1
].
length
}
catch
(
e
)
{
}
// 小数位数
var
digit
=
Math
.
pow
(
10
,
Math
.
abs
(
t1
-
t2
))
// eslint-disable-next-line eqeqeq
if
(
digit
==
1
)
{
digit
=
Math
.
pow
(
10
,
t1
)
}
// 计算余数
r1
=
(
this
*
digit
).
toString
().
split
(
'
.
'
)[
0
]
r2
=
arg
*
digit
// 小数点后数字,直接拼接上即可
var
decimals
=
(
this
*
digit
).
toString
().
split
(
'
.
'
)[
1
]
?
(
this
*
digit
).
toString
().
split
(
'
.
'
)[
1
]
:
''
return
(
r1
%
r2
+
decimals
)
/
digit
}
}
export
default
{
export
default
{
name
:
'
Slider
'
,
name
:
'
Slider
'
,
mixins
:
[
emitter
,
listeners
,
touchtrack
],
mixins
:
[
emitter
,
listeners
,
touchtrack
],
...
@@ -151,22 +223,21 @@ export default {
...
@@ -151,22 +223,21 @@ export default {
})
})
},
},
methods
:
{
methods
:
{
_onUserChangedValue
(
e
)
{
_onUserChangedValue
(
e
)
{
const
sliderRightBox
=
this
.
$refs
[
'
uni-slider-value
'
]
const
sliderRightBox
=
this
.
$refs
[
'
uni-slider-value
'
]
const
sliderRightBoxLeft
=
getComputedStyle
(
sliderRightBox
,
null
).
marginLeft
const
sliderRightBoxLeft
=
getComputedStyle
(
sliderRightBox
,
null
).
marginLeft
let
sliderRightBoxWidth
=
sliderRightBox
.
offsetWidth
let
sliderRightBoxWidth
=
sliderRightBox
.
offsetWidth
sliderRightBoxWidth
=
sliderRightBoxWidth
+
parseInt
(
sliderRightBoxLeft
)
sliderRightBoxWidth
=
sliderRightBoxWidth
+
parseInt
(
sliderRightBoxLeft
)
const
slider
=
this
.
$refs
[
'
uni-slider
'
]
const
slider
=
this
.
$refs
[
'
uni-slider
'
]
const
offsetWidth
=
slider
.
offsetWidth
-
(
this
.
showValue
?
sliderRightBoxWidth
:
0
)
const
offsetWidth
=
slider
.
offsetWidth
-
(
this
.
showValue
?
sliderRightBoxWidth
:
0
)
const
boxLeft
=
slider
.
getBoundingClientRect
().
left
const
boxLeft
=
slider
.
getBoundingClientRect
().
left
const
value
=
(
e
.
x
-
boxLeft
)
*
(
this
.
max
-
this
.
min
)
/
offsetWidth
+
Number
(
this
.
min
)
const
value
=
(
e
.
x
-
boxLeft
)
*
(
this
.
max
-
this
.
min
)
/
offsetWidth
+
Number
(
this
.
min
)
this
.
sliderValue
=
this
.
_filterValue
(
value
)
this
.
sliderValue
=
this
.
_filterValue
(
value
)
},
},
_filterValue
(
e
)
{
_filterValue
(
e
)
{
const
max
=
Number
(
this
.
max
)
const
max
=
Number
(
this
.
max
)
const
min
=
Number
(
this
.
min
)
const
min
=
Number
(
this
.
min
)
return
e
<
min
?
min
:
e
>
max
?
max
:
Math
.
round
((
e
-
min
)
/
this
return
e
<
min
?
min
:
e
>
max
?
max
:
computeController
.
mul
.
call
(
Math
.
round
((
e
-
min
)
/
this
.
step
),
this
.
step
)
+
min
.
step
)
*
this
.
step
+
min
},
},
_getValueWidth
()
{
_getValueWidth
()
{
return
100
*
(
this
.
sliderValue
-
this
.
min
)
/
(
this
.
max
-
this
.
min
)
+
'
%
'
return
100
*
(
this
.
sliderValue
-
this
.
min
)
/
(
this
.
max
-
this
.
min
)
+
'
%
'
...
@@ -180,7 +251,7 @@ export default {
...
@@ -180,7 +251,7 @@ export default {
:
'
#e9e9e9
'
)
:
'
#e9e9e9
'
)
},
},
_onTrack
:
function
(
e
)
{
_onTrack
:
function
(
e
)
{
if
(
!
this
.
disabled
)
{
if
(
!
this
.
disabled
)
{
return
e
.
detail
.
state
===
'
move
'
?
(
this
.
_onUserChangedValue
({
return
e
.
detail
.
state
===
'
move
'
?
(
this
.
_onUserChangedValue
({
x
:
e
.
detail
.
x0
x
:
e
.
detail
.
x0
}),
this
.
$trigger
(
'
changing
'
,
e
,
{
}),
this
.
$trigger
(
'
changing
'
,
e
,
{
...
@@ -288,11 +359,11 @@ export default {
...
@@ -288,11 +359,11 @@ export default {
z-index
:
1
;
z-index
:
1
;
}
}
uni-slider
.uni-slider-value
{
uni-slider
.uni-slider-value
{
width
:
3ch
;
width
:
3ch
;
color
:
#888
;
color
:
#888
;
font-size
:
14px
;
font-size
:
14px
;
margin-left
:
1em
;
margin-left
:
1em
;
}
}
uni-slider
.uni-slider-disabled
.uni-slider-track
{
uni-slider
.uni-slider-disabled
.uni-slider-track
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录