From 5038508842f24da14c0a8663ddfbe8c9cf7f13fe Mon Sep 17 00:00:00 2001 From: cdswyda Date: Fri, 17 Sep 2021 11:56:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=20sheetCreateBefore?= =?UTF-8?q?=20sheetCreateAfter=20=E9=92=A9=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/guide/config.md | 6 +++--- src/controllers/sheetmanage.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/zh/guide/config.md b/docs/zh/guide/config.md index 6283601..acc34da 100644 --- a/docs/zh/guide/config.md +++ b/docs/zh/guide/config.md @@ -1256,15 +1256,15 @@ Luckysheet开放了更细致的自定义配置选项,分别有 ## 工作表 -### sheetCreatekBefore -(TODO) +### sheetCreateBefore + - 类型:Function - 默认值:null - 作用:创建sheet页前触发,sheet页新建也包含数据透视表新建 ------------ ### sheetCreateAfter -(TODO) + - 类型:Function - 默认值:null - 作用:创建sheet页后触发,sheet页新建也包含数据透视表新建 diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index 3a5efe8..b5ed2bf 100644 --- a/src/controllers/sheetmanage.js +++ b/src/controllers/sheetmanage.js @@ -228,6 +228,10 @@ const sheetmanage = { // alert("非编辑模式下不允许该操作!"); return; } + // 钩子 sheetCreateBefore + if(!method.createHookFunction('sheetCreateBefore')){ + return; + } let _this = this; @@ -271,6 +275,8 @@ const sheetmanage = { } _this.changeSheetExec(index, isPivotTable, true); + + // 钩子 sheetCreateAfter 不应该在这里 应在绘制完成后 因此在 changeSheet 实现 }, setSheetHide: function(index) { let _this = this; @@ -1147,6 +1153,11 @@ const sheetmanage = { $("#luckysheet-cell-main #luckysheet-multipleRange-show").empty(); server.multipleIndex = 0; } + let file = Store.luckysheetfile[_this.getSheetIndex(index)] + // 钩子 sheetCreateAfter + if (isNewSheet) { + method.createHookFunction('sheetCreateAfter', { sheet: file }); + } // 钩子函数 method.createHookFunction('sheetActivate', index, isPivotInitial, isNewSheet); @@ -1157,7 +1168,6 @@ const sheetmanage = { _this.storeSheetParamALL(); _this.setCurSheet(index); - let file = Store.luckysheetfile[_this.getSheetIndex(index)] if (!!file.isPivotTable) { Store.luckysheetcurrentisPivotTable = true;