Commit 3aa7d25f688c5746e7ab61f89c47b703924ba7ff
1 parent
dda9c7ca
fix: DEFECT-1660 修复规则链点击测试时需要调用后端接口
Showing
9 changed files
with
37 additions
and
8 deletions
... | ... | @@ -60,6 +60,7 @@ export const formSchemas: FormSchema[] = [ |
60 | 60 | componentProps: { |
61 | 61 | javaScriptEditorProps: { |
62 | 62 | functionName: 'Generate', |
63 | + scriptType: 'generate', | |
63 | 64 | paramsName: ['prevMsg', 'prevMetadata', 'prevMsgType'], |
64 | 65 | }, |
65 | 66 | buttonName: 'Test generator function', | ... | ... |
... | ... | @@ -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 | }; | ... | ... |
... | ... | @@ -11,11 +11,13 @@ |
11 | 11 | value?: string; |
12 | 12 | buttonName?: string; |
13 | 13 | javaScriptEditorProps?: InstanceType<typeof JavaScriptFunctionEditor>['$props']; |
14 | + scriptType?: string; | |
14 | 15 | }>(), |
15 | 16 | { |
16 | 17 | buttonName: 'Test Filter Function', |
17 | 18 | javaScriptEditorProps: () => ({ |
18 | 19 | functionName: 'Filter', |
20 | + scriptType: 'filter', | |
19 | 21 | paramsName: ['msg', 'metadata', 'msgType'], |
20 | 22 | }), |
21 | 23 | } | ... | ... |