吉安感知网项目-前端
罗广辉
2026-01-29 156aa12e43f3ffb6f45b70d9ffb9473475e1a35f
Merge remote-tracking branch 'origin/master'
1 files modified
102 ■■■■■ changed files
applications/task-work-order/src/views/orderView/orderManage/inspectionReport/index.vue 102 ●●●●● patch | view | raw | blame | history
applications/task-work-order/src/views/orderView/orderManage/inspectionReport/index.vue
@@ -306,48 +306,68 @@
let loadingData
// 文档下载
async function handleDownload() {
    // 如果是勾选一个可以直接下载,超过一个打包下载
    // 依次下载每个文件(添加延迟以避免浏览器限制)
    if (selectedFiles.value.length === 0) {
        ElMessage.warning('请选择要下载的文件')
        return
    }
    if (selectedFiles.value.length === 1) {
        selectedFiles.value.forEach((file, index) => {
            // setTimeout(() => {
            if (file.link) {
                const a = document.createElement('a')
                a.href = file.link
                a.download = file.originalName || `attachment_${index + 1}`
                document.body.appendChild(a)
                a.click()
                document.body.removeChild(a)
            }
            // }, index * 300) // 300ms delay between downloads
        })
    } else {
        // 批量下载
        try {
            loadingData = ElLoading.service({ background: 'rgba(0, 0, 0, 0.5)', text: '打包中,请稍等...' })
            const fileIds = selectedFiles.value.map(i => i.id).join(',')
            // const res = await getDownloadStatusApi({ type: 'dpsjzx' })
            // if (!['CANCELLED', 'COMPLETED'].includes(res.data.data?.status || 'COMPLETED')) {
            //     return ElMessage.warning('还有正在处理的')
            // }
            await fjDownloadByByteApi({ attachIds: fileIds }).then(res => {
                if (res.data.code === 200) {
                    ElMessage.success('下载成功')
                } else {
                    ElMessage.error(res.msg || '下载失败')
                }
            })
        } catch (e) {
        } finally {
            loadingData.close()
        }
    }
    if (selectedFiles.value.length === 0) {
        ElMessage.warning('请选择要下载的文件')
        return
    }
    selectedFiles.value.forEach((file, index) => {
        setTimeout(() => {
            if (file.link) {
                // 检查链接是否可能返回 XML
                if (file.link.includes('.xml') || file.link.includes('error') || file.link.includes('exception')) {
                    ElMessage.error(`文件 ${file.originalName} 的链接可能无效`)
                    return
                }
                // 尝试使用 fetch 检查链接是否有效
                fetch(file.link, { method: 'HEAD' })
                    .then(response => {
                        if (response.ok) {
                            const contentType = response.headers.get('content-type')
                            if (contentType && contentType.includes('xml')) {
                                ElMessage.error(`文件 ${file.originalName} 的链接返回 XML 内容,可能无效`)
                                return
                            }
                            // 执行下载
                            const a = document.createElement('a')
                            a.href = file.link
                            a.download = file.originalName || `attachment_${index + 1}`
                            document.body.appendChild(a)
                            a.click()
                            document.body.removeChild(a)
                        } else {
                            ElMessage.error(`文件 ${file.originalName} 的链接无效,状态码:${response.status}`)
                        }
                    })
                    .catch(error => {
                        ElMessage.error(`文件 ${file.originalName} 的链接错误:${error.message}`)
                    })
            }
        }, index * 300) // 300ms delay between downloads
    })
}
// async function handleDownload() {
//     if (selectedFiles.value.length === 0) {
//         ElMessage.warning('请选择要下载的文件')
//         return
//     }
//     console.log(selectedFiles.value, '999')
//     selectedFiles.value.forEach((file, index) => {
//         setTimeout(() => {
//             if (file.link) {
//                 const a = document.createElement('a')
//                 a.href = file.link
//                 a.download = file.originalName || `attachment_${index + 1}`
//                 document.body.appendChild(a)
//                 a.click()
//                 document.body.removeChild(a)
//             }
//         }, index * 300) // 300ms delay between downloads
//     })
// }
// 文档上传
async function handleUpload() {