From fb43a56222c3d4c77b84efa9ff37eed8e1333a1a Mon Sep 17 00:00:00 2001 From: mengshukeji Date: Tue, 24 Nov 2020 18:16:07 +0800 Subject: [PATCH] fix(hook): function 1.Add hook function:cellUpdated/ commentInsertBefore/ commentInsertAfter/ commentDeleteBefore/ commentDeleteAfter/ commentUpdateBefore/ commentUpdateAfter 2.Fix hook function:cellUpdateBefore --- docs/zh/guide/config.md | 37 ++++++++++++++++++++------------ docs/zh/guide/resource.md | 2 +- src/controllers/postil.js | 44 ++++++++++++++++++++++++++++++++++----- src/global/formula.js | 3 ++- src/index.html | 20 +++++++++++++++++- 5 files changed, 85 insertions(+), 21 deletions(-) diff --git a/docs/zh/guide/config.md b/docs/zh/guide/config.md index 2ae8a06af..460bdd157 100644 --- a/docs/zh/guide/config.md +++ b/docs/zh/guide/config.md @@ -1297,56 +1297,67 @@ Luckysheet开放了更细致的自定义配置选项,分别有 ## 批注 ### commentInsertBefore -(TODO) + - 类型:Function - 默认值:null -- 作用:插入批注之前 +- 作用:插入批注之前,`return false` 则不插入批注 - 参数: - - {Object} [cell]: 要插入的批注所在的单元格信息,如:`{ r:0,c:2,v:{m:'233',v:'233'}}` + - {Number} [r]:单元格所在行号 + - {Number} [c]:单元格所在列号 ------------ ### commentInsertAfter -(TODO) + - 类型:Function - 默认值:null - 作用:插入批注之后 - 参数: + - {Number} [r]:单元格所在行号 + - {Number} [c]:单元格所在列号 - {Object} [cell]: 被插入批注所在的单元格信息,如:`{ r:0,c:2,v:{m:'233',v:'233'}}`,包含批注信息 ------------ ### commentDeleteBefore -(TODO) + - 类型:Function - 默认值:null -- 作用:删除批注之前 +- 作用:删除批注之前,`return false` 则不删除批注 - 参数: - - {Object} [cell]: 要删除的批注所在的单元格信息,如:`{ r:0,c:2,v:{m:'233',v:'233'}}` + - {Number} [r]:单元格所在行号 + - {Number} [c]:单元格所在列号 + - {Object} [cell]: 要删除的批注所在的单元格信息,如:`{ r:0,c:2,v:{m:'233',v:'233'}}`,可以看到批注信息 ------------ ### commentDeleteAfter -(TODO) + - 类型:Function - 默认值:null - 作用:删除批注之后 - 参数: - - {Object} [cell]: 被删除批注所在的单元格信息,如:`{ r:0,c:2,v:{m:'233',v:'233'}}` + - {Number} [r]:单元格所在行号 + - {Number} [c]:单元格所在列号 + - {Object} [cell]: 被删除批注所在的单元格信息,如:`{ r:0,c:2,v:{m:'233',v:'233'}}`,可以看到批注已被删除 ------------ ### commentUpdateBefore -(TODO) + - 类型:Function - 默认值:null -- 作用:修改批注之前 +- 作用:修改批注之前,`return false` 则不修改批注 - 参数: - - {Object} [cell]: 批注所在的单元格信息,如:`{ r:0,c:2,v:{m:'233',v:'233'}}` + - {Number} [r]:单元格所在行号 + - {Number} [c]:单元格所在列号 + - {String} [value]: 新的批注内容 ------------ ### commentUpdateAfter -(TODO) + - 类型:Function - 默认值:null - 作用:修改批注之后 - 参数: + - {Number} [r]:单元格所在行号 + - {Number} [c]:单元格所在列号 - {Object} [oldCell]: 修改前批注所在的单元格信息,如:`{ r:0,c:2,v:{m:'233',v:'233'}}` - {Object} [newCell]: 修改后批注所在的单元格信息,如:`{ r:0,c:2,v:{m:'233',v:'233'}}` diff --git a/docs/zh/guide/resource.md b/docs/zh/guide/resource.md index e41b93951..3d52382c8 100644 --- a/docs/zh/guide/resource.md +++ b/docs/zh/guide/resource.md @@ -18,7 +18,7 @@ ### 社区案例 - [Luckysheet保存与恢复](https://gitee.com/ichiva/luckysheet-saved-in-recovery)(Java版) - [基于Luckysheet实现的协同编辑在线表格](https://github.com/DilemmaVi/ecsheet)(Java版) -- [使用.net core 3.1和Npoi 制作基于LuckSheet的基础导出](https://blog.csdn.net/DCDC2020/article/details/108486525)(.NET 版本) +- [使用.net core 3.1和Npoi 制作基于LuckSheet的基础导出](https://gitee.com/xiong-kangli/luck-sheet_.-net-core)(.NET 版本) ## 学习资料 diff --git a/src/controllers/postil.js b/src/controllers/postil.js index 66fd3546f..6c260dc28 100644 --- a/src/controllers/postil.js +++ b/src/controllers/postil.js @@ -11,6 +11,7 @@ import menuButton from './menuButton'; import {checkProtectionAuthorityNormal} from './protection'; import server from './server'; import Store from '../store'; +import method from '../global/method'; //批注 const luckysheetPostil = { @@ -408,6 +409,12 @@ const luckysheetPostil = { if(!checkProtectionAuthorityNormal(Store.currentSheetIndex, "editObjects")){ return; } + + // Hook function + if(!method.createHookFunction('commentInsertBefore',r,c, )){ + return; + } + let _this = this; let row = Store.visibledatarow[r], @@ -486,6 +493,11 @@ const luckysheetPostil = { rc.push(r + "_" + c); _this.ref(d, rc); + + // Hook function + setTimeout(() => { + method.createHookFunction('commentInsertAfter',r,c, d[r][c]) + }, 0); }, editPs: function(r, c){ let _this = this; @@ -575,6 +587,11 @@ const luckysheetPostil = { return; } + // Hook function + if(!method.createHookFunction('commentDeleteBefore',r,c,Store.flowdata[r][c])){ + return; + } + if($("#luckysheet-postil-show_"+ r +"_"+ c).length > 0){ $("#luckysheet-postil-show_"+ r +"_"+ c).remove(); } @@ -586,6 +603,11 @@ const luckysheetPostil = { rc.push(r + "_" + c); this.ref(d, rc); + + // Hook function + setTimeout(() => { + method.createHookFunction('commentDeleteAfter',r,c, Store.flowdata[r][c]) + }, 0); }, showHidePs: function(r, c){ let _this = this; @@ -812,18 +834,26 @@ const luckysheetPostil = { }, removeActivePs: function(){ if($("#luckysheet-postil-showBoxs .luckysheet-postil-show-active").length > 0){ + + let id = $("#luckysheet-postil-showBoxs .luckysheet-postil-show-active").attr("id"); + let r = id.split("luckysheet-postil-show_")[1].split("_")[0]; + let c = id.split("luckysheet-postil-show_")[1].split("_")[1]; + + let value = $("#" + id).find(".formulaInputFocus").text(); + + // Hook function + if(!method.createHookFunction('commentUpdateBefore',r,c,value)){ + return; + } + + const previousCell = $.extend(true,{},Store.flowdata[r][c]); $("#" + id).removeClass("luckysheet-postil-show-active"); $("#" + id).find(".luckysheet-postil-dialog-resize").hide(); $("#" + id).find(".arrowCanvas").css("z-index", 100); $("#" + id).find(".luckysheet-postil-show-main").css("z-index", 100); - let r = id.split("luckysheet-postil-show_")[1].split("_")[0]; - let c = id.split("luckysheet-postil-show_")[1].split("_")[1]; - - let value = $("#" + id).find(".formulaInputFocus").text(); - let d = editor.deepCopyFlowData(Store.flowdata); let rc = []; @@ -835,6 +865,10 @@ const luckysheetPostil = { if(!d[r][c].ps.isshow){ $("#" + id).remove(); } + // Hook function + setTimeout(() => { + method.createHookFunction('commentUpdateAfter',r,c, previousCell, d[r][c]) + }, 0); } }, ref: function(data, rc){ diff --git a/src/global/formula.js b/src/global/formula.js index f429a3fc3..4d2c5ea51 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -1290,7 +1290,8 @@ const luckysheetformula = { value = value || $input.text(); // Hook function - if(!method.createHookFunction("cellUpdateBefore", r, c, value, isRefresh)){ + if(!method.createHookFunction("cellUpdateBefore", r, c, value, isRefresh)){ + _this.cancelNormalSelected(); return; } diff --git a/src/index.html b/src/index.html index d1d20ca5a..745c35cfc 100644 --- a/src/index.html +++ b/src/index.html @@ -120,7 +120,25 @@ }, rangeSelect:function(index, sheet){ // console.info(index, sheet) - } + }, + commentInsertBefore:function(r, c){ + // console.info(r, c) + }, + commentInsertAfter:function(r, c, cell){ + // console.info(r, c, cell) + }, + commentDeleteBefore:function(r, c, cell){ + // console.info(r, c, cell) + }, + commentDeleteAfter:function(r, c, cell){ + // console.info(r, c, cell) + }, + commentUpdateBefore:function(r, c, value){ + // console.info(r, c, value) + }, + commentUpdateAfter:function(r, c, oldCell, newCell ){ + // console.info(r, c, oldCell, newCell) + }, },