Commit 3aa7d25f688c5746e7ab61f89c47b703924ba7ff

Authored by ww
1 parent dda9c7ca

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

@@ -22,11 +22,13 @@ @@ -22,11 +22,13 @@
22 value?: string; 22 value?: string;
23 disabled?: boolean; 23 disabled?: boolean;
24 validateStatus?: boolean; 24 validateStatus?: boolean;
  25 + scriptType?: string;
25 }>(), 26 }>(),
26 { 27 {
27 functionName: 'method', 28 functionName: 'method',
28 paramsName: () => [], 29 paramsName: () => [],
29 height: 200, 30 height: 200,
  31 + scriptType: 'filter',
30 value: '', 32 value: '',
31 } 33 }
32 ); 34 );
@@ -13,6 +13,7 @@ export const formSchemas: FormSchema[] = [ @@ -13,6 +13,7 @@ export const formSchemas: FormSchema[] = [
13 javaScriptEditorProps: { 13 javaScriptEditorProps: {
14 functionName: 'Details', 14 functionName: 'Details',
15 paramsName: ['msg', 'metadata', 'msgType'], 15 paramsName: ['msg', 'metadata', 'msgType'],
  16 + scriptType: 'json',
16 }, 17 },
17 buttonName: 'Test details function', 18 buttonName: 'Test details function',
18 }, 19 },
@@ -36,6 +36,7 @@ export const formSchemas: FormSchema[] = [ @@ -36,6 +36,7 @@ export const formSchemas: FormSchema[] = [
36 componentProps: { 36 componentProps: {
37 javaScriptEditorProps: { 37 javaScriptEditorProps: {
38 functionName: 'Details', 38 functionName: 'Details',
  39 + scriptType: 'json',
39 paramsName: ['msg', 'metadata', 'msgType'], 40 paramsName: ['msg', 'metadata', 'msgType'],
40 }, 41 },
41 buttonName: 'Test details function', 42 buttonName: 'Test details function',
@@ -60,6 +60,7 @@ export const formSchemas: FormSchema[] = [ @@ -60,6 +60,7 @@ export const formSchemas: FormSchema[] = [
60 componentProps: { 60 componentProps: {
61 javaScriptEditorProps: { 61 javaScriptEditorProps: {
62 functionName: 'Generate', 62 functionName: 'Generate',
  63 + scriptType: 'generate',
63 paramsName: ['prevMsg', 'prevMetadata', 'prevMsgType'], 64 paramsName: ['prevMsg', 'prevMetadata', 'prevMsgType'],
64 }, 65 },
65 buttonName: 'Test generator function', 66 buttonName: 'Test generator function',
@@ -14,6 +14,7 @@ export const formSchemas: FormSchema[] = [ @@ -14,6 +14,7 @@ export const formSchemas: FormSchema[] = [
14 componentProps: { 14 componentProps: {
15 javaScriptEditorProps: { 15 javaScriptEditorProps: {
16 functionName: 'ToString', 16 functionName: 'ToString',
  17 + scriptType: 'string',
17 paramsName: ['msg', 'metadata', 'msgType'], 18 paramsName: ['msg', 'metadata', 'msgType'],
18 }, 19 },
19 buttonName: 'Test to string function', 20 buttonName: 'Test to string function',
@@ -16,6 +16,7 @@ export const formSchemas: FormSchema[] = [ @@ -16,6 +16,7 @@ export const formSchemas: FormSchema[] = [
16 javaScriptEditorProps: { 16 javaScriptEditorProps: {
17 height: 230, 17 height: 230,
18 functionName: 'Switch', 18 functionName: 'Switch',
  19 + scriptType: 'switch',
19 paramsName: ['msg', 'metadata', 'mstType'], 20 paramsName: ['msg', 'metadata', 'mstType'],
20 }, 21 },
21 }, 22 },
@@ -15,6 +15,7 @@ export const formSchemas: FormSchema[] = [ @@ -15,6 +15,7 @@ export const formSchemas: FormSchema[] = [
15 javaScriptEditorProps: { 15 javaScriptEditorProps: {
16 functionName: 'Transform', 16 functionName: 'Transform',
17 paramsName: ['msg', 'metadata', 'msgType'], 17 paramsName: ['msg', 'metadata', 'msgType'],
  18 + scriptType: 'update',
18 }, 19 },
19 buttonName: 'Test transformer function', 20 buttonName: 'Test transformer function',
20 }, 21 },
@@ -8,6 +8,8 @@ @@ -8,6 +8,8 @@
8 import { useJsonParse } from '/@/hooks/business/useJsonParse'; 8 import { useJsonParse } from '/@/hooks/business/useJsonParse';
9 import { useMessage } from '/@/hooks/web/useMessage'; 9 import { useMessage } from '/@/hooks/web/useMessage';
10 import { AttributeConfiguration } from '../AttributeConfiguration'; 10 import { AttributeConfiguration } from '../AttributeConfiguration';
  11 + import { testScript } from '/@/api/ruleChainDesigner';
  12 + import { isString } from '/@/utils/is';
11 13
12 interface Value { 14 interface Value {
13 msg: Recordable; 15 msg: Recordable;
@@ -24,6 +26,7 @@ @@ -24,6 +26,7 @@
24 { 26 {
25 javaScriptEditorProps: () => ({ 27 javaScriptEditorProps: () => ({
26 functionName: 'Filter', 28 functionName: 'Filter',
  29 + scriptType: 'filter',
27 paramsName: ['msg', 'metadata', 'msgType'], 30 paramsName: ['msg', 'metadata', 'msgType'],
28 }), 31 }),
29 } 32 }
@@ -74,18 +77,34 @@ @@ -74,18 +77,34 @@
74 const msgType = unref(messageType); 77 const msgType = unref(messageType);
75 const javascriptFunction = unref(scriptContent); 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 try { 89 try {
82 const { javaScriptEditorProps } = props; 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 } catch (error) { 108 } catch (error) {
90 return error; 109 return error;
91 } 110 }
@@ -96,7 +115,7 @@ @@ -96,7 +115,7 @@
96 115
97 flag && emit('test', getValue()); 116 flag && emit('test', getValue());
98 117
99 - const result = executeTestScript(); 118 + const result = await executeTestScript();
100 119
101 outputContent.value = result; 120 outputContent.value = result;
102 }; 121 };
@@ -11,11 +11,13 @@ @@ -11,11 +11,13 @@
11 value?: string; 11 value?: string;
12 buttonName?: string; 12 buttonName?: string;
13 javaScriptEditorProps?: InstanceType<typeof JavaScriptFunctionEditor>['$props']; 13 javaScriptEditorProps?: InstanceType<typeof JavaScriptFunctionEditor>['$props'];
  14 + scriptType?: string;
14 }>(), 15 }>(),
15 { 16 {
16 buttonName: 'Test Filter Function', 17 buttonName: 'Test Filter Function',
17 javaScriptEditorProps: () => ({ 18 javaScriptEditorProps: () => ({
18 functionName: 'Filter', 19 functionName: 'Filter',
  20 + scriptType: 'filter',
19 paramsName: ['msg', 'metadata', 'msgType'], 21 paramsName: ['msg', 'metadata', 'msgType'],
20 }), 22 }),
21 } 23 }