Browse Source

数字输入范围bug修改

zhouna 6 năm trước cách đây
mục cha
commit
8709f83b73

+ 4 - 2
src/components/MultSpread/index.jsx

@@ -98,11 +98,13 @@ class MultSpread extends Component{
                             id={it.id}
                             ikey={inx} hideTag={true}></InlineTag>;
         case +it.controlType===7:
+          const min = data.minValue!=null&&data.minValue!=undefined?data.minValue-1:undefined;
+          const max = data.maxValue!=null&&data.maxValue!=undefined?+data.maxValue+1:undefined;
           return <NumberDrop prefix={it.labelPrefix}
                              suffix={it.labelSuffix}
                              placeholder={it.name}
-                             min={it.minValue-1}
-                             max={+it.maxValue+1}
+                             min={min}
+                             max={max}
                              show={show}
                              allClick={false}
                              ikey={inx}

+ 17 - 13
src/components/NumberDrop/index.jsx

@@ -165,14 +165,18 @@ class NumberDrop extends Component{
       return;
     }
     //输入超出合理范围或输入不是数字提示且清空
-    const txt = e.target.innerText.replace(/^\s*/,'');
-    const isFine = this.validSymbols(txt,min,max);      //有~或/时是否合理
-    const hasSymbol = /[\/|\~]/g.test(txt);           //是否有~或/
-    const singleFine = !isNaN(+txt)&&max!=undefined&&min<txt&&txt<max;   //无~或/时是否合理
-    if(txt!=''&&(!hasSymbol&&!singleFine)||(hasSymbol&&!isFine)){
-      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({
@@ -180,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});
   }
@@ -235,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});
   }

+ 4 - 2
src/containers/eleType.js

@@ -72,10 +72,12 @@ export function singleRadio(params){
                         id={data.id}
                         ikey={showInx}></InlineTag>;
     case 7:
+      const min = data.minValue!=null&&data.minValue!=undefined?data.minValue-1:undefined;
+      const max = data.maxValue!=null&&data.maxValue!=undefined?+data.maxValue+1:undefined;
       return <NumberDrop prefix={data.labelPrefix}
                          suffix={data.labelSuffix}
-                         min={data.minValue-1}
-                         max={+data.maxValue+1}
+                         min={min}
+                         max={max}
                          placeholder={data.name}
                          boxMark={boxMark}
                          id={data.id}