fix
This commit is contained in:
@@ -81,6 +81,7 @@
|
||||
import resultImage from './components/nodes/result-image.vue'
|
||||
import card from './components/nodes/cards/index.vue'
|
||||
import text from './components/nodes/text.vue'
|
||||
import { downImgListToZip } from '../tools/tools'
|
||||
|
||||
const components = {
|
||||
[NODE_COMPONENT.RESULT_IMAGE]: resultImage,
|
||||
@@ -194,8 +195,19 @@
|
||||
return JSON.stringify(stateManager.nodes.value)
|
||||
}
|
||||
const exportFlow = () => {
|
||||
console.log(vueFlow.value)
|
||||
console.log(vueFlow.value.toImage)
|
||||
// console.log(vueFlow.value)
|
||||
// console.log(vueFlow.value.toImage)
|
||||
let arr = stateManager.nodes.value.filter((v) => v.data.type === NODE_COMPONENT.RESULT_IMAGE)
|
||||
let imgList = []
|
||||
arr.forEach((v) => {
|
||||
v.data.data.imageProcessTasks.forEach((item,index) => {
|
||||
let url = item.url
|
||||
let name = url?.split(".").pop().split("?").shift();
|
||||
imgList.push({url:url,name:`${v.data.type}${index == 0?'':index}.${name}`})
|
||||
})
|
||||
})
|
||||
downImgListToZip(imgList)
|
||||
console.log(imgList)
|
||||
return
|
||||
// flowManager.exportFlow()
|
||||
const str = getFlowJson()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import JSZip from 'jszip'
|
||||
export const createId = (before: string = 'node') => {
|
||||
const time = Date.now().toString(36)
|
||||
const random = Math.random().toString(36).substring(2, 20)
|
||||
@@ -15,4 +16,47 @@ export const downloadImage = (url: string, name: string) => {
|
||||
a.download = name || 'image.png'
|
||||
a.click()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/** 批量下载图片 */
|
||||
export const downImgListToZip = async (imagesParams) => {
|
||||
const zip = new JSZip()
|
||||
const promises = []
|
||||
// 遍历下载每个图片
|
||||
imagesParams.forEach((img, index) => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest()
|
||||
xhr.open('GET', img.url, true)
|
||||
xhr.responseType = "blob";
|
||||
xhr.onload = () => {
|
||||
if (xhr.status === 200) {
|
||||
const fileName = img.name
|
||||
zip.file(fileName, xhr.response)
|
||||
resolve('')
|
||||
} else {
|
||||
reject(new Error(`下载失败: ${img.url}`))
|
||||
}
|
||||
}
|
||||
|
||||
xhr.onerror = () => reject(new Error(`网络错误: ${img.url}`))
|
||||
xhr.send()
|
||||
})
|
||||
|
||||
promises.push(promise)
|
||||
console.log(promises,zip)
|
||||
})
|
||||
|
||||
// 等待所有图片下载完成
|
||||
Promise.all(promises)
|
||||
.then(() => zip.generateAsync({ type: 'blob' }))
|
||||
.then((content) => {
|
||||
// 下载zip
|
||||
console.log(content)
|
||||
const link = document.createElement('a')
|
||||
link.href = URL.createObjectURL(content)
|
||||
link.download = 'DesignFiles'
|
||||
link.click()
|
||||
URL.revokeObjectURL(link.href)
|
||||
})
|
||||
.catch((error) => console.error('下载失败:', error))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user