libf 3 år sedan
förälder
incheckning
c08b93ebec
4 ändrade filer med 142 tillägg och 80 borttagningar
  1. 103 73
      src/controllers/handler.js
  2. 2 2
      src/controllers/rowColumnOperation.js
  3. 31 4
      src/global/location.js
  4. 6 1
      src/global/rhchInit.js

+ 103 - 73
src/controllers/handler.js

@@ -42,7 +42,8 @@ import { getSheetIndex, getRangetxt } from '../methods/get';
 import { 
     rowLocation, 
     colLocation, 
-    mouseposition 
+    mouseposition,
+    position,
 } from '../global/location';
 import { rowlenByRange } from '../global/getRowlen';
 import { isRealNull, hasPartMC, isEditMode, checkIsAllowEdit } from '../global/validate';
@@ -1138,7 +1139,7 @@ export default function luckysheetHandler() {
                 return;
             }
 
-            if (isEditMode()) { //非编辑模式下禁止右键功能框
+            if (!isEditMode()) { //非编辑模式下禁止右键功能框
                 return;
             }
 
@@ -1481,50 +1482,84 @@ export default function luckysheetHandler() {
         handleCellDragStopEvent(e);
     }, false);
     document.getElementById('luckysheet-cell-main').addEventListener('dragover', function(e){
-        e.preventDefault();
-        e.stopPropagation();
+        let ret = handleCellDragOverEvent(e);
+        if(ret){
+            e.preventDefault();
+            e.stopPropagation();
+        }
     }, false);
 
+    function handleCellDragOverEvent(event) {
+        if (luckysheetConfigsetting && luckysheetConfigsetting.hook && luckysheetConfigsetting.hook.cellDragOver) {
+	        let pos = position(event.pageX, event.pageY);
+            
+            let margeset = menuButton.mergeborer(Store.flowdata, pos.row_index, pos.col_index);
+            if (!!margeset) {
+                pos.row = margeset.row[1];
+                pos.row_pre = margeset.row[0];
+                pos.row_index = margeset.row[2];
+
+                pos.col = margeset.column[1];
+                pos.col_pre = margeset.column[0];
+                pos.col_index = margeset.column[2];
+            }
+
+	        let sheetFile = sheetmanage.getSheetByIndex();
+	  
+	        let luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d");
+	        return method.createHookFunction("cellDragOver", Store.flowdata[pos.row_index][pos.col_index], {
+	            r:pos.row_index,
+                c:pos.col_index,
+                "start_r": pos.row_pre,
+                "start_c": pos.col_pre, 
+                "end_r": pos.row, 
+                "end_c": pos.col,
+                ox: pos.ox,
+                oy: pos.oy,
+                mx: pos.mx,
+                my: pos.my,
+                or: pos.row_index_ox,
+                oc: pos.col_index_oy,
+	        }, sheetFile, luckysheetTableContent, event);
+        }
+        return true;
+    }
+
     /**
      * 处理单元格上鼠标拖拽停止事件
      * @param {DragEvent} event 
      */
     function handleCellDragStopEvent(event) {
         if (luckysheetConfigsetting && luckysheetConfigsetting.hook && luckysheetConfigsetting.hook.cellDragStop) {
-	        let mouse = mouseposition(event.pageX, event.pageY);
-	        let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
-	        let y = mouse[1] + $("#luckysheet-cell-main").scrollTop();
-	  
-	        let row_location = rowLocation(y),
-	            row = row_location[1],
-	            row_pre = row_location[0],
-	            row_index = row_location[2];
-	        let col_location = colLocation(x),
-	            col = col_location[1],
-	            col_pre = col_location[0],
-	            col_index = col_location[2];
-	  
-	        let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index);
-	        if (!!margeset) {
-	            row = margeset.row[1];
-	            row_pre = margeset.row[0];
-	            row_index = margeset.row[2];
-	  
-	            col = margeset.column[1];
-	            col_pre = margeset.column[0];
-	            col_index = margeset.column[2];
-	        }
-	  
+	        let pos = position(event.pageX, event.pageY);
+            
+            let margeset = menuButton.mergeborer(Store.flowdata, pos.row_index, pos.col_index);
+            if (!!margeset) {
+                pos.row = margeset.row[1];
+                pos.row_pre = margeset.row[0];
+                pos.row_index = margeset.row[2];
+
+                pos.col = margeset.column[1];
+                pos.col_pre = margeset.column[0];
+                pos.col_index = margeset.column[2];
+            }
+
 	        let sheetFile = sheetmanage.getSheetByIndex();
 	  
 	        let luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d");
-	        method.createHookFunction("cellDragStop", Store.flowdata[row_index][col_index], {
-	            r: row_index,
-	            c: col_index,
-	            "start_r": row_pre,
-	            "start_c": col_pre,
-	            "end_r": row,
-	            "end_c": col
+	        method.createHookFunction("cellDragStop", Store.flowdata[pos.row_index][pos.col_index], {
+	            r:pos.row_index,
+                c:pos.col_index,
+                "start_r": pos.row_pre,
+                "start_c": pos.col_pre, 
+                "end_r": pos.row, 
+                "end_c": pos.col,
+                ox: pos.ox,
+                oy: pos.oy,
+                mx: pos.mx,
+                my: pos.my,
+                or: pos.row_index_ox,
+                oc: pos.col_index_oy,
 	        }, sheetFile, luckysheetTableContent, event);
         }
     }
@@ -1537,32 +1572,21 @@ export default function luckysheetHandler() {
         window.cancelAnimationFrame(Store.jfautoscrollTimeout);
 
         if(luckysheetConfigsetting  && luckysheetConfigsetting.hook && luckysheetConfigsetting.hook.sheetMousemove){
-            let mouse = mouseposition(event.pageX, event.pageY);
-            let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
-            let y = mouse[1] + $("#luckysheet-cell-main").scrollTop();
-
-            let row_location = rowLocation(y),
-                row = row_location[1],
-                row_pre = row_location[0],
-                row_index = row_location[2];
-            let col_location = colLocation(x),
-                col = col_location[1],
-                col_pre = col_location[0],
-                col_index = col_location[2];
-
-            let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index);
+            let pos = position(event.pageX, event.pageY);
+            
+            let margeset = menuButton.mergeborer(Store.flowdata, pos.row_index, pos.col_index);
             if (!!margeset) {
-                row = margeset.row[1];
-                row_pre = margeset.row[0];
-                row_index = margeset.row[2];
+                pos.row = margeset.row[1];
+                pos.row_pre = margeset.row[0];
+                pos.row_index = margeset.row[2];
 
-                col = margeset.column[1];
-                col_pre = margeset.column[0];
-                col_index = margeset.column[2];
+                pos.col = margeset.column[1];
+                pos.col_pre = margeset.column[0];
+                pos.col_index = margeset.column[2];
             }
 
 
-            // if(Store.flowdata[row_index] && Store.flowdata[row_index][col_index]){
+            // if(Store.flowdata[pos.row_index] && Store.flowdata[pos.row_index][pos.col_index]){
                 let sheetFile = sheetmanage.getSheetByIndex();
 
                 let moveState = {
@@ -1587,14 +1611,20 @@ export default function luckysheetHandler() {
     
                 let luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d");
 
-                if(Store.flowdata && Store.flowdata[row_index]){
-                    method.createHookFunction("sheetMousemove", Store.flowdata[row_index][col_index], {
-                        r:row_index,
-                        c:col_index,
-                        "start_r": row_pre,
-                        "start_c": col_pre, 
-                        "end_r": row, 
-                        "end_c": col 
+                if(Store.flowdata && Store.flowdata[pos.row_index]){
+                    method.createHookFunction("sheetMousemove", Store.flowdata[pos.row_index][pos.col_index], {
+                        r:pos.row_index,
+                        c:pos.col_index,
+                        "start_r": pos.row_pre,
+                        "start_c": pos.col_pre, 
+                        "end_r": pos.row, 
+                        "end_c": pos.col,
+                        ox: pos.ox,
+                        oy: pos.oy,
+                        mx: pos.mx,
+                        my: pos.my,
+                        or: pos.row_index_ox,
+                        oc: pos.col_index_oy,
                     }, sheetFile,moveState,luckysheetTableContent);
                 }
             // }
@@ -2416,14 +2446,14 @@ export default function luckysheetHandler() {
                     let mouse = mouseposition(event.pageX, event.pageY);
                     let scrollTop = $("#luckysheet-rows-h").scrollTop();
                     let y = mouse[1] + scrollTop;
-                    let winH = $(window).height();
+                    let winH = $("#luckysheet-cell-main").height();
 
                     let row_location = rowLocation(y),
                         row = row_location[1],
                         row_pre = row_location[0],
                         row_index = row_location[2];
 
-                    if ((y + 3) - Store.luckysheet_rows_change_size_start[0] > 19 && y < winH + scrollTop - 200) {
+                    if ((y + 3) - Store.luckysheet_rows_change_size_start[0] > 19 && y < winH + scrollTop) {
                         $("#luckysheet-change-size-line").css({ "top": y });
                         $("#luckysheet-rows-change-size").css({ "top": y });
                     }
@@ -3634,23 +3664,23 @@ export default function luckysheetHandler() {
             let mouse = mouseposition(event.pageX, event.pageY);
             let scrollTop = $("#luckysheet-rows-h").scrollTop();
             let y = mouse[1] + scrollTop;
-            let winH = $(window).height();
+            let winH = $("#luckysheet-cell-main").height();
 
             let row_location = rowLocation(y),
                 row = row_location[1],
                 row_pre = row_location[0],
                 row_index = row_location[2];
 
+            if (y >= winH + scrollTop) {
+                y = winH + scrollTop;
+            }
+            
             let size = (y + 3) - Store.luckysheet_rows_change_size_start[0];
-
-            if ((y + 3) - Store.luckysheet_rows_change_size_start[0] < 19) {
+            
+            if (size < 19) {
                 size = 19;
             }
 
-            if (y >= winH - 200 + scrollTop) {
-                size = winH - 200 - Store.luckysheet_rows_change_size_start[0] + scrollTop;
-            }
-
             let cfg = $.extend(true, {}, Store.config);
             if (cfg["rowlen"] == null) {
                 cfg["rowlen"] = {};

+ 2 - 2
src/controllers/rowColumnOperation.js

@@ -385,7 +385,7 @@ export function rowColumnOperationInitial(){
             if (!checkIsAllowEdit()) {
                 return
             }
-            if(isEditMode()){ //非编辑模式下禁止右键功能框
+            if(!isEditMode()){ //非编辑模式下禁止右键功能框
                 return;
             }
 
@@ -823,7 +823,7 @@ export function rowColumnOperationInitial(){
             if (!checkIsAllowEdit()) {
                 return
             }
-            if(isEditMode()){ //非编辑模式下禁止右键功能框
+            if(!isEditMode()){ //非编辑模式下禁止右键功能框
                 return;
             }
 

+ 31 - 4
src/global/location.js

@@ -17,6 +17,7 @@ function rowLocationByIndex(row_index) {
 
 function rowLocation(y) {
     let row_index = luckysheet_searcharray(Store.visibledatarow, y);
+    let orow_index = row_index;
 
     if (row_index == -1 && y > 0) {
         row_index = Store.visibledatarow.length - 1;
@@ -24,8 +25,9 @@ function rowLocation(y) {
     else if (row_index == -1 && y <= 0) {
         row_index = 0;
     }
-
-    return rowLocationByIndex(row_index);
+    let rowloc = rowLocationByIndex(row_index);
+    rowloc.push(orow_index);
+    return rowloc;
 }
 
 function colLocationByIndex(col_index){
@@ -58,6 +60,7 @@ function colSpanLocationByIndex(col_index, span){
 
 function colLocation(x) {
     let col_index = luckysheet_searcharray(Store.visibledatacolumn, x);
+    let ocol_index = col_index;
 
     if (col_index == -1 && x > 0) {
         col_index = Store.visibledatacolumn.length - 1;
@@ -65,8 +68,9 @@ function colLocation(x) {
     else if (col_index == -1 && x <= 0) {
         col_index = 0;
     }
-
-    return colLocationByIndex(col_index);
+    let colloc = colLocationByIndex(col_index);
+    colloc.push(ocol_index);
+    return colloc;
 }
 
 function mouseposition(x, y) {
@@ -78,6 +82,28 @@ function mouseposition(x, y) {
     return [newX, newY];
 }
 
+function position(x,y){
+    let pos = {
+        ox: x,
+        oy: y,
+    }
+    let mouse = mouseposition(x, y);
+    pos.mx = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
+    pos.my = mouse[1] + $("#luckysheet-cell-main").scrollTop();
+
+    let row_location = rowLocation(pos.my);
+    pos.row = row_location[1];
+    pos.row_pre = row_location[0];
+    pos.row_index = row_location[2];
+    pos.row_index_ox = row_location[3];
+    let col_location = colLocation(pos.mx);
+    pos.col = col_location[1];
+    pos.col_pre = col_location[0];
+    pos.col_index = col_location[2];
+    pos.col_index_oy = col_location[3];
+    return pos;
+}
+
 export {
     rowLocationByIndex,
     rowLocation,
@@ -85,4 +111,5 @@ export {
     colSpanLocationByIndex,
     colLocation,
     mouseposition,
+    position,
 }

+ 6 - 1
src/global/rhchInit.js

@@ -25,6 +25,11 @@ export default function rhchInit(rowheight, colwidth) {
             if (rowlen === 'auto') {
                 rowlen = computeRowlenByContent(Store.flowdata, r);
             }
+
+            if (rowlen < 19) {
+                rowlen = 19;
+            }
+
             Store.rh_height += Math.round((rowlen + 1) * Store.zoomRatio);
 
             Store.visibledatarow.push(Store.rh_height); //行的临时长度分布
@@ -32,7 +37,7 @@ export default function rhchInit(rowheight, colwidth) {
 
         // 如果增加行和回到顶部按钮隐藏,则减少底部空白区域,但是预留足够空间给单元格下拉按钮
         if (!luckysheetConfigsetting.enableAddRow && !luckysheetConfigsetting.enableAddBackTop) {
-            Store.rh_height += Store.allowEdit?30:Store.cellMainSrollBarSize;
+            Store.rh_height += (Store.allowEdit?40:0) + Store.cellMainSrollBarSize;
         } else {
             Store.rh_height += 80;  //最底部增加空白
         }