@steedos-labs/plugin-workflow 3.0.0-beta.27 → 3.0.0-beta.28

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.
@@ -16,6 +16,7 @@ const pushManager = require('./push_manager');
16
16
  const { t } = require('@steedos/i18n')
17
17
  const moment = require('moment')
18
18
  const { getObject } = require('@steedos/objectql');
19
+ const { evaluate } = require('amis-formula');
19
20
 
20
21
  const UUFlowManager = {};
21
22
 
@@ -556,6 +557,47 @@ UUFlowManager.isFlowSpaceMatched = function (flow, space_id) {
556
557
  }
557
558
  };
558
559
 
560
+ const isAmisFormula = (formula) => {
561
+ // 有${}包裹的表达式就识别为amis公式
562
+ return /\$\{.+\}/.test(formula);
563
+ };
564
+
565
+ const runAmisFormula = function (formula, data) {
566
+ try {
567
+ const amisFormulaValue = evaluate(
568
+ formula,
569
+ Object.assign({}, data),
570
+ {},
571
+ );
572
+ if (formula === amisFormulaValue) {
573
+ throw new Error(
574
+ `Workflow Condition Step Amis formula "${formula}" evaluate failed "Function is not defined".`,
575
+ );
576
+ } else {
577
+ return amisFormulaValue;
578
+ }
579
+ } catch (e) {
580
+ throw new Error(
581
+ `Catch an error "${e.message}" while evaluate condition step amis formula "${formula}".`,
582
+ );
583
+ }
584
+ }
585
+
586
+ /**
587
+ * Calculate condition for conditional step
588
+ * @param {Object} values - Form values
589
+ * @param {String} condition_str - Condition string
590
+ * @returns {Boolean} Condition result
591
+ */
592
+ UUFlowManager.calculateConditionWithAmis = function (values, condition_str) {
593
+ try {
594
+ return runAmisFormula(condition_str, values);
595
+ } catch (error) {
596
+ console.error(error.stack);
597
+ return false;
598
+ }
599
+ };
600
+
559
601
  /**
560
602
  * Calculate condition for conditional step
561
603
  * @param {Object} values - Form values
@@ -829,10 +871,17 @@ UUFlowManager.getNextSteps = async function (instance, flow, step, judge, values
829
871
 
830
872
  for (const step_line of step.lines) {
831
873
  if (step_line.state === "submitted") {
832
- const step_line_condition = step_line.condition.replace(reg, (vowel) => {
833
- return prefix + vowel.replace(/\{\s*/, "[\"").replace(/\s*\}/, "\"]").replace(/\s*\.\s*/g, "\"][\"");
834
- });
835
- const allow = UUFlowManager.calculateCondition(__values, step_line_condition);
874
+ let step_line_condition = step_line.condition;
875
+ let allow = false;
876
+ if (isAmisFormula(step_line_condition)) {
877
+ allow = UUFlowManager.calculateConditionWithAmis(__values, step_line_condition);
878
+ }
879
+ else {
880
+ step_line_condition = step_line.condition.replace(reg, (vowel) => {
881
+ return prefix + vowel.replace(/\{\s*/, "[\"").replace(/\s*\}/, "\"]").replace(/\s*\.\s*/g, "\"][\"");
882
+ });
883
+ allow = UUFlowManager.calculateCondition(__values, step_line_condition);
884
+ }
836
885
  if (allow) {
837
886
  nextSteps.push(step_line.to_step);
838
887
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos-labs/plugin-workflow",
3
- "version": "3.0.0-beta.27",
3
+ "version": "3.0.0-beta.28",
4
4
  "main": "package.service.js",
5
5
  "license": "MIT",
6
6
  "scripts": {