2026-02-08 15:59:14 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="w-full">
|
2026-03-14 22:35:21 +08:00
|
|
|
<a-collapse v-model:activeKey="activeKey" :accordion="true" class="platform-collapse">
|
2026-02-08 15:59:14 +08:00
|
|
|
<a-collapse-panel key="1">
|
|
|
|
|
<template #header>
|
2026-03-14 22:35:21 +08:00
|
|
|
<span class="ks-model-builder-title-icon icon-model"></span>平台名称
|
2026-02-08 15:59:14 +08:00
|
|
|
</template>
|
|
|
|
|
<div class="w-full h-full">
|
|
|
|
|
<a-row>
|
2026-03-14 22:35:21 +08:00
|
|
|
<a-col v-for="nm in templateData" :span="12">
|
2026-02-08 15:59:14 +08:00
|
|
|
<div
|
|
|
|
|
:key="nm.id"
|
|
|
|
|
class="ks-model-drag-item"
|
|
|
|
|
@dragend="handleDragEnd"
|
2026-03-14 22:35:21 +08:00
|
|
|
@dragstart="handleDragStart($event, nm)"
|
2026-02-08 15:59:14 +08:00
|
|
|
>
|
2026-03-14 22:35:21 +08:00
|
|
|
<img :alt="nm.description ?? nm.name ?? ''" class="icon" src="@/assets/icons/model-4.svg" />
|
|
|
|
|
<span class="desc">{{ nm.description ?? nm.name }}</span>
|
2026-02-08 15:59:14 +08:00
|
|
|
</div>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
|
|
|
|
</div>
|
|
|
|
|
</a-collapse-panel>
|
|
|
|
|
</a-collapse>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import { defineComponent, onMounted, ref } from 'vue';
|
|
|
|
|
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
2026-03-14 22:35:21 +08:00
|
|
|
import {findPlatformWithComponents} from './api'
|
|
|
|
|
import {type PlatformWithComponents} from './types'
|
2026-02-08 15:59:14 +08:00
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
emits: ['drag-item-start', 'drag-item-end'],
|
|
|
|
|
setup(_props, { emit }) {
|
|
|
|
|
|
|
|
|
|
const activeKey = ref<number>(1);
|
2026-03-14 22:35:21 +08:00
|
|
|
const templateData = ref<PlatformWithComponents[]>([]);
|
2026-02-08 20:14:07 +08:00
|
|
|
const isDraggingOver = ref<boolean>(false);
|
2026-03-14 22:35:21 +08:00
|
|
|
const draggedNodeData = ref<PlatformWithComponents | null>(null);
|
2026-02-08 15:59:14 +08:00
|
|
|
|
|
|
|
|
const loadTress = () => {
|
2026-03-14 22:35:21 +08:00
|
|
|
templateData.value = []
|
|
|
|
|
findPlatformWithComponents(1).then(r => {
|
|
|
|
|
templateData.value = r.data ?? []
|
2026-02-08 15:59:14 +08:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-14 22:35:21 +08:00
|
|
|
const handleDragStart = (e: DragEvent, nm: PlatformWithComponents) => {
|
|
|
|
|
let dragNode: PlatformWithComponents = { ...nm };
|
|
|
|
|
draggedNodeData.value = dragNode as PlatformWithComponents;
|
2026-02-08 15:59:14 +08:00
|
|
|
|
|
|
|
|
if (e.dataTransfer) {
|
|
|
|
|
e.dataTransfer.setData('text/plain', JSON.stringify(draggedNodeData.value));
|
|
|
|
|
e.dataTransfer.effectAllowed = 'copyMove';
|
|
|
|
|
|
|
|
|
|
const dragPreview = document.createElement('div');
|
2026-03-13 17:05:08 +08:00
|
|
|
dragPreview.textContent = dragNode.name || '';
|
2026-02-08 15:59:14 +08:00
|
|
|
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);
|
2026-03-13 17:05:08 +08:00
|
|
|
emit('drag-item-start', dragNode, group, isDraggingOver.value, e);
|
|
|
|
|
console.log('开始拖动:', dragNode);
|
2026-02-08 15:59:14 +08:00
|
|
|
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);
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-14 22:35:21 +08:00
|
|
|
|
|
|
|
|
const load = ()=> {
|
|
|
|
|
findPlatformWithComponents(1).then(re=> {
|
|
|
|
|
console.error(re);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-08 15:59:14 +08:00
|
|
|
onMounted(() => {
|
|
|
|
|
loadTress();
|
2026-03-14 22:35:21 +08:00
|
|
|
load();
|
2026-02-08 15:59:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
activeKey,
|
2026-03-14 22:35:21 +08:00
|
|
|
templateData,
|
2026-02-08 15:59:14 +08:00
|
|
|
handleDragStart,
|
|
|
|
|
handleDragEnd,
|
|
|
|
|
};
|
|
|
|
|
},
|
2026-02-08 22:31:13 +08:00
|
|
|
});
|
2026-02-08 15:59:14 +08:00
|
|
|
|
|
|
|
|
</script>
|