From 95979ed9ff1810751f66c4d8d1cc7da6ce2a9e6a Mon Sep 17 00:00:00 2001 From: flowerField Date: Sat, 26 Dec 2020 11:22:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0setCellValue=20APi=E4=B8=AD?= =?UTF-8?q?=E9=92=A9=E5=AD=90=E5=87=BD=E6=95=B0=E7=9A=84=E8=A7=A6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/global/api.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/global/api.js b/src/global/api.js index 5efcb6b..9c074fc 100644 --- a/src/global/api.js +++ b/src/global/api.js @@ -2,7 +2,7 @@ import Store from "../store"; import { replaceHtml, getObjType, chatatABC, luckysheetactiveCell } from "../utils/util"; import { getSheetIndex, getluckysheet_select_save, getluckysheetfile } from "../methods/get"; import locale from "../locale/locale"; - +import method from './method'; import formula from './formula'; import func_methods from "./func_methods"; import tooltip from "./tooltip"; @@ -99,6 +99,12 @@ export function getCellValue(row, column, options = {}) { * @param {Function} options.success 操作结束的回调函数 */ export function setCellValue(row, column, value, options = {}) { + + let curv = Store.flowdata[row][column]; + + // Store old value for hook function + const oldValue = JSON.stringify(curv); + if (!isRealNum(row) || !isRealNum(column)) { return tooltip.info('The row or column parameter is invalid.', ''); } @@ -115,6 +121,12 @@ export function setCellValue(row, column, value, options = {}) { return tooltip.info("The order parameter is invalid.", ""); } + /* cell更新前触发 */ + if (!method.createHookFunction("cellUpdateBefore", row, column, value, isRefresh)) { + /* 如果cellUpdateBefore函数返回false 则不执行后续的更新 */ + return; + } + let data = file.data; if(isRefresh) { data = $.extend(true, [], file.data); @@ -203,6 +215,12 @@ export function setCellValue(row, column, value, options = {}) { } } + /* cell更新后触发 */ + setTimeout(() => { + // Hook function + method.createHookFunction("cellUpdated", row, column, JSON.parse(oldValue), Store.flowdata[row][column], isRefresh); + }, 0); + if(file.index == Store.currentSheetIndex && isRefresh){ jfrefreshgrid(data, [{ "row": [row, row], "column": [column, column] }]);//update data, meanwhile refresh canvas and store data to history }