diff --git a/docs/zh/guide/config.md b/docs/zh/guide/config.md index 9f8c760..90704b6 100644 --- a/docs/zh/guide/config.md +++ b/docs/zh/guide/config.md @@ -1271,6 +1271,24 @@ Luckysheet开放了更细致的自定义配置选项,分别有 - 参数: - {Object} [sheet]: 当前新创建的sheet页的配置 +------------ +### sheetCopyBefore + +- 类型:Function +- 默认值:null +- 作用:拷贝创建sheet页前触发,sheet页新建也包含数据透视表新建 +- 参数: + - {Object} [targetSheet]: 被拷贝的sheet页配置 + - {Object} [copySheet]: 拷贝得到的sheet页的配置 +------------ +### sheetCopyAfter + +- 类型:Function +- 默认值:null +- 作用:拷贝创建sheet页后触发,sheet页新建也包含数据透视表新建 +- 参数: + - {Object} [sheet]: 当前创建的sheet页的配置 + ------------ ### sheetHideBefore diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index e154c4b..ec070c2 100644 --- a/src/controllers/sheetmanage.js +++ b/src/controllers/sheetmanage.js @@ -478,6 +478,14 @@ const sheetmanage = { copyjson.order = order; copyjson.index = index; copyjson.name = _this.generateCopySheetName(Store.luckysheetfile, copyjson.name); + + // 钩子 sheetCreateBefore + if(!method.createHookFunction('sheetCopyBefore', { + targetSheet: Store.luckysheetfile[copyarrindex], + copySheet: copyjson + })){ + return; + } let colorset = ''; if(copyjson.color != null){ @@ -496,7 +504,7 @@ const sheetmanage = { server.saveParam("shc", index, { "copyindex": copyindex, "name": copyjson.name }); - _this.changeSheetExec(index); + _this.changeSheetExec(index, undefined, undefined, true); _this.reOrderAllSheet(); if (Store.clearjfundo) { @@ -1149,7 +1157,7 @@ const sheetmanage = { } } }, - changeSheet: function(index, isPivotInitial, isNewSheet) { + changeSheet: function(index, isPivotInitial, isNewSheet, isCopySheet) { if(isEditMode()){ // alert("非编辑模式下不允许该操作!"); return; @@ -1170,6 +1178,10 @@ const sheetmanage = { if (isNewSheet) { method.createHookFunction('sheetCreateAfter', { sheet: file }); } + // 钩子 sheetCopyAfter + if (isCopySheet) { + method.createHookFunction('sheetCopyAfter', { sheet: file }); + } // 钩子函数 method.createHookFunction('sheetActivate', index, isPivotInitial, isNewSheet); @@ -1489,7 +1501,7 @@ const sheetmanage = { return null; }, - changeSheetExec: function(index, isPivotInitial, isNewSheet) { + changeSheetExec: function(index, isPivotInitial, isNewSheet, isCopySheet) { let $sheet = $("#luckysheet-sheets-item" + index); @@ -1498,7 +1510,7 @@ const sheetmanage = { $sheet.addClass("luckysheet-sheets-item-active").show(); cleargridelement(); - this.changeSheet(index, isPivotInitial, isNewSheet); + this.changeSheet(index, isPivotInitial, isNewSheet, isCopySheet); $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();