From f8716c18db05c7ab8bf59d1feb0dc4c3b364c560 Mon Sep 17 00:00:00 2001 From: wpxp123456 <2677556700@qq.com> Date: Fri, 30 Oct 2020 11:13:45 +0800 Subject: [PATCH 1/4] fix(bug): bug freeze bug fix #67, fix #85 --- src/controllers/freezen.js | 168 +++++++++++++++++++--------------- src/controllers/handler.js | 16 ++++ src/controllers/updateCell.js | 45 +++++---- 3 files changed, 140 insertions(+), 89 deletions(-) diff --git a/src/controllers/freezen.js b/src/controllers/freezen.js index 8f2f10d..43e00cd 100644 --- a/src/controllers/freezen.js +++ b/src/controllers/freezen.js @@ -1176,61 +1176,73 @@ const luckysheetFreezen = { let show = true; let show2 = true; - if(postil_top + postil_height < freezenTop){ - $(e).show().find(".luckysheet-postil-show-main").css("top", postil_top + offTop); - $(e).show().find(".arrowCanvas").css("top", size[1] + offTop); - } - else{ - if(postil_top < freezenTop + offTop){ - if(postil_top + postil_height <= freezenTop + offTop){ - show = false; + if(r >= _this.freezenhorizontaldata[1]){ + if(postil_top + postil_height < freezenTop){ + $(e).show().find(".luckysheet-postil-show-main").css("top", postil_top + offTop); + $(e).show().find(".arrowCanvas").css("top", size[1] + offTop); + } + else{ + if(postil_top < freezenTop + offTop){ + if(postil_top + postil_height <= freezenTop + offTop){ + show = false; + } + else{ + $(e).show().find(".luckysheet-postil-show-main").css({ "top": freezenTop + offTop, "height": postil_height - (freezenTop + offTop - postil_top) }); + $(e).show().find(".formulaInputFocus").css("margin-top", -(freezenTop + offTop - postil_top)); + $(e).show().find(".arrowCanvas").hide(); + + show2 = false; + } } else{ - $(e).show().find(".luckysheet-postil-show-main").css({ "top": freezenTop + offTop, "height": postil_height - (freezenTop + offTop - postil_top) }); - $(e).show().find(".formulaInputFocus").css("margin-top", -(freezenTop + offTop - postil_top)); - $(e).show().find(".arrowCanvas").hide(); - - show2 = false; + $(e).show().find(".luckysheet-postil-show-main").css({ + "top": postil_top, + "height": postil_height + }); + $(e).show().find(".formulaInputFocus").css("margin-top", 0); + $(e).show().find(".arrowCanvas").css("top", size[1]); + // luckysheetPostil.buildPs(r, c, postil); } } - else{ - $(e).show().find(".luckysheet-postil-show-main").css({ - "top": postil_top, - "height": postil_height - }); - $(e).show().find(".formulaInputFocus").css("margin-top", 0); - $(e).show().find(".arrowCanvas").css("top", size[1]); - // luckysheetPostil.buildPs(r, c, postil); - } - } - - if(postil_left + postil_width < freezenLeft){ - $(e).show().find(".luckysheet-postil-show-main").css("left", postil_left + offLeft); - $(e).show().find(".arrowCanvas").css("left", size[0] + offLeft); } else{ - if(postil_left < freezenLeft + offLeft){ - if(postil_left + postil_width <= freezenLeft + offLeft){ - show = false; - } - else{ - $(e).show().find(".luckysheet-postil-show-main").css({ "left": freezenLeft + offLeft, "width": postil_width - (freezenLeft + offLeft - postil_left) }); - $(e).show().find(".formulaInputFocus").css("margin-left", -(freezenLeft + offLeft - postil_left)); - $(e).show().find(".arrowCanvas").hide(); + $(e).show().find(".luckysheet-postil-show-main").css("top", postil_top + offTop); + $(e).show().find(".arrowCanvas").css("top", size[1] + offTop); + } - show2 = false; - } + if(c >= _this.freezenverticaldata[1]){ + if(postil_left + postil_width < freezenLeft){ + $(e).show().find(".luckysheet-postil-show-main").css("left", postil_left + offLeft); + $(e).show().find(".arrowCanvas").css("left", size[0] + offLeft); } else{ - $(e).show().find(".luckysheet-postil-show-main").css({ - "left": postil_left, - "width": postil_width - }); - $(e).show().find(".formulaInputFocus").css("margin-left", 0); - $(e).show().find(".arrowCanvas").css("left", size[0]); - // luckysheetPostil.buildPs(r, c, postil); + if(postil_left < freezenLeft + offLeft){ + if(postil_left + postil_width <= freezenLeft + offLeft){ + show = false; + } + else{ + $(e).show().find(".luckysheet-postil-show-main").css({ "left": freezenLeft + offLeft, "width": postil_width - (freezenLeft + offLeft - postil_left) }); + $(e).show().find(".formulaInputFocus").css("margin-left", -(freezenLeft + offLeft - postil_left)); + $(e).show().find(".arrowCanvas").hide(); + + show2 = false; + } + } + else{ + $(e).show().find(".luckysheet-postil-show-main").css({ + "left": postil_left, + "width": postil_width + }); + $(e).show().find(".formulaInputFocus").css("margin-left", 0); + $(e).show().find(".arrowCanvas").css("left", size[0]); + // luckysheetPostil.buildPs(r, c, postil); + } } } + else{ + $(e).show().find(".luckysheet-postil-show-main").css("left", postil_left + offLeft); + $(e).show().find(".arrowCanvas").css("left", size[0] + offLeft); + } if(!show){ $(e).hide(); @@ -1281,24 +1293,30 @@ const luckysheetFreezen = { let size = luckysheetPostil.getArrowCanvasSize(postil_left, postil_top, toX, toY); - if(postil_top + postil_height < freezenTop){ - $(e).show().find(".luckysheet-postil-show-main").css("top", postil_top + offTop); - $(e).show().find(".arrowCanvas").css("top", size[1] + offTop); - } - else{ - if(postil_top < freezenTop + offTop){ - if(postil_top + postil_height <= freezenTop + offTop){ - $(e).hide(); + if(r >= _this.freezenhorizontaldata[1]){ + if(postil_top + postil_height < freezenTop){ + $(e).show().find(".luckysheet-postil-show-main").css("top", postil_top + offTop); + $(e).show().find(".arrowCanvas").css("top", size[1] + offTop); + } + else{ + if(postil_top < freezenTop + offTop){ + if(postil_top + postil_height <= freezenTop + offTop){ + $(e).hide(); + } + else{ + $(e).show().find(".luckysheet-postil-show-main").css({ "top": freezenTop + offTop, "height": postil_height - (freezenTop + offTop - postil_top) }); + $(e).show().find(".formulaInputFocus").css("margin-top", -(freezenTop + offTop - postil_top)); + $(e).show().find(".arrowCanvas").hide(); + } } else{ - $(e).show().find(".luckysheet-postil-show-main").css({ "top": freezenTop + offTop, "height": postil_height - (freezenTop + offTop - postil_top) }); - $(e).show().find(".formulaInputFocus").css("margin-top", -(freezenTop + offTop - postil_top)); - $(e).show().find(".arrowCanvas").hide(); + luckysheetPostil.buildPs(r, c, postil); } } - else{ - luckysheetPostil.buildPs(r, c, postil); - } + } + else{ + $(e).show().find(".luckysheet-postil-show-main").css("top", postil_top + offTop); + $(e).show().find(".arrowCanvas").css("top", size[1] + offTop); } }) } @@ -1342,24 +1360,30 @@ const luckysheetFreezen = { let size = luckysheetPostil.getArrowCanvasSize(postil_left, postil_top, toX, toY); - if(postil_left + postil_width < freezenLeft){ - $(e).show().find(".luckysheet-postil-show-main").css("left", postil_left + offLeft); - $(e).show().find(".arrowCanvas").css("left", size[0] + offLeft); - } - else{ - if(postil_left < freezenLeft + offLeft){ - if(postil_left + postil_width <= freezenLeft + offLeft){ - $(e).hide(); + if(c >= _this.freezenverticaldata[1]){ + if(postil_left + postil_width < freezenLeft){ + $(e).show().find(".luckysheet-postil-show-main").css("left", postil_left + offLeft); + $(e).show().find(".arrowCanvas").css("left", size[0] + offLeft); + } + else{ + if(postil_left < freezenLeft + offLeft){ + if(postil_left + postil_width <= freezenLeft + offLeft){ + $(e).hide(); + } + else{ + $(e).show().find(".luckysheet-postil-show-main").css({ "left": freezenLeft + offLeft, "width": postil_width - (freezenLeft + offLeft - postil_left) }); + $(e).show().find(".formulaInputFocus").css("margin-left", -(freezenLeft + offLeft - postil_left)); + $(e).show().find(".arrowCanvas").hide(); + } } else{ - $(e).show().find(".luckysheet-postil-show-main").css({ "left": freezenLeft + offLeft, "width": postil_width - (freezenLeft + offLeft - postil_left) }); - $(e).show().find(".formulaInputFocus").css("margin-left", -(freezenLeft + offLeft - postil_left)); - $(e).show().find(".arrowCanvas").hide(); + luckysheetPostil.buildPs(r, c, postil); } } - else{ - luckysheetPostil.buildPs(r, c, postil); - } + } + else{ + $(e).show().find(".luckysheet-postil-show-main").css("left", postil_left + offLeft); + $(e).show().find(".arrowCanvas").css("left", size[0] + offLeft); } }) } diff --git a/src/controllers/handler.js b/src/controllers/handler.js index 4b0acb6..4730f3a 100644 --- a/src/controllers/handler.js +++ b/src/controllers/handler.js @@ -187,6 +187,10 @@ export default function luckysheetHandler() { let col_st = luckysheet_searcharray(visibledatacolumn_c, scrollLeft); let row_st = luckysheet_searcharray(visibledatarow_c, scrollTop); + if (luckysheetFreezen.freezenhorizontaldata != null) { + row_st = luckysheet_searcharray(visibledatarow_c, scrollTop + luckysheetFreezen.freezenhorizontaldata[0]); + } + let colscroll = 0; let rowscroll = 0; @@ -212,6 +216,10 @@ export default function luckysheetHandler() { rowscroll = row_ed == 0 ? 0 : visibledatarow_c[row_ed - 1]; + if (luckysheetFreezen.freezenhorizontaldata != null) { + rowscroll -= luckysheetFreezen.freezenhorizontaldata[0]; + } + $("#luckysheet-scrollbar-y").scrollTop(rowscroll); } else if(event.deltaX != 0){ @@ -1241,6 +1249,14 @@ export default function luckysheetHandler() { let x = mouse[0] + scrollLeft; let y = mouse[1] + scrollTop; + if(luckysheetFreezen.freezenverticaldata != null && mouse[0] < (luckysheetFreezen.freezenverticaldata[0] - luckysheetFreezen.freezenverticaldata[2])){ + x = mouse[0] + luckysheetFreezen.freezenverticaldata[2]; + } + + if(luckysheetFreezen.freezenhorizontaldata != null && mouse[1] < (luckysheetFreezen.freezenhorizontaldata[0] - luckysheetFreezen.freezenhorizontaldata[2])){ + y = mouse[1] + luckysheetFreezen.freezenhorizontaldata[2]; + } + let row_location = rowLocation(y), row_index = row_location[2]; diff --git a/src/controllers/updateCell.js b/src/controllers/updateCell.js index a7ec886..27322cf 100644 --- a/src/controllers/updateCell.js +++ b/src/controllers/updateCell.js @@ -17,7 +17,6 @@ import {isInlineStringCell} from './inlineString'; import Store from '../store'; export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocus) { - if(!checkProtectionLocked(row_index1, col_index1, Store.currentSheetIndex)){ $("#luckysheet-functionbox-cell").blur(); return; @@ -27,8 +26,6 @@ export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocu return; } - - //数据验证 if(dataVerificationCtrl.dataVerification != null && dataVerificationCtrl.dataVerification[row_index1 + '_' + col_index1] != null){ let dataVerificationItem = dataVerificationCtrl.dataVerification[row_index1 + '_' + col_index1]; @@ -41,7 +38,12 @@ export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocu } let size = getColumnAndRowSize(row_index1, col_index1, d); - let row = size.row, row_pre = size.row_pre, col = size.col, col_pre = size.col_pre, row_index = size.row_index, col_index = size.col_index; + let row = size.row, + row_pre = size.row_pre, + col = size.col, + col_pre = size.col_pre, + row_index = size.row_index, + col_index = size.col_index; if($("#luckysheet-dropCell-icon").is(":visible")){ $("#luckysheet-dropCell-icon").remove(); @@ -56,14 +58,24 @@ export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocu return; } + let left = col_pre + container_offset.left + Store.rowHeaderWidth - scrollLeft - 2; + if(col_index1 <= luckysheetFreezen.freezenverticaldata[1]){ + left = col_pre + container_offset.left + Store.rowHeaderWidth - 2; + } + + let top = row_pre + container_offset.top + Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columeHeaderHeight - scrollTop - 2; + if(row_index1 <= luckysheetFreezen.freezenhorizontaldata[1]){ + top = row_pre + container_offset.top + Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columeHeaderHeight - 2; + } + let input_postition = { "min-width": col - col_pre+ 1- 8, "min-height": row - row_pre + 1- 4, - "max-width":winW + scrollLeft - col_pre - 20 - Store.rowHeaderWidth, + "max-width": winW + scrollLeft - col_pre - 20 - Store.rowHeaderWidth, "max-height": winH + scrollTop - row_pre - 20 - 15 - Store.toolbarHeight - Store.infobarHeight - Store.calculatebarHeight - Store.sheetBarHeight - Store.statisticBarHeight, - "left": col_pre + container_offset.left + Store.rowHeaderWidth - scrollLeft - 2, - "top": row_pre + container_offset.top + Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columeHeaderHeight - scrollTop - 2, + "left": left, + "top": top, } let inputContentScale = { @@ -193,8 +205,6 @@ export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocu if(input_postition["min-width"] > input_postition["max-width"]){ input_postition["min-width"] = input_postition["max-width"]; } - - if((value == null || value.toString() == "") && !cover){ value = "
"; @@ -242,7 +252,6 @@ export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocu cleargridelement(); } - export function setCenterInputPosition(row_index, col_index, d){ if(row_index==null ||col_index==null){ return; @@ -294,9 +303,11 @@ export function getColumnAndRowSize(row_index, col_index, d){ row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1]; let col = Store.visibledatacolumn[col_index], col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1]; - if(d==null){ + + if(d == null){ d = Store.flowdata; } + let margeset = menuButton.mergeborer(d, row_index, col_index); if(!!margeset){ row = margeset.row[1]; @@ -308,11 +319,11 @@ export function getColumnAndRowSize(row_index, col_index, d){ } return { - row:row, - row_pre:row_pre, - row_index:row_index, - col:col, - col_pre:col_pre, - col_index:col_index + row: row, + row_pre: row_pre, + row_index: row_index, + col: col, + col_pre: col_pre, + col_index: col_index } } From 801cbe5a8040d80f2e672b3607c0b92c922281a9 Mon Sep 17 00:00:00 2001 From: wpxp123456 <2677556700@qq.com> Date: Fri, 30 Oct 2020 14:08:19 +0800 Subject: [PATCH 2/4] fix(bug): bug --- src/controllers/updateCell.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/updateCell.js b/src/controllers/updateCell.js index 27322cf..4d29402 100644 --- a/src/controllers/updateCell.js +++ b/src/controllers/updateCell.js @@ -59,12 +59,12 @@ export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocu } let left = col_pre + container_offset.left + Store.rowHeaderWidth - scrollLeft - 2; - if(col_index1 <= luckysheetFreezen.freezenverticaldata[1]){ + if(luckysheetFreezen.freezenverticaldata != null && col_index1 <= luckysheetFreezen.freezenverticaldata[1]){ left = col_pre + container_offset.left + Store.rowHeaderWidth - 2; } let top = row_pre + container_offset.top + Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columeHeaderHeight - scrollTop - 2; - if(row_index1 <= luckysheetFreezen.freezenhorizontaldata[1]){ + if(luckysheetFreezen.freezenhorizontaldata != null && row_index1 <= luckysheetFreezen.freezenhorizontaldata[1]){ top = row_pre + container_offset.top + Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columeHeaderHeight - 2; } From 845c6c30e49b196bae69ad5996db49bea0964213 Mon Sep 17 00:00:00 2001 From: zhangchen Date: Thu, 29 Oct 2020 21:32:29 +0800 Subject: [PATCH 3/4] add: @babel/preset-env --- gulpfile.js | 19 +++++++++++++------ package.json | 6 ++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index bbfd919..6728463 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -43,7 +43,14 @@ const babelConfig = { plugins: [ ], presets: [ - '@babel/preset-env' + ['@babel/preset-env', { + useBuiltIns: 'usage', + corejs: 3, + targets: { + chrome: 58, + ie: 11 + } + }] ] }; @@ -68,7 +75,7 @@ const paths = { destStaticCssImages: ['dist/css'], //core es module - core: ['src/**/*.js','!src/demoData/*.js','src/expendPlugins/**/plugin.js','!src/plugins/js/*.js'], + core: ['src/**/*.js','!src/demoData/*.js','src/expendPlugins/**/plugin.js','!src/plugins/js/*.js'], //plugins src pluginsCss: ['src/plugins/css/*.css'], @@ -98,7 +105,7 @@ const paths = { concatPlugins: 'plugins.css', concatCss: 'luckysheet.css', concatPluginsJs: 'plugin.js', - + //plugins dest destPluginsCss: ['dist/plugins/css'], destPlugins: ['dist/plugins'], @@ -187,7 +194,7 @@ async function core() { inlineDynamicImports:true, }); } - + } // According to the build tag in html, package js and css @@ -196,7 +203,7 @@ function pluginsCss() { .pipe(concat(paths.concatPluginsCss)) .pipe(gulpif(production, cleanCSS())) .pipe(dest(paths.destPluginsCss)) - + } function plugins() { @@ -255,4 +262,4 @@ const build = series(clean, parallel(pluginsCss, plugins, css, pluginsJs, copySt exports.dev = dev; exports.build = build; -exports.default = dev; \ No newline at end of file +exports.default = dev; diff --git a/package.json b/package.json index 23d2ba3..fa288fc 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,10 @@ "browser": "dist/luckysheet.umd.js", "devDependencies": { "@babel/preset-env": "^7.10.2", + "@babel/runtime-corejs3": "^7.12.1", "@commitlint/cli": "^9.1.1", "@commitlint/config-conventional": "^9.1.1", - "@rollup/plugin-babel": "^5.0.3", + "@rollup/plugin-babel": "^5.2.1", "@rollup/plugin-commonjs": "^13.0.0", "@rollup/plugin-node-resolve": "^8.0.1", "browser-sync": "^2.26.7", @@ -21,12 +22,13 @@ "gulp-if": "^3.0.0", "gulp-uglify": "^3.0.2", "gulp-useref": "^4.0.1", - "rollup": "^2.16.1", + "rollup": "^2.32.1", "rollup-plugin-terser": "^6.1.0", "standard-version": "^8.0.2", "vuepress": "^1.5.0" }, "dependencies": { + "@babel/runtime": "^7.12.1", "jspdf": "^2.1.1" }, "scripts": { From 927ff46949f688a5bcffcb3fe48dc6b4b12b61c9 Mon Sep 17 00:00:00 2001 From: liuyang Date: Fri, 30 Oct 2020 17:10:32 +0800 Subject: [PATCH 4/4] feat(cell hooks add): go to document for detail --- src/controllers/handler.js | 149 +++++++++++++++++++++++++++++++++ src/controllers/sheetmanage.js | 1 + src/core.js | 4 +- src/global/draw.js | 72 +++++++++++++++- src/global/method.js | 22 +++++ src/index.html | 33 ++++++++ 6 files changed, 275 insertions(+), 6 deletions(-) diff --git a/src/controllers/handler.js b/src/controllers/handler.js index 432681d..0be0803 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 bf008a6..cacac06 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 b0453d6..5112c64 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 e62fb50..a62adc2 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 7e48c7c..ca2bcbc 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 eda4e48..4a6086a 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":[