|
@@ -2,7 +2,7 @@
|
|
|
import { useVueFlow, Position, MarkerType } from "@vue-flow/core"
|
|
|
import { ref, watch } from "vue"
|
|
|
import { ElMessage, ElButton, ElDialog, ElSelect } from "element-plus"
|
|
|
-import { request, getImage } from "@/utils/request"
|
|
|
+import { request, getImage, getImageBase64 } from "@/utils/request"
|
|
|
import emitter from "@/utils/emitter"
|
|
|
import { useProjectStore } from "@/store/project"
|
|
|
import { nextTick } from "vue"
|
|
@@ -11,6 +11,7 @@ import tempic from "@/assets/img/temp.png"
|
|
|
|
|
|
const projectStore = useProjectStore()
|
|
|
let nid = 0
|
|
|
+let imageSer = ""; // 用于存储组件image ID
|
|
|
// 用于计数
|
|
|
let nodecount = 0
|
|
|
let treeobj = ref([])
|
|
@@ -26,12 +27,13 @@ function getId() {
|
|
|
const timestamp = Date.now() // 获取当前时间的毫秒数
|
|
|
return `${nid}${nodecount++}_${timestamp}`
|
|
|
}
|
|
|
-function imagefun() {
|
|
|
- console.log(nid)
|
|
|
+async function imagefun() {
|
|
|
+ const imageData = await getImageBase64(imageSer);
|
|
|
return (datas = {
|
|
|
comId: com.comId,
|
|
|
label: com.name,
|
|
|
- image: getImage(com.image) || tempic,
|
|
|
+ image: imageData || tempic,
|
|
|
+ imageIdentify: imageSer,
|
|
|
idCode: com.idCode,
|
|
|
pcId: "",
|
|
|
idCodeser: ""
|
|
@@ -95,6 +97,8 @@ export default function useDragAndDrop() {
|
|
|
if (event.dataTransfer) {
|
|
|
com = data //传递组件数据
|
|
|
nid = data.comId //传递组件ID
|
|
|
+
|
|
|
+ imageSer = data.image //传递组件image ID
|
|
|
event.dataTransfer.setData("application/vueflow", type)
|
|
|
event.dataTransfer.effectAllowed = "move"
|
|
|
}
|
|
@@ -103,7 +107,7 @@ export default function useDragAndDrop() {
|
|
|
//draggedType.value = 'smoothstep'
|
|
|
isDragging.value = true
|
|
|
|
|
|
- document.addEventListener("drop", onDragEnd)
|
|
|
+ // document.addEventListener("drop", onDragEnd)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -128,11 +132,14 @@ export default function useDragAndDrop() {
|
|
|
}
|
|
|
|
|
|
function onDragEnd() {
|
|
|
+
|
|
|
isDragging.value = false
|
|
|
isDragOver.value = false
|
|
|
draggedType.value = null
|
|
|
- nid = ""
|
|
|
- document.removeEventListener("drop", onDragEnd)
|
|
|
+ nid = "";
|
|
|
+ com = {};
|
|
|
+ imageSer = "";
|
|
|
+ // document.removeEventListener("drop", onDragEnd)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -153,7 +160,8 @@ async function onDrop(event) {
|
|
|
|
|
|
const pid = projectStore.pid;
|
|
|
const nodeId = getId();
|
|
|
- const image1 = imagefun();
|
|
|
+
|
|
|
+ const image1 = await imagefun();
|
|
|
const componentName = image1.idCode;
|
|
|
|
|
|
if (!nameCount[componentName]) {
|
|
@@ -195,6 +203,7 @@ async function onDrop(event) {
|
|
|
|
|
|
// 3. 异步获取 pcId 和 idCodeser,并更新节点
|
|
|
try {
|
|
|
+
|
|
|
const { pcId, ser, idCode } = await createComponent(pid, nid);
|
|
|
updateNode(nodeId, (node) => ({
|
|
|
...node,
|
|
@@ -210,6 +219,9 @@ async function onDrop(event) {
|
|
|
ElMessage.error("添加组件失败");
|
|
|
// 如果失败,可以考虑移除节点:
|
|
|
// removeNodes([nodeId]);
|
|
|
+ }finally {
|
|
|
+ // 在 onDrop 完成后调用 onDragEnd
|
|
|
+ onDragEnd();
|
|
|
}
|
|
|
}
|
|
|
return {
|