rapid-spreadjs 1.0.67 → 1.0.68

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