Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas
/
scrm-micro-presale
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b956061a
authored
Jun 27, 2023
by
zhangquan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
formatInput组件
1 parent
3a144e91
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
src/components/FormatInput/index.vue
src/components/FormatInput/index.vue
0 → 100644
View file @
b956061
<
template
>
<el-input
:value=
"value"
v-bind=
"$attrs"
v-on=
"
{...$listeners}" @blur="blurFn">
</el-input>
</
template
>
<
script
>
export
default
{
name
:
'FormatInput'
,
props
:
[
'value'
,
'precise'
,
'intDigit'
,
'maxVal'
,
'minVal'
],
data
()
{
return
{
}
},
watch
:{
value
:{
handler
(
nVal
,
oVal
){
this
.
inputFn
(
nVal
)
},
deep
:
true
}
},
mounted
(){
},
methods
:{
inputFn
(
e
){
e
=
e
?
String
(
e
)
:
''
this
.
intDigit
=
this
.
intDigit
||
6
this
.
precise
=
this
.
precise
||
2
let
value
=
e
if
(
this
.
maxVal
){
if
(
+
this
.
maxVal
<=
+
e
)
value
=
this
.
maxVal
//加等号是因为 '500' == '500.' 导致多了点
}
else
{
const
intDigitReg
=
this
.
intDigit
==
-
1
?
`(^\\d+)(\\.\\d+)?`
:
`(^\\d{
${
this
.
intDigit
}
})\\d+(\\.\\d+)?`
value
=
e
.
replace
(
/^0
\d
/g
,
'0'
).
replace
(
/
[^\d
.
]
/g
,
''
).
replace
(
/^
\.
/g
,
''
).
replace
(
new
RegExp
(
intDigitReg
,
'g'
),
'$1'
).
replace
(
'.'
,
'$#$'
)
.
replace
(
/
\.
/g
,
''
).
replace
(
'$#$'
,
'.'
).
replace
(
new
RegExp
(
`^(-)*(\\d+)\\.(\\d{
${
this
.
precise
}
}).*$`
),
this
.
intDigit
==
-
1
?
'$1$2'
:
'$1$2.$3'
)
}
this
.
$emit
(
'input'
,
value
)
},
blurFn
(
e
){
let
value
=
e
.
target
.
value
if
(
this
.
minVal
&&
+
this
.
minVal
>=
value
)
value
=
this
.
minVal
this
.
$emit
(
'input'
,
value
)
}
}
}
</
script
>
<
style
lang=
"scss"
scoped
>
</
style
>
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment