Commit 575ff3f01ceff549ef0e789592c1fb62fb825c48
Merge branch 'fix/DEFECT-2098' into 'v1.4.0_dev'
fix: TCP产品详情,点击传输配置时,点击测试转换脚本无效 See merge request yunteng/thingskit-front!1355
Showing
2 changed files
with
42 additions
and
9 deletions
| 1 | 1 | <script lang="ts" setup> |
| 2 | 2 | import { Button, Tag } from 'ant-design-vue'; |
| 3 | - import { h, onMounted, ref, unref, Ref } from 'vue'; | |
| 3 | + import { h, onMounted, ref, unref } from 'vue'; | |
| 4 | 4 | import { DeviceProfileModel } from '/@/api/device/model/deviceModel'; |
| 5 | 5 | import { getScriptManageMeList } from '/@/api/scriptmanage/scriptManager'; |
| 6 | 6 | import { Description, useDescription } from '/@/components/Description'; |
| 7 | 7 | import { useModal } from '/@/components/Modal'; |
| 8 | - import { SelectTypes } from 'ant-design-vue/es/select'; | |
| 9 | 8 | import { TCPProtocolTypeEnum, TCPProtocolTypeNameEnum } from '/@/enums/deviceEnum'; |
| 9 | + import ConvertScriptModal from '/@/views/rule/script/TcpConversionScript/components/ConvertScriptModal.vue'; | |
| 10 | + import { ScriptLanguageEnum } from '/@/enums/scriptEnum'; | |
| 11 | + import { DataActionModeEnum } from '/@/enums/toolEnum'; | |
| 12 | + import JavaScriptTestModal from '/@/views/rule/designer/src/components/JavaScriptFilterModal/JavaScriptTestModal.vue'; | |
| 10 | 13 | |
| 11 | 14 | const props = defineProps<{ |
| 12 | 15 | record: DeviceProfileModel['profileData']['transportConfiguration']; |
| ... | ... | @@ -14,7 +17,7 @@ |
| 14 | 17 | |
| 15 | 18 | const upScriptIdStr = ref(''); |
| 16 | 19 | |
| 17 | - const selectUpOptions: Ref<SelectTypes['options']> = ref([]); | |
| 20 | + const selectUpOptions: any = ref([]); | |
| 18 | 21 | |
| 19 | 22 | onMounted(async () => { |
| 20 | 23 | selectUpOptions.value = await getAllScriptType('TRANSPORT_TCP_UP'); |
| ... | ... | @@ -25,7 +28,7 @@ |
| 25 | 28 | |
| 26 | 29 | const getAllScriptType = async (type) => { |
| 27 | 30 | const rest = await getScriptManageMeList({ scriptType: type }); |
| 28 | - return rest.map((m) => ({ label: m.name, value: m.id })); | |
| 31 | + return rest.map((m) => ({ ...m, label: m.name, value: m.id })); | |
| 29 | 32 | }; |
| 30 | 33 | |
| 31 | 34 | const findScriptUpName = (scriptId) => { |
| ... | ... | @@ -73,17 +76,44 @@ |
| 73 | 76 | |
| 74 | 77 | const [registerModal, { openModal }] = useModal(); |
| 75 | 78 | |
| 79 | + const testScriptLanguage = ref<string>(ScriptLanguageEnum.JavaScript); | |
| 76 | 80 | const handleTestUpScript = () => { |
| 77 | - const modalParams = { | |
| 78 | - record: { id: unref(upScriptIdStr) }, | |
| 79 | - }; | |
| 80 | - openModal(true, modalParams); | |
| 81 | + // const modalParams = { | |
| 82 | + // record: { id: unref(upScriptIdStr) }, | |
| 83 | + // }; | |
| 84 | + const record = selectUpOptions.value?.find((it) => it.value === unref(upScriptIdStr)); | |
| 85 | + const { scriptLanguage = ScriptLanguageEnum.JavaScript, convertJs, convertTbel } = record; | |
| 86 | + testScriptLanguage.value = scriptLanguage!; | |
| 87 | + openModal(true, { | |
| 88 | + mode: DataActionModeEnum.CREATE, | |
| 89 | + record: scriptLanguage === ScriptLanguageEnum.JavaScript ? convertJs : convertTbel, | |
| 90 | + } as ModalParamsType<string>); | |
| 91 | + | |
| 92 | + // openModal(true, modalParams); | |
| 93 | + }; | |
| 94 | + | |
| 95 | + const beforeTest = (params: Recordable) => { | |
| 96 | + return { ...params, needMetadataAndMsgType: true }; | |
| 81 | 97 | }; |
| 82 | 98 | </script> |
| 83 | 99 | |
| 84 | 100 | <template> |
| 85 | 101 | <section> |
| 86 | 102 | <Description @register="register" /> |
| 87 | - <ConverScriptModal @register="registerModal" /> | |
| 103 | + <ConvertScriptModal @register="registerModal" /> | |
| 104 | + <JavaScriptTestModal | |
| 105 | + onlyTest | |
| 106 | + @register="registerModal" | |
| 107 | + :language="testScriptLanguage" | |
| 108 | + :messageValue="{ | |
| 109 | + params: '010304026C00883BF0', | |
| 110 | + }" | |
| 111 | + :javaScriptEditorProps="{ | |
| 112 | + functionName: 'Transform', | |
| 113 | + paramsName: ['msg', 'metadata', 'msgType'], | |
| 114 | + scriptType: 'update', | |
| 115 | + }" | |
| 116 | + :beforeTest="beforeTest" | |
| 117 | + /> | |
| 88 | 118 | </section> |
| 89 | 119 | </template> | ... | ... |
| ... | ... | @@ -136,6 +136,9 @@ |
| 136 | 136 | const setValue = async (value) => { |
| 137 | 137 | const scriptOption = await getAllScriptType(props.scriptType, props.serviceType); |
| 138 | 138 | selectOptions.value = scriptOption; |
| 139 | + if (props.modelValue && !unref(selectOptions)?.some((item) => item.id === props.modelValue)) { | |
| 140 | + emits('update:modelValue', null); | |
| 141 | + } | |
| 139 | 142 | if (!scriptOption.map((item) => item.value).includes(value)) { |
| 140 | 143 | scriptId.value = null; |
| 141 | 144 | } else scriptId.value = value; | ... | ... |