高敬炎 2 年之前
父節點
當前提交
66d9de28a5
共有 1 個文件被更改,包括 40 次插入4 次删除
  1. 40 4
      src/global/directive.js

+ 40 - 4
src/global/directive.js

@@ -27,18 +27,51 @@
 const enterToNext = {
   install (Vue, options = {}) {
     Vue.directive('enterToNext',{
-      inserted:function(el){
+      // inserted:function(el){
+      //   console.log(el)
+      //   console.log("enterToNext...")
+      //   //let frm = el.querySelector('.el-form');
+      //   let inputs = el.querySelectorAll('input');
+      //   console.log(inputs)
+      //   var arr=[]
+      //   for( var i = 0 ;i < inputs.length ; i++ ){
+      //     if(!inputs[i].disabled){
+      //       arr.push(inputs[i])
+      //     }
+      //   }
+      //   //绑定回写事件
+      //   for( var i = 0 ;i < arr.length ; i++ ){
+      //     arr[i].setAttribute("keyFocusIndex",i);
+      //     arr[i].addEventListener('keyup', (ev) => {
+      //       if (ev.keyCode === 13) {
+      //         let targetTo = ev.srcElement.getAttribute('keyFocusTo');
+      //         if(targetTo){
+      //           this.$refs[targetTo].$el.focus();
+      //         }else{
+      //           var attrIndex = ev.srcElement.getAttribute('keyFocusIndex');
+      //           var ctlI = parseInt(attrIndex);
+      //           if(ctlI<arr.length-1)
+      //             arr[ctlI+1].focus();
+      //         }
+      //       }
+      //     });
+      //   }
+    
+      // },
+      update:function(el){
         console.log(el)
         console.log("enterToNext...")
         //let frm = el.querySelector('.el-form');
+        setTimeout(function(){
         let inputs = el.querySelectorAll('input');
-       
+        console.log(inputs)
         var arr=[]
         for( var i = 0 ;i < inputs.length ; i++ ){
-          if(!inputs[i].disabled){
+          if(!inputs[i].disabled&&inputs[i].parentNode.parentNode.className.indexOf('el-select')==-1&&inputs[i].parentNode.className.indexOf('el-date-editor')==-1){
             arr.push(inputs[i])
           }
         }
+        console.log(arr)
         //绑定回写事件
         for( var i = 0 ;i < arr.length ; i++ ){
           arr[i].setAttribute("keyFocusIndex",i);
@@ -51,13 +84,16 @@ const enterToNext = {
                 var attrIndex = ev.srcElement.getAttribute('keyFocusIndex');
                 var ctlI = parseInt(attrIndex);
                 if(ctlI<arr.length-1)
+
                   arr[ctlI+1].focus();
               }
             }
           });
         }
+        },1000)
+        
     
-      }
+      },
     })
   }
 }