diff --git a/offer_frontend/src/components/JobCard.vue b/offer_frontend/src/components/JobCard.vue index 79010fe..182cc0e 100644 --- a/offer_frontend/src/components/JobCard.vue +++ b/offer_frontend/src/components/JobCard.vue @@ -1,6 +1,13 @@ + + diff --git a/offer_frontend/src/views/admin/ApplicationManageView.vue b/offer_frontend/src/views/admin/ApplicationManageView.vue index c377a39..b88f116 100644 --- a/offer_frontend/src/views/admin/ApplicationManageView.vue +++ b/offer_frontend/src/views/admin/ApplicationManageView.vue @@ -135,19 +135,48 @@ function getGenderLabel(gender) { return genderMap[gender] || '-' } -function downloadAttachment() { +async function downloadAttachment() { if (!currentResume.value?.attachment_url) { ElMessage.warning('附件不可用') return } - // 直接通过 media URL 下载(由 Django 代理) - const link = document.createElement('a') - link.href = currentResume.value.attachment_url - link.download = `${currentResume.value.name}_resume.pdf` - document.body.appendChild(link) - link.click() - document.body.removeChild(link) - ElMessage.success('下载已启动') + try { + // 修正 /media/media/ 双重前缀问题 + let url = currentResume.value.attachment_url.replace(/\/media\/media\//, '/media/') + + // 用 fetch+blob 确保触发下载而不是浏览器预览 + const response = await fetch(url) + if (!response.ok) throw new Error('请求失败') + + // 优先用 Content-Type 判断扩展名,避免无扩展名文件名导致乱码 + const contentType = (response.headers.get('content-type') || '').split(';')[0].trim() + const mimeMap = { + 'application/pdf': 'pdf', + 'application/msword': 'doc', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx', + 'image/jpeg': 'jpg', + 'image/png': 'png', + } + let ext = mimeMap[contentType] + if (!ext) { + const urlExt = url.split('.').pop().split('?')[0] + ext = /^[a-zA-Z0-9]{1,5}$/.test(urlExt) ? urlExt : 'pdf' + } + const filename = `${currentResume.value.name}_resume.${ext}` + + const blob = await response.blob() + const blobUrl = URL.createObjectURL(blob) + const link = document.createElement('a') + link.href = blobUrl + link.download = filename + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + URL.revokeObjectURL(blobUrl) + ElMessage.success('下载已启动') + } catch { + ElMessage.error('下载失败,请重试') + } } diff --git a/offer_frontend/src/views/portal/JobDetailView.vue b/offer_frontend/src/views/portal/JobDetailView.vue index 267e3f8..bd552a7 100644 --- a/offer_frontend/src/views/portal/JobDetailView.vue +++ b/offer_frontend/src/views/portal/JobDetailView.vue @@ -132,7 +132,7 @@