Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
b206747e
Commit
b206747e
authored
Jan 21, 2018
by
baiyaaaaa
Committed by
杨奕
Jan 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
InputNumber: support undefined value (#9361)
parent
98bdee26
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
24 deletions
+21
-24
packages/input-number/src/input-number.vue
packages/input-number/src/input-number.vue
+21
-24
No files found.
packages/input-number/src/input-number.vue
View file @
b206747e
...
@@ -8,39 +8,39 @@
...
@@ -8,39 +8,39 @@
]"
]"
>
>
<span
<span
v-if=
"controls"
class=
"el-input-number__decrease"
class=
"el-input-number__decrease"
:class=
"
{'is-disabled': minDisabled}"
role=
"button"
v-if=
"controls"
v-repeat-click=
"decrease"
v-repeat-click=
"decrease"
:class=
"
{'is-disabled': minDisabled}"
@keydown.enter="decrease"
@keydown.enter="decrease"
role="button"
>
>
<i
:class=
"`el-icon-$
{controlsAtRight ? 'arrow-down' : 'minus'}`">
</i>
<i
:class=
"`el-icon-$
{controlsAtRight ? 'arrow-down' : 'minus'}`">
</i>
</span>
</span>
<span
<span
v-if=
"controls"
class=
"el-input-number__increase"
class=
"el-input-number__increase"
:class=
"
{'is-disabled': maxDisabled}"
role=
"button"
v-if=
"controls"
v-repeat-click=
"increase"
v-repeat-click=
"increase"
:class=
"
{'is-disabled': maxDisabled}"
@keydown.enter="increase"
@keydown.enter="increase"
role="button"
>
>
<i
:class=
"`el-icon-$
{controlsAtRight ? 'arrow-up' : 'plus'}`">
</i>
<i
:class=
"`el-icon-$
{controlsAtRight ? 'arrow-up' : 'plus'}`">
</i>
</span>
</span>
<el-input
<el-input
ref=
"input"
:value=
"currentValue"
:value=
"currentValue"
@
keydown.up.native.prevent=
"increase"
@
keydown.down.native.prevent=
"decrease"
@
blur=
"handleBlur"
@
focus=
"handleFocus"
@
change=
"handleInputChange"
:disabled=
"disabled"
:disabled=
"disabled"
:size=
"inputNumberSize"
:size=
"inputNumberSize"
:max=
"max"
:max=
"max"
:min=
"min"
:min=
"min"
:name=
"name"
:name=
"name"
ref=
"input"
:label=
"label"
:label=
"label"
@
keydown.up.native.prevent=
"increase"
@
keydown.down.native.prevent=
"decrease"
@
blur=
"handleBlur"
@
focus=
"handleFocus"
@
change=
"handleInputChange"
>
>
<template
slot=
"prepend"
v-if=
"$slots.prepend"
>
<template
slot=
"prepend"
v-if=
"$slots.prepend"
>
<slot
name=
"prepend"
></slot>
<slot
name=
"prepend"
></slot>
...
@@ -83,9 +83,7 @@
...
@@ -83,9 +83,7 @@
type
:
Number
,
type
:
Number
,
default
:
-
Infinity
default
:
-
Infinity
},
},
value
:
{
value
:
{},
default
:
0
},
disabled
:
Boolean
,
disabled
:
Boolean
,
size
:
String
,
size
:
String
,
controls
:
{
controls
:
{
...
@@ -108,8 +106,8 @@
...
@@ -108,8 +106,8 @@
value
:
{
value
:
{
immediate
:
true
,
immediate
:
true
,
handler
(
value
)
{
handler
(
value
)
{
let
newVal
=
Number
(
value
);
let
newVal
=
value
===
undefined
?
value
:
Number
(
value
);
if
(
isNaN
(
newVal
))
return
;
if
(
newVal
!==
undefined
&&
isNaN
(
newVal
))
return
;
if
(
newVal
>=
this
.
max
)
newVal
=
this
.
max
;
if
(
newVal
>=
this
.
max
)
newVal
=
this
.
max
;
if
(
newVal
<=
this
.
min
)
newVal
=
this
.
min
;
if
(
newVal
<=
this
.
min
)
newVal
=
this
.
min
;
this
.
currentValue
=
newVal
;
this
.
currentValue
=
newVal
;
...
@@ -144,6 +142,7 @@
...
@@ -144,6 +142,7 @@
return
parseFloat
(
parseFloat
(
Number
(
num
).
toFixed
(
precision
)));
return
parseFloat
(
parseFloat
(
Number
(
num
).
toFixed
(
precision
)));
},
},
getPrecision
(
value
)
{
getPrecision
(
value
)
{
if
(
value
===
undefined
)
return
0
;
const
valueString
=
value
.
toString
();
const
valueString
=
value
.
toString
();
const
dotPosition
=
valueString
.
indexOf
(
'
.
'
);
const
dotPosition
=
valueString
.
indexOf
(
'
.
'
);
let
precision
=
0
;
let
precision
=
0
;
...
@@ -153,14 +152,14 @@
...
@@ -153,14 +152,14 @@
return
precision
;
return
precision
;
},
},
_increase
(
val
,
step
)
{
_increase
(
val
,
step
)
{
if
(
typeof
val
!==
'
number
'
)
return
this
.
currentValue
;
if
(
typeof
val
!==
'
number
'
&&
val
!==
undefined
)
return
this
.
currentValue
;
const
precisionFactor
=
Math
.
pow
(
10
,
this
.
precision
);
const
precisionFactor
=
Math
.
pow
(
10
,
this
.
precision
);
// Solve the accuracy problem of JS decimal calculation by converting the value to integer.
return
this
.
toPrecision
((
precisionFactor
*
val
+
precisionFactor
*
step
)
/
precisionFactor
);
return
this
.
toPrecision
((
precisionFactor
*
val
+
precisionFactor
*
step
)
/
precisionFactor
);
},
},
_decrease
(
val
,
step
)
{
_decrease
(
val
,
step
)
{
if
(
typeof
val
!==
'
number
'
)
return
this
.
currentValue
;
if
(
typeof
val
!==
'
number
'
&&
val
!==
undefined
)
return
this
.
currentValue
;
const
precisionFactor
=
Math
.
pow
(
10
,
this
.
precision
);
const
precisionFactor
=
Math
.
pow
(
10
,
this
.
precision
);
...
@@ -170,14 +169,12 @@
...
@@ -170,14 +169,12 @@
if
(
this
.
disabled
||
this
.
maxDisabled
)
return
;
if
(
this
.
disabled
||
this
.
maxDisabled
)
return
;
const
value
=
this
.
value
||
0
;
const
value
=
this
.
value
||
0
;
const
newVal
=
this
.
_increase
(
value
,
this
.
step
);
const
newVal
=
this
.
_increase
(
value
,
this
.
step
);
if
(
newVal
>
this
.
max
)
return
;
this
.
setCurrentValue
(
newVal
);
this
.
setCurrentValue
(
newVal
);
},
},
decrease
()
{
decrease
()
{
if
(
this
.
disabled
||
this
.
minDisabled
)
return
;
if
(
this
.
disabled
||
this
.
minDisabled
)
return
;
const
value
=
this
.
value
||
0
;
const
value
=
this
.
value
||
0
;
const
newVal
=
this
.
_decrease
(
value
,
this
.
step
);
const
newVal
=
this
.
_decrease
(
value
,
this
.
step
);
if
(
newVal
<
this
.
min
)
return
;
this
.
setCurrentValue
(
newVal
);
this
.
setCurrentValue
(
newVal
);
},
},
handleBlur
(
event
)
{
handleBlur
(
event
)
{
...
@@ -200,8 +197,8 @@
...
@@ -200,8 +197,8 @@
this
.
currentValue
=
newVal
;
this
.
currentValue
=
newVal
;
},
},
handleInputChange
(
value
)
{
handleInputChange
(
value
)
{
const
newVal
=
Number
(
value
);
const
newVal
=
value
===
''
?
undefined
:
Number
(
value
);
if
(
!
isNaN
(
newVal
))
{
if
(
!
isNaN
(
newVal
)
||
value
===
''
)
{
this
.
setCurrentValue
(
newVal
);
this
.
setCurrentValue
(
newVal
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment