From 627183f571976335433798667ba26657de0d8dbc Mon Sep 17 00:00:00 2001 From: zhangsimu Date: Thu, 25 Mar 2021 08:29:53 +0800 Subject: [PATCH] feat(controllers/rowcolumnoperation.j): youjian add he delete hook hanshu,api charu xiangxiacharu he xiangyoucharu --- src/controllers/rowColumnOperation.js | 20 ++++++- src/global/api.js | 79 ++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 4 deletions(-) diff --git a/src/controllers/rowColumnOperation.js b/src/controllers/rowColumnOperation.js index bd5768d..0c5d654 100644 --- a/src/controllers/rowColumnOperation.js +++ b/src/controllers/rowColumnOperation.js @@ -4,6 +4,7 @@ import luckysheetPostil from './postil'; import imageCtrl from './imageCtrl'; import menuButton from './menuButton'; import server from './server'; +import method from '../global/method'; import { selectHightlightShow, luckysheet_count_show,selectHelpboxFill } from './select'; import { getObjType, @@ -1103,7 +1104,10 @@ export function rowColumnOperationInitial(){ } let st_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][0]; - luckysheetextendtable(Store.luckysheetRightHeadClickIs, st_index, value, "lefttop"); + if(!method.createHookFunction("rowInsertBefore", st_index, value, "lefttop")){ + return; + } + luckysheetextendtable(Store.luckysheetRightHeadClickIs, st_index, value, "lefttop"); }); @@ -1117,6 +1121,9 @@ export function rowColumnOperationInitial(){ } let st_index = Store.luckysheet_select_save[0].row[0]; + if(!method.createHookFunction("rowInsertBefore", st_index, 1, "lefttop")){ + return; + } luckysheetextendtable('row', st_index, 1, "lefttop"); @@ -1307,6 +1314,9 @@ export function rowColumnOperationInitial(){ } let st_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][1]; + if(!method.createHookFunction("rowInsertBefore", st_index, value, "rightbottom")){ + return; + } luckysheetextendtable(Store.luckysheetRightHeadClickIs, st_index, value, "rightbottom"); }); @@ -1453,7 +1463,10 @@ export function rowColumnOperationInitial(){ let st_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][0], ed_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][1]; - luckysheetdeletetable(Store.luckysheetRightHeadClickIs, st_index, ed_index); + if(!method.createHookFunction("rowDeleteBefore", st_index, ed_index)){ + return; + } + luckysheetdeletetable(Store.luckysheetRightHeadClickIs, st_index, ed_index); }); $("#luckysheet-delRows").click(function (event) { $("#luckysheet-rightclick-menu").hide(); @@ -1483,6 +1496,9 @@ export function rowColumnOperationInitial(){ let st_index = Store.luckysheet_select_save[0].row[0], ed_index = Store.luckysheet_select_save[0].row[1]; + if(!method.createHookFunction("rowDeleteBefore", st_index, ed_index)){ + return; + } luckysheetdeletetable('row', st_index, ed_index); }) $("#luckysheet-delCols").click(function (event) { diff --git a/src/global/api.js b/src/global/api.js index 3d586b6..e9c9c39 100644 --- a/src/global/api.js +++ b/src/global/api.js @@ -1082,7 +1082,62 @@ export function insertRowOrColumn(type, index = 0, options = {}) { success(); } } +/** + * 在第index行或列的位置,插入number行或列 + * @param {String} type 插入行或列 row-行 column-列 + * @param {Number} index 在第几行插入空白行,从0开始 + * @param {Object} options 可选参数 + * @param {Number} options.number 插入的空白行数;默认为 1 + * @param {Number} options.order 工作表索引;默认值为当前工作表索引 + * @param {Function} options.success 操作结束的回调函数 + */ +export function insertRowBottomOrColumnRight(type, index = 0, options = {}) { + if(!isRealNum(index)){ + return tooltip.info('The index parameter is invalid.', ''); + } + + let curSheetOrder = getSheetIndex(Store.currentSheetIndex); + let { + number = 1, + order = curSheetOrder, + success + } = {...options} + let _locale = locale(); + let locale_info = _locale.info; + if (!isRealNum(number)) { + if(isEditMode()){ + alert(locale_info.tipInputNumber); + } else{ + tooltip.info(locale_info.tipInputNumber, ""); + } + return; + } + + number = parseInt(number); + if (number < 1 || number > 100) { + if(isEditMode()){ + alert(locale_info.tipInputNumberLimit); + } else{ + tooltip.info(locale_info.tipInputNumberLimit, ""); + } + return; + } + + // 默认在行上方增加行,列左侧增加列 + let sheetIndex; + if(order){ + if(Store.luckysheetfile[order]){ + sheetIndex = Store.luckysheetfile[order].index; + } + } + + luckysheetextendtable(type, index, number, "rightbottom", sheetIndex); + + if (success && typeof success === 'function') { + success(); + } +} /** * 在第row行的位置,插入number行空白行 * @param {Number} row 在第几行插入空白行,从0开始 @@ -1094,7 +1149,17 @@ export function insertRowOrColumn(type, index = 0, options = {}) { export function insertRow(row = 0, options = {}) { insertRowOrColumn('row', row, options) } - +/** + * 在第row行的位置,插入number行空白行 + * @param {Number} row 在第几行插入空白行,从0开始 + * @param {Object} options 可选参数 + * @param {Number} options.number 插入的空白行数;默认为 1 + * @param {Number} options.order 工作表索引;默认值为当前工作表索引 + * @param {Function} options.success 操作结束的回调函数 + */ +export function insertRowBottom(row = 0, options = {}) { + insertRowBottomOrColumnRight('row', row, options) +} /** * 在第column列的位置,插入number列空白列 * @param {Number} column 在第几列插入空白列,从0开始 @@ -1106,7 +1171,17 @@ export function insertRow(row = 0, options = {}) { export function insertColumn(column = 0, options = {}) { insertRowOrColumn('column', column, options) } - +/** + * 在第column列的位置,插入number列空白列 + * @param {Number} column 在第几列插入空白列,从0开始 + * @param {Object} options 可选参数 + * @param {Number} options.number 插入的空白列数;默认为 1 + * @param {Number} options.order 工作表索引;默认值为当前工作表索引 + * @param {Function} options.success 操作结束的回调函数 + */ +export function insertColumnRight(column = 0, options = {}) { + insertRowBottomOrColumnRight('column', column, options) +} /** * 删除指定的行或列。删除行列之后,行列的序号并不会变化,下面的行(右侧的列)会补充到上(左)面,注意观察数据是否被正确删除即可。 * @param {String} type 删除行或列 row-行 column-列