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.esm.js
CHANGED
|
@@ -19463,15 +19463,34 @@ const FormulaUtils = {
|
|
|
19463
19463
|
repeatable: false,
|
|
19464
19464
|
optional: false,
|
|
19465
19465
|
},
|
|
19466
|
+
{
|
|
19467
|
+
name: '是否返回相反的结果(传数字的1或0,0:满足条件的结果、1:相反的结果),默认为:0',
|
|
19468
|
+
repeatable: false,
|
|
19469
|
+
optional: false,
|
|
19470
|
+
},
|
|
19466
19471
|
],
|
|
19467
19472
|
funCallback: (spread, sheet, retData) => {
|
|
19468
|
-
|
|
19473
|
+
// 如果传递的参数小于5个,则返回空字符串
|
|
19474
|
+
// 本来有6个参数,最后一个参数可以不传,默认为:0
|
|
19469
19475
|
if (retData.allCellValsEw.length < 5) {
|
|
19470
|
-
return '';
|
|
19476
|
+
return '/';
|
|
19471
19477
|
}
|
|
19472
|
-
let array1 = retData.allCellValsEw[0], array2 = retData.allCellValsEw[1], operator = retData.allCellValsEw[2], value = retData.allCellValsEw[3], delimiter = retData.allCellValsEw[4];
|
|
19478
|
+
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];
|
|
19473
19479
|
try {
|
|
19474
|
-
//
|
|
19480
|
+
// 处理array1和array2的默认值
|
|
19481
|
+
if (array1 == null || array1 == undefined || (typeof array1 == 'string' && array1.trim().length == 0)) {
|
|
19482
|
+
array1 = [];
|
|
19483
|
+
}
|
|
19484
|
+
if (array2 == null || array2 == undefined || (typeof array2 == 'string' && array2.trim().length == 0)) {
|
|
19485
|
+
array2 = [];
|
|
19486
|
+
}
|
|
19487
|
+
if (typeof array1 == 'string' && array1.trim().length > 0) {
|
|
19488
|
+
array1 = [array1];
|
|
19489
|
+
}
|
|
19490
|
+
if (typeof array2 == 'string' && array2.trim().length > 0) {
|
|
19491
|
+
array2 = [array2];
|
|
19492
|
+
}
|
|
19493
|
+
// 如果operator、value、delimiter、isOpposite为数组,则设置其取第一个值
|
|
19475
19494
|
if (Array.isArray(operator) && operator.length > 0) {
|
|
19476
19495
|
operator = operator[0];
|
|
19477
19496
|
}
|
|
@@ -19481,10 +19500,23 @@ const FormulaUtils = {
|
|
|
19481
19500
|
if (Array.isArray(delimiter) && delimiter.length > 0) {
|
|
19482
19501
|
delimiter = delimiter[0];
|
|
19483
19502
|
}
|
|
19503
|
+
if (Array.isArray(isOpposite) && isOpposite.length > 0) {
|
|
19504
|
+
isOpposite = isOpposite[0];
|
|
19505
|
+
}
|
|
19506
|
+
// 设置isOpposite的默认值
|
|
19507
|
+
if (isOpposite == '1' || isOpposite == '0') {
|
|
19508
|
+
isOpposite = parseInt(isOpposite);
|
|
19509
|
+
}
|
|
19510
|
+
if (isOpposite != 0 && isOpposite != 1) {
|
|
19511
|
+
isOpposite = 0;
|
|
19512
|
+
}
|
|
19513
|
+
// TODO:暂定此情况
|
|
19514
|
+
// 第一个参数是否为单值(array1为一个值的时候,此时array2的所有元素可能需要参与计算,满足要求的就返回array2中的值)
|
|
19515
|
+
const isSingleValue1 = array2.length > array1.length && array1.length == 1;
|
|
19484
19516
|
// 参数基础校验
|
|
19485
19517
|
if (!Array.isArray(array1) ||
|
|
19486
19518
|
!Array.isArray(array2) ||
|
|
19487
|
-
array1.length !== array2.length ||
|
|
19519
|
+
// array1.length !== array2.length ||
|
|
19488
19520
|
typeof operator !== 'string' ||
|
|
19489
19521
|
typeof delimiter !== 'string') {
|
|
19490
19522
|
return '/';
|
|
@@ -19496,36 +19528,61 @@ const FormulaUtils = {
|
|
|
19496
19528
|
}
|
|
19497
19529
|
// 判断第一个数组的元素类型
|
|
19498
19530
|
const isNumericArray = array1.length > 0 && (typeof array1[0] === 'number' || !isNaN(parseFloat(array1[0])));
|
|
19499
|
-
//
|
|
19500
|
-
const validIndices = [];
|
|
19501
|
-
for (let i = 0; i <
|
|
19531
|
+
// 收集满足条件的索引和不满足条件的索引
|
|
19532
|
+
const validIndices = [], oppositeIndices = [];
|
|
19533
|
+
for (let i = 0; i < array2.length; i++) {
|
|
19502
19534
|
let conditionMet = false;
|
|
19503
19535
|
if (isNumericArray) {
|
|
19504
|
-
//
|
|
19505
|
-
const num1 = parseFloat(array1[i]);
|
|
19536
|
+
// 第一个参数为单值的时候,取第一个值
|
|
19537
|
+
const num1 = isSingleValue1 ? parseFloat(array1[0]) : parseFloat(array1[i]);
|
|
19538
|
+
const num2 = parseFloat(array2[i]);
|
|
19506
19539
|
const numValue = parseFloat(value);
|
|
19507
|
-
if (isNaN(num1) || isNaN(numValue)) {
|
|
19540
|
+
if (isNaN(num1) || (isNaN(numValue) && !isSingleValue1)) {
|
|
19508
19541
|
continue; // 跳过非数字元素
|
|
19509
19542
|
}
|
|
19510
19543
|
switch (operator) {
|
|
19511
19544
|
case '>':
|
|
19512
|
-
|
|
19545
|
+
if (isSingleValue1) {
|
|
19546
|
+
conditionMet = num1 > num2;
|
|
19547
|
+
}
|
|
19548
|
+
else {
|
|
19549
|
+
conditionMet = num1 > numValue;
|
|
19550
|
+
}
|
|
19513
19551
|
break;
|
|
19514
19552
|
case '<':
|
|
19515
|
-
|
|
19553
|
+
if (isSingleValue1) {
|
|
19554
|
+
conditionMet = num1 < num2;
|
|
19555
|
+
}
|
|
19556
|
+
else {
|
|
19557
|
+
conditionMet = num1 < numValue;
|
|
19558
|
+
}
|
|
19516
19559
|
break;
|
|
19517
19560
|
case '>=':
|
|
19518
|
-
|
|
19561
|
+
if (isSingleValue1) {
|
|
19562
|
+
conditionMet = num1 >= num2;
|
|
19563
|
+
}
|
|
19564
|
+
else {
|
|
19565
|
+
conditionMet = num1 >= numValue;
|
|
19566
|
+
}
|
|
19519
19567
|
break;
|
|
19520
19568
|
case '<=':
|
|
19521
|
-
|
|
19569
|
+
if (isSingleValue1) {
|
|
19570
|
+
conditionMet = num1 <= num2;
|
|
19571
|
+
}
|
|
19572
|
+
else {
|
|
19573
|
+
conditionMet = num1 <= numValue;
|
|
19574
|
+
}
|
|
19522
19575
|
break;
|
|
19523
19576
|
case '=':
|
|
19524
|
-
|
|
19577
|
+
if (isSingleValue1) {
|
|
19578
|
+
conditionMet = num1 === num2;
|
|
19579
|
+
}
|
|
19580
|
+
else {
|
|
19581
|
+
conditionMet = num1 === numValue;
|
|
19582
|
+
}
|
|
19525
19583
|
break;
|
|
19526
19584
|
case '±':
|
|
19527
|
-
|
|
19528
|
-
conditionMet = num1 >= -numValue && num1 <= numValue;
|
|
19585
|
+
conditionMet = num2 >= num1 - numValue && num2 <= num1 + numValue;
|
|
19529
19586
|
break;
|
|
19530
19587
|
}
|
|
19531
19588
|
}
|
|
@@ -19536,9 +19593,12 @@ const FormulaUtils = {
|
|
|
19536
19593
|
if (conditionMet) {
|
|
19537
19594
|
validIndices.push(i);
|
|
19538
19595
|
}
|
|
19596
|
+
else {
|
|
19597
|
+
oppositeIndices.push(i);
|
|
19598
|
+
}
|
|
19539
19599
|
}
|
|
19540
19600
|
// 从第二个数组中获取对应索引的值
|
|
19541
|
-
const resultValues = validIndices
|
|
19601
|
+
const resultValues = (isOpposite == 0 ? validIndices : oppositeIndices)
|
|
19542
19602
|
.map((index) => {
|
|
19543
19603
|
// 确保索引在第二个数组范围内
|
|
19544
19604
|
if (index >= 0 && index < array2.length) {
|