From 1333a885d1cce82bfca1cd978360f348a5274385 Mon Sep 17 00:00:00 2001 From: "X1627315083@163.com" <1627315083@qq.com> Date: Fri, 13 Mar 2026 15:06:33 +0800 Subject: [PATCH] fix --- .../Canvas/FlowCanvas/flow-canvas.vue | 30 +++------------ src/components/Canvas/FlowCanvas/index.vue | 38 ++++++++++++++++--- .../Canvas/FlowCanvas/manager/NodeManager.ts | 1 + 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/components/Canvas/FlowCanvas/flow-canvas.vue b/src/components/Canvas/FlowCanvas/flow-canvas.vue index 387f808..456db4d 100644 --- a/src/components/Canvas/FlowCanvas/flow-canvas.vue +++ b/src/components/Canvas/FlowCanvas/flow-canvas.vue @@ -78,8 +78,6 @@ import card from './components/nodes/cards/index.vue' import text from './components/nodes/text.vue' - // 接口 - import { getSketchFlowCanvas, putSketchFlowCanvas } from '@/api/flow-canvas' const components = { [NODE_COMPONENT.RESULT_IMAGE]: resultImage, [NODE_COMPONENT.CARD]: card, @@ -100,6 +98,7 @@ default: () => ({}) } }) + const emit = defineEmits(['exportFlow']) const vueFlow = ref() const nodeTypes = ref([NODE_TYPE.INPUT, NODE_TYPE.SECONDARY, NODE_TYPE.OUTPUT, NODE_TYPE.ALONE]) @@ -146,6 +145,7 @@ const { layout } = useLayout() const index = ref(0) async function layoutGraph(direction) { + if(props.config.json > 0)return if (index.value > 0) return index.value++ setTimeout(() => { @@ -190,15 +190,7 @@ // flowManager.exportFlow() const str = JSON.stringify(stateManager.nodes.value) - const json = JSON.parse(str) - putSketchFlowCanvas({ - id: props.config.imgId, - canvasData: str - }).then((res) => { - if (res) { - console.log(res) - } - }) + emit('exportFlow', str) // localStorage.setItem('flow_json', str) } // 导入流程 @@ -229,19 +221,9 @@ onMounted(async () => { // window['vueFlow'] = vueFlow // window['nodes'] = nodes - let json = [] - await new Promise((resolve) => { - getSketchFlowCanvas({ id: props.config.imgId }).then((res:any) => { - if (res) { - json = JSON.parse(res) - } - resolve(true) - }).catch(() => { - resolve(true) - }) - }) - if(json.length > 0){ - importFlow(json) + + if(props.config.json.length > 0){ + importFlow(props.config.json) }else{ const timestamp = Date.now() nodeManager.createResultNode({ diff --git a/src/components/Canvas/FlowCanvas/index.vue b/src/components/Canvas/FlowCanvas/index.vue index be86005..744fb80 100644 --- a/src/components/Canvas/FlowCanvas/index.vue +++ b/src/components/Canvas/FlowCanvas/index.vue @@ -1,6 +1,6 @@ @@ -8,18 +8,46 @@ import FullscreenDialog from '../components/fullscreen-dialog.vue' import flowCanvas from './flow-canvas.vue' import { ref } from 'vue' + import { getSketchFlowCanvas, putSketchFlowCanvas } from '@/api/flow-canvas' + const dialogVisible = ref(false) - const config = ref({}) - const open = (options) => { - dialogVisible.value = true + const config = ref({}) as any + const open = async (options) => { + let json = [] + await new Promise((resolve) => { + getSketchFlowCanvas({ id: options.imgId }).then((res:any) => { + if (res) { + json = JSON.parse(res) + } + resolve(true) + }).catch(() => { + resolve(true) + }) + }) config.value = options || {} + config.value.json = json + dialogVisible.value = true } + const exportFlow = async (str) => { + if(!config.value.imgId)return + await new Promise((resolve) => { + putSketchFlowCanvas({ + id: config.value.imgId, + canvasData: str }).then(() => { + resolve(true) + }).catch(() => { + resolve(true) + }) + }) + } + const close = () => { dialogVisible.value = false } defineExpose({ open, - close + close, + exportFlow })