<template>
|
<view class="page">
|
<!-- 通知栏 -->
|
<uni-notice-bar show-icon text="仅能查出该亲友最新的体检报告哦!" class="notice-bar" />
|
|
<!-- 报告列表 -->
|
<scroll-view scroll-y class="report-list" v-if="reports.length > 0">
|
<view class="card" v-for="(report, index) in reports" :key="report.tjNum">
|
<view class="card-inner">
|
<view class="card-left">
|
<text class="name">{{ report.name || '未知姓名' }}</text>
|
<text class="sex">{{ report.sex || '未知性别' }}</text>
|
</view>
|
<view class="card-right">
|
<view class="info">
|
<text class="time">{{ report.time || '未知时间' }}</text>
|
<text class="hospital">{{ hospName || '未知医院' }}</text>
|
<text class="tj-num">体检号:{{ report.tjNum }}</text>
|
</view>
|
<view class="label">
|
<text class="label-text">体检报告</text>
|
</view>
|
</view>
|
</view>
|
<!-- 按钮组 -->
|
<view class="button-group">
|
<view class="action-button open-pdf" @click.stop="openPDF(report)">打开PDF</view>
|
<view class="action-button go-report" @click.stop="goToReportBaogao(report)">查看报告详情</view>
|
</view>
|
</view>
|
</scroll-view>
|
|
<!-- 无数据提示 -->
|
<view v-else class="no-data">
|
<text>暂无体检报告</text>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import {
|
PDF
|
} from "@/api/system/report";
|
|
export default {
|
name: 'FriendReportOverview',
|
data() {
|
return {
|
reports: [],
|
customer: null,
|
hospName: '' // 新增字段存储医院名称
|
};
|
},
|
onLoad(option) {
|
// 从本地存储获取 hospName
|
this.hospName = uni.getStorageSync('hospName') || '未知医院';
|
this.reports = JSON.parse(uni.getStorageSync(reportData));
|
// 解析路由参数
|
if (this.reports) {
|
this.customer = {
|
name: this.reports[0]?.name
|
};
|
}
|
},
|
methods: {
|
openPDF(report) {
|
console.log('加载中...', {
|
tjNum: report.tjNum
|
});
|
uni.showLoading({
|
title: '加载中...'
|
});
|
PDF({
|
tjNum: report.tjNum
|
})
|
.then((res) => {
|
console.log('PDF response:', res);
|
|
if (!res.msg || typeof res.msg !== 'string') {
|
console.error('无效的 PDF 文件路径:', res.msg);
|
uni.showToast({
|
title: 'PDF 文件路径无效',
|
icon: 'none',
|
duration: 2000
|
});
|
uni.hideLoading();
|
return;
|
}
|
|
// 构造 PDF URL
|
const pdfPath = encodeURIComponent(res.msg);
|
const isTestEnv = process.env.VUE_APP_ENV === 'test' || process.env.NODE_ENV === 'development';
|
const pdfUrl = isTestEnv ?
|
`http://ltpeis.xaltjdkj.cn:5904/report-file/${pdfPath}` :
|
`${window.location.origin}/report-file/${pdfPath}`;
|
const fileName = res.msg;
|
console.log('Generated PDF URL:', pdfUrl);
|
|
// 测试 URL 状态码
|
fetch(pdfUrl, {
|
method: 'HEAD',
|
credentials: 'include'
|
})
|
.then((response) => {
|
console.log('URL 状态码:', response.status);
|
|
if (response.status === 404) {
|
uni.showToast({
|
title: '文件不存在,请联系管理员',
|
icon: 'none',
|
duration: 2000
|
});
|
uni.hideLoading();
|
return;
|
}
|
|
if (response.status >= 300 && response.status < 400) {
|
const redirectUrl = response.headers.get('Location') || '未知重定向地址';
|
console.warn('URL 被重定向:', redirectUrl);
|
uni.showToast({
|
title: `文件请求被重定向到: ${redirectUrl}`,
|
icon: 'none',
|
duration: 2000
|
});
|
uni.hideLoading();
|
return;
|
}
|
|
if (response.status !== 200) {
|
console.error('URL 请求失败,状态码:', response.status);
|
uni.showToast({
|
title: `无法访问文件,状态码: ${response.status}`,
|
icon: 'none',
|
duration: 2000
|
});
|
uni.hideLoading();
|
return;
|
}
|
|
// 状态码为 200,尝试打开 PDF
|
const newWindow = window.open(pdfUrl, '_blank');
|
if (!newWindow) {
|
console.warn('窗口被阻止,尝试下载PDF');
|
const downloadLink = document.createElement('a');
|
downloadLink.href = pdfUrl;
|
downloadLink.download = fileName;
|
downloadLink.dispatchEvent(new MouseEvent('click', {
|
view: window,
|
bubbles: true,
|
cancelable: true
|
}));
|
uni.showToast({
|
title: '窗口被阻止,已触发下载',
|
icon: 'none',
|
duration: 2000
|
});
|
uni.hideLoading();
|
return;
|
}
|
|
// 检查是否被重定向
|
setTimeout(() => {
|
try {
|
const currentUrl = newWindow.location.href;
|
console.log('新窗口当前 URL:', currentUrl);
|
if (
|
currentUrl === 'about:blank' ||
|
currentUrl === window.location.origin + '/' ||
|
currentUrl.includes('select-hospital') ||
|
newWindow.closed
|
) {
|
console.warn('新窗口可能被重定向或加载失败,尝试下载PDF');
|
newWindow.close();
|
const downloadLink = document.createElement('a');
|
downloadLink.href = pdfUrl;
|
downloadLink.download = fileName;
|
downloadLink.dispatchEvent(new MouseEvent('click', {
|
view: window,
|
bubbles: true,
|
cancelable: true
|
}));
|
uni.showToast({
|
title: 'PDF 加载失败,已触发下载',
|
icon: 'none',
|
duration: 2000
|
});
|
}
|
} catch (e) {
|
console.error('检查新窗口 URL 失败:', e);
|
uni.showToast({
|
title: '无法加载 PDF,已触发下载',
|
icon: 'none',
|
duration: 2000
|
});
|
newWindow.close();
|
const downloadLink = document.createElement('a');
|
downloadLink.href = pdfUrl;
|
downloadLink.download = fileName;
|
downloadLink.dispatchEvent(new MouseEvent('click', {
|
view: window,
|
bubbles: true,
|
cancelable: true
|
}));
|
}
|
uni.hideLoading();
|
console.log('加载完成');
|
}, 2000);
|
})
|
.catch((fetchError) => {
|
console.error('测试 URL 失败:', fetchError);
|
uni.showToast({
|
title: '无法验证文件状态,请稍后重试',
|
icon: 'none',
|
duration: 2000
|
});
|
uni.hideLoading();
|
console.log('加载完成');
|
});
|
})
|
.catch((err) => {
|
console.log('加载完成');
|
console.error('PDF 接口错误:', err);
|
uni.showToast({
|
title: err?.msg || '获取 PDF 失败,请稍后重试',
|
icon: 'none',
|
duration: 2000
|
});
|
uni.hideLoading();
|
});
|
},
|
goToReportBaogao(report) {
|
console.log('跳转到ReportBaogao', {
|
tjNum: report.tjNum
|
});
|
uni.navigateTo({
|
url: `/pages/ReportBaogao/ReportBaogao?tjNum=${report.tjNum}`
|
});
|
},
|
ReportDetails(report) {
|
const isWeChat = /MicroMessenger/i.test(navigator.userAgent);
|
if (isWeChat) {
|
// 微信环境,直接跳转到 ReportBaogao
|
this.goToReportBaogao(report);
|
} else {
|
// 非微信环境,打开 PDF
|
this.openPDF(report);
|
}
|
}
|
}
|
};
|
</script>
|
|
<style lang="scss">
|
.page {
|
width: 100%;
|
min-height: 100vh;
|
background: linear-gradient(180deg, #fff 10%, #f5f7fa 100%);
|
padding-bottom: 20rpx;
|
}
|
|
.notice-bar {
|
margin: 20rpx 30rpx;
|
border-radius: 16rpx;
|
background: rgba(255, 245, 230, 0.95);
|
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
|
font-size: 28rpx;
|
color: #e58e26;
|
}
|
|
.report-list {
|
height: calc(100vh - 120rpx);
|
padding: 0 30rpx;
|
}
|
|
.card {
|
margin-top: 30rpx;
|
}
|
|
.card-inner {
|
width: 100%;
|
height: 180rpx;
|
background: #ffffff;
|
border-radius: 20rpx;
|
box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.08);
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
transition: transform 0.2s ease;
|
}
|
|
.card-inner:active {
|
transform: scale(0.98);
|
}
|
|
.card-left {
|
width: 140rpx;
|
height: 100%;
|
display: flex;
|
flex-direction: column;
|
justify-content: center;
|
align-items: center;
|
border-right: 2rpx dashed #e0e0e0;
|
}
|
|
.name {
|
font-size: 34rpx;
|
font-weight: 600;
|
color: #333;
|
margin-bottom: 10rpx;
|
}
|
|
.sex {
|
font-size: 26rpx;
|
color: #888;
|
}
|
|
.card-right {
|
flex: 1;
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
padding: 20rpx 0;
|
}
|
|
.info {
|
padding: 0 30rpx;
|
display: flex;
|
flex-direction: column;
|
gap: 12rpx;
|
}
|
|
.time {
|
font-size: 28rpx;
|
color: #666;
|
}
|
|
.hospital {
|
font-size: 26rpx;
|
color: #999;
|
}
|
|
.tj-num {
|
font-size: 28rpx;
|
color: #fd8b4d;
|
font-weight: 500;
|
}
|
|
.label {
|
width: 80rpx;
|
height: 100%;
|
background: linear-gradient(135deg, #fd8b4d, #ffaa70);
|
border-radius: 0 20rpx 20rpx 0;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
padding: 22rpx;
|
}
|
|
.label-text {
|
font-size: 30rpx;
|
color: #fff;
|
font-weight: 600;
|
writing-mode: vertical-rl;
|
letter-spacing: 4rpx;
|
}
|
|
.no-data {
|
height: calc(100vh - 120rpx);
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
font-size: 32rpx;
|
color: #999;
|
}
|
|
.button-group {
|
display: flex;
|
justify-content: space-between;
|
padding: 20rpx 30rpx;
|
margin-top: 10rpx;
|
}
|
|
.action-button {
|
flex: 1;
|
text-align: center;
|
padding: 20rpx 0;
|
font-size: 28rpx;
|
color: #ffffff;
|
border-radius: 8rpx;
|
margin: 0 10rpx;
|
cursor: pointer;
|
}
|
|
.open-pdf {
|
background: #419ffd;
|
}
|
|
.go-report {
|
background: #fd8b4d;
|
}
|
</style>
|