|
@@ -54,14 +54,17 @@ class NumberDrop extends Component{
|
|
|
}else{
|
|
|
//console.log(text,isNaN(+text),max<+text)
|
|
|
if(needCompare){
|
|
|
- if(text!=''&&(isNaN(+text)||max<+text)){ //数值过大
|
|
|
+ /*if(text!=''&&(isNaN(+text)||max<+text)){ //数值过大
|
|
|
this.beyondArea();
|
|
|
return;
|
|
|
- }
|
|
|
+ }*/
|
|
|
const that = this;
|
|
|
- timer = setTimeout(function(){ //数值过小
|
|
|
+ const isFine = this.validSymbols(text,min,max); //有~或/时是否合理
|
|
|
+ const hasSymbol = /[\/|\~]/g.test(text); //是否有~或/
|
|
|
+ const singleFine = !isNaN(+text)&&max!=undefined&&min<text&&text<max; //无~或/时是否合理
|
|
|
+ timer = setTimeout(function(){
|
|
|
clearTimeout(that.state.sltTimer);
|
|
|
- if(text!=''&&(isNaN(+text)||min>+text)){
|
|
|
+ if(text!=''&&(!hasSymbol&&!singleFine)||(hasSymbol&&!isFine)){
|
|
|
that.beyondArea();
|
|
|
return;
|
|
|
}
|
|
@@ -132,18 +135,48 @@ class NumberDrop extends Component{
|
|
|
}
|
|
|
e.stopPropagation();
|
|
|
}
|
|
|
+ validSymbols(txt,min,max){
|
|
|
+ //输入只有一个~或/时判断两边是否为合理数字,有多个为不合理
|
|
|
+ const index1 = txt.indexOf('~');
|
|
|
+ const index2 = txt.indexOf('/');
|
|
|
+ let arr1=[],arr2=[];
|
|
|
+ if(index1!=-1&&index1==txt.lastIndexOf('~')&&index1!=txt.length-1){ //有且只有一个~,且不在最后
|
|
|
+ arr1 = txt.split('~');
|
|
|
+ //~的范围在合理范围内为合理值
|
|
|
+ if(!isNaN(+arr1[0])&&!isNaN(+arr1[1])&&+arr1[0]>min&&+arr1[1]<max){
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if(index2!=-1&&index2==txt.lastIndexOf('/')&&index2!=txt.length-1){ //有且只有一个~,且不在最后
|
|
|
+ arr2 = txt.split('/');
|
|
|
+ // /两边的数字分别在合理范围内为合理值
|
|
|
+ if(!isNaN(+arr2[0])&&!isNaN(+arr2[1])&&min<arr2[0]&&arr2[0]<max&&min<arr2[1]&&arr2[1]<max){
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
numInpBlur(e){ //数字框失焦,保存值到store中
|
|
|
e.stopPropagation();
|
|
|
const {handleSelect,ikey,suffix,prefix,mainSaveText,min,max,show} = this.props;
|
|
|
if(show){ //修改清空后第一次点击键盘不触发click事件bug
|
|
|
return;
|
|
|
}
|
|
|
- //输入超出合理范围提示且清空
|
|
|
- const txt = e.target.innerText.replace(/^\s*/,'');
|
|
|
- if(txt!=''&&(isNaN(+txt)||(max!=undefined&&(min>+txt||max<+txt)))){
|
|
|
- this.beyondArea();
|
|
|
- return;
|
|
|
+ //输入超出合理范围或输入不是数字提示且清空
|
|
|
+ const needCompare=min!=undefined&&max!=undefined;
|
|
|
+ if(needCompare){
|
|
|
+ const txt = e.target.innerText.trim();
|
|
|
+ const isFine = this.validSymbols(txt,min,max); //有~或/时是否合理
|
|
|
+ const hasSymbol = /[\/|\~]/g.test(txt); //是否有~或/
|
|
|
+ const singleFine = !isNaN(+txt)&&min<txt&&txt<max; //无~或/时是否合理
|
|
|
+ if(txt!=''&&(!hasSymbol&&!singleFine)||(hasSymbol&&!isFine)){
|
|
|
+ this.beyondArea();
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
//输入为空时显示placeholder
|
|
|
if(!e.target.innerText.trim()){
|
|
|
this.setState({
|
|
@@ -151,9 +184,9 @@ class NumberDrop extends Component{
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- const val = e.target.innerText.replace(/^\s*/,'');
|
|
|
+ const val = e.target.innerText.trim();
|
|
|
const {placeholder} = this.state;
|
|
|
- let text = val===placeholder?'':val.replace(/[\u4e00-\u9fa5]/g,'');
|
|
|
+ let text = val===placeholder?'':val;
|
|
|
//e.target.innerText = ''; //避免出现重复输入值
|
|
|
handleSelect&&handleSelect({ikey,text,suffix,prefix,mainSaveText});
|
|
|
}
|
|
@@ -206,10 +239,10 @@ class NumberDrop extends Component{
|
|
|
this.setState({
|
|
|
editable: false
|
|
|
});
|
|
|
- let totalVal = e.target.innerText;
|
|
|
- let changeVal = this.$span.current.innerText.replace(/^\s*/,'');//数字框值-修改后;去掉前空格避免多空格叠加
|
|
|
- let prefix = this.$pre.current.innerText.replace(/^\s*/,''); //前缀值-修改后
|
|
|
- let suffix = this.$suf.current.innerText.replace(/^\s*/,''); //后缀值-修改后
|
|
|
+ let totalVal = e.target.innerText.trim();
|
|
|
+ let changeVal = this.$span.current.innerText.trim();//数字框值-修改后;去掉前空格避免多空格叠加
|
|
|
+ let prefix = this.$pre.current.innerText.trim(); //前缀值-修改后
|
|
|
+ let suffix = this.$suf.current.innerText.trim(); //后缀值-修改后
|
|
|
//console.log('数字框:'+changeVal,";全部:"+totalVal,";前缀:"+prefix+";后缀:"+suffix);
|
|
|
handleLabelChange && handleLabelChange({ikey,changeVal,type:boxMark,totalVal,prefix,suffix});
|
|
|
}
|