...
|
...
|
@@ -8,6 +8,8 @@ |
8
|
8
|
import { useJsonParse } from '/@/hooks/business/useJsonParse';
|
9
|
9
|
import { useMessage } from '/@/hooks/web/useMessage';
|
10
|
10
|
import { AttributeConfiguration } from '../AttributeConfiguration';
|
|
11
|
+ import { testScript } from '/@/api/ruleChainDesigner';
|
|
12
|
+ import { isString } from '/@/utils/is';
|
11
|
13
|
|
12
|
14
|
interface Value {
|
13
|
15
|
msg: Recordable;
|
...
|
...
|
@@ -24,6 +26,7 @@ |
24
|
26
|
{
|
25
|
27
|
javaScriptEditorProps: () => ({
|
26
|
28
|
functionName: 'Filter',
|
|
29
|
+ scriptType: 'filter',
|
27
|
30
|
paramsName: ['msg', 'metadata', 'msgType'],
|
28
|
31
|
}),
|
29
|
32
|
}
|
...
|
...
|
@@ -74,18 +77,34 @@ |
74
|
77
|
const msgType = unref(messageType);
|
75
|
78
|
const javascriptFunction = unref(scriptContent);
|
76
|
79
|
|
77
|
|
- return { msg, msgType, metadata: toRaw(unref(metadata)), javascriptFunction };
|
|
80
|
+ return {
|
|
81
|
+ msg,
|
|
82
|
+ msgType,
|
|
83
|
+ metadata: toRaw(unref(metadata)),
|
|
84
|
+ javascriptFunction,
|
|
85
|
+ };
|
78
|
86
|
};
|
79
|
87
|
|
80
|
|
- function executeTestScript() {
|
|
88
|
+ async function executeTestScript() {
|
81
|
89
|
try {
|
82
|
90
|
const { javaScriptEditorProps } = props;
|
83
|
|
- const { paramsName } = javaScriptEditorProps;
|
84
|
|
- const fn = new Function(...(paramsName || [])!, unref(scriptContent));
|
85
|
|
- const value = getValue();
|
86
|
|
- const executeParams = paramsName!.map((key) => value[key]);
|
|
91
|
+ const { paramsName, scriptType } = javaScriptEditorProps;
|
|
92
|
+ const { msg, msgType, metadata } = getValue();
|
|
93
|
+
|
|
94
|
+ const { output, error } = await testScript({
|
|
95
|
+ argNames: paramsName,
|
|
96
|
+ scriptType,
|
|
97
|
+ script: unref(scriptContent),
|
|
98
|
+ msg: isString(msg) ? msg : JSON.stringify(msg),
|
|
99
|
+ metadata,
|
|
100
|
+ msgType,
|
|
101
|
+ });
|
|
102
|
+
|
|
103
|
+ if (error) {
|
|
104
|
+ createMessage.error(error);
|
|
105
|
+ }
|
87
|
106
|
|
88
|
|
- return fn(...executeParams);
|
|
107
|
+ return output;
|
89
|
108
|
} catch (error) {
|
90
|
109
|
return error;
|
91
|
110
|
}
|
...
|
...
|
@@ -96,7 +115,7 @@ |
96
|
115
|
|
97
|
116
|
flag && emit('test', getValue());
|
98
|
117
|
|
99
|
|
- const result = executeTestScript();
|
|
118
|
+ const result = await executeTestScript();
|
100
|
119
|
|
101
|
120
|
outputContent.value = result;
|
102
|
121
|
};
|
...
|
...
|
|