| | |
| | | } |
| | | }; |
| | | |
| | | const autoPreviewReport = async () => { |
| | | try { |
| | | await generateReport(); |
| | | if (!filePath.value) { |
| | | // 如果没有文件路径,不执行预览 |
| | | return; |
| | | } |
| | | const encodedFilePath = encodeURIComponent(filePath.value); |
| | | |
| | | const response = await request.get('/glassOptimize/reports/pdf', { |
| | | params: { filePath: encodedFilePath }, |
| | | responseType: 'blob', |
| | | headers: { |
| | | 'Accept': 'application/pdf' |
| | | } |
| | | }); |
| | | |
| | | // 检查响应数据是否存在且有效 |
| | | if (!response) { |
| | | ElMessage.error('未能获取到PDF数据'); |
| | | return; |
| | | } |
| | | |
| | | const blob = new Blob([response], { type: 'application/pdf' }); |
| | | |
| | | // 检查 blob 是否有效 |
| | | if (blob.size === 0) { |
| | | ElMessage.error('接收到空的PDF文件'); |
| | | return; |
| | | } |
| | | |
| | | // 创建PDF URL并赋值给 pdfUrl 用于界面显示 |
| | | const url = URL.createObjectURL(blob); |
| | | pdfUrl.value = url; |
| | | |
| | | } catch (error) { |
| | | console.error('自动预览流程异常:', error); |
| | | } |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | // 优先使用注入的 projectNo,其次使用 props,最后使用 localStorage |
| | | if (injectedProjectNo) { |
| | | processId.value = injectedProjectNo.value || injectedProjectNo; |
| | | } else if (props.project) { |
| | | processId.value = props.project.projectNumber || ''; |
| | | state.value = props.state; |
| | | } else if (savedProjectNo) { |
| | | processId.value = savedProjectNo; |
| | | } |
| | | |
| | | if (processId.value) { |
| | | selectLayout(); |
| | | selectReportData(); |
| | | selectMaterialData(); |
| | | selectProductData(); |
| | | |
| | | // 数据加载完成后自动预览 |
| | | setTimeout(() => { |
| | | autoPreviewReport(); |
| | | }, 1000); // 延迟1秒确保所有数据加载完成 |
| | | } |
| | | }); |
| | | // const autoPreviewReport = async () => { |
| | | // try { |
| | | // await generateReport(); |
| | | // if (!filePath.value) { |
| | | // // 如果没有文件路径,不执行预览 |
| | | // return; |
| | | // } |
| | | // const encodedFilePath = encodeURIComponent(filePath.value); |
| | | // |
| | | // const response = await request.get('/glassOptimize/reports/pdf', { |
| | | // params: { filePath: encodedFilePath }, |
| | | // responseType: 'blob', |
| | | // headers: { |
| | | // 'Accept': 'application/pdf' |
| | | // } |
| | | // }); |
| | | // |
| | | // // 检查响应数据是否存在且有效 |
| | | // if (!response) { |
| | | // ElMessage.error('未能获取到PDF数据'); |
| | | // return; |
| | | // } |
| | | // |
| | | // const blob = new Blob([response], { type: 'application/pdf' }); |
| | | // |
| | | // // 检查 blob 是否有效 |
| | | // if (blob.size === 0) { |
| | | // ElMessage.error('接收到空的PDF文件'); |
| | | // return; |
| | | // } |
| | | // |
| | | // // 创建PDF URL并赋值给 pdfUrl 用于界面显示 |
| | | // const url = URL.createObjectURL(blob); |
| | | // pdfUrl.value = url; |
| | | // |
| | | // } catch (error) { |
| | | // console.error('自动预览流程异常:', error); |
| | | // } |
| | | // }; |
| | | // |
| | | // onMounted(() => { |
| | | // // 优先使用注入的 projectNo,其次使用 props,最后使用 localStorage |
| | | // if (injectedProjectNo) { |
| | | // processId.value = injectedProjectNo.value || injectedProjectNo; |
| | | // } else if (props.project) { |
| | | // processId.value = props.project.projectNumber || ''; |
| | | // state.value = props.state; |
| | | // } else if (savedProjectNo) { |
| | | // processId.value = savedProjectNo; |
| | | // } |
| | | // |
| | | // if (processId.value) { |
| | | // selectLayout(); |
| | | // selectReportData(); |
| | | // selectMaterialData(); |
| | | // selectProductData(); |
| | | // |
| | | // // 数据加载完成后自动预览 |
| | | // setTimeout(() => { |
| | | // autoPreviewReport(); |
| | | // }, 1000); // 延迟1秒确保所有数据加载完成 |
| | | // } |
| | | // }); |
| | | |
| | | const config = reactive({ |
| | | columnTypes: '两列', |
| | |
| | | plain: true, |
| | | printLayouts: true, |
| | | printReport: true, |
| | | glassInfo: '不显示', |
| | | glassInfo: '显示在下侧', |
| | | cutInfo: '显示' |
| | | |
| | | }) |