Commit 57589133 authored by rockyl's avatar rockyl

完善比较节点

parent 39a1173e
...@@ -23,9 +23,21 @@ ...@@ -23,9 +23,21 @@
">", ">",
">=", ">=",
"<", "<",
"<=" "<=",
"exist"
], ],
"default": "==" "default": "=="
},
"type": {
"alias": "判断类型",
"type": "enum",
"enum": [
"unset",
"string",
"number",
"boolean"
],
"default": "unset"
} }
}, },
"output": [ "output": [
...@@ -33,7 +45,7 @@ ...@@ -33,7 +45,7 @@
"false" "false"
], ],
"id": "compare", "id": "compare",
"script": "var leftValue = typeof props.left === 'string' ? '\"' + props.left + '\"' : props.left;\nvar rightValue = typeof props.right === 'string' ? '\"' + props.right + '\"' : props.right;\nvar operator = props.operator;\nvar func = new Function('return ' + leftValue + operator + rightValue);\nvar result = func();\nnext(result ? 'true' : 'false');\n", "script": "var leftValue = engine.findVariable('left', args, props);\nvar rightValue = engine.findVariable('right', args, props);\nvar operator = engine.findVariable('operator', args, props);\nvar result;\nif (operator === 'exist') {\n result = !!leftValue;\n}\nelse {\n switch (props.type) {\n case 'string':\n leftValue = '\"' + leftValue + '\"';\n rightValue = '\"' + rightValue + '\"';\n break;\n case 'number':\n leftValue = typeof leftValue === 'number' ? leftValue : parseFloat(leftValue);\n rightValue = typeof rightValue === 'number' ? rightValue : parseFloat(rightValue);\n break;\n case 'boolean':\n leftValue = typeof leftValue === 'boolean' ? leftValue :\n (leftValue === 'true' ? true :\n (leftValue === 'false' ? false : !!leftValue));\n rightValue = typeof rightValue === 'boolean' ? rightValue :\n (rightValue === 'true' ? true :\n (rightValue === 'false' ? false : !!rightValue));\n break;\n }\n var func = new Function('return ' + leftValue + operator + rightValue);\n result = func();\n}\nnext(result ? 'true' : 'false');\n",
"group": "base", "group": "base",
"type": "builtin" "type": "builtin"
} }
{ {
"name": "发送事件", "name": "派发事件",
"desc": "发送事件", "desc": "派发事件",
"props": { "props": {
"eventName": { "eventName": {
"type": "string", "type": "string",
......
...@@ -2,9 +2,37 @@ ...@@ -2,9 +2,37 @@
* Created by rockyl on 2019-11-16. * Created by rockyl on 2019-11-16.
*/ */
let leftValue = typeof props.left === 'string' ? '"' + props.left + '"' : props.left; let leftValue = engine.findVariable('left', args, props);
let rightValue = typeof props.right === 'string' ? '"' + props.right + '"' : props.right; let rightValue = engine.findVariable('right', args, props);
let operator = props.operator; let operator = engine.findVariable('operator', args, props);
let func = new Function('return ' + leftValue + operator + rightValue);
let result = func(); let result;
if (operator === 'exist') {
result = !!leftValue;
} else {
switch (props.type) {
case 'string':
leftValue = '"' + leftValue + '"';
rightValue = '"' + rightValue + '"';
break;
case 'number':
leftValue = typeof leftValue === 'number' ? leftValue : parseFloat(leftValue);
rightValue = typeof rightValue === 'number' ? rightValue : parseFloat(rightValue);
break;
case 'boolean':
leftValue = typeof leftValue === 'boolean' ? leftValue :
(leftValue === 'true' ? true :
(leftValue === 'false' ? false : !!leftValue));
rightValue = typeof rightValue === 'boolean' ? rightValue :
(rightValue === 'true' ? true :
(rightValue === 'false' ? false : !!rightValue));
break;
}
let func = new Function('return ' + leftValue + operator + rightValue);
result = func();
}
next(result ? 'true' : 'false'); next(result ? 'true' : 'false');
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
"name": "比较", "name": "比较",
"desc": "比较两个值", "desc": "比较两个值",
"props": { "props": {
"left": {"alias": "左值","type": "dynamic", "default": ""}, "left": {"alias": "左值", "type": "dynamic", "default": ""},
"right": {"alias": "右值","type": "dynamic", "default": ""}, "right": {"alias": "右值", "type": "dynamic", "default": ""},
"operator": {"alias": "操作符","type": "enum", "operator": {"alias": "操作符","type": "enum",
"enum": ["==","!=","===","!==",">",">=","<","<="], "enum": ["==","!=","===","!==",">",">=","<","<=","exist"],
"default": "=="} "default": "=="},
"type": {"alias": "判断类型", "type": "enum",
"enum": ["unset","string","number","boolean"],
"default": "unset"}
}, },
"output": [ "output": [
"true", "false" "true", "false"
......
...@@ -9,4 +9,5 @@ const useCapture = engine.findVariable('useCapture', args, props); ...@@ -9,4 +9,5 @@ const useCapture = engine.findVariable('useCapture', args, props);
if(eventName){ if(eventName){
engine.globalEvent.dispatchEvent(eventName, data, useCapture); engine.globalEvent.dispatchEvent(eventName, data, useCapture);
} }
next('success', args); next('success', args);
{ {
"name": "发送事件", "name": "派发事件",
"desc": "发送事件", "desc": "派发事件",
"props": { "props": {
"eventName": { "eventName": {
"type": "string", "type": "string",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment