diff --git a/docs/zh/guide/config.md b/docs/zh/guide/config.md index da6e48d..029e88d 100644 --- a/docs/zh/guide/config.md +++ b/docs/zh/guide/config.md @@ -1262,21 +1262,75 @@ Luckysheet开放了更细致的自定义配置选项,分别有 ## 工作表 -### sheetCreatekBefore -(TODO) +### sheetCreateBefore + - 类型:Function - 默认值:null - 作用:创建sheet页前触发,sheet页新建也包含数据透视表新建 ------------ ### sheetCreateAfter -(TODO) + - 类型:Function - 默认值:null - 作用:创建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 + +- 类型:Function +- 默认值:null +- 作用:隐藏sheet页前触发 +- 参数: + - {Object} [sheet]: 将要隐藏的sheet页的配置 + +------------ +### sheetHideAfter + +- 类型:Function +- 默认值:null +- 作用:隐藏sheet页后触发 +- 参数: + - {Object} [sheet]: 要隐藏的sheet页的配置 + +------------ +### sheetShowBefore + +- 类型:Function +- 默认值:null +- 作用:显示sheet页前触发 +- 参数: + - {Object} [sheet]: 将要显示的sheet页的配置 + +------------ +### sheetShowAfter + +- 类型:Function +- 默认值:null +- 作用:显示sheet页后触发 +- 参数: + - {Object} [sheet]: 要显示的sheet页的配置 + ------------ ### sheetMoveBefore (TODO) @@ -1300,7 +1354,7 @@ Luckysheet开放了更细致的自定义配置选项,分别有 ------------ ### sheetDeleteBefore -(TODO) + - 类型:Function - 默认值:null - 作用:sheet删除前 @@ -1309,7 +1363,7 @@ Luckysheet开放了更细致的自定义配置选项,分别有 ------------ ### sheetDeleteAfter -(TODO) + - 类型:Function - 默认值:null - 作用:sheet删除后 @@ -1318,7 +1372,7 @@ Luckysheet开放了更细致的自定义配置选项,分别有 ------------ ### sheetEditNameBefore -(TODO) + - 类型:Function - 默认值:null - 作用:sheet修改名称前 @@ -1328,7 +1382,7 @@ Luckysheet开放了更细致的自定义配置选项,分别有 ------------ ### sheetEditNameAfter -(TODO) + - 类型:Function - 默认值:null - 作用:sheet修改名称后 diff --git a/src/controllers/sheetBar.js b/src/controllers/sheetBar.js index 356cd47..6f76ea5 100644 --- a/src/controllers/sheetBar.js +++ b/src/controllers/sheetBar.js @@ -17,6 +17,7 @@ import locale from '../locale/locale'; import Store from '../store'; import luckysheetConfigsetting from './luckysheetConfigsetting'; import {pagerInit} from '../global/api' +import method from '../global/method'; //表格底部名称栏区域 相关事件(增、删、改、隐藏显示、颜色等等) @@ -325,6 +326,11 @@ export function initialSheetBar(){ Store.jfundo.length = 0; Store.jfredo.push(redo); } + // 钩子: sheetEditNameAfter + method.createHookFunction('sheetEditNameAfter', { + i: Store.luckysheetfile[index].index, + oldName: oldtxt, newName: txt + }); }); $("#luckysheet-sheet-area").on("keydown", "span.luckysheet-sheets-item-name", function (e) { @@ -342,6 +348,11 @@ export function initialSheetBar(){ }); $("#luckysheetsheetconfigrename").click(function () { + var $name = luckysheetcurrentSheetitem.find("span.luckysheet-sheets-item-name") + // 钩子 sheetEditNameBefore + if (!method.createHookFunction('sheetEditNameBefore', { i: luckysheetcurrentSheetitem.data('index') , name: $name.text() })){ + return; + } luckysheetsheetnameeditor(luckysheetcurrentSheetitem.find("span.luckysheet-sheets-item-name")); $("#luckysheet-input-box").removeAttr("style"); $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index 3a5efe8..884273d 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,10 +275,16 @@ const sheetmanage = { } _this.changeSheetExec(index, isPivotTable, true); + + // 钩子 sheetCreateAfter 不应该在这里 应在绘制完成后 因此在 changeSheet 实现 }, - setSheetHide: function(index) { + setSheetHide: function(index, isDelete) { let _this = this; let currentIdx = _this.getSheetIndex(index); + // 钩子 sheetHideBefore + if(!isDelete && !method.createHookFunction('sheetHideBefore', {sheet: Store.luckysheetfile[currentIdx]})){ + return; + } Store.luckysheetfile[currentIdx].hide = 1; let luckysheetcurrentSheetitem = $("#luckysheet-sheets-item" + index); @@ -311,14 +321,24 @@ const sheetmanage = { _this.changeSheetExec(indicator); server.saveParam("sh", luckysheetcurrentSheetitem.data("index"), 1, { "op": "hide", "cur": indicator }); + // 钩子 sheetHideAfter + if (!isDelete) { + method.createHookFunction('sheetHideAfter', {sheet: Store.luckysheetfile[currentIdx]}); + } }, setSheetShow: function(index) { let _this = this; - - Store.luckysheetfile[_this.getSheetIndex(index)].hide = 0; + const file = Store.luckysheetfile[_this.getSheetIndex(index)] + // 钩子 sheetShowBefore + if(!method.createHookFunction('sheetShowBefore', {sheet: file})){ + return; + } + file.hide = 0; _this.changeSheetExec(index); server.saveParam("sh", index, 0, {"op": "show", "cur": null}); + // 钩子 sheetShowAfter + method.createHookFunction('sheetShowAfter', {sheet: file}); }, sheetMaxIndex: 0, ordersheet: function(property) { @@ -460,6 +480,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){ @@ -478,7 +506,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) { @@ -560,7 +588,15 @@ const sheetmanage = { } let arrIndex = _this.getSheetIndex(index); - _this.setSheetHide(index); + + const file = Store.luckysheetfile[arrIndex]; + + // 钩子 sheetDeleteBefore + if(!method.createHookFunction('sheetDeleteBefore', { sheet: file })){ + return; + } + + _this.setSheetHide(index, true); $("#luckysheet-sheets-item" + index).remove(); $("#luckysheet-datavisual-selection-set-" + index).remove(); @@ -574,6 +610,8 @@ const sheetmanage = { removedsheet[0].type = "deleteSheet"; Store.jfredo.push(removedsheet[0]); } + // 钩子 sheetDeleteAfter + method.createHookFunction('sheetDeleteAfter', { sheet: file }); }, nulldata: null, getGridData: function(d) { @@ -1131,7 +1169,7 @@ const sheetmanage = { } } }, - changeSheet: function(index, isPivotInitial, isNewSheet) { + changeSheet: function(index, isPivotInitial, isNewSheet, isCopySheet) { if(isEditMode()){ // alert("非编辑模式下不允许该操作!"); return; @@ -1147,6 +1185,15 @@ 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 }); + } + // 钩子 sheetCopyAfter + if (isCopySheet) { + method.createHookFunction('sheetCopyAfter', { sheet: file }); + } // 钩子函数 method.createHookFunction('sheetActivate', index, isPivotInitial, isNewSheet); @@ -1157,7 +1204,6 @@ const sheetmanage = { _this.storeSheetParamALL(); _this.setCurSheet(index); - let file = Store.luckysheetfile[_this.getSheetIndex(index)] if (!!file.isPivotTable) { Store.luckysheetcurrentisPivotTable = true; @@ -1467,7 +1513,7 @@ const sheetmanage = { return null; }, - changeSheetExec: function(index, isPivotInitial, isNewSheet) { + changeSheetExec: function(index, isPivotInitial, isNewSheet, isCopySheet) { let $sheet = $("#luckysheet-sheets-item" + index); @@ -1476,7 +1522,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();