CMVR-IOT-UI/src/views/flow/nodes/function/codeNode.vue

140 lines
3.6 KiB
Vue
Raw Normal View History

2026-03-04 14:41:38 +08:00
<template>
<div class="node__container" :class="props.model.id">
2026-04-15 10:59:17 +08:00
<NodeState :state="nodeOperatingStatus" :runtimes="runtimes" ref="nodeStateRef">
2026-03-04 14:41:38 +08:00
<template #input>
<JsonViewer :value="inputJsonData" copyable boxed sort theme="light" />
</template>
<template #output>
2026-03-19 13:36:14 +08:00
<div v-if="nodeOperatingStatus != 'FAILED'">
<JsonViewer
v-if="props.properties.outputType === 'json'"
:value="outputJsonData"
copyable
boxed
sort
theme="light"
/>
<el-image
v-if="props.properties.outputType === 'img'"
v-for="item in outputJsonData.imageUrl"
style="width: 60px; height: 60px"
:src="item"
:preview-src-list="outputJsonData.imageUrl"
:preview-teleported="true"
show-progress
fit="fill"
/>
<IPlayer
v-if="props.properties.outputType === 'video'"
v-for="item in outputJsonData.videoUrl"
:videoUrl="item"
/>
</div>
<div v-else>{{ errorInfoData }}</div>
2026-03-04 14:41:38 +08:00
</template>
</NodeState>
<NodeTitle
:icon="props.properties.icon"
:nodeId="props.model.id"
:nodeProperties="props.properties"
:nodeType="props.properties.nodeType || 'NONE'"
:nodeName="props.properties.name"
:nodeDesc="props.properties.desc"
@setNodeName="setNodeName"
/>
</div>
</template>
<script setup>
2026-04-13 15:17:11 +08:00
import { ref, onMounted, onUnmounted } from "vue";
2026-03-04 14:41:38 +08:00
import NodeTitle from "../../components/NodeTitle.vue";
import NodeState from "../../components/NodeState.vue";
import { emitter } from "@/utils/eventBus";
2026-07-06 11:11:59 +08:00
import IPlayer from "@/components/IPlayer/index.vue";
2026-03-04 14:41:38 +08:00
const props = defineProps({
model: Object,
properties: Object,
});
const emits = defineEmits(["contentChange"]);
const setNodeName = (name) => {
const properties = lf.getProperties(props.model.id);
lf.setProperties(props.model.id, {
...properties,
name
});
emits("contentChange");
}
const nodeOperatingStatus = ref("NORMAL");
2026-04-14 17:22:08 +08:00
const runtimes = ref(0);
2026-03-04 14:41:38 +08:00
const inputJsonData = ref({});
const outputJsonData = ref({});
2026-03-19 13:36:14 +08:00
const errorInfoData = ref('');
2026-03-04 14:41:38 +08:00
2026-04-15 10:59:17 +08:00
const nodeStateRef = ref(null);
const closePopover = () => {
if (nodeStateRef.value) {
nodeStateRef.value.closePopover();
}
}
2026-03-04 14:41:38 +08:00
onMounted(() => {
emitter.on("changeNodeState", (data) => {
if (data.nodeId === props.model.id) {
nodeOperatingStatus.value = data.status;
2026-04-14 17:22:08 +08:00
if (data.endTime && data.startTime) {
runtimes.value = data.endTime - data.startTime;
}
2026-03-04 14:41:38 +08:00
let inputData = {};
let output = {};
2026-03-19 13:36:14 +08:00
errorInfoData.value = data?.message || ''
2026-03-04 14:41:38 +08:00
try {
inputData = JSON.parse(data.paramsIn) || {};
output = JSON.parse(data.paramsOut) || {};
} catch (error) {
inputData = data.paramsIn || {};
output = data.paramsOut || {};
}
inputJsonData.value = inputData;
outputJsonData.value = output;
emits("contentChange");
}
});
emitter.on("contentChange", (data) => {
if (data.id === props.model.id) {
nodeOperatingStatus.value = "NORMAL";
inputJsonData.value = {};
outputJsonData.value = {};
emits("contentChange");
}
});
2026-04-13 15:17:11 +08:00
emitter.on("setProperties", (data) => {
if (data.id === props.model.id) {
emits("contentChange");
}
});
2026-03-04 14:41:38 +08:00
})
onUnmounted(() => {
emitter.off("changeNodeState");
emitter.off("contentChange");
2026-04-13 15:17:11 +08:00
emitter.off("setProperties");
2026-03-04 14:41:38 +08:00
});
2026-04-15 10:59:17 +08:00
defineExpose({ closePopover })
2026-03-04 14:41:38 +08:00
</script>
<style lang="scss" scoped>
.node__container {
width: 100%;
height: auto;
}
</style>