Commit 679686ef by Sweet Zhang

暂存

parent 7eaa3816
...@@ -96,6 +96,33 @@ ...@@ -96,6 +96,33 @@
<text class="empty-text">暂无对比产品数据</text> <text class="empty-text">暂无对比产品数据</text>
</view> </view>
</view> </view>
<!-- 放在 </view> 最后,</template> 之前 -->
<!-- PDF 查看弹窗 -->
<uni-popup
ref="pdfPopupRef"
:mask-click="true"
type="bottom"
@change="onPopupChange"
>
<view class="pdf-modal-container">
<!-- 关闭按钮 -->
<view class="modal-header">
<button class="close-btn" @click="closePdfModal"></button>
</view>
<!-- PDF 查看器 -->
<view class="pdf-viewer-wrapper" v-if="showPdfModal">
<PdfViewer
:pdfInfo="{ url: currentPdfUrl }"
:autoLoad="true"
:lazyLoad="true"
:maxRetryCount="2"
:loadingStatus="true"
style="height: 100%; width: 100%;"
/>
</view>
</view>
</uni-popup>
</template> </template>
<script setup> <script setup>
...@@ -103,6 +130,12 @@ import { ref, computed, onMounted } from 'vue'; ...@@ -103,6 +130,12 @@ import { ref, computed, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router'; import { useRouter, useRoute } from 'vue-router';
import common from '@/common/common'; import common from '@/common/common';
import api from '@/api/api'; import api from '@/api/api';
import { onBeforeUnmount } from 'vue';
import PdfViewer from '@/components/pdf-viewer/pdf-viewer.vue';
import uniPopup from '@dcloudio/uni-ui/lib/uni-popup/uni-popup.vue';
const pdfPopupRef = ref();
// 路由实例 // 路由实例
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
...@@ -172,42 +205,42 @@ const wxShare = (productIds,categoryId)=>{ ...@@ -172,42 +205,42 @@ const wxShare = (productIds,categoryId)=>{
} }
hshare(data, url) hshare(data, url)
} }
const getUrl = (fileUrl) => { // const getUrl = (fileUrl) => {
if (!fileUrl) { // if (!fileUrl) {
uni.showToast({ title: '暂无文档', icon: 'none' }); // uni.showToast({ title: '暂无文档', icon: 'none' });
return; // return;
} // }
// 区分环境:H5 端直接打开 URL,其他端用原下载逻辑 // // 区分环境:H5 端直接打开 URL,其他端用原下载逻辑
if (uni.getSystemInfoSync().uniPlatform === 'web') { // if (uni.getSystemInfoSync().uniPlatform === 'web') {
// H5 方案:用浏览器新窗口打开 PDF(依赖浏览器原生支持) // // H5 方案:用浏览器新窗口打开 PDF(依赖浏览器原生支持)
const opened = window.open(fileUrl, '_blank'); // const opened = window.open(fileUrl, '_blank');
} else { // } else {
// 非 H5 端(小程序/APP):保留原下载+打开逻辑 // // 非 H5 端(小程序/APP):保留原下载+打开逻辑
uni.downloadFile({ // uni.downloadFile({
url: fileUrl, // url: fileUrl,
success: (res) => { // success: (res) => {
if (res.statusCode === 200) { // if (res.statusCode === 200) {
uni.openDocument({ // uni.openDocument({
filePath: res.tempFilePath, // filePath: res.tempFilePath,
showMenu: true, // showMenu: true,
success: () => console.log('打开文档成功'), // success: () => console.log('打开文档成功'),
fail: (err) => { // fail: (err) => {
uni.showToast({ title: '打开失败,请重试', icon: 'none' }); // uni.showToast({ title: '打开失败,请重试', icon: 'none' });
console.error('openDocument 失败:', err); // console.error('openDocument 失败:', err);
} // }
}); // });
} else { // } else {
uni.showToast({ title: '下载失败', icon: 'none' }); // uni.showToast({ title: '下载失败', icon: 'none' });
} // }
}, // },
fail: (err) => { // fail: (err) => {
uni.showToast({ title: '下载失败,请检查网络', icon: 'none' }); // uni.showToast({ title: '下载失败,请检查网络', icon: 'none' });
console.error('downloadFile 失败:', err); // console.error('downloadFile 失败:', err);
} // }
}); // });
} // }
}; // };
// 【核心1:获取第一个产品的分组列表(A/B/C组)】 // 【核心1:获取第一个产品的分组列表(A/B/C组)】
// 所有产品的分组结构一致,取第一个产品的 basicInfos 作为分组源 // 所有产品的分组结构一致,取第一个产品的 basicInfos 作为分组源
...@@ -258,6 +291,48 @@ const navigateToPKPage = () => { ...@@ -258,6 +291,48 @@ const navigateToPKPage = () => {
}; };
const showPdfModal = ref(false);
const currentPdfUrl = ref('');
// 修改 getUrl 方法
const getUrl = (fileUrl) => {
if (!fileUrl) {
uni.showToast({ title: '暂无文档', icon: 'none' });
return;
}
uni.showLoading({ title: '加载PDF中...' });
// 所有平台统一处理:弹出 PdfViewer
currentPdfUrl.value = fileUrl;
showPdfModal.value = true;
};
// 关闭弹窗
const closePdfModal = () => {
showPdfModal.value = false;
// 延迟关闭 popup,避免 PdfViewer 销毁过快
setTimeout(() => {
pdfPopupRef.value?.close?.();
}, 100);
};
// 监听弹窗状态变化(可选)
const onPopupChange = (e) => {
if (!e.show && showPdfModal.value) {
// 用户点击遮罩关闭
showPdfModal.value = false;
}
};
// 组件销毁前关闭弹窗(防内存泄漏)
onBeforeUnmount(() => {
if (pdfPopupRef.value) {
pdfPopupRef.value.close();
}
});
// 初始化数据 // 初始化数据
onMounted(() => { onMounted(() => {
...@@ -488,4 +563,35 @@ onMounted(() => { ...@@ -488,4 +563,35 @@ onMounted(() => {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.pdf-modal-container {
width: 100vw;
height: 90vh; /* 占屏 90% */
background: #fff;
border-top-left-radius: 20rpx;
border-top-right-radius: 20rpx;
overflow: hidden;
display: flex;
flex-direction: column;
}
.modal-header {
padding: 20rpx;
text-align: right;
}
.close-btn {
width: 60rpx;
height: 60rpx;
font-size: 36rpx;
background: #f5f5f5;
border-radius: 50%;
border: none;
color: #999;
}
.pdf-viewer-wrapper {
flex: 1;
width: 100%;
overflow: hidden;
}
</style> </style>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment