From 54230b6cfd7527addfaaa87892e81102174e2c90 Mon Sep 17 00:00:00 2001 From: TianyangZhang Date: Wed, 25 Mar 2026 16:38:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(admin):=20=E7=AE=80=E5=8C=96=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E8=BD=BD=EF=BC=8C=E7=9B=B4=E6=8E=A5=E4=BD=BF?= =?UTF-8?q?=E7=94=A8Django=E5=AA=92=E4=BD=93=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- offer_backend/apps/applications/views.py | 22 ------------ .../src/views/admin/ApplicationManageView.vue | 34 ++++++------------- 2 files changed, 11 insertions(+), 45 deletions(-) diff --git a/offer_backend/apps/applications/views.py b/offer_backend/apps/applications/views.py index b878f41..17deb93 100644 --- a/offer_backend/apps/applications/views.py +++ b/offer_backend/apps/applications/views.py @@ -1,7 +1,4 @@ from rest_framework import generics, viewsets -from rest_framework.response import Response -from rest_framework.decorators import action -from django.http import FileResponse from .models import Application from .serializers import ApplicationCreateSerializer, ApplicationSerializer, ApplicationStatusSerializer from .emails import notify_status_change @@ -31,25 +28,6 @@ class ApplicationManageViewSet(viewsets.ReadOnlyModelViewSet): job__organization=user.organization ).select_related('job__organization', 'applicant') - @action(detail=True, methods=['get']) - def download_resume(self, request, pk=None): - """下载求职者的简历附件""" - application = self.get_object() - attachment_url = application.resume_snapshot.get('attachment_url') - - if not attachment_url: - return Response({'detail': '附件不可用'}, status=404) - - try: - from django.core.files.storage import default_storage - # 获取文件 - file = default_storage.open(attachment_url.lstrip('/media/'), 'rb') - response = FileResponse(file) - response['Content-Type'] = 'application/octet-stream' - response['Content-Disposition'] = f'attachment; filename="{application.resume_snapshot.get("name", "resume")}.pdf"' - return response - except Exception as e: - return Response({'detail': f'下载失败: {str(e)}'}, status=400) class ApplicationStatusUpdateView(generics.UpdateAPIView): serializer_class = ApplicationStatusSerializer diff --git a/offer_frontend/src/views/admin/ApplicationManageView.vue b/offer_frontend/src/views/admin/ApplicationManageView.vue index 4fc373f..c377a39 100644 --- a/offer_frontend/src/views/admin/ApplicationManageView.vue +++ b/offer_frontend/src/views/admin/ApplicationManageView.vue @@ -104,7 +104,6 @@ const applications = ref([]) const loading = ref(false) const resumeVisible = ref(false) const currentResume = ref(null) -const currentApplicationId = ref(null) const genderMap = { 'male': '男', @@ -129,7 +128,6 @@ async function updateStatus(row) { function viewResume(row) { currentResume.value = row.resume_snapshot - currentApplicationId.value = row.id resumeVisible.value = true } @@ -137,29 +135,19 @@ function getGenderLabel(gender) { return genderMap[gender] || '-' } -async function downloadAttachment() { - if (!currentApplicationId.value) { - ElMessage.warning('无法获取投递记录') +function downloadAttachment() { + if (!currentResume.value?.attachment_url) { + ElMessage.warning('附件不可用') return } - try { - const response = await fetch(`/api/applications/manage/${currentApplicationId.value}/download_resume/`) - if (!response.ok) throw new Error('下载失败') - - const blob = await response.blob() - const url = window.URL.createObjectURL(blob) - const link = document.createElement('a') - link.href = url - link.download = `${currentResume.value.name}_resume.pdf` - document.body.appendChild(link) - link.click() - document.body.removeChild(link) - window.URL.revokeObjectURL(url) - ElMessage.success('下载已启动') - } catch (e) { - ElMessage.error('下载失败,请重试') - console.error(e) - } + // 直接通过 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('下载已启动') }