Commit 49ba68d57ec50f200202a57cf809dcedff354d4d

Authored by ww
1 parent 72b813a2

fix: 修复测试转换脚本保存时数据结构不正确

@@ -96,7 +96,7 @@ @@ -96,7 +96,7 @@
96 }; 96 };
97 97
98 const set = (val: string, cursorPos?: number) => { 98 const set = (val: string, cursorPos?: number) => {
99 - return unref(editorInstance)?.setValue(val, cursorPos); 99 + return unref(editorInstance)?.setValue(unref(val), cursorPos);
100 }; 100 };
101 101
102 function destroy() { 102 function destroy() {
@@ -12,13 +12,7 @@ @@ -12,13 +12,7 @@
12 import { isFunction, isString } from '/@/utils/is'; 12 import { isFunction, isString } from '/@/utils/is';
13 import { ScriptLanguageEnum } from '/@/enums/scriptEnum'; 13 import { ScriptLanguageEnum } from '/@/enums/scriptEnum';
14 import { ScriptTestParams } from '/@/api/ruleChainDesigner/model'; 14 import { ScriptTestParams } from '/@/api/ruleChainDesigner/model';
15 -  
16 - interface Value {  
17 - msg: Recordable;  
18 - metadata: Recordable;  
19 - msgType: MessageTypesEnum;  
20 - javascriptFunction: string;  
21 - } 15 + import { TestModalValueType } from '.';
22 16
23 const props = withDefaults( 17 const props = withDefaults(
24 defineProps<{ 18 defineProps<{
@@ -45,8 +39,8 @@ @@ -45,8 +39,8 @@
45 39
46 const emit = defineEmits<{ 40 const emit = defineEmits<{
47 (eventName: 'cancel'): void; 41 (eventName: 'cancel'): void;
48 - (eventName: 'test', value: Value): void;  
49 - (eventName: 'save', value: Value): void; 42 + (eventName: 'test', value: TestModalValueType): void;
  43 + (eventName: 'save', value: TestModalValueType): void;
50 }>(); 44 }>();
51 45
52 const jsonEditor = ref<InstanceType<typeof JSONEditor>>(); 46 const jsonEditor = ref<InstanceType<typeof JSONEditor>>();
@@ -85,7 +79,7 @@ @@ -85,7 +79,7 @@
85 return true; 79 return true;
86 }; 80 };
87 81
88 - const getValue = (): Value => { 82 + const getValue = (): TestModalValueType => {
89 const msg = unref(messageContent); 83 const msg = unref(messageContent);
90 const msgType = unref(messageType); 84 const msgType = unref(messageType);
91 const javascriptFunction = unref(scriptContent); 85 const javascriptFunction = unref(scriptContent);
@@ -138,14 +132,13 @@ @@ -138,14 +132,13 @@
138 132
139 const result = await executeTestScript(); 133 const result = await executeTestScript();
140 134
141 - outputContent.value = result; 135 + outputContent.value = result || '';
142 await nextTick(); 136 await nextTick();
143 unref(jsonEditor)?.handleFormat(); 137 unref(jsonEditor)?.handleFormat();
144 }; 138 };
145 139
146 const handleSave = async () => { 140 const handleSave = async () => {
147 const flag = await handleValidate(); 141 const flag = await handleValidate();
148 -  
149 flag && emit('save', getValue()); 142 flag && emit('save', getValue());
150 }; 143 };
151 144
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 import { DataActionModeEnum } from '/@/enums/toolEnum'; 6 import { DataActionModeEnum } from '/@/enums/toolEnum';
7 import { computed, ref, toRaw, unref, watch } from 'vue'; 7 import { computed, ref, toRaw, unref, watch } from 'vue';
8 import { ScriptLanguageEnum } from '/@/enums/scriptEnum'; 8 import { ScriptLanguageEnum } from '/@/enums/scriptEnum';
9 - import { ScriptEditorValueType } from '.'; 9 + import { ScriptEditorValueType, TestModalValueType } from '.';
10 import { ScriptTestParams } from '/@/api/ruleChainDesigner/model'; 10 import { ScriptTestParams } from '/@/api/ruleChainDesigner/model';
11 11
12 const props = withDefaults( 12 const props = withDefaults(
@@ -74,14 +74,14 @@ @@ -74,14 +74,14 @@
74 }, 74 },
75 }); 75 });
76 76
77 - const handleSave = (value: Record<'javascriptFunction', string>) => { 77 + const handleSave = ({ javascriptFunction }: TestModalValueType) => {
78 const { jsScript, tbelScript } = props.value || {}; 78 const { jsScript, tbelScript } = props.value || {};
79 const scriptLang = unref(activeLanguage); 79 const scriptLang = unref(activeLanguage);
80 emit( 80 emit(
81 'update:value', 81 'update:value',
82 toRaw({ 82 toRaw({
83 - jsScript: scriptLang === ScriptLanguageEnum.JavaScript ? value : jsScript,  
84 - tbelScript: scriptLang === ScriptLanguageEnum.TBEL ? value : tbelScript, 83 + jsScript: scriptLang === ScriptLanguageEnum.JavaScript ? javascriptFunction : jsScript,
  84 + tbelScript: scriptLang === ScriptLanguageEnum.TBEL ? javascriptFunction : tbelScript,
85 scriptLang, 85 scriptLang,
86 } as ScriptEditorValueType) 86 } as ScriptEditorValueType)
87 ); 87 );
  1 +import { MessageTypesEnum } from '../../../enum/form';
1 import { ScriptLanguageEnum } from '/@/enums/scriptEnum'; 2 import { ScriptLanguageEnum } from '/@/enums/scriptEnum';
2 3
3 export { default as JavaScriptTestModal } from './JavaScriptTestModal.vue'; 4 export { default as JavaScriptTestModal } from './JavaScriptTestModal.vue';
@@ -9,3 +10,10 @@ export interface ScriptEditorValueType { @@ -9,3 +10,10 @@ export interface ScriptEditorValueType {
9 jsScript: string; 10 jsScript: string;
10 tbelScript: string; 11 tbelScript: string;
11 } 12 }
  13 +
  14 +export interface TestModalValueType {
  15 + msg: Recordable;
  16 + metadata: Recordable;
  17 + msgType: MessageTypesEnum;
  18 + javascriptFunction: string;
  19 +}