| | |
| | | let sourceInsItemId = null; |
| | | // 当前消息版本。Worker 单线程串行处理消息,供递归公式计算完成后回传给主线程。 |
| | | let currentRevision = null; |
| | | // 本次输入是否往单元格写入过计算结果。链式公式只有最外层会回传保存, |
| | | // 用它在最外层判断计算的中间值是否也需要落库。 |
| | | let hasComputedWrite = false; |
| | | |
| | | /** |
| | | * 生成模板结构签名 |
| | |
| | | comparisonList = JSON.parse(JSON.stringify(data.comparisonList)); |
| | | currentSample = JSON.parse(JSON.stringify(data.currentSample)); |
| | | PROJECT = data.PROJECT; |
| | | // 执行计算方法 |
| | | // 执行计算方法。每次输入重置标记,由本次调用栈的最外层决定是否回传保存 |
| | | hasComputedWrite = false; |
| | | changeInput("", code); |
| | | }; |
| | | |
| | |
| | | return !(typeof r === "number" && isNaN(r)); |
| | | } |
| | | |
| | | function changeInput(m, code) { |
| | | function changeInput(m, code, isComputed) { |
| | | let str = code.split("-"); |
| | | let r = str[1]; //当前行 |
| | | let c = str[2]; //当前列 |
| | |
| | | a[b].v.v = comResult; |
| | | console.log("error---", error); |
| | | } |
| | | hasComputedWrite = true; |
| | | break; |
| | | } |
| | | } |
| | |
| | | // 如果此计算结果所属单元格,同时也是另一个excel函数的参数,那么就需要递归进行计算 |
| | | // 只有算出有效结果才继续向下游公式传递,避免把空值/NaN 传染给其它单元格 |
| | | if (isValidComputedResult(comResult)) { |
| | | changeInput(comResult, `${id}-${item.r}-${item.c}-${pId}`); //改变最终值 |
| | | // 标记为计算层:它可能是下游公式的参数(isSave 会被置成 false),但自身也是结果, |
| | | // 保存交给最外层统一回传,中间值不会被漏掉,也不会每一级都发一次保存请求 |
| | | changeInput(comResult, `${id}-${item.r}-${item.c}-${pId}`, true); //改变最终值 |
| | | } |
| | | currentInsItemId = item.i; |
| | | } catch (error) { |
| | |
| | | } |
| | | } |
| | | }); |
| | | if (index === -1 || (inputType === undefined && isSave === "true")) { |
| | | if ( |
| | | !isComputed && |
| | | (hasComputedWrite || index === -1 || (inputType === undefined && isSave === "true")) |
| | | ) { |
| | | // 赋值传递到主线程的数据,method:saveInsContext表示此消息需要保存数据 |
| | | result = { |
| | | method: "saveInsContext", |