|
|
@@ -97,12 +97,12 @@ export function doEvaluateDynamicDataExpression(expressions: string, context: ID
|
|
|
if (preSerialize.prased)
|
|
|
return preSerialize.value;
|
|
|
let type = 'string';
|
|
|
- let dat = '';
|
|
|
+ let dat = key;
|
|
|
const sp = key.split('#');
|
|
|
if (sp.length > 1) {
|
|
|
type = sp[0];
|
|
|
dat = sp[1];
|
|
|
- }
|
|
|
+ }
|
|
|
switch (type) {
|
|
|
case 'string': return dat as string;
|
|
|
case 'number': return Number(dat);
|
|
|
@@ -240,15 +240,9 @@ export function doEvaluateDynamicDataExpression(expressions: string, context: ID
|
|
|
return result;
|
|
|
}
|
|
|
/**
|
|
|
- * 评估动态比较表达式
|
|
|
- *
|
|
|
- * 格式:
|
|
|
- * 取值:符号:值
|
|
|
- *
|
|
|
- * @param expression
|
|
|
- * @returns
|
|
|
+ * 评估单条动态比较表达式(格式: 取值:符号:值)
|
|
|
*/
|
|
|
-export function doEvaluateDynamicCompareExpression(expression: string, context: IDynamicCompareExpressionContext) : boolean {
|
|
|
+function evaluateSingleCompareExpression(expression: string, context: IDynamicCompareExpressionContext): boolean {
|
|
|
const arr = expression.split(':');
|
|
|
if (arr.length !== 3)
|
|
|
return false;
|
|
|
@@ -256,37 +250,55 @@ export function doEvaluateDynamicCompareExpression(expression: string, context:
|
|
|
const symbol = arr[1];
|
|
|
const value = doEvaluateDynamicDataExpression(arr[2], context);
|
|
|
const data = doEvaluateDynamicDataExpression(key, context);
|
|
|
- const negate = symbol.charAt(0) === 'n';
|
|
|
+ const negate = symbol.charAt(0) === '!';
|
|
|
switch (symbol) {
|
|
|
- case 'nempty':
|
|
|
+ case '!empty':
|
|
|
case 'empty': {
|
|
|
let compareValue = data === undefined || data === null || data === '';
|
|
|
if (Array.isArray(data))
|
|
|
compareValue = data.length === 0;
|
|
|
return negate ? !compareValue : compareValue;
|
|
|
}
|
|
|
- case 'eq':
|
|
|
- case 'neq': {
|
|
|
- let compareValue = data == value;
|
|
|
+ case '==':
|
|
|
+ case '!==': {
|
|
|
+ const compareValue = data == value;
|
|
|
return negate ? !compareValue : compareValue;
|
|
|
}
|
|
|
- case 'gt':
|
|
|
- case 'gte':
|
|
|
- case 'lt':
|
|
|
- case 'lte': {
|
|
|
+ case '>':
|
|
|
+ case '>=':
|
|
|
+ case '<':
|
|
|
+ case '<=': {
|
|
|
let compareValue = false;
|
|
|
- if (symbol.startsWith('g'))
|
|
|
- compareValue = data > value;
|
|
|
- if (symbol.endsWith('e'))
|
|
|
- compareValue = data >= value;
|
|
|
- if (symbol.startsWith('l'))
|
|
|
- compareValue = data < value;
|
|
|
- if (symbol.startsWith('l'))
|
|
|
- compareValue = data <= value;
|
|
|
+ if (symbol.startsWith('>'))
|
|
|
+ compareValue = symbol === '>=' ? data >= value : data > value;
|
|
|
+ if (symbol.startsWith('<'))
|
|
|
+ compareValue = symbol === '<=' ? data <= value : data < value;
|
|
|
return negate ? !compareValue : compareValue;
|
|
|
}
|
|
|
default: {
|
|
|
throw new Error('doEvaluateDynamicCompareExpression: unknown symbol: ' + symbol);
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 评估动态比较表达式
|
|
|
+ *
|
|
|
+ * 格式:
|
|
|
+ * 取值:符号:值
|
|
|
+ * 多个表达式用逻辑 && || 分隔:&& 优先于 ||,按顺序求值
|
|
|
+ * 例如: key1:empty: && key2:eq:1 || key3:neq:0
|
|
|
+ *
|
|
|
+ * @param expression
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+export function doEvaluateDynamicCompareExpression(expression: string, context: IDynamicCompareExpressionContext): boolean {
|
|
|
+ const trimmed = expression.trim();
|
|
|
+ if (!trimmed) return false;
|
|
|
+
|
|
|
+ const orParts = trimmed.split(/\s*\|\|\s*/).map((s) => s.trim()).filter(Boolean);
|
|
|
+ return orParts.some((orPart) => {
|
|
|
+ const andParts = orPart.split(/\s*&&\s*/).map((s) => s.trim()).filter(Boolean);
|
|
|
+ return andParts.every((andPart) => evaluateSingleCompareExpression(andPart, context));
|
|
|
+ });
|
|
|
}
|