2026-02-08 15:59:14 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="w-full">
|
|
|
|
|
<a-collapse v-model:activeKey="activeKey" :accordion="true">
|
|
|
|
|
<a-collapse-panel key="1">
|
|
|
|
|
<template #header>
|
|
|
|
|
<span class="ks-model-builder-title-icon icon-model"></span>控制节点
|
|
|
|
|
</template>
|
|
|
|
|
<div class="w-full h-full">
|
|
|
|
|
<a-row>
|
2026-02-08 16:01:21 +08:00
|
|
|
<a-col :span="12" v-for="nm in controlTemplates">
|
2026-02-08 15:59:14 +08:00
|
|
|
<div
|
|
|
|
|
:key="nm.id"
|
|
|
|
|
:data-type="nm.type"
|
|
|
|
|
class="ks-model-drag-item"
|
|
|
|
|
@dragend="handleDragEnd"
|
|
|
|
|
@dragstart="handleDragStart($event, nm)"
|
|
|
|
|
>
|
2026-02-08 16:01:21 +08:00
|
|
|
<img class="icon" src="@/assets/icons/model-4.svg" :alt="nm.name ?? ''" />
|
2026-02-08 15:59:14 +08:00
|
|
|
<span class="desc">{{ nm.name }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
|
|
|
|
</div>
|
|
|
|
|
</a-collapse-panel>
|
|
|
|
|
<a-collapse-panel key="2">
|
|
|
|
|
<template #header>
|
|
|
|
|
<span class="ks-model-builder-title-icon icon-model"></span>条件节点
|
|
|
|
|
</template>
|
|
|
|
|
<div class="w-full h-full">
|
|
|
|
|
<a-row>
|
2026-02-08 16:01:21 +08:00
|
|
|
<a-col :span="12" v-for="nm in conditionTemplates">
|
2026-02-08 15:59:14 +08:00
|
|
|
<div
|
|
|
|
|
:key="nm.id"
|
|
|
|
|
:data-type="nm.type"
|
|
|
|
|
class="ks-model-drag-item"
|
|
|
|
|
@dragend="handleDragEnd"
|
|
|
|
|
@dragstart="handleDragStart($event, nm)"
|
|
|
|
|
>
|
2026-02-08 16:01:21 +08:00
|
|
|
<img class="icon" src="@/assets/icons/model-4.svg" :alt="nm.name ?? ''" />
|
2026-02-08 15:59:14 +08:00
|
|
|
<span class="desc">{{ nm.name }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
|
|
|
|
</div>
|
|
|
|
|
</a-collapse-panel>
|
|
|
|
|
<a-collapse-panel key="3">
|
|
|
|
|
<template #header>
|
|
|
|
|
<span class="ks-model-builder-title-icon icon-model"></span>行为节点
|
|
|
|
|
</template>
|
|
|
|
|
<div class="w-full h-full">
|
|
|
|
|
<a-row>
|
2026-02-08 16:01:21 +08:00
|
|
|
<a-col :span="12" v-for="nm in actionsTemplates">
|
2026-02-08 15:59:14 +08:00
|
|
|
<div
|
|
|
|
|
:key="nm.id"
|
|
|
|
|
:data-type="nm.type"
|
|
|
|
|
class="ks-model-drag-item"
|
|
|
|
|
@dragend="handleDragEnd"
|
|
|
|
|
@dragstart="handleDragStart($event, nm)"
|
|
|
|
|
>
|
2026-02-08 16:01:21 +08:00
|
|
|
<img class="icon" src="@/assets/icons/model-4.svg" :alt="nm.name ?? ''" />
|
2026-02-08 15:59:14 +08:00
|
|
|
<span class="desc">{{ nm.name }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
|
|
|
|
</div>
|
|
|
|
|
</a-collapse-panel>
|
|
|
|
|
</a-collapse>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import { defineComponent, onMounted, ref } from 'vue';
|
2026-02-08 16:44:50 +08:00
|
|
|
import type { NodeTemplate } from './types';
|
|
|
|
|
import { findNodeTemplates } from './api';
|
2026-02-08 15:59:14 +08:00
|
|
|
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
emits: ['drag-item-start', 'drag-item-end'],
|
|
|
|
|
setup(_props, { emit }) {
|
|
|
|
|
|
|
|
|
|
const activeKey = ref<number>(1);
|
2026-02-08 16:44:50 +08:00
|
|
|
const templateData = ref<NodeTemplate[]>([]);
|
2026-02-08 15:59:14 +08:00
|
|
|
const isDraggingOver = ref(false);
|
|
|
|
|
const draggedNodeData = ref<NodeTemplate | null>(null);
|
|
|
|
|
|
|
|
|
|
// 控制节点
|
|
|
|
|
const controlTemplates = ref<NodeTemplate[]>([]);
|
|
|
|
|
// 条件节点
|
|
|
|
|
const conditionTemplates = ref<NodeTemplate[]>([]);
|
|
|
|
|
// 行为节点
|
|
|
|
|
const actionsTemplates = ref<NodeTemplate[]>([]);
|
|
|
|
|
|
|
|
|
|
const loadTress = () => {
|
|
|
|
|
controlTemplates.value = [];
|
|
|
|
|
conditionTemplates.value = [];
|
|
|
|
|
actionsTemplates.value = [];
|
|
|
|
|
|
2026-02-08 16:44:50 +08:00
|
|
|
findNodeTemplates().then(r => {
|
2026-02-08 15:59:14 +08:00
|
|
|
templateData.value = r.data;
|
2026-02-08 16:44:50 +08:00
|
|
|
if (r.data) {
|
|
|
|
|
r.data.forEach(tpl => {
|
2026-02-08 15:59:14 +08:00
|
|
|
if (tpl.type === 'action') {
|
2026-02-08 16:44:50 +08:00
|
|
|
actionsTemplates.value.push(tpl);
|
2026-02-08 15:59:14 +08:00
|
|
|
} else if (tpl.type === 'parallel' || tpl.type === 'sequence' || tpl.type === 'precondition') {
|
|
|
|
|
conditionTemplates.value.push(tpl);
|
|
|
|
|
} else {
|
|
|
|
|
controlTemplates.value.push(tpl);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDragStart = (e: DragEvent, nm: NodeTemplate) => {
|
|
|
|
|
draggedNodeData.value = nm;
|
|
|
|
|
|
|
|
|
|
if (e.dataTransfer) {
|
|
|
|
|
e.dataTransfer.setData('text/plain', JSON.stringify(draggedNodeData.value));
|
|
|
|
|
e.dataTransfer.effectAllowed = 'copyMove';
|
|
|
|
|
|
|
|
|
|
const dragPreview = document.createElement('div');
|
|
|
|
|
dragPreview.textContent = draggedNodeData.value.name || '';
|
|
|
|
|
dragPreview.style.cssText = `
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: -1000px;
|
|
|
|
|
padding: 6px 12px;
|
|
|
|
|
background: #3b82f6;
|
|
|
|
|
color: white;
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
`;
|
|
|
|
|
document.body.appendChild(dragPreview);
|
|
|
|
|
e.dataTransfer.setDragImage(dragPreview, dragPreview.offsetWidth / 2, dragPreview.offsetHeight / 2);
|
|
|
|
|
emit('drag-item-start', nm, isDraggingOver.value, e);
|
|
|
|
|
console.log('开始拖动:', nm);
|
|
|
|
|
setTimeout(() => document.body.removeChild(dragPreview), 0);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDragEnd = (e: DragEvent) => {
|
|
|
|
|
safePreventDefault(e);
|
|
|
|
|
safeStopPropagation(e);
|
|
|
|
|
isDraggingOver.value = false;
|
|
|
|
|
console.log('拖动结束');
|
|
|
|
|
emit('drag-item-end', isDraggingOver.value, e);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
loadTress();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
activeKey,
|
|
|
|
|
|
|
|
|
|
controlTemplates,
|
|
|
|
|
conditionTemplates,
|
|
|
|
|
actionsTemplates,
|
|
|
|
|
|
|
|
|
|
handleDragStart,
|
|
|
|
|
handleDragEnd,
|
|
|
|
|
};
|
|
|
|
|
},
|
2026-02-08 16:01:21 +08:00
|
|
|
})
|
2026-02-08 15:59:14 +08:00
|
|
|
|
|
|
|
|
</script>
|