| | |
| | | catalogResourceName: fieldRules(true), |
| | | objectionDesc: fieldRules(true), |
| | | objectionBasis: fieldRules(true), |
| | | // attachId: dialogMode.value === 'add' ? fieldRules(true) : fieldRules(false) |
| | | attachId: fieldRules(true) |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | // 提交数据的通用函数 |
| | | async function submitForm(objectionStatus) { |
| | | formData.value.attachId = uploadedFiles.value.length > 0 ? uploadedFiles.value.length : '' |
| | | const isValid = await formRef.value?.validate().catch(() => false) |
| | | if (!isValid) return |
| | | |
| | |
| | | attachmentDetailsList.value = results.map(res => res.data.data).filter(Boolean) |
| | | } |
| | | // 处理附件下载 |
| | | async function handleDownloadAttach() { |
| | | if (attachmentDetailsList.value.length === 0) { |
| | | ElMessage.warning('没有可下载的附件') |
| | | return |
| | | } |
| | | const handleDownloadAttach = async () => { |
| | | if (!attachmentDetailsList.value || attachmentDetailsList.value.length === 0) { |
| | | ElMessage.warning('没有可下载的附件') |
| | | return |
| | | } |
| | | |
| | | // 遍历所有附件并下载 |
| | | attachmentDetailsList.value.forEach(attach => { |
| | | if (attach.link) { |
| | | const link = document.createElement('a') |
| | | link.href = attach.link |
| | | link.download = attach.originalName || attach.name |
| | | link.style.display = 'none' |
| | | document.body.appendChild(link) |
| | | link.click() |
| | | document.body.removeChild(link) |
| | | } |
| | | }) |
| | | |
| | | // 顺序下载每个附件 |
| | | for (let i = 0; i < attachmentDetailsList.value.length; i++) { |
| | | const attach = attachmentDetailsList.value[i] |
| | | |
| | | if (!attach.link) { |
| | | console.warn(`附件 ${attach.originalName || attach.name} 链接无效,跳过`) |
| | | continue |
| | | } |
| | | |
| | | try { |
| | | // 显示当前下载的文件信息 |
| | | const currentFileName = attach.originalName || attach.name || `附件_${i + 1}` |
| | | |
| | | |
| | | const response = await fetch(attach.link) |
| | | const blob = await response.blob() |
| | | const url = window.URL.createObjectURL(blob) |
| | | const a = document.createElement('a') |
| | | a.href = url |
| | | |
| | | // 设置文件名:优先使用 originalName |
| | | let fileName = attach.originalName || attach.name || `附件_${i + 1}` |
| | | |
| | | // 确保有扩展名 |
| | | if (fileName && !fileName.includes('.')) { |
| | | const contentType = response.headers.get('content-type') |
| | | if (contentType && contentType.includes('zip')) { |
| | | fileName += '.zip' |
| | | } else if (contentType && contentType.includes('rar')) { |
| | | fileName += '.rar' |
| | | } else { |
| | | fileName += '.zip' |
| | | } |
| | | } |
| | | |
| | | a.download = fileName |
| | | a.style.display = 'none' |
| | | document.body.appendChild(a) |
| | | a.click() |
| | | |
| | | // 清理 |
| | | setTimeout(() => { |
| | | window.URL.revokeObjectURL(url) |
| | | document.body.removeChild(a) |
| | | }, 100) |
| | | |
| | | // 文件间延迟(除了最后一个) |
| | | if (i < attachmentDetailsList.value.length - 1) { |
| | | await new Promise(resolve => setTimeout(resolve, 1000)) |
| | | } |
| | | |
| | | } catch (error) { |
| | | console.error(`下载失败: ${attach.originalName || attach.name}`, error) |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |