Commit 8dd73048 by linjinhong

fix:修改排版下载问题

parent ec5291a4
......@@ -1560,7 +1560,7 @@
</span>
<span class="operate-item">
<ElButton
disabled
:disabled="!row.tiffUrl"
link
type="primary"
@click="handleDownload(row, 'tiff')"
......@@ -3654,50 +3654,176 @@ const downloadTifItem = async () => {
background: 'rgba(0, 0, 0, 0.3)',
})
const type = (typesettingForm.value?.typeArr?.join(',') as string) || ''
const templateWidth =
(typesettingForm.value?.templateWidth as number) || undefined
typesettingVisible.value = false
try {
const res = await composingDesignImages([row.id], type, templateWidth)
const url =
type === 'tiff'
? `https://ps.jomalls.com/tiff/` + res.message
: filePath + res.message
if (type === 'tiff') {
window.open(url, '_blank')
const { templateWidth, typeArr } = typesettingForm.value
const type = typeArr?.join(',') || ''
typesettingVisible.value = false
// 处理下载逻辑
if ((typeArr as string[]).length > 1) {
// 并行处理多个类型
await Promise.allSettled(
(typeArr as string[]).map((el) =>
downloadSingleType(row.id, el, templateWidth),
),
)
} else {
fetch(url)
.then((response) => {
// 确保响应是 OK
if (!response.ok) {
throw new Error('网络响应错误')
}
// 返回图片的二进制数据(Blob)
return response.blob()
})
.then((blob) => {
const a = document.createElement('a')
a.href = window.URL.createObjectURL(blob)
a.target = '_blank'
a.download = (res.message as string).split('/')[
(res.message as string).split('/').length - 1
]
a.click()
pngDownloadLoading.value = false
})
.catch((error) => {
console.error('下载图片时出错:', error)
pngDownloadLoading.value = false
})
// 处理单个类型
await downloadSingleType(row.id, type, templateWidth)
}
} catch (e) {
console.log(e)
} catch (error) {
console.error('下载过程中出错:', error)
} finally {
typesettingRow.value = undefined
loading.close()
}
}
// 提取下载单个类型的逻辑为独立函数
const downloadSingleType = async (
id: number,
type: string,
templateWidth?: number,
) => {
try {
const res = await composingDesignImages([id], type, templateWidth)
const isTiff = type === 'tiff'
const url = isTiff
? `https://ps.jomalls.com/tiff/${res.message}`
: `${filePath}${res.message}`
if (isTiff) {
// 对于tiff类型,直接在新窗口打开
window.open(url, '_blank')
} else {
// 对于其他类型,使用下载方式
await downloadFile(url, res.message as string)
}
} catch (error) {
console.error(`下载类型 ${type} 时出错:`, error)
throw error // 重新抛出错误以便外部捕获
}
}
// 提取文件下载逻辑为独立函数
const downloadFile = async (url: string, message: string) => {
try {
const response = await fetch(url)
const blob = await response.blob()
const filename = message.split('/').pop() || 'download'
// 创建下载链接
const a = document.createElement('a')
a.href = URL.createObjectURL(blob)
a.download = filename
a.target = '_blank'
// 模拟点击下载
document.body.appendChild(a)
a.click()
// 清理
setTimeout(() => {
document.body.removeChild(a)
URL.revokeObjectURL(a.href)
}, 100)
} catch (error) {
console.error('下载文件时出错:', error)
throw error // 重新抛出错误
} finally {
pngDownloadLoading.value = false
}
}
// const downloadTifItem = async () => {
// const row = { ...(typesettingRow.value as PodUsOrderListData) }
// const loading = ElLoading.service({
// fullscreen: true,
// text: '操作中...',
// background: 'rgba(0, 0, 0, 0.3)',
// })
// const { templateWidth, typeArr } = typesettingForm.value
// const type = (typeArr?.join(',') as string) || ''
// typesettingVisible.value = false
// try {
// if ((typeArr as string[]).length > 1) {
// typeArr?.forEach(async (el) => {
// const res = await composingDesignImages([row.id], el, templateWidth)
// const url =
// type === 'tiff'
// ? `https://ps.jomalls.com/tiff/` + res.message
// : filePath + res.message
// if (el === 'tiff') {
// window.open(url, '_blank')
// } else {
// fetch(url)
// .then((response) => {
// // 确保响应是 OK
// if (!response.ok) {
// throw new Error('网络响应错误')
// }
// // 返回图片的二进制数据(Blob)
// return response.blob()
// })
// .then((blob) => {
// const a = document.createElement('a')
// a.href = window.URL.createObjectURL(blob)
// a.target = '_blank'
// a.download = (res.message as string).split('/')[
// (res.message as string).split('/').length - 1
// ]
// a.click()
// pngDownloadLoading.value = false
// })
// .catch((error) => {
// console.error('下载图片时出错:', error)
// pngDownloadLoading.value = false
// })
// }
// })
// } else {
// const res = await composingDesignImages([row.id], type, templateWidth)
// const url =
// type === 'tiff'
// ? `https://ps.jomalls.com/tiff/` + res.message
// : filePath + res.message
// if (type === 'tiff') {
// window.open(url, '_blank')
// } else {
// fetch(url)
// .then((response) => {
// // 确保响应是 OK
// if (!response.ok) {
// throw new Error('网络响应错误')
// }
// // 返回图片的二进制数据(Blob)
// return response.blob()
// })
// .then((blob) => {
// const a = document.createElement('a')
// a.href = window.URL.createObjectURL(blob)
// a.target = '_blank'
// a.download = (res.message as string).split('/')[
// (res.message as string).split('/').length - 1
// ]
// a.click()
// pngDownloadLoading.value = false
// })
// .catch((error) => {
// console.error('下载图片时出错:', error)
// pngDownloadLoading.value = false
// })
// }
// }
// } catch (e) {
// console.log(e)
// } finally {
// typesettingRow.value = undefined
// loading.close()
// }
// }
const loadProductionClient = async () => {
try {
const res = await getProductionClientApi()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment