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
8efa184c
Commit
8efa184c
authored
Sep 12, 2023
by
linhuandong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
type=moneyinput 千分位格式化
parent
a4d046a4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
27 deletions
+78
-27
examples/docs/zh-CN/input.md
examples/docs/zh-CN/input.md
+2
-2
examples/versions.json
examples/versions.json
+1
-1
package.json
package.json
+1
-1
packages/input/src/input.vue
packages/input/src/input.vue
+73
-22
src/index.js
src/index.js
+1
-1
No files found.
examples/docs/zh-CN/input.md
View file @
8efa184c
...
...
@@ -14,13 +14,13 @@ Input 为受控组件,它**总会显示 Vue 绑定值**。
:::demo
```
html
<el-input
v-model=
"input"
placeholder=
"请输入内容"
></el-input>
<el-input
v-model=
"input"
type=
"moneyinput"
placeholder=
"请输入内容"
></el-input>
<script>
export
default
{
data
()
{
return
{
input
:
''
input
:
'
123123123
'
}
}
}
...
...
examples/versions.json
View file @
8efa184c
{
"1.4.13"
:
"1.4"
,
"2.0.11"
:
"2.0"
,
"2.1.0"
:
"2.1"
,
"2.2.2"
:
"2.2"
,
"2.3.9"
:
"2.3"
,
"2.4.11"
:
"2.4"
,
"2.5.4"
:
"2.5"
,
"2.6.3"
:
"2.6"
,
"2.7.2"
:
"2.7"
,
"2.8.2"
:
"2.8"
,
"2.9.2"
:
"2.9"
,
"2.10.1"
:
"2.10"
,
"2.11.1"
:
"2.11"
,
"2.12.0"
:
"2.12"
,
"2.13.2"
:
"2.13"
,
"2.14.1"
:
"2.14"
,
"2.15.7"
:
"2.15"
}
\ No newline at end of file
{
"1.4.13"
:
"1.4"
,
"2.0.11"
:
"2.0"
,
"2.1.0"
:
"2.1"
,
"2.2.2"
:
"2.2"
,
"2.3.9"
:
"2.3"
,
"2.4.11"
:
"2.4"
,
"2.5.4"
:
"2.5"
,
"2.6.3"
:
"2.6"
,
"2.7.2"
:
"2.7"
,
"2.8.2"
:
"2.8"
,
"2.9.2"
:
"2.9"
,
"2.10.1"
:
"2.10"
,
"2.11.1"
:
"2.11"
,
"2.12.0"
:
"2.12"
,
"2.13.2"
:
"2.13"
,
"2.14.1"
:
"2.14"
,
"2.15.7675"
:
"2.15"
}
\ No newline at end of file
package.json
View file @
8efa184c
{
"name"
:
"element-ui"
,
"version"
:
"2.15.76
67
"
,
"version"
:
"2.15.76
75
"
,
"description"
:
"A Component Library for Vue.js."
,
"main"
:
"lib/element-ui.common.js"
,
"files"
:
[
...
...
packages/input/src/input.vue
View file @
8efa184c
<
template
>
<
template
>
<div
:class=
"[
type === 'textarea' ? 'el-textarea' : 'el-input',
inputSize ? 'el-input--' + inputSize : '',
...
...
@@ -21,24 +21,44 @@
<slot
name=
"prepend"
></slot>
</div>
<input
:tabindex=
"tabindex"
v-if=
"type !== 'textarea'"
class=
"el-input__inner"
v-bind=
"$attrs"
:type=
"showPassword ? (passwordVisible ? 'text': 'password') : type"
:disabled=
"inputDisabled"
:readonly=
"readonly"
:autocomplete=
"autoComplete || autocomplete"
ref=
"input"
@
compositionstart=
"handleCompositionStart"
@
compositionupdate=
"handleCompositionUpdate"
@
compositionend=
"handleCompositionEnd"
@
input=
"handleInput"
@
focus=
"handleFocus"
@
blur=
"handleBlur"
@
change=
"handleChange"
:aria-label=
"label"
>
:tabindex=
"tabindex"
v-if=
"type === 'moneyinput'"
class=
"el-input__inner"
v-bind=
"$attrs"
:type=
"showPassword ? (passwordVisible ? 'text' : 'password') : type"
:disabled=
"inputDisabled"
:readonly=
"readonly"
:autocomplete=
"autoComplete || autocomplete"
ref=
"input"
@
compositionstart=
"handleCompositionStart"
@
compositionupdate=
"handleCompositionUpdate"
@
compositionend=
"handleCompositionEnd"
@
input=
"handleInput"
@
focus=
"handleFocus"
@
blur=
"handleBlur"
@
change=
"handleChange"
:aria-label=
"label"
v-money
>
<input
:tabindex=
"tabindex"
v-else-if=
"type !== 'textarea'"
class=
"el-input__inner"
v-bind=
"$attrs"
:type=
"showPassword ? (passwordVisible ? 'text' : 'password') : type"
:disabled=
"inputDisabled"
:readonly=
"readonly"
:autocomplete=
"autoComplete || autocomplete"
ref=
"input"
@
compositionstart=
"handleCompositionStart"
@
compositionupdate=
"handleCompositionUpdate"
@
compositionend=
"handleCompositionEnd"
@
input=
"handleInput"
@
focus=
"handleFocus"
@
blur=
"handleBlur"
@
change=
"handleChange"
:aria-label=
"label"
>
<!-- 前置内容 -->
<span
class=
"el-input__prefix"
v-if=
"$slots.prefix || prefixIcon"
>
<slot
name=
"prefix"
></slot>
...
...
@@ -143,7 +163,6 @@
focusOpen
:
false
};
},
props
:
{
value
:
[
String
,
Number
],
size
:
String
,
...
...
@@ -260,7 +279,30 @@
(
this
.
textLength
>
this
.
upperLimit
);
}
},
directives
:
{
money
:
{
// 指令的定义
inserted
:
function
(
el
,
binding
)
{
// 指令作用在 element-input 节点,对应原生 div.el-input (真实input节点的父节点)
if
(
el
.
tagName
.
toLocaleUpperCase
()
!==
'
INPUT
'
)
{
el
=
el
.
getElementsByTagName
(
'
input
'
)[
0
];
}
// 带¥符号、保留2位小数+千分位
// el.value = (Number(el.value)).toLocaleString('zh', {style:'currency', currency: 'CNY', minimumFractionDigits: 2});
// 保留2位小数+千分位
el
.
value
=
parseFloat
(
el
.
value
).
toLocaleString
(
undefined
,
{
'
minimumFractionDigits
'
:
2
,
'
maximumFractionDigits
'
:
8
});
// console.log(el);
el
.
onblur
=
(
e
)
=>
{
// 去除‘,’
let
a
=
el
.
value
.
replace
(
/,/g
,
''
);
if
(
a
)
{
el
.
value
=
parseFloat
(
a
).
toLocaleString
(
undefined
,
{
'
minimumFractionDigits
'
:
2
,
'
maximumFractionDigits
'
:
8
});
// console.log(el.value);
}
};
}
}
},
watch
:
{
value
(
val
)
{
this
.
$nextTick
(
this
.
resizeTextarea
);
...
...
@@ -329,11 +371,20 @@
this
.
textareaCalcStyle
=
calcTextareaHeight
(
this
.
$refs
.
textarea
,
minRows
,
maxRows
);
},
formatMoney
(
val
)
{
if
(
this
.
type
===
'
moneyinput
'
)
{
try
{
val
=
parseFloat
(
val
||
'
0
'
).
toLocaleString
(
undefined
,
{
'
minimumFractionDigits
'
:
2
,
'
maximumFractionDigits
'
:
8
});
}
catch
(
ex
)
{
}
}
return
val
;
},
setNativeInputValue
()
{
const
input
=
this
.
getInput
();
if
(
!
input
)
return
;
if
(
input
.
value
===
this
.
nativeInputValue
)
return
;
input
.
value
=
this
.
nativeInputValue
;
input
.
value
=
this
.
formatMoney
(
this
.
nativeInputValue
)
;
},
handleFocus
(
event
)
{
this
.
focused
=
true
;
...
...
src/index.js
View file @
8efa184c
...
...
@@ -210,7 +210,7 @@ if (typeof window !== 'undefined' && window.Vue) {
}
export
default
{
version
:
'
2.15.76
67
'
,
version
:
'
2.15.76
75
'
,
locale
:
locale
.
use
,
i18n
:
locale
.
i18n
,
install
,
...
...
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