画布删除最后一张图更新版本图

This commit is contained in:
X1627315083@163.com
2026-04-20 11:10:58 +08:00
parent 8cc83ae12b
commit d4d9c2eede
7 changed files with 49 additions and 6 deletions

View File

@@ -59,6 +59,10 @@
updateVersionSketchUrlApi({
sketchId: stateManager.sketchId.value,
newUrl: options.url,
}).then(()=>{
//更新VersionNode的versionImgUpdataList中指定key的URL值
let initialNode = stateManager.getInitialNode()
initialNode.data.versionImgUpdataList.push(options.url)
})
},
}

View File

@@ -230,6 +230,10 @@
updateVersionSketchUrlApi({
sketchId: stateManager.sketchId.value,
newUrl: options.url,
}).then(()=>{
//更新VersionNode的versionImgUpdataList中指定key的URL值
let initialNode = stateManager.getInitialNode()
initialNode.data.versionImgUpdataList.push(options.url)
})
},
onClose:depthCanvasClose

View File

@@ -289,6 +289,7 @@
const timestamp = Date.now()
nodeManager.createResultNode({
data: {
versionImgUpdataList:[props.config.url],
disableDelete: true,
isHeader: false,
data: {
@@ -307,6 +308,9 @@
})
}
})
const putFlowJson = async () => {
await stateManager.exportFlow(0,true)
}
onBeforeUnmount(() => {
stateManager.dispose()
eventManager.dispose()
@@ -315,7 +319,8 @@
toolManager.dispose()
})
defineExpose({
getFlowJson
getFlowJson,
putFlowJson
})
</script>
<style lang="less">

View File

@@ -33,6 +33,7 @@
dialogVisible.value = true
}
const close = async () => {
await flowCanvasRef.value?.putFlowJson()
dialogVisible.value = false
myEvent.emit('closeFlowCanvas')
}

View File

@@ -55,11 +55,14 @@ export class GenerateManager {
nodeDataItem.url = item.url
nodeDataItem.createTime = item.createTime
nodeDataItem.status = item.status
//更新VersionNode的sketchIDAndUrl中指定key的URL值
updateVersionSketchUrlApi({
sketchId: this.stateManager.sketchId.value,
newUrl: item.url,
}).then(()=>{
//更新VersionNode的versionImgUpdataList中指定key的URL值
let initialNode = this.stateManager.getInitialNode()
initialNode.data.versionImgUpdataList.push(item.url)
})
if(item.glbPath){
nodeDataItem.glbPath = item.glbPath

View File

@@ -14,6 +14,7 @@ interface NodeData {
disableCopy?: boolean// 是否禁用复制
createIndexPosition?: number// 创建索引位置
isActive?: boolean// 是否激活
versionImgUpdataList?: Array<any>// 版本节点
}
interface NodeOptions {
id?: string
@@ -98,7 +99,6 @@ export class NodeManager {
}
/** 创建结果节点 */
createResultNode(options?: NodeOptions) {
console.log(options)
const options_ = {
...(options ? options : {}),
component: NODE_COMPONENT.RESULT_IMAGE,

View File

@@ -4,6 +4,7 @@ import { ElMessageBox } from 'element-plus'
import i18n from '@/lang'
import { putSketchFlowCanvas } from '@/api/flow-canvas'
import myEvent from '@/utils/myEvent'
import { updateVersionSketchUrlApi } from '@/api/flow-canvas'
const t = i18n.global.t
@@ -161,6 +162,8 @@ export class StateManager {
this.nodes.value = this.nodes.value.filter((node: NodesItem) => node.id !== id)
}
/** 获取初始节点 */
getInitialNode() { return this.nodes.value.find((node: NodesItem) => node?.data?.versionImgUpdataList) }
/** 获取节点 */
getNodeById(id: string) { return this.nodes.value.find((node: NodesItem) => node.id === id) }
/** 获取下级节点 */
@@ -186,12 +189,19 @@ export class StateManager {
if (node.data.disableDelete) return ElMessage.error(t('FlowCanvas.initialNodeProhibited'))
const result = [node]
const deleteVersionImgUpdataList = []
node.data.data?.imageProcessTasks?.forEach((item) =>{
deleteVersionImgUpdataList.push(item.url)
})
const findChildren = (parentId: string) => {
const children = this.nodes.value.filter(item => item.data.superiorID === parentId)
children.forEach(child => {
if(child.data.type !== NODE_DATATYPE.RESULT_IMAGE){
result.push(child)
console.log(child)
child.data.data?.imageProcessTasks?.forEach((item) =>{
deleteVersionImgUpdataList.push(item.url)
})
}
findChildren(child.id)
})
@@ -215,6 +225,22 @@ export class StateManager {
}
if(!deletePromise) return console.log('删除操作被取消')
// 删除如果是最后一张图需要更新版本图url
let initialNode = this.getInitialNode()
let updataListIndex
let isUpdataEndUrl = false
deleteVersionImgUpdataList?.forEach((item) => {
updataListIndex = initialNode.data.versionImgUpdataList.indexOf(item)
if(updataListIndex == (initialNode.data.versionImgUpdataList.length - 1))isUpdataEndUrl = true
if(initialNode.data.versionImgUpdataList.length > 1)initialNode.data.versionImgUpdataList = initialNode.data.versionImgUpdataList.filter((v) => v !== item)
})
if(isUpdataEndUrl){
updateVersionSketchUrlApi({
sketchId: this.sketchId.value,
newUrl: initialNode.data.versionImgUpdataList[initialNode.data.versionImgUpdataList.length - 1],
})
}
if(node.data.data?.imageProcessTasks?.length > 1){
node.data.data.imageProcessTasks = node.data.data.imageProcessTasks.filter((item) => item.taskId !== node.data.data.selectTaskId)
return
@@ -263,7 +289,7 @@ export class StateManager {
this.historyIndex.value = this.historyList.value.length - 1
}
/** 画布数据存储 */
async exportFlow (time:number = 0){
async exportFlow (time:number = 0,loading:boolean = false){
if(!this.sketchId.value)return
clearTimeout(this.saveCanvasTime)
await new Promise((resolve) => {
@@ -272,7 +298,7 @@ export class StateManager {
id: this.sketchId.value,
canvasData: JSON.stringify(this.nodes.value) }).then(() => {
resolve(true)
}).catch(() => {
},loading).catch(() => {
resolve(true)
})
},time)