Browse Source

feat: 新增 sheetCopyBefore 、 sheetCopyAfter 钩子

master
cdswyda 4 years ago
parent
commit
0d17df93ec
  1. 18
      docs/zh/guide/config.md
  2. 20
      src/controllers/sheetmanage.js

18
docs/zh/guide/config.md

@ -1271,6 +1271,24 @@ Luckysheet开放了更细致的自定义配置选项,分别有
- 参数: - 参数:
- {Object} [sheet]: 当前新创建的sheet页的配置 - {Object} [sheet]: 当前新创建的sheet页的配置
------------
### sheetCopyBefore
- 类型:Function
- 默认值:null
- 作用:拷贝创建sheet页前触发,sheet页新建也包含数据透视表新建
- 参数:
- {Object} [targetSheet]: 被拷贝的sheet页配置
- {Object} [copySheet]: 拷贝得到的sheet页的配置
------------
### sheetCopyAfter
- 类型:Function
- 默认值:null
- 作用:拷贝创建sheet页后触发,sheet页新建也包含数据透视表新建
- 参数:
- {Object} [sheet]: 当前创建的sheet页的配置
------------ ------------
### sheetHideBefore ### sheetHideBefore

20
src/controllers/sheetmanage.js

@ -479,6 +479,14 @@ const sheetmanage = {
copyjson.index = index; copyjson.index = index;
copyjson.name = _this.generateCopySheetName(Store.luckysheetfile, copyjson.name); copyjson.name = _this.generateCopySheetName(Store.luckysheetfile, copyjson.name);
// 钩子 sheetCreateBefore
if(!method.createHookFunction('sheetCopyBefore', {
targetSheet: Store.luckysheetfile[copyarrindex],
copySheet: copyjson
})){
return;
}
let colorset = ''; let colorset = '';
if(copyjson.color != null){ if(copyjson.color != null){
colorset = '<div class="luckysheet-sheets-item-color" style=" position: absolute; width: 100%; height: 3px; bottom: 0px; left: 0px; background-color: ' + copyjson.color + ';"></div>'; colorset = '<div class="luckysheet-sheets-item-color" style=" position: absolute; width: 100%; height: 3px; bottom: 0px; left: 0px; background-color: ' + copyjson.color + ';"></div>';
@ -496,7 +504,7 @@ const sheetmanage = {
server.saveParam("shc", index, { "copyindex": copyindex, "name": copyjson.name }); server.saveParam("shc", index, { "copyindex": copyindex, "name": copyjson.name });
_this.changeSheetExec(index); _this.changeSheetExec(index, undefined, undefined, true);
_this.reOrderAllSheet(); _this.reOrderAllSheet();
if (Store.clearjfundo) { if (Store.clearjfundo) {
@ -1149,7 +1157,7 @@ const sheetmanage = {
} }
} }
}, },
changeSheet: function(index, isPivotInitial, isNewSheet) { changeSheet: function(index, isPivotInitial, isNewSheet, isCopySheet) {
if(isEditMode()){ if(isEditMode()){
// alert("非编辑模式下不允许该操作!"); // alert("非编辑模式下不允许该操作!");
return; return;
@ -1170,6 +1178,10 @@ const sheetmanage = {
if (isNewSheet) { if (isNewSheet) {
method.createHookFunction('sheetCreateAfter', { sheet: file }); method.createHookFunction('sheetCreateAfter', { sheet: file });
} }
// 钩子 sheetCopyAfter
if (isCopySheet) {
method.createHookFunction('sheetCopyAfter', { sheet: file });
}
// 钩子函数 // 钩子函数
method.createHookFunction('sheetActivate', index, isPivotInitial, isNewSheet); method.createHookFunction('sheetActivate', index, isPivotInitial, isNewSheet);
@ -1489,7 +1501,7 @@ const sheetmanage = {
return null; return null;
}, },
changeSheetExec: function(index, isPivotInitial, isNewSheet) { changeSheetExec: function(index, isPivotInitial, isNewSheet, isCopySheet) {
let $sheet = $("#luckysheet-sheets-item" + index); let $sheet = $("#luckysheet-sheets-item" + index);
@ -1498,7 +1510,7 @@ const sheetmanage = {
$sheet.addClass("luckysheet-sheets-item-active").show(); $sheet.addClass("luckysheet-sheets-item-active").show();
cleargridelement(); cleargridelement();
this.changeSheet(index, isPivotInitial, isNewSheet); this.changeSheet(index, isPivotInitial, isNewSheet, isCopySheet);
$("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();

Loading…
Cancel
Save