Parcourir la source

数字组件输入限制bug修改815

zhouna il y a 6 ans
Parent
commit
3aef816f8f
1 fichiers modifiés avec 6 ajouts et 10 suppressions
  1. 6 10
      src/components/NumberDrop/index.jsx

+ 6 - 10
src/components/NumberDrop/index.jsx

@@ -52,16 +52,11 @@ class NumberDrop extends Component{
         placeholder:this.props.placeholder
       });
     }else{
-      //console.log(text,isNaN(+text),max<+text)
       if(needCompare){
-        /*if(text!=''&&(isNaN(+text)||max<+text)){    //数值过大
-          this.beyondArea();
-          return;
-        }*/
         const that = this;
         const isFine = this.validSymbols(text,min,max);      //有~或/时是否合理
         const hasSymbol = /[\/|\~]/g.test(text);           //是否有~或/
-        const singleFine = !isNaN(+text)&&max!=undefined&&min<text&&text<max;   //无~或/时是否合理
+        const singleFine = !isNaN(+text)&&min<text&&text<max;   //无~或/时是否合理
         timer = setTimeout(function(){
           clearTimeout(that.state.sltTimer);
           if(text!=''&&(!hasSymbol&&!singleFine)||(hasSymbol&&!isFine)){
@@ -139,6 +134,7 @@ class NumberDrop extends Component{
     //输入只有一个~或/时判断两边是否为合理数字,有多个为不合理
     const index1 = txt.indexOf('~');
     const index2 = txt.indexOf('/');
+    const needCompare = min!=undefined&&max!=undefined;
     let arr1=[],arr2=[];
     if(index1!=-1&&index1==txt.lastIndexOf('~')&&index1!=txt.length-1){   //有且只有一个~,且不在最后
       arr1 = txt.split('~');
@@ -151,7 +147,7 @@ class NumberDrop extends Component{
     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){
+      if(!isNaN(+arr2[0])&&!isNaN(+arr2[1])&&((!needCompare)||(needCompare&&min<arr2[0]&&arr2[0]<max&&min<arr2[1]&&arr2[1]<max))){
         return true
       }
       return false;
@@ -166,16 +162,16 @@ class NumberDrop extends Component{
     }
     //输入超出合理范围或输入不是数字提示且清空
     const needCompare=min!=undefined&&max!=undefined;
-    if(needCompare){
+    //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;   //无~或/时是否合理
+      const singleFine = (!isNaN(+txt)&&!needCompare)||(!isNaN(+txt)&&needCompare&&min<txt&&txt<max);   //无~或/时是否合理
       if(txt!=''&&(!hasSymbol&&!singleFine)||(hasSymbol&&!isFine)){
         this.beyondArea();
         return;
       }
-    }
+    //}
 
     //输入为空时显示placeholder
     if(!e.target.innerText.trim()){