Commit 3aa7d25f688c5746e7ab61f89c47b703924ba7ff

Authored by ww
1 parent dda9c7ca

fix: DEFECT-1660 修复规则链点击测试时需要调用后端接口

... ... @@ -22,11 +22,13 @@
22 22 value?: string;
23 23 disabled?: boolean;
24 24 validateStatus?: boolean;
  25 + scriptType?: string;
25 26 }>(),
26 27 {
27 28 functionName: 'method',
28 29 paramsName: () => [],
29 30 height: 200,
  31 + scriptType: 'filter',
30 32 value: '',
31 33 }
32 34 );
... ...
... ... @@ -13,6 +13,7 @@ export const formSchemas: FormSchema[] = [
13 13 javaScriptEditorProps: {
14 14 functionName: 'Details',
15 15 paramsName: ['msg', 'metadata', 'msgType'],
  16 + scriptType: 'json',
16 17 },
17 18 buttonName: 'Test details function',
18 19 },
... ...
... ... @@ -36,6 +36,7 @@ export const formSchemas: FormSchema[] = [
36 36 componentProps: {
37 37 javaScriptEditorProps: {
38 38 functionName: 'Details',
  39 + scriptType: 'json',
39 40 paramsName: ['msg', 'metadata', 'msgType'],
40 41 },
41 42 buttonName: 'Test details function',
... ...
... ... @@ -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',
... ...
... ... @@ -14,6 +14,7 @@ export const formSchemas: FormSchema[] = [
14 14 componentProps: {
15 15 javaScriptEditorProps: {
16 16 functionName: 'ToString',
  17 + scriptType: 'string',
17 18 paramsName: ['msg', 'metadata', 'msgType'],
18 19 },
19 20 buttonName: 'Test to string function',
... ...
... ... @@ -16,6 +16,7 @@ export const formSchemas: FormSchema[] = [
16 16 javaScriptEditorProps: {
17 17 height: 230,
18 18 functionName: 'Switch',
  19 + scriptType: 'switch',
19 20 paramsName: ['msg', 'metadata', 'mstType'],
20 21 },
21 22 },
... ...
... ... @@ -15,6 +15,7 @@ export const formSchemas: FormSchema[] = [
15 15 javaScriptEditorProps: {
16 16 functionName: 'Transform',
17 17 paramsName: ['msg', 'metadata', 'msgType'],
  18 + scriptType: 'update',
18 19 },
19 20 buttonName: 'Test transformer function',
20 21 },
... ...
... ... @@ -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 }
... ...