update
This commit is contained in:
parent
e205e05247
commit
c87f7f730b
1 changed files with 15 additions and 37 deletions
|
@ -16,7 +16,7 @@
|
||||||
<input
|
<input
|
||||||
:id="elementId"
|
:id="elementId"
|
||||||
:class="inputClasses"
|
:class="inputClasses"
|
||||||
:disabled="disabled"
|
:disabled="itemDisabled"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
spellcheck="false"
|
spellcheck="false"
|
||||||
:autofocus="autofocus"
|
:autofocus="autofocus"
|
||||||
|
@ -24,7 +24,6 @@
|
||||||
@blur="blur"
|
@blur="blur"
|
||||||
@keydown.stop="keyDown"
|
@keydown.stop="keyDown"
|
||||||
@input="change"
|
@input="change"
|
||||||
ref="precisionCursor"
|
|
||||||
@mouseup="preventDefault"
|
@mouseup="preventDefault"
|
||||||
@change="change"
|
@change="change"
|
||||||
:readonly="readonly || !editable"
|
:readonly="readonly || !editable"
|
||||||
|
@ -37,6 +36,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { oneOf, findComponentUpward } from '../../utils/assist';
|
import { oneOf, findComponentUpward } from '../../utils/assist';
|
||||||
import Emitter from '../../mixins/emitter';
|
import Emitter from '../../mixins/emitter';
|
||||||
|
import mixinsForm from '../../mixins/form';
|
||||||
|
|
||||||
const prefixCls = 'ivu-input-number';
|
const prefixCls = 'ivu-input-number';
|
||||||
const iconPrefixCls = 'ivu-icon';
|
const iconPrefixCls = 'ivu-icon';
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'InputNumber',
|
name: 'InputNumber',
|
||||||
mixins: [ Emitter ],
|
mixins: [ Emitter, mixinsForm ],
|
||||||
props: {
|
props: {
|
||||||
max: {
|
max: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
@ -87,7 +87,7 @@
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: null,
|
default: 1
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
validator (value) {
|
validator (value) {
|
||||||
|
@ -147,7 +147,7 @@
|
||||||
`${prefixCls}`,
|
`${prefixCls}`,
|
||||||
{
|
{
|
||||||
[`${prefixCls}-${this.size}`]: !!this.size,
|
[`${prefixCls}-${this.size}`]: !!this.size,
|
||||||
[`${prefixCls}-disabled`]: this.disabled,
|
[`${prefixCls}-disabled`]: this.itemDisabled,
|
||||||
[`${prefixCls}-focused`]: this.focused
|
[`${prefixCls}-focused`]: this.focused
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
@ -187,13 +187,8 @@
|
||||||
},
|
},
|
||||||
precisionValue () {
|
precisionValue () {
|
||||||
// can not display 1.0
|
// can not display 1.0
|
||||||
// if(!this.currentValue) return this.currentValue;
|
if(!this.currentValue) return this.currentValue;
|
||||||
// return this.precision ? this.currentValue.toFixed(this.precision) : this.currentValue;
|
return this.precision ? this.currentValue.toFixed(this.precision) : this.currentValue;
|
||||||
let arr = (this.currentValue + '').split('.');
|
|
||||||
if (this.precision && arr[1] && this.precision < arr[1].length) {
|
|
||||||
return this.currentValue.toFixed(this.precision);
|
|
||||||
}
|
|
||||||
return this.currentValue;
|
|
||||||
},
|
},
|
||||||
formatterValue () {
|
formatterValue () {
|
||||||
if (this.formatter && this.precisionValue !== null) {
|
if (this.formatter && this.precisionValue !== null) {
|
||||||
|
@ -222,9 +217,10 @@
|
||||||
this.changeStep('down', e);
|
this.changeStep('down', e);
|
||||||
},
|
},
|
||||||
changeStep (type, e) {
|
changeStep (type, e) {
|
||||||
if (this.disabled || this.readonly) {
|
if (this.itemDisabled || this.readonly) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetVal = Number(e.target.value);
|
const targetVal = Number(e.target.value);
|
||||||
let val = Number(this.currentValue);
|
let val = Number(this.currentValue);
|
||||||
const step = Number(this.step);
|
const step = Number(this.step);
|
||||||
|
@ -261,8 +257,7 @@
|
||||||
if (val && !isNaN(this.precision)) val = Number(Number(val).toFixed(this.precision));
|
if (val && !isNaN(this.precision)) val = Number(Number(val).toFixed(this.precision));
|
||||||
|
|
||||||
const {min, max} = this;
|
const {min, max} = this;
|
||||||
// #6245
|
if (val!==null) {
|
||||||
if ( val!==null && !this.activeChange ) {
|
|
||||||
if (val > max) {
|
if (val > max) {
|
||||||
val = max;
|
val = max;
|
||||||
} else if (val < min) {
|
} else if (val < min) {
|
||||||
|
@ -298,7 +293,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
change (event) {
|
change (event) {
|
||||||
if (event.type == 'change') return;
|
if (event.type == 'change' && this.activeChange) return;
|
||||||
|
|
||||||
if (event.type == 'input' && !this.activeChange) return;
|
if (event.type == 'input' && !this.activeChange) return;
|
||||||
let val = event.target.value.trim();
|
let val = event.target.value.trim();
|
||||||
|
@ -311,24 +306,15 @@
|
||||||
this.setValue(null);
|
this.setValue(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.type == 'input' && val.match(/^\-?\.?$|\.$/g)) return; // prevent fire early if decimal. If no more input the change event will fire later
|
if (event.type == 'input' && val.match(/^\-?\.?$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later
|
||||||
|
|
||||||
//#fixed when setting the precision val, input point cannot show problem
|
|
||||||
const precision = this.precision;
|
|
||||||
let cacheVal = this.currentValue;
|
|
||||||
if( precision ){
|
|
||||||
const valMatchPointArr = (val+'').match(/\./g);
|
|
||||||
if( valMatchPointArr && valMatchPointArr.length >= 2 ){
|
|
||||||
cacheVal = this.currentValue + '.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val = Number(val);
|
val = Number(val);
|
||||||
|
|
||||||
if (!isNaN(val)) {
|
if (!isNaN(val)) {
|
||||||
this.currentValue = val;
|
this.currentValue = val;
|
||||||
this.setValue(val);
|
this.setValue(val);
|
||||||
} else {
|
} else {
|
||||||
event.target.value = cacheVal;
|
event.target.value = this.currentValue;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
changeVal (val) {
|
changeVal (val) {
|
||||||
|
@ -353,14 +339,6 @@
|
||||||
},
|
},
|
||||||
currentValue (val) {
|
currentValue (val) {
|
||||||
this.changeVal(val);
|
this.changeVal(val);
|
||||||
//optimization - Solve the problem of cursor positioning inaccuracy
|
|
||||||
this.$nextTick(()=>{
|
|
||||||
if( this.precision ){
|
|
||||||
const currentValueLength = ( this.currentValue || 0 ).toString().length;
|
|
||||||
const precisionCursor = this.$refs.precisionCursor;
|
|
||||||
precisionCursor.selectionStart = precisionCursor.selectionEnd = currentValueLength;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
min () {
|
min () {
|
||||||
this.changeVal(this.currentValue);
|
this.changeVal(this.currentValue);
|
||||||
|
|
Loading…
Add table
Reference in a new issue