Parcourir la source

标签删除bug解决

luolei il y a 5 ans
Parent
commit
c737508f81

+ 17 - 10
src/common/components/EditableSpan/index.jsx

@@ -178,7 +178,7 @@ class EditableSpan extends Component{
 
     let range = window.getSelection();
     let textIndex = range.focusOffset;
-    let textLength = range.anchorNode.length;
+    let textLength = range.anchorNode&&range.anchorNode.length;
     let preObj = $(this.$span.current).prev();
     if(ev.keyCode==37){//向左
       let preObj = $(this.$span.current).prev();
@@ -229,10 +229,11 @@ class EditableSpan extends Component{
 
       let nextObj = $(this.$span.current);
       let nexObj = $(this.$span.current).next();
+      let nexObjN = nexObj.next();
       let preObj = $(this.$span.current).prev();
       let nexVal = nexObj[0]&&nexObj[0].innerText || nexObj[0]&&nexObj[0].innerHTML; 
       if(preVal.trim().length==1&& !innerVal){
-        console.log('delete前面是标签,内容为空时再删一次才移除标签;前面是文本,则直接移除')
+        // console.log('delete前面是标签,内容为空时再删一次才移除标签;前面是文本,则直接移除')
         removeId && removeId({boxMark,i:index,text:"",flag:'del'});
         handleClear && handleClear({boxMark});//删除最后一个字时清空搜索结果,避免现病史搜索框不立即消失的情况
         //如果后一个不是标签,则光标移到最前
@@ -247,27 +248,33 @@ class EditableSpan extends Component{
       if(innerVal == preVal){
         let data = innerVal.trim();
         if(nextObj && !config.punctuationReg.test(data) || data=='<br>'){
+          
           handleKeydown&&handleKeydown({boxMark,i:index,text:data,flag:'del'});
           if(nextObj && nextObj[0] && nextObj[0].nodeName !=="DIV"){
             // IE浏览器focus光标在最后,其他浏览器在最前
             // nextObj.focus();
-            this.moveEnd(nextObj[0],1);
+            // console.log(this.props.data,this.props.data[index+1],2323223223)
+            if(boxMark==2&&this.props.data[index+1]&&this.props.data[index+1].flag==3){
+              this.moveEnd(nexObjN[0],1);
+            }else{
+              this.moveEnd(nextObj[0],1);
+            }
           }
           /*this.setState({
             index: null
           })*/
         }else if(indexNum ==innerVal.length&&nexObj[0]&&nexObj[0].nodeName=="DIV"){//span最后一位后面为div标签
-          console.log(99)
+          // console.log(99)
           handleKeydown&&handleKeydown({boxMark,i:index+1,text:data,flag:'del'});
           this.moveEnd(nextObj[0]);
         }else if(nexObj[0]&&nexObj[0].nodeName=="SPAN"){
-          console.log('delete text: '+config.punctuationReg.test(nexVal),nexVal,textIndex,innerVal)
+          // console.log('delete text: '+config.punctuationReg.test(nexVal),nexVal,textIndex,innerVal)
           if(nexVal.length <= 1){//为空或者一个字delete时候
-            console.log(8988998)
-            handleChange&&handleChange({text1:'',boxMark,i:index+1});
-            // removeId && removeId({boxMark,i:index+1,text:"",flag:'del'});
+            // console.log(8988998)
+            // handleChange&&handleChange({text1:'',boxMark,i:index+1});
+            removeId && removeId({boxMark,i:index+1,text:"",flag:'del'});
             handleClear && handleClear({boxMark});
-            this.moveEnd(nextObj[0])
+            this.moveEnd(nexObj[0])
           }else if(nexVal.length > 1){
             let tmpVal = nexVal.substr(1,data.length)
             handleChange&&handleChange({text1:tmpVal,boxMark,i:index+1});
@@ -284,7 +291,7 @@ class EditableSpan extends Component{
       let preObj = $(this.$span.current).prev();
       let curObj = $(this.$span.current);
       if(index!==0&&preVal.trim().length==1&& !innerVal){
-        console.log('backspace前面是标签,内容为空时再删一次才移除标签;前面是文本,则直接移除')
+        // console.log('backspace前面是标签,内容为空时再删一次才移除标签;前面是文本,则直接移除')
         removeId && removeId({boxMark,i:index,text:""});
         handleClear && handleClear({boxMark});//删除最后一个字时清空搜索结果,避免现病史搜索框不立即消失的情况
         if(preObj[0].nodeName !=="DIV"){

+ 1 - 0
src/containers/EditableSpan.js

@@ -14,6 +14,7 @@ function mapStateToProps(state){//console.log(state)
   return {
     mainSaveText:state.mainSuit.saveText,
     isRead:state.homePage.isRead,
+    data:state.currentIll.data
   }
 }
 

+ 1 - 0
src/store/actions/currentIll.js

@@ -526,6 +526,7 @@ export const bigDataSymptom = (state,action) => {
 export function setCheckText(state,action) {
   let res = Object.assign({},state);
   const {i,text} = action;
+  // console.log(action,res.data,res.data[i])
   if(res.data[i]){
     res.data[i].value=text;
     //res.data[i].name='';      //默认显示的文字