Commit ae9c2018af156978a3e4a9a091e829abfd215902

Authored by xp.Huang
2 parents eba9e51c 49ba68d5

Merge branch 'fix/script-manage' into 'main'

Fix/script manage

See merge request yunteng/thingskit-front!1416
@@ -43,6 +43,7 @@ export interface TransportScriptParamsType { @@ -43,6 +43,7 @@ export interface TransportScriptParamsType {
43 scriptLanguage: ScriptLanguageEnum; 43 scriptLanguage: ScriptLanguageEnum;
44 status: number; 44 status: number;
45 serviceType?: string; 45 serviceType?: string;
  46 + scriptType: string;
46 } 47 }
47 48
48 export interface TransportScriptRecordType { 49 export interface TransportScriptRecordType {
@@ -58,4 +59,5 @@ export interface TransportScriptRecordType { @@ -58,4 +59,5 @@ export interface TransportScriptRecordType {
58 convertJs?: string; 59 convertJs?: string;
59 serviceType?: string; 60 serviceType?: string;
60 saveOriginalData: boolean; 61 saveOriginalData: boolean;
  62 + scriptType: string;
61 } 63 }
@@ -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() {
@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 import { BasicForm, useForm } from '/@/components/Form'; 3 import { BasicForm, useForm } from '/@/components/Form';
4 import { formSchemas } from './create.config'; 4 import { formSchemas } from './create.config';
5 import { NodeData } from '../../../types/node'; 5 import { NodeData } from '../../../types/node';
  6 + import { ScriptEditorValueType } from '/@/views/rule/designer/src/components/JavaScriptFilterModal';
  7 + import { ScriptFieldsEnum } from '../../../enum/formField/transformation';
6 8
7 defineProps<{ 9 defineProps<{
8 config: NodeData; 10 config: NodeData;
@@ -16,12 +18,15 @@ @@ -16,12 +18,15 @@
16 const getValue: CreateModalDefineExposeType['getFieldsValue'] = async () => { 18 const getValue: CreateModalDefineExposeType['getFieldsValue'] = async () => {
17 await validate(); 19 await validate();
18 const value = getFieldsValue() || {}; 20 const value = getFieldsValue() || {};
19 - return value; 21 + const { scriptLang, jsScript, tbelScript } = (value || {})?.jsScript as ScriptEditorValueType;
  22 + return { scriptLang, jsScript, tbelScript };
20 }; 23 };
21 24
22 const setValue: CreateModalDefineExposeType['setFieldsValue'] = (value) => { 25 const setValue: CreateModalDefineExposeType['setFieldsValue'] = (value) => {
23 resetFields(); 26 resetFields();
24 - setFieldsValue(value); 27 + setFieldsValue({
  28 + [ScriptFieldsEnum.JS_SCRIPT]: value,
  29 + });
25 }; 30 };
26 31
27 defineExpose({ 32 defineExpose({
@@ -27,7 +27,9 @@ export const ScriptConfig: NodeItemConfigType = { @@ -27,7 +27,9 @@ export const ScriptConfig: NodeItemConfigType = {
27 customRelations: false, 27 customRelations: false,
28 ruleChainNode: false, 28 ruleChainNode: false,
29 defaultConfiguration: { 29 defaultConfiguration: {
  30 + scriptLang: 'TBEL',
30 jsScript: 'return {msg: msg, metadata: metadata, msgType: msgType};', 31 jsScript: 'return {msg: msg, metadata: metadata, msgType: msgType};',
  32 + tbelScript: 'return {msg: msg, metadata: metadata, msgType: msgType};',
31 }, 33 },
32 uiResources: ['static/rulenode/rulenode-core-config.js'], 34 uiResources: ['static/rulenode/rulenode-core-config.js'],
33 configDirective: 'tbTransformationNodeScriptConfig', 35 configDirective: 'tbTransformationNodeScriptConfig',
@@ -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
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 const props = defineProps<{ 10 const props = defineProps<{
11 onlyTest?: boolean; 11 onlyTest?: boolean;
12 visible?: boolean; 12 visible?: boolean;
13 - language?: ScriptLanguageEnum; 13 + language: ScriptLanguageEnum;
14 messageValue?: Recordable; 14 messageValue?: Recordable;
15 beforeTest?: (params: ScriptTestParams) => Promise<Recordable>; 15 beforeTest?: (params: ScriptTestParams) => Promise<Recordable>;
16 javaScriptEditorProps?: InstanceType<typeof JavaScriptFunctionEditor>['$props']; 16 javaScriptEditorProps?: InstanceType<typeof JavaScriptFunctionEditor>['$props'];
@@ -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(
@@ -36,14 +36,15 @@ @@ -36,14 +36,15 @@
36 const [register, { openModal }] = useModal(); 36 const [register, { openModal }] = useModal();
37 37
38 const handleOpen = () => { 38 const handleOpen = () => {
  39 + const { scriptLang, jsScript, tbelScript } = props.value || {};
39 openModal(true, { 40 openModal(true, {
40 - record: props.value?.value, 41 + record: scriptLang === ScriptLanguageEnum.JavaScript ? jsScript : tbelScript,
41 mode: DataActionModeEnum.CREATE, 42 mode: DataActionModeEnum.CREATE,
42 } as ModalParamsType<string>); 43 } as ModalParamsType<string>);
43 }; 44 };
44 45
45 watch( 46 watch(
46 - () => props.value?.scriptLanguage, 47 + () => props.value?.scriptLang,
47 (target) => { 48 (target) => {
48 target && (activeLanguage.value = target); 49 target && (activeLanguage.value = target);
49 }, 50 },
@@ -56,28 +57,49 @@ @@ -56,28 +57,49 @@
56 57
57 const getValue = computed<string>({ 58 const getValue = computed<string>({
58 get() { 59 get() {
59 - return props.value?.value || ''; 60 + const { scriptLang, jsScript = '', tbelScript = '' } = props.value || {};
  61 + return scriptLang === ScriptLanguageEnum.JavaScript ? jsScript : tbelScript;
60 }, 62 },
61 set(value) { 63 set(value) {
  64 + const { jsScript, tbelScript } = props.value || {};
  65 + const scriptLang = unref(activeLanguage);
62 emit( 66 emit(
63 'update:value', 67 'update:value',
64 toRaw({ 68 toRaw({
65 - value,  
66 - scriptLanguage: unref(activeLanguage), 69 + jsScript: scriptLang === ScriptLanguageEnum.JavaScript ? value : jsScript,
  70 + tbelScript: scriptLang === ScriptLanguageEnum.TBEL ? value : tbelScript,
  71 + scriptLang,
67 } as ScriptEditorValueType) 72 } as ScriptEditorValueType)
68 ); 73 );
69 }, 74 },
70 }); 75 });
71 76
72 - const handleSave = (value: Record<'javascriptFunction', string>) => { 77 + const handleSave = ({ javascriptFunction }: TestModalValueType) => {
  78 + const { jsScript, tbelScript } = props.value || {};
  79 + const scriptLang = unref(activeLanguage);
73 emit( 80 emit(
74 'update:value', 81 'update:value',
75 toRaw({ 82 toRaw({
76 - value: value.javascriptFunction,  
77 - scriptLanguage: unref(activeLanguage), 83 + jsScript: scriptLang === ScriptLanguageEnum.JavaScript ? javascriptFunction : jsScript,
  84 + tbelScript: scriptLang === ScriptLanguageEnum.TBEL ? javascriptFunction : tbelScript,
  85 + scriptLang,
78 } as ScriptEditorValueType) 86 } as ScriptEditorValueType)
79 ); 87 );
80 }; 88 };
  89 +
  90 + function onScriptLangteChange(item: string) {
  91 + activeLanguage.value = ScriptLanguageEnum[item];
  92 + const { jsScript, tbelScript } = props.value || {};
  93 + const scriptLang = unref(activeLanguage);
  94 + emit(
  95 + 'update:value',
  96 + toRaw({
  97 + scriptLang,
  98 + jsScript,
  99 + tbelScript,
  100 + } as ScriptEditorValueType)
  101 + );
  102 + }
81 </script> 103 </script>
82 104
83 <template> 105 <template>
@@ -91,7 +113,7 @@ @@ -91,7 +113,7 @@
91 :key="item" 113 :key="item"
92 class="cursor-pointer text-center w-40 rounded-3xl h-8 leading-8" 114 class="cursor-pointer text-center w-40 rounded-3xl h-8 leading-8"
93 :class="activeLanguage === ScriptLanguageEnum[item] && 'bg-blue-500 text-light-50'" 115 :class="activeLanguage === ScriptLanguageEnum[item] && 'bg-blue-500 text-light-50'"
94 - @click="activeLanguage = ScriptLanguageEnum[item]" 116 + @click="onScriptLangteChange(item)"
95 > 117 >
96 {{ item }} 118 {{ item }}
97 </div> 119 </div>
  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';
@@ -5,6 +6,14 @@ export { default as JavascriptEditorWithTestModal } from './JavascriptEditorWith @@ -5,6 +6,14 @@ export { default as JavascriptEditorWithTestModal } from './JavascriptEditorWith
5 export { default as JavaScriptFilterTest } from './JavaScriptFilterTest.vue'; 6 export { default as JavaScriptFilterTest } from './JavaScriptFilterTest.vue';
6 7
7 export interface ScriptEditorValueType { 8 export interface ScriptEditorValueType {
8 - scriptLanguage: ScriptLanguageEnum;  
9 - value: string; 9 + scriptLang: ScriptLanguageEnum;
  10 + jsScript: string;
  11 + tbelScript: string;
  12 +}
  13 +
  14 +export interface TestModalValueType {
  15 + msg: Recordable;
  16 + metadata: Recordable;
  17 + msgType: MessageTypesEnum;
  18 + javascriptFunction: string;
10 } 19 }
@@ -7,7 +7,6 @@ @@ -7,7 +7,6 @@
7 TransportScriptParamsType, 7 TransportScriptParamsType,
8 TransportScriptRecordType, 8 TransportScriptRecordType,
9 } from '/@/api/scriptmanage/model/scriptModel'; 9 } from '/@/api/scriptmanage/model/scriptModel';
10 - import { ScriptLanguageEnum } from '/@/enums/scriptEnum';  
11 import { computed, ref, unref } from 'vue'; 10 import { computed, ref, unref } from 'vue';
12 import { DataActionModeEnum } from '/@/enums/toolEnum'; 11 import { DataActionModeEnum } from '/@/enums/toolEnum';
13 12
@@ -21,22 +20,26 @@ @@ -21,22 +20,26 @@
21 resetFields(); 20 resetFields();
22 clearValidate(); 21 clearValidate();
23 if ([DataActionModeEnum.UPDATE, DataActionModeEnum.READ].includes(mode)) { 22 if ([DataActionModeEnum.UPDATE, DataActionModeEnum.READ].includes(mode)) {
24 - const { name, description, convertTbel, convertJs, scriptLanguage, serviceType } =  
25 - record || {};  
26 - activeLanguage.value = scriptLanguage; 23 + const {
  24 + name,
  25 + description,
  26 + convertTbel,
  27 + convertJs,
  28 + scriptLanguage,
  29 + serviceType,
  30 + scriptType = 'TRANSPORT_TCP_UP',
  31 + } = record || {};
27 setFieldsValue({ 32 setFieldsValue({
28 name, 33 name,
29 description, 34 description,
30 serviceType, 35 serviceType,
31 language: scriptLanguage, 36 language: scriptLanguage,
32 scriptContent: { 37 scriptContent: {
33 - scriptLanguage: 'JS',  
34 - value: convertJs,  
35 - },  
36 - tbelContent: {  
37 - scriptLanguage: 'TBEL',  
38 - value: convertTbel, 38 + scriptLang: scriptLanguage,
  39 + jsScript: convertJs,
  40 + tbelScript: convertTbel,
39 }, 41 },
  42 + scriptType,
40 } as FormFieldsValueType); 43 } as FormFieldsValueType);
41 } 44 }
42 currentData.value = data; 45 currentData.value = data;
@@ -57,26 +60,20 @@ @@ -57,26 +60,20 @@
57 try { 60 try {
58 setModalProps({ loading: true, confirmLoading: true }); 61 setModalProps({ loading: true, confirmLoading: true });
59 await validate(); 62 await validate();
60 - const {  
61 - name,  
62 - description,  
63 - scriptContent: { value },  
64 - language,  
65 - scriptType,  
66 - tbelContent: { value: taelValue },  
67 - serviceType,  
68 - } = getFieldsValue() as FormFieldsValueType; 63 + const { name, description, scriptContent, scriptType, serviceType } =
  64 + getFieldsValue() as FormFieldsValueType;
69 65
  66 + const { scriptLang, tbelScript, jsScript } = scriptContent || {};
70 const params: TransportScriptParamsType = { 67 const params: TransportScriptParamsType = {
71 name, 68 name,
72 description, 69 description,
73 status: 1, 70 status: 1,
74 scriptType, 71 scriptType,
75 - scriptLanguage: language, 72 + scriptLanguage: scriptLang,
  73 + convertJs: jsScript,
  74 + convertTbel: tbelScript,
76 serviceType, 75 serviceType,
77 }; 76 };
78 - params.convertJs = value;  
79 - params.convertTbel = taelValue;  
80 77
81 if (unref(currentData)?.mode === DataActionModeEnum.UPDATE) { 78 if (unref(currentData)?.mode === DataActionModeEnum.UPDATE) {
82 params.id = unref(currentData)!.record.id; 79 params.id = unref(currentData)!.record.id;
@@ -89,11 +86,6 @@ @@ -89,11 +86,6 @@
89 setModalProps({ loading: false, confirmLoading: false }); 86 setModalProps({ loading: false, confirmLoading: false });
90 } 87 }
91 }; 88 };
92 - const activeLanguage = ref<string>(ScriptLanguageEnum.JavaScript);  
93 - const languageChange = (type, model) => {  
94 - activeLanguage.value = type;  
95 - model.language = type;  
96 - };  
97 </script> 89 </script>
98 90
99 <template> 91 <template>
@@ -104,20 +96,6 @@ @@ -104,20 +96,6 @@
104 @ok="handleOk" 96 @ok="handleOk"
105 :showOkBtn="currentData?.mode !== DataActionModeEnum.READ" 97 :showOkBtn="currentData?.mode !== DataActionModeEnum.READ"
106 > 98 >
107 - <BasicForm @register="registerForm">  
108 - <template #language="{ model }">  
109 - <div class="bg-gray-200 text-gray-400 font-medium rounded-3xl flex w-80 mb-2 mx-auto">  
110 - <div  
111 - v-for="item in Object.keys(ScriptLanguageEnum)"  
112 - :key="item"  
113 - class="cursor-pointer text-center w-40 rounded-3xl h-8 leading-8"  
114 - :class="activeLanguage === ScriptLanguageEnum[item] && 'bg-blue-500 text-light-50'"  
115 - @click="languageChange(ScriptLanguageEnum[item], model)"  
116 - >  
117 - {{ item }}  
118 - </div>  
119 - </div>  
120 - </template>  
121 - </BasicForm> 99 + <BasicForm @register="registerForm" />
122 </BasicModal> 100 </BasicModal>
123 </template> 101 </template>
@@ -9,6 +9,7 @@ import { Tag, Tooltip } from 'ant-design-vue'; @@ -9,6 +9,7 @@ import { Tag, Tooltip } from 'ant-design-vue';
9 import Icon from '/@/components/Icon'; 9 import Icon from '/@/components/Icon';
10 import { ScriptLanguageEnum } from '/@/enums/scriptEnum'; 10 import { ScriptLanguageEnum } from '/@/enums/scriptEnum';
11 import { findDictItemByCode } from '/@/api/system/dict'; 11 import { findDictItemByCode } from '/@/api/system/dict';
  12 +import { DeviceTypeEnum } from '../../../dataFlow/cpns/config';
12 13
13 useComponentRegister('JavascriptEditorWithTestModal', JavascriptEditorWithTestModal); 14 useComponentRegister('JavascriptEditorWithTestModal', JavascriptEditorWithTestModal);
14 15
@@ -16,17 +17,15 @@ export enum FormFieldsEnum { @@ -16,17 +17,15 @@ export enum FormFieldsEnum {
16 Name = 'name', 17 Name = 'name',
17 Description = 'description', 18 Description = 'description',
18 ScriptContent = 'scriptContent', 19 ScriptContent = 'scriptContent',
19 - TbelContent = 'tbelContent',  
20 ServiceType = 'serviceType', 20 ServiceType = 'serviceType',
21 } 21 }
22 22
23 export interface FormFieldsValueType { 23 export interface FormFieldsValueType {
24 [FormFieldsEnum.Name]: string; 24 [FormFieldsEnum.Name]: string;
25 [FormFieldsEnum.ScriptContent]: ScriptEditorValueType; 25 [FormFieldsEnum.ScriptContent]: ScriptEditorValueType;
26 - [FormFieldsEnum.TbelContent]: ScriptEditorValueType;  
27 [FormFieldsEnum.Description]?: string; 26 [FormFieldsEnum.Description]?: string;
28 [FormFieldsEnum.ServiceType]?: string; 27 [FormFieldsEnum.ServiceType]?: string;
29 - language: string; 28 + scriptType: string;
30 } 29 }
31 30
32 export const formSchemas: FormSchema[] = [ 31 export const formSchemas: FormSchema[] = [
@@ -65,32 +64,28 @@ export const formSchemas: FormSchema[] = [ @@ -65,32 +64,28 @@ export const formSchemas: FormSchema[] = [
65 labelField: 'itemText', 64 labelField: 'itemText',
66 valueField: 'itemValue', 65 valueField: 'itemValue',
67 onChange(e) { 66 onChange(e) {
68 - if (e === 'SENSOR' || e === 'DIRECT_CONNECTION') {  
69 - formModel[FormFieldsEnum.ScriptContent].value = getDirectWithSensorScript().JavaScript;  
70 - formModel[FormFieldsEnum.TbelContent].value = getDirectWithSensorScript().TBEL;  
71 - } else {  
72 - formModel[FormFieldsEnum.ScriptContent].value = getGatewayScript().JavaScript;  
73 - formModel[FormFieldsEnum.TbelContent].value = getGatewayScript().TBEL;  
74 - } 67 + const { jsScript, tbelScript, scriptLang } = (formModel[FormFieldsEnum.ScriptContent] ||
  68 + {}) as ScriptEditorValueType;
  69 +
  70 + const { JavaScript, TBEL } =
  71 + e === DeviceTypeEnum.SENSOR || e === DeviceTypeEnum.DIRECT_CONNECTION
  72 + ? getDirectWithSensorScript()
  73 + : getGatewayScript();
  74 +
  75 + formModel[FormFieldsEnum.ScriptContent] = {
  76 + scriptLang,
  77 + jsScript: scriptLang === ScriptLanguageEnum.JavaScript ? JavaScript : jsScript,
  78 + tbelScript: scriptLang === ScriptLanguageEnum.TBEL ? TBEL : tbelScript,
  79 + };
75 }, 80 },
76 }; 81 };
77 }, 82 },
78 }, 83 },
79 - {  
80 - label: '',  
81 - field: 'language',  
82 - component: 'Input',  
83 - defaultValue: ScriptLanguageEnum.JavaScript,  
84 - slot: 'language',  
85 - },  
86 - //Javascript 84 +
87 { 85 {
88 label: '', 86 label: '',
89 field: FormFieldsEnum.ScriptContent, 87 field: FormFieldsEnum.ScriptContent,
90 component: 'JavascriptEditorWithTestModal', 88 component: 'JavascriptEditorWithTestModal',
91 - ifShow: ({ model }) => {  
92 - return model.language === ScriptLanguageEnum.JavaScript;  
93 - },  
94 componentProps: { 89 componentProps: {
95 buttonName: '测试转换脚本', 90 buttonName: '测试转换脚本',
96 javaScriptEditorProps: { 91 javaScriptEditorProps: {
@@ -101,14 +96,14 @@ export const formSchemas: FormSchema[] = [ @@ -101,14 +96,14 @@ export const formSchemas: FormSchema[] = [
101 messageValue: { 96 messageValue: {
102 params: '010304026C00883BF0', 97 params: '010304026C00883BF0',
103 }, 98 },
104 - isShowLanguage: false,  
105 beforeTest: (params: Recordable) => { 99 beforeTest: (params: Recordable) => {
106 return { ...params, needMetadataAndMsgType: true }; 100 return { ...params, needMetadataAndMsgType: true };
107 }, 101 },
108 }, 102 },
109 defaultValue: { 103 defaultValue: {
110 - scriptLanguage: ScriptLanguageEnum.JavaScript,  
111 - value: getGatewayScript().JavaScript, 104 + scriptLang: ScriptLanguageEnum.JavaScript,
  105 + jsScript: getGatewayScript().JavaScript,
  106 + tbelScript: getGatewayScript().TBEL,
112 } as ScriptEditorValueType, 107 } as ScriptEditorValueType,
113 changeEvent: 'update:value', 108 changeEvent: 'update:value',
114 valueField: 'value', 109 valueField: 'value',
@@ -126,9 +121,13 @@ export const formSchemas: FormSchema[] = [ @@ -126,9 +121,13 @@ export const formSchemas: FormSchema[] = [
126 event: 'directWithSensor', 121 event: 'directWithSensor',
127 onClick: () => { 122 onClick: () => {
128 const { JavaScript, TBEL } = getDirectWithSensorScript(); 123 const { JavaScript, TBEL } = getDirectWithSensorScript();
  124 + const { jsScript, tbelScript } = (model[FormFieldsEnum.ScriptContent] ||
  125 + {}) as ScriptEditorValueType;
129 model[FormFieldsEnum.ScriptContent] = { 126 model[FormFieldsEnum.ScriptContent] = {
130 - scriptLanguage,  
131 - value: scriptLanguage === ScriptLanguageEnum.JavaScript ? JavaScript : TBEL, 127 + scriptLang: scriptLanguage,
  128 + jsScript:
  129 + scriptLanguage === ScriptLanguageEnum.JavaScript ? JavaScript : jsScript,
  130 + tbelScript: scriptLanguage === ScriptLanguageEnum.TBEL ? TBEL : tbelScript,
132 }; 131 };
133 }, 132 },
134 }, 133 },
@@ -137,9 +136,13 @@ export const formSchemas: FormSchema[] = [ @@ -137,9 +136,13 @@ export const formSchemas: FormSchema[] = [
137 event: 'gateway', 136 event: 'gateway',
138 onClick: () => { 137 onClick: () => {
139 const { JavaScript, TBEL } = getGatewayScript(); 138 const { JavaScript, TBEL } = getGatewayScript();
  139 + const { jsScript, tbelScript } = (model[FormFieldsEnum.ScriptContent] ||
  140 + {}) as ScriptEditorValueType;
140 model[FormFieldsEnum.ScriptContent] = { 141 model[FormFieldsEnum.ScriptContent] = {
141 - scriptLanguage,  
142 - value: scriptLanguage === ScriptLanguageEnum.JavaScript ? JavaScript : TBEL, 142 + scriptLang: scriptLanguage,
  143 + jsScript:
  144 + scriptLanguage === ScriptLanguageEnum.JavaScript ? JavaScript : jsScript,
  145 + tbelScript: scriptLanguage === ScriptLanguageEnum.TBEL ? TBEL : tbelScript,
143 }; 146 };
144 }, 147 },
145 }, 148 },
@@ -169,96 +172,6 @@ export const formSchemas: FormSchema[] = [ @@ -169,96 +172,6 @@ export const formSchemas: FormSchema[] = [
169 }; 172 };
170 }, 173 },
171 }, 174 },
172 - // TBEL  
173 - {  
174 - label: '',  
175 - field: FormFieldsEnum.TbelContent,  
176 - component: 'JavascriptEditorWithTestModal',  
177 - ifShow: ({ model }) => {  
178 - return model.language === ScriptLanguageEnum.TBEL;  
179 - },  
180 - componentProps: {  
181 - buttonName: '测试转换脚本',  
182 - javaScriptEditorProps: {  
183 - functionName: 'Transform',  
184 - paramsName: ['msg', 'metadata', 'msgType'],  
185 - scriptType: 'update',  
186 - },  
187 - messageValue: {  
188 - params: '010304026C00883BF0',  
189 - },  
190 - isShowLanguage: false,  
191 - beforeTest: (params: Recordable) => {  
192 - return { ...params, needMetadataAndMsgType: true };  
193 - },  
194 - },  
195 - defaultValue: {  
196 - scriptLanguage: ScriptLanguageEnum.TBEL,  
197 - value: getGatewayScript().TBEL,  
198 - } as ScriptEditorValueType,  
199 - changeEvent: 'update:value',  
200 - valueField: 'value',  
201 - renderComponentContent: ({ model }) => {  
202 - return {  
203 - beforeFormat: ({ scriptLanguage }) => {  
204 - return [  
205 - h(Tooltip, { title: '脚本用例' }, () =>  
206 - h(  
207 - Dropdown,  
208 - {  
209 - trigger: ['click'],  
210 - dropMenuList: [  
211 - {  
212 - text: '直连/子设备用例',  
213 - event: 'directWithSensor',  
214 - onClick: () => {  
215 - const { JavaScript, TBEL } = getDirectWithSensorScript();  
216 - model[FormFieldsEnum.TbelContent] = {  
217 - scriptLanguage,  
218 - value:  
219 - scriptLanguage === ScriptLanguageEnum.JavaScript ? JavaScript : TBEL,  
220 - };  
221 - },  
222 - },  
223 - {  
224 - text: '网关用例',  
225 - event: 'gateway',  
226 - onClick: () => {  
227 - const { JavaScript, TBEL } = getGatewayScript();  
228 - model[FormFieldsEnum.TbelContent] = {  
229 - scriptLanguage,  
230 - value:  
231 - scriptLanguage === ScriptLanguageEnum.JavaScript ? JavaScript : TBEL,  
232 - };  
233 - },  
234 - },  
235 - ],  
236 - },  
237 - () =>  
238 - h(  
239 - Tag,  
240 - { color: '#2a79ef', class: 'cursor-pointer' },  
241 - {  
242 - icon: () =>  
243 - h(Icon, {  
244 - icon: 'magic',  
245 - prefix: 'mdi',  
246 - size: 14,  
247 - class: 'cursor-pointer svg:text-sm',  
248 - }),  
249 - default: () => '脚本用例',  
250 - }  
251 - )  
252 - )  
253 - ),  
254 - h(Tooltip, { title: '复制' }, () =>  
255 - h(Icon, { icon: 'copy-filled', prefix: 'ant-design', class: 'cursor-pointer' })  
256 - ),  
257 - ];  
258 - },  
259 - };  
260 - },  
261 - },  
262 { 175 {
263 field: FormFieldsEnum.Description, 176 field: FormFieldsEnum.Description,
264 label: '备注', 177 label: '备注',
@@ -174,7 +174,7 @@ @@ -174,7 +174,7 @@
174 } 174 }
175 }; 175 };
176 176
177 - const testScriptLanguage = ref<string>(ScriptLanguageEnum.JavaScript); 177 + const testScriptLanguage = ref<ScriptLanguageEnum>(ScriptLanguageEnum.JavaScript);
178 const handleOpenTestModal = (record: TransportScriptRecordType) => { 178 const handleOpenTestModal = (record: TransportScriptRecordType) => {
179 const { scriptLanguage = ScriptLanguageEnum.JavaScript, convertJs, convertTbel } = record; 179 const { scriptLanguage = ScriptLanguageEnum.JavaScript, convertJs, convertTbel } = record;
180 testScriptLanguage.value = scriptLanguage!; 180 testScriptLanguage.value = scriptLanguage!;
@@ -150,8 +150,9 @@ export const formSchema: FormSchema[] = [ @@ -150,8 +150,9 @@ export const formSchema: FormSchema[] = [
150 label: '转换函数', 150 label: '转换函数',
151 changeEvent: 'update:value', 151 changeEvent: 'update:value',
152 defaultValue: { 152 defaultValue: {
153 - value: 'return {msg: msg, metadata: metadata, msgType: msgType};',  
154 - scriptLanguage: ScriptLanguageEnum.JavaScript, 153 + jsScript: 'return {msg: msg, metadata: metadata, msgType: msgType};',
  154 + scriptLang: ScriptLanguageEnum.JavaScript,
  155 + tbelScript: 'return {msg: msg, metadata: metadata, msgType: msgType};',
155 }, 156 },
156 componentProps: { 157 componentProps: {
157 javaScriptEditorProps: { 158 javaScriptEditorProps: {
@@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
32 resetFields(); 32 resetFields();
33 setDrawerProps({ confirmLoading: false }); 33 setDrawerProps({ confirmLoading: false });
34 isUpdate.value = data.isUpdate; 34 isUpdate.value = data.isUpdate;
  35 +
35 switch (isUpdate.value) { 36 switch (isUpdate.value) {
36 case 'view': 37 case 'view':
37 isView.value = false; 38 isView.value = false;
@@ -41,7 +42,10 @@ @@ -41,7 +42,10 @@
41 loading: false, 42 loading: false,
42 }); 43 });
43 editId.value = data.record.id; 44 editId.value = data.record.id;
44 - setFieldsValue({ ...data.record, function: data.record?.configuration?.jsScript }); 45 + setFieldsValue({
  46 + ...data.record,
  47 + function: data?.record?.configuration,
  48 + });
45 break; 49 break;
46 case true: 50 case true:
47 isView.value = true; 51 isView.value = true;
@@ -51,7 +55,10 @@ @@ -51,7 +55,10 @@
51 loading: false, 55 loading: false,
52 }); 56 });
53 editId.value = data.record.id; 57 editId.value = data.record.id;
54 - setFieldsValue({ ...data.record, function: data.record?.configuration?.jsScript }); 58 + setFieldsValue({
  59 + ...data.record,
  60 + function: data?.record?.configuration,
  61 + });
55 break; 62 break;
56 case false: 63 case false:
57 isView.value = true; 64 isView.value = true;
@@ -75,10 +82,9 @@ @@ -75,10 +82,9 @@
75 setDrawerProps({ confirmLoading: true }); 82 setDrawerProps({ confirmLoading: true });
76 const fieldsValue = await validate(); 83 const fieldsValue = await validate();
77 if (!fieldsValue) return; 84 if (!fieldsValue) return;
  85 +
78 await createOrEditTransformScriptApi({ 86 await createOrEditTransformScriptApi({
79 - configuration: {  
80 - jsScript: fieldsValue.function,  
81 - }, 87 + configuration: fieldsValue.function,
82 type: 'org.thingsboard.rule.engine.transform.TbTransformMsgNode', 88 type: 'org.thingsboard.rule.engine.transform.TbTransformMsgNode',
83 ...fieldsValue, 89 ...fieldsValue,
84 ...editIdPost, 90 ...editIdPost,