2025-09-04 16:41:54 +08:00
|
|
|
|
<template>
|
2025-11-17 14:54:32 +08:00
|
|
|
|
<div class="group__container" :class="props.model.id" @mouseleave="setNodeProperties">
|
2025-09-24 08:59:23 +08:00
|
|
|
|
<NodeTitle
|
|
|
|
|
|
:icon="loop"
|
|
|
|
|
|
:nodeId="props.model.id"
|
|
|
|
|
|
:nodeProperties="props.properties"
|
|
|
|
|
|
:nodeName="props.properties?.name || '循环'"
|
|
|
|
|
|
nodeDesc="循环执行一系列任务,直至输出所有结果"
|
2025-11-17 14:54:32 +08:00
|
|
|
|
:showZoom="false"
|
2025-09-24 08:59:23 +08:00
|
|
|
|
/>
|
2025-11-17 14:54:32 +08:00
|
|
|
|
<div class="loop__container">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<el-form
|
|
|
|
|
|
:inline="true"
|
|
|
|
|
|
:model="formData"
|
|
|
|
|
|
:rules="rules"
|
|
|
|
|
|
ref="dynamicForm"
|
|
|
|
|
|
label-position="top"
|
|
|
|
|
|
label-width="auto"
|
|
|
|
|
|
:disabled="flowStore.disableForm"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div v-for="(property, index) in formData.nodeParams" :key="index">
|
|
|
|
|
|
<el-row>
|
2025-09-24 08:59:23 +08:00
|
|
|
|
<el-form-item
|
2025-11-17 14:54:32 +08:00
|
|
|
|
:label="index === 0 ? '参数名' : ''"
|
|
|
|
|
|
:prop="`nodeParams.${index}.name`"
|
2025-09-24 08:59:23 +08:00
|
|
|
|
:rules="[
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
2025-11-17 14:54:32 +08:00
|
|
|
|
message: '请输入参数名',
|
2025-09-24 08:59:23 +08:00
|
|
|
|
trigger: 'blur',
|
|
|
|
|
|
},
|
|
|
|
|
|
]"
|
|
|
|
|
|
>
|
2025-11-17 14:54:32 +08:00
|
|
|
|
<el-input
|
|
|
|
|
|
:disabled="index === 0"
|
|
|
|
|
|
v-model="property.name"
|
2025-09-24 08:59:23 +08:00
|
|
|
|
placeholder="请输入"
|
|
|
|
|
|
clearable
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item
|
2025-11-17 14:54:32 +08:00
|
|
|
|
:label="index === 0 ? '参数值' : ''"
|
|
|
|
|
|
:prop="`nodeParams.${index}.type`"
|
2025-09-24 08:59:23 +08:00
|
|
|
|
>
|
2025-11-17 14:54:32 +08:00
|
|
|
|
<el-select
|
|
|
|
|
|
v-model="property.type"
|
|
|
|
|
|
@change="handleTypeChange(index)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-option label="引用" value="quote" />
|
|
|
|
|
|
<el-option label="输入" value="input" />
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
<el-form-item
|
|
|
|
|
|
v-if="property.type === 'input'"
|
|
|
|
|
|
:rules="[
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: '请输入参数值',
|
|
|
|
|
|
trigger: 'blur',
|
|
|
|
|
|
},
|
|
|
|
|
|
]"
|
|
|
|
|
|
:prop="`nodeParams.${index}.input`"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-input-number
|
|
|
|
|
|
v-model="property.input"
|
|
|
|
|
|
:min="0"
|
|
|
|
|
|
:controls="false"
|
|
|
|
|
|
:step-strictly="true"
|
|
|
|
|
|
placeholder="请输入"
|
|
|
|
|
|
clearable
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item
|
|
|
|
|
|
v-if="property.type === 'quote'"
|
|
|
|
|
|
:rules="[
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: '请选择参数值',
|
|
|
|
|
|
trigger: 'blur',
|
|
|
|
|
|
},
|
|
|
|
|
|
]"
|
|
|
|
|
|
:prop="`nodeParams.${index}.quote`"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-cascader
|
|
|
|
|
|
:ref="
|
|
|
|
|
|
(el) => {
|
|
|
|
|
|
if (el) cascaderRefs[index] = el;
|
|
|
|
|
|
}
|
|
|
|
|
|
"
|
|
|
|
|
|
v-model="property.quote"
|
|
|
|
|
|
:checkStrictly="true"
|
|
|
|
|
|
:options="quoteOptions"
|
|
|
|
|
|
placeholder="请选择"
|
|
|
|
|
|
@visible-change="
|
|
|
|
|
|
(visible) =>
|
|
|
|
|
|
visibleChange(visible, index, property.quote)
|
|
|
|
|
|
"
|
|
|
|
|
|
@change="(value) => cascaderChange(value, index)"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
2025-09-24 08:59:23 +08:00
|
|
|
|
</el-form-item>
|
2025-11-17 14:54:32 +08:00
|
|
|
|
</el-row>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>循环体</div>
|
|
|
|
|
|
<div
|
|
|
|
|
|
class="child__container"
|
|
|
|
|
|
@drop="handleDrop"
|
|
|
|
|
|
@dragover="handleDragover"
|
|
|
|
|
|
>
|
|
|
|
|
|
<slot></slot>
|
2025-09-24 08:59:23 +08:00
|
|
|
|
</div>
|
2025-09-04 16:41:54 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
2025-09-24 08:59:23 +08:00
|
|
|
|
import { ref, onMounted, nextTick } from "vue";
|
|
|
|
|
|
import NodeTitle from "../../components/NodeTitle.vue";
|
|
|
|
|
|
import loop from "../../icon/loop.svg";
|
|
|
|
|
|
import { useFlowStore } from "@/store/modules/flow";
|
|
|
|
|
|
import { addNewEdge, getInput } from "@/utils/flow";
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
model: Object,
|
|
|
|
|
|
graphModel: Object,
|
|
|
|
|
|
properties: Object,
|
|
|
|
|
|
nowTime: Number,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
const flowStore = useFlowStore();
|
2025-09-04 16:41:54 +08:00
|
|
|
|
const formData = reactive({
|
2025-09-24 08:59:23 +08:00
|
|
|
|
nodeParams: [{ name: "loopNum", type: "input", input: null, quote: "" }],
|
|
|
|
|
|
});
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
const quoteOptions = ref([]);
|
2025-09-04 16:41:54 +08:00
|
|
|
|
const handleTypeChange = (index) => {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
if (formData.nodeParams[index].type === "input") {
|
|
|
|
|
|
formData.nodeParams[index].quote = "";
|
2025-09-04 16:41:54 +08:00
|
|
|
|
} else {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
formData.nodeParams[index].input = null;
|
|
|
|
|
|
const option = getInput(props.model.id);
|
2025-09-04 16:41:54 +08:00
|
|
|
|
if (option) {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
quoteOptions.value = option;
|
2025-09-04 16:41:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-24 08:59:23 +08:00
|
|
|
|
};
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
const rules = reactive({});
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
const emits = defineEmits(["bindRef", "addToGroup", "contentChange"]);
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
|
|
|
|
|
const handleDragover = (e) => {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
};
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
|
|
|
|
|
const handleDrop = (e) => {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
|
|
|
|
let flowNode = e.dataTransfer.getData("flowNode");
|
|
|
|
|
|
flowNode = JSON.parse(flowNode);
|
|
|
|
|
|
const point = lf.getPointByClient(e.clientX, e.clientY);
|
|
|
|
|
|
const { type, ...other } = flowNode;
|
|
|
|
|
|
const node = lf.addNode({
|
|
|
|
|
|
type,
|
|
|
|
|
|
x: point.canvasOverlayPosition.x,
|
|
|
|
|
|
y: point.canvasOverlayPosition.y,
|
|
|
|
|
|
properties: {
|
|
|
|
|
|
parentId: props.model.id,
|
|
|
|
|
|
...other,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
emits("addToGroup", node.id);
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
addNewEdge(props.model.id);
|
|
|
|
|
|
}, 50);
|
|
|
|
|
|
};
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
const dynamicForm = ref();
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
|
|
|
|
|
const setNodeProperties = async () => {
|
|
|
|
|
|
try {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
const valid = await dynamicForm.value.validate();
|
2025-09-04 16:41:54 +08:00
|
|
|
|
if (valid) {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
const data = toRaw(formData);
|
2025-09-04 16:41:54 +08:00
|
|
|
|
setTimeout(() => {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
const properties = lf.getProperties(props.model.id);
|
2025-09-04 16:41:54 +08:00
|
|
|
|
window.lf.setProperties(props.model.id, {
|
|
|
|
|
|
...properties,
|
2025-09-24 08:59:23 +08:00
|
|
|
|
...data,
|
|
|
|
|
|
});
|
|
|
|
|
|
}, 50);
|
2025-09-04 16:41:54 +08:00
|
|
|
|
}
|
2025-09-24 08:59:23 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
dynamicForm.value.clearValidate();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
const visibleChange = async (value, index, quote) => {
|
2025-09-04 16:41:54 +08:00
|
|
|
|
if (value) {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
const option = getInput(props.model.id);
|
2025-09-04 16:41:54 +08:00
|
|
|
|
if (option) {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
quoteOptions.value = option;
|
|
|
|
|
|
const currentValue = [...quote];
|
|
|
|
|
|
// 强制级联选择器重新处理选中值与选项的匹配
|
|
|
|
|
|
if (cascaderRefs.value[index]) {
|
|
|
|
|
|
// 等待DOM更新后再设置值,确保新options已生效
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
// 如果当前有选中值,重新设置一次以触发重新匹配
|
|
|
|
|
|
if (currentValue.length) {
|
|
|
|
|
|
formData.nodeParams[index].quote = [];
|
|
|
|
|
|
// 确保响应式更新
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
console.log(1247);
|
|
|
|
|
|
formData.nodeParams[index].quote = currentValue;
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 手动触发级联选择器的重新渲染
|
|
|
|
|
|
// cascaderRefs.value[index].updatePopper();
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
}
|
2025-09-04 16:41:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-24 08:59:23 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const cascaderRefs = ref([]);
|
|
|
|
|
|
const cascaderChange = (value, index) => {
|
|
|
|
|
|
const selectedOptions = cascaderRefs.value[index].getCheckedNodes(true);
|
|
|
|
|
|
formData.nodeParams[index].quote = value;
|
|
|
|
|
|
formData.nodeParams[index].quoteType = selectedOptions[0].data.type;
|
|
|
|
|
|
};
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => props.properties,
|
|
|
|
|
|
() => {
|
|
|
|
|
|
if (props.properties.nodeParams && props.properties.nodeParams.length > 0) {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
formData.nodeParams = props.properties.nodeParams;
|
|
|
|
|
|
const option = getInput(props.model.id);
|
2025-09-04 16:41:54 +08:00
|
|
|
|
if (option) {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
quoteOptions.value = option;
|
2025-09-04 16:41:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-24 08:59:23 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-09-04 16:41:54 +08:00
|
|
|
|
immediate: true,
|
2025-09-24 08:59:23 +08:00
|
|
|
|
deep: true,
|
2025-09-04 16:41:54 +08:00
|
|
|
|
}
|
2025-09-24 08:59:23 +08:00
|
|
|
|
);
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
emits("bindRef", dynamicForm.value);
|
|
|
|
|
|
});
|
2025-09-04 16:41:54 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.group__container {
|
2025-09-24 08:59:23 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
min-height: 420px;
|
|
|
|
|
|
background: #fff;
|
|
|
|
|
|
padding: 12px;
|
|
|
|
|
|
cursor: default;
|
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
|
border: 2px solid white;
|
|
|
|
|
|
box-shadow: 0 5px 15px 0#00000008;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
position: relative;
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
.title {
|
|
|
|
|
|
height: 40px;
|
|
|
|
|
|
}
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
:deep(.loop__container) {
|
|
|
|
|
|
height: auto;
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
.el-input {
|
|
|
|
|
|
width: 240px;
|
|
|
|
|
|
}
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
.el-input-number {
|
|
|
|
|
|
width: 92px;
|
|
|
|
|
|
}
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
.el-select {
|
|
|
|
|
|
width: 120px;
|
2025-09-04 16:41:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
.el-cascader {
|
|
|
|
|
|
width: 240px;
|
2025-09-04 16:41:54 +08:00
|
|
|
|
}
|
2025-09-24 08:59:23 +08:00
|
|
|
|
}
|
2025-09-04 16:41:54 +08:00
|
|
|
|
|
2025-09-24 08:59:23 +08:00
|
|
|
|
.child__container {
|
|
|
|
|
|
min-height: 100px;
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
background-color: #f6f8fa;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.el-row {
|
|
|
|
|
|
align-items: end;
|
|
|
|
|
|
}
|
2025-09-04 16:41:54 +08:00
|
|
|
|
}
|
2025-09-24 08:59:23 +08:00
|
|
|
|
</style>
|