diff --git a/src/controllers/handler.js b/src/controllers/handler.js index 432681ddc..0be08039f 100644 --- a/src/controllers/handler.js +++ b/src/controllers/handler.js @@ -311,6 +311,9 @@ export default function luckysheetHandler() { y = mouse[1] + luckysheetFreezen.freezenhorizontaldata[2]; } + let sheetFile = sheetmanage.getSheetByIndex(); + let luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d"); + let row_location = rowLocation(y), row = row_location[1], row_pre = row_location[0], @@ -335,6 +338,18 @@ export default function luckysheetHandler() { col_index_ed = margeset.column[3]; } + + //单元格单击之前 + if(!method.createHookFunction("cellMousedownBefore", 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 + }, sheetFile,luckysheetTableContent)){ return; } + + //数据验证 单元格聚焦 dataVerificationCtrl.cellFocus(row_index, col_index, true); @@ -1087,6 +1102,15 @@ export default function luckysheetHandler() { luckysheetContainerFocus(); + method.createHookFunction("cellMousedown", 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 + }, sheetFile,luckysheetTableContent); + //$("#luckysheet-cols-h-c .luckysheet-cols-h-cells-c .luckysheet-cols-h-cells-clip .luckysheet-cols-h-cell-sel").removeClass("luckysheet-cols-h-cell-sel").addClass("luckysheet-cols-h-cell-nosel"); //$("#luckysheet-rows-h .luckysheet-rows-h-cells .luckysheet-rows-h-cells-c .luckysheet-rows-h-cells-clip .luckysheet-rows-h-cell-sel").removeClass("luckysheet-rows-h-cell-sel").addClass("luckysheet-rows-h-cell-nosel"); @@ -1344,6 +1368,68 @@ export default function luckysheetHandler() { luckysheetPostil.overshow(event); //有批注显示 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); + 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]; + } + + + // if(Store.flowdata[row_index] && Store.flowdata[row_index][col_index]){ + let sheetFile = sheetmanage.getSheetByIndex(); + + let moveState = { + functionResizeStatus:formula.functionResizeStatus, + horizontalmoveState:!!luckysheetFreezen.horizontalmovestate, + verticalmoveState:!!luckysheetFreezen.verticalmovestate, + pivotTableMoveState:!!pivotTable && pivotTable.movestate, + sheetMoveStatus:Store.luckysheet_sheet_move_status, + scrollStatus:!!Store.luckysheet_scroll_status, + selectStatus:!!Store.luckysheet_select_status, + rowsSelectedStatus:!!Store.luckysheet_rows_selected_status, + colsSelectedStatus:!!Store.luckysheet_cols_selected_status, + cellSelectedMove:!!Store.luckysheet_cell_selected_move, + cellSelectedExtend:!!Store.luckysheet_cell_selected_extend, + colsChangeSize:!!Store.luckysheet_cols_change_size, + rowsChangeSize:!!Store.luckysheet_rows_change_size, + chartMove:!!Store.chartparam.luckysheetCurrentChartMove, + chartResize:!!Store.chartparam.luckysheetCurrentChartResize, + rangeResize:!!formula.rangeResize , + rangeMove:!!formula.rangeMove, + } + + let luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d"); + + 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 + }, sheetFile,moveState,luckysheetTableContent); + // } + } if(formula.functionResizeStatus){ let y = event.pageY; @@ -3055,6 +3141,69 @@ export default function luckysheetHandler() { }); //表格mouseup $(document).on("mouseup.luckysheetEvent",function (event) { + + if(luckysheetConfigsetting && luckysheetConfigsetting.hook && luckysheetConfigsetting.hook.sheetMouseup){ + 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]; + } + + + // if(Store.flowdata[row_index] && Store.flowdata[row_index][col_index]){ + let sheetFile = sheetmanage.getSheetByIndex(); + + let moveState = { + functionResizeStatus:formula.functionResizeStatus, + horizontalmoveState:!!luckysheetFreezen.horizontalmovestate, + verticalmoveState:!!luckysheetFreezen.verticalmovestate, + pivotTableMoveState:!!pivotTable && pivotTable.movestate, + sheetMoveStatus:Store.luckysheet_sheet_move_status, + scrollStatus:!!Store.luckysheet_scroll_status, + selectStatus:!!Store.luckysheet_select_status, + rowsSelectedStatus:!!Store.luckysheet_rows_selected_status, + colsSelectedStatus:!!Store.luckysheet_cols_selected_status, + cellSelectedMove:!!Store.luckysheet_cell_selected_move, + cellSelectedExtend:!!Store.luckysheet_cell_selected_extend, + colsChangeSize:!!Store.luckysheet_cols_change_size, + rowsChangeSize:!!Store.luckysheet_rows_change_size, + chartMove:!!Store.chartparam.luckysheetCurrentChartMove, + chartResize:!!Store.chartparam.luckysheetCurrentChartResize, + rangeResize:!!formula.rangeResize , + rangeMove:!!formula.rangeMove, + } + + let luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d"); + + method.createHookFunction("sheetMouseup", 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 + }, sheetFile,moveState,luckysheetTableContent); + // } + } + //数据窗格主体 if (Store.luckysheet_select_status) { clearTimeout(Store.countfuncTimeout); diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index bf008a642..cacac06a5 100644 --- a/src/controllers/sheetmanage.js +++ b/src/controllers/sheetmanage.js @@ -28,6 +28,7 @@ import { renderChartShow } from '../expendPlugins/chart/plugin'; import {changeSheetContainerSize, menuToolBarWidth} from './resize'; import {zoomNumberDomBind} from './zoom'; import menuButton from './menuButton'; +import method from '../global/method'; const sheetmanage = { generateRandomSheetIndex: function(prefix) { diff --git a/src/core.js b/src/core.js index b0453d60a..5112c6475 100644 --- a/src/core.js +++ b/src/core.js @@ -62,7 +62,6 @@ luckysheet.create = function (setting) { Store.lang = extendsetting.lang; //language Store.allowEdit = extendsetting.allowEdit; Store.fontList = extendsetting.fontList; - Store.defaultFontSize = extendsetting.defaultFontSize; server.gridKey = extendsetting.gridKey; server.loadUrl = extendsetting.loadUrl; server.updateUrl = extendsetting.updateUrl; @@ -105,15 +104,14 @@ luckysheet.create = function (setting) { luckysheetConfigsetting.plugins = extendsetting.plugins; luckysheetConfigsetting.rowHeaderWidth = extendsetting.rowHeaderWidth; - Store.rowHeaderWidth = extendsetting.rowHeaderWidth; luckysheetConfigsetting.columeHeaderHeight = extendsetting.columeHeaderHeight; - Store.columeHeaderHeight = extendsetting.columeHeaderHeight; luckysheetConfigsetting.defaultColWidth = extendsetting.defaultColWidth; luckysheetConfigsetting.defaultRowHeight = extendsetting.defaultRowHeight; luckysheetConfigsetting.title = extendsetting.title; luckysheetConfigsetting.container = extendsetting.container; + luckysheetConfigsetting.hook = extendsetting.hook; // Register plugins initPlugins(extendsetting.plugins , extendsetting.data); diff --git a/src/global/draw.js b/src/global/draw.js index e62fb503e..a62adc2ce 100644 --- a/src/global/draw.js +++ b/src/global/draw.js @@ -15,8 +15,10 @@ import { getBorderInfoCompute } from './border'; import { getSheetIndex } from '../methods/get'; import { getObjType, chatatABC, luckysheetfontformat } from '../utils/util'; import { isInlineStringCell } from '../controllers/inlineString'; +import method from './method'; import Store from '../store'; import locale from '../locale/locale'; +import sheetmanage from '../controllers/sheetmanage'; function luckysheetDrawgridRowTitle(scrollHeight, drawHeight, offsetTop) { if (scrollHeight == null) { @@ -79,14 +81,21 @@ function luckysheetDrawgridRowTitle(scrollHeight, drawHeight, offsetTop) { // if(end_r > scrollHeight + drawHeight){ // break; // } + let firstOffset = (dataset_row_st==r)?-2:0; + let lastOffset = (dataset_row_ed==r)?-2:0; + //列标题单元格渲染前触发,return false 则不渲染该单元格 + if(!method.createHookFunction("rowTitleCellRenderBefore", r+1, { + r:r, + top:(start_r + offsetTop + firstOffset), + width:Store.rowHeaderWidth -1, + height:(end_r - start_r + 1+lastOffset-firstOffset) + }, luckysheetTableContent)){ continue; } if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) { } else { luckysheetTableContent.fillStyle = "#ffffff"; - let firstOffset = (dataset_row_st==r)?-2:0; - let lastOffset = (dataset_row_ed==r)?-2:0; luckysheetTableContent.fillRect( 0, (start_r + offsetTop + firstOffset) , @@ -174,6 +183,14 @@ function luckysheetDrawgridRowTitle(scrollHeight, drawHeight, offsetTop) { preEndR = end_r; + //列标题单元格渲染前触发,return false 则不渲染该单元格 + method.createHookFunction("rowTitleCellRenderAfter", r+1, { + r:r, + top:(start_r + offsetTop + firstOffset), + width:Store.rowHeaderWidth -1, + height:(end_r - start_r + 1+lastOffset-firstOffset) + }, luckysheetTableContent) + } //行标题栏竖线 @@ -262,6 +279,14 @@ function luckysheetDrawgridColumnTitle(scrollWidth, drawWidth, offsetLeft) { // if(end_c > scrollWidth + drawWidth+1){ // break; // } + let abc = chatatABC(c); + //列标题单元格渲染前触发,return false 则不渲染该单元格 + if(!method.createHookFunction("columnTitleCellRenderBefore", abc, { + c:c, + left:(start_c + offsetLeft - 1), + width:(end_c - start_c), + height:Store.columeHeaderHeight -1 + }, luckysheetTableContent)){ continue; } if (Store.config["colhidden"] != null && Store.config["colhidden"][c] != null) { @@ -279,7 +304,7 @@ function luckysheetDrawgridColumnTitle(scrollWidth, drawWidth, offsetLeft) { //列标题栏序列号 luckysheetTableContent.save();//save scale before draw text luckysheetTableContent.scale(Store.zoomRatio,Store.zoomRatio); - let abc = chatatABC(c); + let textMetrics = getMeasureText(abc, luckysheetTableContent); //luckysheetTableContent.measureText(abc); @@ -357,6 +382,13 @@ function luckysheetDrawgridColumnTitle(scrollWidth, drawWidth, offsetLeft) { luckysheetTableContent.closePath(); preEndC = end_c; + + method.createHookFunction("columnTitleCellRenderAfter", abc, { + c:c, + left:(start_c + offsetLeft - 1), + width:(end_c - start_c), + height:Store.columeHeaderHeight -1 + }, luckysheetTableContent) } //列标题栏横线 @@ -387,6 +419,7 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of return; } + let sheetFile = sheetmanage.getSheetByIndex(); // console.trace(); clearTimeout(Store.measureTextCacheTimeOut); @@ -571,6 +604,8 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of firstcolumnlen = Store.config["columnlen"][c]; } + + if (Store.flowdata[r] != null && Store.flowdata[r][c] != null) { let value = Store.flowdata[r][c]; @@ -617,6 +652,18 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of } } } + else{ + //空单元格渲染前 + if(!method.createHookFunction("cellRenderBefore", Store.flowdata[r][c], { + r:r, + c:c, + "start_r": start_r, + "start_c": start_c, + "end_r": end_r, + "end_c": end_c + }, sheetFile,luckysheetTableContent)){ continue; } + } + cellupdate.push({ "r": r, @@ -663,6 +710,16 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of if(Store.flowdata[r] == null){ continue; } + + //有值单元格渲染前 + if(!method.createHookFunction("cellRenderBefore", Store.flowdata[r][c], { + r:r, + c:c, + "start_r": start_r, + "start_c": start_c, + "end_r": end_r, + "end_c": end_c + }, sheetFile,luckysheetTableContent)){ continue; } if(Store.flowdata[r][c] == null){ //空单元格 nullCellRender(r, c, start_r, start_c, end_r, end_c,luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05); @@ -700,6 +757,15 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of cellRender(r, c, start_r, start_c, end_r, end_c, value,luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05); } } + + method.createHookFunction("cellRenderAfter", Store.flowdata[r][c], { + r:r, + c:c, + "start_r": start_r, + "start_c": start_c, + "end_r": end_r, + "end_c": end_c + }, sheetFile,luckysheetTableContent) } //合并单元格再处理 diff --git a/src/global/method.js b/src/global/method.js index 7e48c7c63..ca2bcbcc3 100644 --- a/src/global/method.js +++ b/src/global/method.js @@ -506,7 +506,29 @@ const method = { luckysheet.insertChartTosheet(c.sheetIndex, c.dataSheetIndex, c.option, c.chartType, c.selfOption, c.defaultOption, c.row, c.column, chart_selection_color, chart_id, chart_selection_id, c.chartStyle, c.rangeConfigCheck, c.rangeRowCheck, c.rangeColCheck, c.chartMarkConfig, c.chartTitleConfig, c.winWidth, c.winHeight, c.scrollLeft, c.scrollTop, chartTheme, c.myWidth, c.myHeight, c.myLeft!=null?parseFloat(c.myLeft):null, c.myTop!=null?parseFloat(c.myTop):null, c.myindexrank, true); $("#"+chart_id).find(".luckysheet-modal-controll-update").click(); + }, + /** + * 获取单元格的值 + * @param {name} 函数名称 + * @param {arguments} 函数参数 + */ + createHookFunction:function(){ + let hookName = arguments[0]; + if(luckysheetConfigsetting.hook && luckysheetConfigsetting.hook[hookName]!=null && (typeof luckysheetConfigsetting.hook[hookName] == "function")){ + var args = Array.prototype.slice.apply(arguments); + args.shift(); + let ret = luckysheetConfigsetting.hook[hookName].apply(this, args); + if(ret===false){ + return false; + } + else{ + return true; + } + } + + return true; } + } export default method; \ No newline at end of file diff --git a/src/index.html b/src/index.html index eda4e4883..4a6086a5d 100644 --- a/src/index.html +++ b/src/index.html @@ -62,6 +62,39 @@ "url":"./assets/iconfont/Pacifico-Regular.ttf" } ], + hook:{ + rowTitleCellRenderBefore:function(rowNum,postion,ctx){ + // console.log(rowNum); + }, + rowTitleCellRenderAfter:function(rowNum,postion,ctx){ + // console.log(ctx); + }, + columnTitleCellRenderBefore:function(columnAbc,postion,ctx){ + // console.log(columnAbc); + }, + columnTitleCellRenderAfter:function(columnAbc,postion,ctx){ + // console.log(postion); + }, + cellRenderBefore:function(cell,postion,sheetFile,ctx){ + // console.log(cell,postion,sheetFile,ctx); + }, + cellRenderAfter:function(cell,postion,sheetFile,ctx){ + // console.log(postion); + }, + cellMousedownBefore:function(cell,postion,sheetFile,ctx){ + // console.log(postion); + }, + cellMousedown:function(cell,postion,sheetFile,ctx){ + // console.log(sheetFile); + }, + sheetMousemove:function(cell,postion,sheetFile,moveState,ctx){ + // console.log(cell,postion,sheetFile,moveState,ctx); + }, + sheetMouseup:function(cell,postion,sheetFile,moveState,ctx){ + // console.log(cell,postion,sheetFile,moveState,ctx); + }, + + }, data: [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart,sheetPicture,sheetDataVerification] /*[{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[