diff --git a/public/HRV-report.html b/public/HRV-report.html index 10dd7bb..e9d7c4d 100644 --- a/public/HRV-report.html +++ b/public/HRV-report.html @@ -520,6 +520,9 @@ // 页面加载完成后初始化 window.addEventListener('load', function() { + // 清理缓存 + sessionStorage.removeItem('hrvReportData'); + // 从sessionStorage中获取数据 const storedData = sessionStorage.getItem('hrvReportData'); let data = null; diff --git a/src/api/hrv/index.ts b/src/api/hrv/index.ts index 7da7f6f..665c3ab 100644 --- a/src/api/hrv/index.ts +++ b/src/api/hrv/index.ts @@ -62,5 +62,12 @@ export const HrvApi = { return await request.post({ url: `/system/hrv/apply-superior-review?id=` + id + '&orgid=' + orgid }) + }, + + // 处理HRV分析 + processHrv: async (examid: string) => { + return await request.get({ + url: `https://58.57.172.62:6042/api/file/process-hrv?examid=${examid}` + }) } } diff --git a/src/views/analysis/HRV.vue b/src/views/analysis/HRV.vue index 21ec60a..8fce333 100644 --- a/src/views/analysis/HRV.vue +++ b/src/views/analysis/HRV.vue @@ -150,28 +150,17 @@ - + - - - - - - - + { return } - const loading = ElLoading.service({ - lock: true, - text: '正在获取检查数据...', - background: 'rgba(0, 0, 0, 0.7)' - }) + // 调用HRV分析接口 + const response = await HrvApi.processHrv(examid) - try { - // 根据examid查询自主神经系统平衡检查数据 - const res = await HrvdataApi.getHrvdataPage({ examid: examid, pageNo: 1, pageSize: 1 }) - if (res && res.list && res.list.length > 0) { - const hrvData = res.list[0] - console.log('获取到的HRV数据:', hrvData) - - // 打开报告页面并传递数据 - openHrvReport(hrvData, row) - ElMessage.success('数据获取成功,正在生成报告') - } else { - ElMessage.warning('未找到相关检查数据') - } - } finally { - loading.close() + if (response) { + ElMessage.success('分析请求已发送,请稍后查看报告!') + } else { + ElMessage.error('分析请求失败,请稍后重试') } } catch (error) { console.error('分析过程中出错:', error) @@ -1277,58 +1230,87 @@ const confirmFileSelect = async (file?: any) => { } } - console.log('最终文件路径:', finalFilePath) - // 显示加载提示 const loading = ElLoading.service({ lock: true, - text: `正在处理文件 ${targetFile.name}...`, + text: `正在处理... 0%`, background: 'rgba(0, 0, 0, 0.8)', customClass: 'upload-loading' }) + // 模拟进度条更新(虚假进度) + let fakeProgress = 0 + const progressInterval = setInterval(() => { + fakeProgress += Math.random() * 15 + 5 // 随机增加5-20的进度 + if (fakeProgress > 90) fakeProgress = 90 // 最多到90%,等待真实结果 + loading.setText(`正在处理... ${Math.floor(fakeProgress)}%`) + }, 300) + try { - // 调用移动文件接口 - const response = await fetch('http://localhost:48082/api/movefile-json', { + // 通过后端API读取文件内容 + const fileResponse = await fetch('http://localhost:48082/api/readfile', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - filePath: finalFilePath, - examId: currentRow.value.examid + filePath: finalFilePath }) }) - - if (!response.ok) { - const errorText = await response.text() - console.error('服务器响应:', errorText) - throw new Error(`HTTP error! status: ${response.status}, message: ${errorText}`) + const fileData = await fileResponse.json() + if (!fileData.success) { + throw new Error(fileData.message || '读取文件失败') } - const result = await response.json() - console.log('服务器返回结果:', result) + // 将base64转换为blob + const binaryString = atob(fileData.data) + const bytes = new Uint8Array(binaryString.length) + for (let i = 0; i < binaryString.length; i++) { + bytes[i] = binaryString.charCodeAt(i) + } + const blob = new Blob([bytes]) + const file = new File([blob], `${currentRow.value.examid}`) - if (result.success) { - // 更新心电图的文件名称 - console.log(currentRow.value) - await HrvApi.updateFilename({ - ...currentRow.value, - filename: result.targetFile - }) + // 调用分片上传 + const uploadResult = await uploadFileInChunks({ + file: file, + url: import.meta.env.VITE_FILE_UPLOAD_URL, + name: `${currentRow.value.examid}.png`, + onProgress: (progress, currentChunk, totalChunks) => { + // 更新按钮上的进度 + if (currentRow.value) currentRow.value.uploadProgress = progress + }, + onError: (error, chunkIndex) => { + console.error(`分片 ${chunkIndex} 上传失败:`, error) + } + }) - ElMessage.success(`文件 ${targetFile.name} 导入成功`) - getList() // 刷新列表 - fileBrowserVisible.value = false + // 清除进度条定时器 + clearInterval(progressInterval) + + if (uploadResult.success) { + // 显示100%完成 + loading.setText('正在处理... 100%') + // 延迟一下让用户看到100% + setTimeout(() => { + loading.close() + ElMessage.success('文件上传成功') + // 关闭文件选择弹窗 + fileBrowserVisible.value = false + // 刷新列表 + getList() + }, 500) } else { - throw new Error(result.message || '文件导入失败') + loading.close() + ElMessage.error(`文件上传失败: ${uploadResult.message}`) } } catch (error) { + // 清除进度条定时器 + clearInterval(progressInterval) + loading.close() console.error('文件导入失败:', error) const errorMessage = error instanceof Error ? error.message : '文件导入失败,请重试' ElMessage.error(`文件导入失败: ${errorMessage}`) - } finally { - loading.close() } } catch (error) { console.error('文件选择处理失败:', error) @@ -1346,109 +1328,78 @@ const cancelFileSelect = () => { searchKeyword.value = '' } -/** 处理上传 */ -const handleUpload = async (row: any) => { +/** 处理文件上传(整合到导入功能中) */ +const handleFileUpload = async (row: any, filePath: string) => { try { - // 显示加载提示 - const loading = ElLoading.service({ - lock: true, - text: '正在进行压缩文件中...', - background: 'rgba(0, 0, 0, 0.8)' - }) + // 设置上传状态 + row.uploading = true + row.uploadProgress = 0 + // 关闭之前的加载提示(如果有的话) + + // 调用上传工具上传文件 try { - // 请求接口检查文件状态 - const response = await fetch( - `http://localhost:48082/api/check-exam-file?examId=${row.examid}` - ) - console.log('检查文件状态:', response) - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`) + // 通过后端API读取文件内容 + const fileResponse = await fetch('http://localhost:48082/api/readfile', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + filePath: filePath + }) + }) + const fileData = await fileResponse.json() + if (!fileData.success) { + throw new Error(fileData.message || '读取文件失败') } - const result = await response.json() - let sipdffile - // 判断success字段 - if (result.success) { - // 判断message字段 - if (result.message === '文件存在') { - // 文件存在,继续往下走 - const fullFilePath = result.fullFilePath - sipdffile = result.isPdfFile - // 设置上传状态 - row.uploading = true - row.uploadProgress = 0 + // 将base64转换为blob + const binaryString = atob(fileData.data) + const bytes = new Uint8Array(binaryString.length) + for (let i = 0; i < binaryString.length; i++) { + bytes[i] = binaryString.charCodeAt(i) + } + const blob = new Blob([bytes]) + const file = new File([blob], `${row.examid}`) - // 关闭之前的加载提示 - loading.close() - - // 调用上传工具上传文件 - try { - // 通过后端API读取文件内容 - const fileResponse = await fetch('http://localhost:48082/api/readfile', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - filePath: fullFilePath - }) - }) - const fileData = await fileResponse.json() - if (!fileData.success) { - throw new Error(fileData.message || '读取文件失败') - } - - // 将base64转换为blob - const binaryString = atob(fileData.data) - const bytes = new Uint8Array(binaryString.length) - for (let i = 0; i < binaryString.length; i++) { - bytes[i] = binaryString.charCodeAt(i) - } - const blob = new Blob([bytes]) - const file = new File([blob], `${row.examid}`) - - // 调用分片上传 - const uploadResult = await uploadFileInChunks({ - file: file, - url: import.meta.env.VITE_FILE_UPLOAD_URL, - name: `${row.examid}`, - onProgress: (progress, currentChunk, totalChunks) => { - // 更新按钮上的进度 - row.uploadProgress = progress - }, - onError: (error, chunkIndex) => { - console.error(`分片 ${chunkIndex} 上传失败:`, error) - } - }) - - if (uploadResult.success) { - ElMessage.success('文件上传成功') - // 刷新列表 - getList() - } else { - ElMessage.error(`文件上传失败: ${uploadResult.message}`) - } - } catch (uploadError) { - console.error('文件上传失败:', uploadError) - ElMessage.error('文件上传失败,请重试') - } finally { - // 重置上传状态 - row.uploading = false - row.uploadProgress = 0 - } + // 调用分片上传 + const uploadResult = await uploadFileInChunks({ + file: file, + url: import.meta.env.VITE_FILE_UPLOAD_URL, + name: `${row.examid}`, + onProgress: (progress, currentChunk, totalChunks) => { + // 更新按钮上的进度 + row.uploadProgress = progress + }, + onError: (error, chunkIndex) => { + console.error(`分片 ${chunkIndex} 上传失败:`, error) } + }) + + if (uploadResult.success) { + ElMessage.success('文件上传成功') + // 关闭文件选择弹窗 + fileBrowserVisible.value = false + // 刷新列表 + getList() } else { - // success不是ok,显示错误消息 - ElMessage.error(result.message || '请求失败') - return + ElMessage.error(`文件上传失败: ${uploadResult.message}`) } + } catch (uploadError) { + console.error('文件上传失败:', uploadError) + ElMessage.error('文件上传失败,请重试') } finally { - loading.close() + // 重置上传状态 + row.uploading = false + row.uploadProgress = 0 } } catch (error) { - console.error('网络请求失败:', error) - ElMessage.error('网络请求失败,请检查服务是否正常') + console.error('文件上传处理失败:', error) + ElMessage.error('文件上传处理失败,请重试') + // 重置上传状态 + row.uploading = false + row.uploadProgress = 0 } } @@ -1456,7 +1407,7 @@ const handleUpload = async (row: any) => { const handleApply = async (row) => { try { const userinfo = await getUserProfile() - const orginfo = await OrgApi.getOrg(userinfo.orgid) + const orginfo = await OrgApi.getOrgByOrgId(userinfo.orgid) if (orginfo.parentOrgId != null) { await HrvApi.applySuperiorReview(row.id, orginfo.parentOrgId) ElMessage.success(`${row.name} 申请成功`) @@ -1732,7 +1683,7 @@ const handlePrintNewReport = () => { width: 100%; height: 100%; } - + .print-image { width: 100%; height: 100%; @@ -1742,20 +1693,20 @@ const handlePrintNewReport = () => { page-break-after: avoid; page-break-before: avoid; } - + @media print { @page { size: landscape; margin: 0; } - + body { margin: 0; padding: 0; width: 100%; height: 100%; } - + .print-image { width: 100%; height: 100%; @@ -1770,7 +1721,7 @@ const handlePrintNewReport = () => { - 新报告 + 报告 ` @@ -1802,70 +1753,6 @@ const handlePrintNewReport = () => { } } -/** 下载 */ -const handleDownload = async (row) => { - // 设置下载状态 - row.downloading = true - row.downloadProgress = 0 - - // 开始模拟进度条 - const progressInterval = setInterval(() => { - if (row.downloadProgress < 90) { - row.downloadProgress += 5 // 每2秒增加5% - } - }, 2000) // 每2秒增加一次 - - try { - // 先显示开始下载的进度 - row.downloadProgress = 10 - await new Promise((resolve) => setTimeout(resolve, 200)) - - // 调用下载接口 - const response = await fetch('http://localhost:48082/api/download-file', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - fileName: `${row.examid}` - }) - }) - - const result = await response.json() - - // 停止进度条模拟 - clearInterval(progressInterval) - - // 判断返回结果 - if (result.success) { - if (result.message === '文件不存在于服务器') { - ElMessage.error('文件不存在于服务器') - } else { - // 接口返回成功,进度条变满 - row.downloadProgress = 100 - - // 等待一小段时间让用户看到100% - await new Promise((resolve) => { - setTimeout(() => { - resolve(true) - }, 500) - }) - ElMessage.success('下载成功') - } - } else { - ElMessage.error(result.message || '下载失败') - } - } catch (error) { - clearInterval(progressInterval) - console.error('下载失败:', error) - ElMessage.error('下载失败,请重试') - } finally { - // 重置下载状态 - row.downloading = false - row.downloadProgress = 0 - } -} - /** 导出 */ const handleExport = async () => { exportLoading.value = true @@ -2207,7 +2094,6 @@ onMounted(async () => { .analysis-btn, .upload-btn, - .download-btn, .apply-btn, .new-report-btn { border-radius: 12px; @@ -2231,10 +2117,6 @@ onMounted(async () => { background: linear-gradient(135deg, #4facfe, #00f2fe); } - .download-btn { - background: linear-gradient(135deg, #43e97b, #38f9d7); - } - .apply-btn { background: linear-gradient(135deg, #ff9a56, #ff6b6b); } @@ -2884,43 +2766,6 @@ onMounted(async () => { } } -// 下载进度样式 -.download-progress { - display: flex; - align-items: center; - gap: 8px; - width: 100%; - height: 32px; - padding: 0 8px; - border-radius: 6px; - background: #f0f8ff; - border: 1px solid #91d5ff; - - .progress-bar { - flex: 1; - height: 8px; - - :deep(.el-progress-bar__outer) { - background-color: #e6f7ff; - border-radius: 4px; - } - - :deep(.el-progress-bar__inner) { - background: linear-gradient(135deg, #52c41a, #73d13d); - border-radius: 4px; - transition: width 0.3s ease; - } - } - - .progress-text { - font-size: 11px; - font-weight: 600; - color: #52c41a; - min-width: 30px; - text-align: center; - } -} - // 佩戴时间编辑样式 .wear-time-display { display: flex;