rapid-spreadjs 1.0.67 → 1.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +79 -19
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +79 -19
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -19485,15 +19485,34 @@ const FormulaUtils = {
|
|
|
19485
19485
|
repeatable: false,
|
|
19486
19486
|
optional: false,
|
|
19487
19487
|
},
|
|
19488
|
+
{
|
|
19489
|
+
name: '是否返回相反的结果(传数字的1或0,0:满足条件的结果、1:相反的结果),默认为:0',
|
|
19490
|
+
repeatable: false,
|
|
19491
|
+
optional: false,
|
|
19492
|
+
},
|
|
19488
19493
|
],
|
|
19489
19494
|
funCallback: (spread, sheet, retData) => {
|
|
19490
|
-
|
|
19495
|
+
// 如果传递的参数小于5个,则返回空字符串
|
|
19496
|
+
// 本来有6个参数,最后一个参数可以不传,默认为:0
|
|
19491
19497
|
if (retData.allCellValsEw.length < 5) {
|
|
19492
|
-
return '';
|
|
19498
|
+
return '/';
|
|
19493
19499
|
}
|
|
19494
|
-
let array1 = retData.allCellValsEw[0], array2 = retData.allCellValsEw[1], operator = retData.allCellValsEw[2], value = retData.allCellValsEw[3], delimiter = retData.allCellValsEw[4];
|
|
19500
|
+
let array1 = retData.allCellValsEw[0], array2 = retData.allCellValsEw[1], operator = retData.allCellValsEw[2], value = retData.allCellValsEw[3], delimiter = retData.allCellValsEw[4], isOpposite = retData.allCellValsEw.length == 5 ? 0 : retData.allCellValsEw[5];
|
|
19495
19501
|
try {
|
|
19496
|
-
//
|
|
19502
|
+
// 处理array1和array2的默认值
|
|
19503
|
+
if (array1 == null || array1 == undefined || (typeof array1 == 'string' && array1.trim().length == 0)) {
|
|
19504
|
+
array1 = [];
|
|
19505
|
+
}
|
|
19506
|
+
if (array2 == null || array2 == undefined || (typeof array2 == 'string' && array2.trim().length == 0)) {
|
|
19507
|
+
array2 = [];
|
|
19508
|
+
}
|
|
19509
|
+
if (typeof array1 == 'string' && array1.trim().length > 0) {
|
|
19510
|
+
array1 = [array1];
|
|
19511
|
+
}
|
|
19512
|
+
if (typeof array2 == 'string' && array2.trim().length > 0) {
|
|
19513
|
+
array2 = [array2];
|
|
19514
|
+
}
|
|
19515
|
+
// 如果operator、value、delimiter、isOpposite为数组,则设置其取第一个值
|
|
19497
19516
|
if (Array.isArray(operator) && operator.length > 0) {
|
|
19498
19517
|
operator = operator[0];
|
|
19499
19518
|
}
|
|
@@ -19503,10 +19522,23 @@ const FormulaUtils = {
|
|
|
19503
19522
|
if (Array.isArray(delimiter) && delimiter.length > 0) {
|
|
19504
19523
|
delimiter = delimiter[0];
|
|
19505
19524
|
}
|
|
19525
|
+
if (Array.isArray(isOpposite) && isOpposite.length > 0) {
|
|
19526
|
+
isOpposite = isOpposite[0];
|
|
19527
|
+
}
|
|
19528
|
+
// 设置isOpposite的默认值
|
|
19529
|
+
if (isOpposite == '1' || isOpposite == '0') {
|
|
19530
|
+
isOpposite = parseInt(isOpposite);
|
|
19531
|
+
}
|
|
19532
|
+
if (isOpposite != 0 && isOpposite != 1) {
|
|
19533
|
+
isOpposite = 0;
|
|
19534
|
+
}
|
|
19535
|
+
// TODO:暂定此情况
|
|
19536
|
+
// 第一个参数是否为单值(array1为一个值的时候,此时array2的所有元素可能需要参与计算,满足要求的就返回array2中的值)
|
|
19537
|
+
const isSingleValue1 = array2.length > array1.length && array1.length == 1;
|
|
19506
19538
|
// 参数基础校验
|
|
19507
19539
|
if (!Array.isArray(array1) ||
|
|
19508
19540
|
!Array.isArray(array2) ||
|
|
19509
|
-
array1.length !== array2.length ||
|
|
19541
|
+
// array1.length !== array2.length ||
|
|
19510
19542
|
typeof operator !== 'string' ||
|
|
19511
19543
|
typeof delimiter !== 'string') {
|
|
19512
19544
|
return '/';
|
|
@@ -19518,36 +19550,61 @@ const FormulaUtils = {
|
|
|
19518
19550
|
}
|
|
19519
19551
|
// 判断第一个数组的元素类型
|
|
19520
19552
|
const isNumericArray = array1.length > 0 && (typeof array1[0] === 'number' || !isNaN(parseFloat(array1[0])));
|
|
19521
|
-
//
|
|
19522
|
-
const validIndices = [];
|
|
19523
|
-
for (let i = 0; i <
|
|
19553
|
+
// 收集满足条件的索引和不满足条件的索引
|
|
19554
|
+
const validIndices = [], oppositeIndices = [];
|
|
19555
|
+
for (let i = 0; i < array2.length; i++) {
|
|
19524
19556
|
let conditionMet = false;
|
|
19525
19557
|
if (isNumericArray) {
|
|
19526
|
-
//
|
|
19527
|
-
const num1 = parseFloat(array1[i]);
|
|
19558
|
+
// 第一个参数为单值的时候,取第一个值
|
|
19559
|
+
const num1 = isSingleValue1 ? parseFloat(array1[0]) : parseFloat(array1[i]);
|
|
19560
|
+
const num2 = parseFloat(array2[i]);
|
|
19528
19561
|
const numValue = parseFloat(value);
|
|
19529
|
-
if (isNaN(num1) || isNaN(numValue)) {
|
|
19562
|
+
if (isNaN(num1) || (isNaN(numValue) && !isSingleValue1)) {
|
|
19530
19563
|
continue; // 跳过非数字元素
|
|
19531
19564
|
}
|
|
19532
19565
|
switch (operator) {
|
|
19533
19566
|
case '>':
|
|
19534
|
-
|
|
19567
|
+
if (isSingleValue1) {
|
|
19568
|
+
conditionMet = num1 > num2;
|
|
19569
|
+
}
|
|
19570
|
+
else {
|
|
19571
|
+
conditionMet = num1 > numValue;
|
|
19572
|
+
}
|
|
19535
19573
|
break;
|
|
19536
19574
|
case '<':
|
|
19537
|
-
|
|
19575
|
+
if (isSingleValue1) {
|
|
19576
|
+
conditionMet = num1 < num2;
|
|
19577
|
+
}
|
|
19578
|
+
else {
|
|
19579
|
+
conditionMet = num1 < numValue;
|
|
19580
|
+
}
|
|
19538
19581
|
break;
|
|
19539
19582
|
case '>=':
|
|
19540
|
-
|
|
19583
|
+
if (isSingleValue1) {
|
|
19584
|
+
conditionMet = num1 >= num2;
|
|
19585
|
+
}
|
|
19586
|
+
else {
|
|
19587
|
+
conditionMet = num1 >= numValue;
|
|
19588
|
+
}
|
|
19541
19589
|
break;
|
|
19542
19590
|
case '<=':
|
|
19543
|
-
|
|
19591
|
+
if (isSingleValue1) {
|
|
19592
|
+
conditionMet = num1 <= num2;
|
|
19593
|
+
}
|
|
19594
|
+
else {
|
|
19595
|
+
conditionMet = num1 <= numValue;
|
|
19596
|
+
}
|
|
19544
19597
|
break;
|
|
19545
19598
|
case '=':
|
|
19546
|
-
|
|
19599
|
+
if (isSingleValue1) {
|
|
19600
|
+
conditionMet = num1 === num2;
|
|
19601
|
+
}
|
|
19602
|
+
else {
|
|
19603
|
+
conditionMet = num1 === numValue;
|
|
19604
|
+
}
|
|
19547
19605
|
break;
|
|
19548
19606
|
case '±':
|
|
19549
|
-
|
|
19550
|
-
conditionMet = num1 >= -numValue && num1 <= numValue;
|
|
19607
|
+
conditionMet = num2 >= num1 - numValue && num2 <= num1 + numValue;
|
|
19551
19608
|
break;
|
|
19552
19609
|
}
|
|
19553
19610
|
}
|
|
@@ -19558,9 +19615,12 @@ const FormulaUtils = {
|
|
|
19558
19615
|
if (conditionMet) {
|
|
19559
19616
|
validIndices.push(i);
|
|
19560
19617
|
}
|
|
19618
|
+
else {
|
|
19619
|
+
oppositeIndices.push(i);
|
|
19620
|
+
}
|
|
19561
19621
|
}
|
|
19562
19622
|
// 从第二个数组中获取对应索引的值
|
|
19563
|
-
const resultValues = validIndices
|
|
19623
|
+
const resultValues = (isOpposite == 0 ? validIndices : oppositeIndices)
|
|
19564
19624
|
.map((index) => {
|
|
19565
19625
|
// 确保索引在第二个数组范围内
|
|
19566
19626
|
if (index >= 0 && index < array2.length) {
|