Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(hook): function
Browse files Browse the repository at this point in the history
1.Add hook function:cellUpdated/   commentInsertBefore/    commentInsertAfter/
commentDeleteBefore/   commentDeleteAfter/   commentUpdateBefore/   commentUpdateAfter 2.Fix hook
function:cellUpdateBefore
  • Loading branch information
mengshukeji committed Nov 24, 2020
1 parent dad6e2b commit fb43a56
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 21 deletions.
37 changes: 24 additions & 13 deletions docs/zh/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}`

Expand Down
2 changes: 1 addition & 1 deletion docs/zh/guide/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 版本)

## 学习资料

Expand Down
44 changes: 39 additions & 5 deletions src/controllers/postil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 = [];

Expand All @@ -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){
Expand Down
3 changes: 2 additions & 1 deletion src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
20 changes: 19 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},


},
Expand Down

0 comments on commit fb43a56

Please sign in to comment.