在historylist页面的ActionPanel中添加批量下载按钮,实现诊断报告的批量下载功能。支持按日期查询、多选报告、分页显示、进度提示,适配Electron、Cordova、浏览器三端。
src/pages/patient/components/ActionPanel.tsx 中提供一个批量下载按钮getReportList(params: ReportQueryParams)
POST /dr/api/v1/auth/report{start_time?, end_time?, page?, page_size?}ReportListResponsedownloadReportXlsx(params: {start_time, end_time})
GET /dr/api/v1/auth/report/xls{start_time: string, end_time: string} (查询参数)Blob (XLSX文件)fetchDiagnosisReportContent(studyId: string)
GET /dr/api/v1/auth/study/{id}/report_contentReportContentResponsedownloadDiagnosisReportPdf(studyId: string)
GET /dr/api/v1/auth/study/{id}/reportBlob (PDF文件)ActionPanel (入口)
↓
DiagnosticReportBatchDownloadModal (UI容器)
↓
├── DateRangePicker (日期选择)
├── DownloadProgress (下载进度)
└── DiagnosticReportBatchDownloadService (业务逻辑)
↓
├── DateRangeCalculator (日期范围计算)
└── DownloadManager (跨平台下载)
interface DiagnosticReportBatchDownloadState {
modalVisible: boolean;
downloading: boolean;
progress: number;
error?: string;
startTime?: string;
endTime?: string;
}
src/components/DiagnosticReportBatchDownloadModal.tsx - 诊断报告批量下载Modal组件src/states/patient/diagnosticReportBatchDownloadSlice.ts - Redux状态管理src/services/diagnosticReportBatchDownloadService.ts - 诊断报告批量下载业务逻辑src/utils/dateRangeValidator.ts - 日期范围验证工具src/types/diagnosticReportBatchDownload.ts - 诊断报告批量下载类型定义src/pages/patient/components/ActionPanel.tsx - 添加诊断报告批量下载按钮和Modal触发src/API/report/ReportActions.ts - 确保downloadReportXlsx API导出正确src/states/store.ts - 添加diagnosticReportBatchDownload reducersequenceDiagram
participant U as 用户
participant AP as ActionPanel
participant MODAL as DiagnosticReportBatchDownloadModal
participant DRBS as DiagnosticReportBatchDownloadService
participant RS as Redux Store
participant AS as API Service
participant DM as DownloadManager
U->>AP: 点击诊断报告批量下载按钮
AP->>MODAL: 打开Modal
MODAL->>RS: 设置modalVisible=true
U->>MODAL: 选择开始时间和结束时间
MODAL->>RS: 更新日期范围
U->>MODAL: 点击下载按钮
MODAL->>DRBS: 调用批量下载服务
DRBS->>AS: 调用downloadReportXlsx API
AS-->>DRBS: 返回XLSX数据
DRBS->>DM: 调用downloadManager下载
DM-->>DRBS: 下载进度更新
DRBS->>RS: 更新下载进度
RS-->>MODAL: 显示进度状态
DM-->>DRBS: 下载完成
DRBS->>RS: 下载完成
RS-->>MODAL: 显示完成提示
MODAL->>RS: 设置modalVisible=false
flowchart TD
A[用户进入historylist页面] --> B{点击诊断报告批量下载按钮?}
B -->|是| C[打开批量下载Modal]
B -->|否| A
C --> D[显示默认日期范围]
D --> E{用户修改日期范围?}
E -->|是| F[更新日期范围]
E -->|否| G{点击下载按钮?}
F --> G
G -->|是| H[验证日期范围]
G -->|否| D
H --> I{日期范围有效?}
I -->|否| J[显示日期错误提示]
I -->|是| K[调用downloadReportXlsx API]
J --> D
K --> L{API成功?}
L -->|是| M[显示下载进度]
L -->|否| N[显示下载失败]
M --> O[调用downloadManager下载]
O --> P{下载成功?}
P -->|是| Q[显示成功提示]
P -->|否| R[显示失败提示]
Q --> S[关闭Modal]
R --> D
N --> D
S --> A
classDiagram
class ActionPanel {
+handleDiagnosticReportBatchDownload()
+render()
}
class DiagnosticReportBatchDownloadModal {
+handleDateRangeChange()
+handleDownload()
+render()
}
class DiagnosticReportBatchDownloadService {
+downloadReports(dateRange)
}
class DateRangeValidator {
+validateRange(range)
}
class DownloadManager {
+download(options)
}
class DiagnosticReportBatchDownloadSlice {
+setModalVisible()
+setDownloading()
+setProgress()
+setError()
+setDateRange()
}
ActionPanel --> DiagnosticReportBatchDownloadModal
DiagnosticReportBatchDownloadModal --> DiagnosticReportBatchDownloadService
DiagnosticReportBatchDownloadModal --> DateRangeValidator
DiagnosticReportBatchDownloadModal --> DiagnosticReportBatchDownloadSlice
DiagnosticReportBatchDownloadService --> DownloadManager
DiagnosticReportBatchDownloadService --> DiagnosticReportBatchDownloadSlice
DiagnosticReportBatchDownloadService --> API
用户 ActionPanel DiagnosticReportBatchDownloadModal DiagnosticReportBatchDownloadService Redux Store API Service DownloadManager
| | | | | | |
|---点击诊断报告批量下载按钮------->| | | | | |
| |---打开Modal------------>| | | | |
| | |---设置modalVisible=true| | | |
| | | |---更新modal状态----->| | |
| | |<-----------------------|<--------------------| |
| | |---显示Modal------------>| | | |
| | | | | | |
|---选择日期范围---------->| | | | | |
| | |---更新日期范围-------->| | | |
| | | |---保存日期范围------>| | |
| | |<-----------------------|<--------------------| |
| | | | | | |
|---点击下载按钮---------->| | | | | |
| | |---调用批量下载服务---->| | | |
| | | |---调用downloadReportXlsx| | |
| | | | |---API调用---------->| |
| | | | |<--------------------| |
| | | |<--------------------|---返回XLSX数据----->| |
| | | |---调用downloadManager| | |
| | | | | |---开始下载--------->|
| | | | | | |---文件保存|
| | | | | |<--------------------|<--------|
| | | |<--------------------|---更新下载进度----->| |
| | |---显示下载进度-------->| | | |
| | | | | | |
| | |<-----------------------|---下载完成---------->| |
| | |---显示完成提示-------->| | | |
| | |---关闭Modal------------>| | | |
| | | |---设置modalVisible=false| | |
选中study列表 → DateRangeCalculator → 日期范围 → downloadReportXlsx API → XLSX数据 → DownloadManager → 文件保存
↓
进度更新 → Redux Store → ActionPanel显示
用户操作 → ActionPanel → BatchDownloadService → Redux Store → UI状态更新
// 日期范围
interface DateRange {
start_time: string;
end_time: string;
}
// 诊断报告批量下载状态
interface DiagnosticReportBatchDownloadState {
downloading: boolean;
progress: number;
error?: string;
startTime?: string;
endTime?: string;
}
// Study数据结构(简化)
interface StudyItem {
StudyID: string;
StudyDate?: string;
StudyTime?: string;
}
DownloadOptions: 下载选项DownloadResult: 下载结果ReportQueryParams: 报告查询参数(用于API调用)用户在historylist页面的ActionPanel中点击批量下载按钮
正常下载流程
边界情况测试
异常情况测试
跨平台测试
大文件下载: XLSX文件可能很大,需要考虑内存使用
网络超时: 长列表查询或大文件下载可能超时
并发下载: 用户可能同时下载多个文件
权限问题: 不同平台的文件写入权限
API错误: 后端服务异常
网络中断: 下载过程中网络断开
磁盘空间不足: 下载目录空间不足
文件名冲突: 同名文件已存在
src/states/patient/diagnosticReportBatchDownloadSlice.tssrc/services/diagnosticReportBatchDownloadService.tssrc/utils/dateRangeCalculator.tssrc/types/diagnosticReportBatchDownload.tssrc/pages/patient/components/ActionPanel.tsx这个文档提供了完整的实现思路和详细的技术方案,为后续开发提供了清晰的指导。