|
|
|
@ -293,41 +293,90 @@ export default {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
//预览照片
|
|
|
|
|
showImgViewer(row) {
|
|
|
|
|
// 假设你的图片URL基础路径
|
|
|
|
|
this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name=";
|
|
|
|
|
//预览照片
|
|
|
|
|
// 文件分类与预览执行函数
|
|
|
|
|
async showImgViewer(row) {
|
|
|
|
|
// 配置基础路径
|
|
|
|
|
this.certFileUrl = `${this.BASE_URL}/udiwms/image/register/file/getImage?type=device&name=`;
|
|
|
|
|
this.imgList = [];
|
|
|
|
|
|
|
|
|
|
// 检查文件是否为PDF
|
|
|
|
|
const isPdf = row.filePath.toLowerCase().includes('.pdf');
|
|
|
|
|
if (isPdf) {
|
|
|
|
|
// 如果不是PDF,则尝试预览图片
|
|
|
|
|
previewImage({ imageUrl: row.filePath, certFileUrl: this.certFileUrl }).then(response => {
|
|
|
|
|
if (response.code === 20000) {
|
|
|
|
|
// 如果是PDF,则在新标签页中打开
|
|
|
|
|
this.imgList = response.data;
|
|
|
|
|
window.open(this.imgList, '_blank');
|
|
|
|
|
// 你可以在这里添加一些逻辑来关闭图片查看器(如果它之前已经打开)
|
|
|
|
|
// 例如,如果你有一个模态框或类似的UI元素
|
|
|
|
|
this.imgViewerVisible = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// 如果不是PDF,则尝试预览图片
|
|
|
|
|
previewImage({ imageUrl: row.filePath, certFileUrl: this.certFileUrl }).then(response => {
|
|
|
|
|
if (response.code === 20000) {
|
|
|
|
|
this.imgList = response.data;
|
|
|
|
|
// 安全分割文件路径
|
|
|
|
|
const filePaths = row.filePath
|
|
|
|
|
.split(',')
|
|
|
|
|
.map(path => path.trim().replace(/[^\w\-.]/g, '')) // 过滤非法字符
|
|
|
|
|
.filter(Boolean);
|
|
|
|
|
|
|
|
|
|
// 高效文件分类器
|
|
|
|
|
const { pdfs, images } = filePaths.reduce((acc, file) => {
|
|
|
|
|
const extension = file.split('.').pop().toLowerCase();
|
|
|
|
|
if (extension === 'pdf') {
|
|
|
|
|
acc.pdfs.push(file);
|
|
|
|
|
} else if (['png', 'jpg', 'jpeg'].includes(extension)) {
|
|
|
|
|
acc.images.push(file);
|
|
|
|
|
}
|
|
|
|
|
return acc;
|
|
|
|
|
}, { pdfs: [], images: [] });
|
|
|
|
|
|
|
|
|
|
// 处理图片预览
|
|
|
|
|
if (images.length > 0) {
|
|
|
|
|
try {
|
|
|
|
|
const previewTasks = images.map(file =>
|
|
|
|
|
previewImage({
|
|
|
|
|
imageUrl: file,
|
|
|
|
|
certFileUrl: this.certFileUrl
|
|
|
|
|
}).then(res => res.code === 20000 ? res.data : null)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const validImages = (await Promise.all(previewTasks)).filter(Boolean);
|
|
|
|
|
if (validImages.length) {
|
|
|
|
|
this.imgList = validImages;
|
|
|
|
|
this.imgViewerVisible = true;
|
|
|
|
|
// 禁止页面滑动
|
|
|
|
|
const m = (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
};
|
|
|
|
|
document.body.style.overflow = 'hidden';
|
|
|
|
|
document.addEventListener("touchmove", m, false);
|
|
|
|
|
this.lockScroll();
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('图片加载异常:', error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理PDF文件(防弹窗拦截方案)
|
|
|
|
|
if (pdfs.length > 0) {
|
|
|
|
|
let popupAttempts = 0;
|
|
|
|
|
const openPdfWindow = (fileName, index) => {
|
|
|
|
|
const fullUrl = `${this.certFileUrl}${encodeURIComponent(fileName)}`;
|
|
|
|
|
const newWindow = window.open(fullUrl, `pdf_${Date.now()}`);
|
|
|
|
|
|
|
|
|
|
if (!newWindow || newWindow.closed) {
|
|
|
|
|
if (popupAttempts++ === 0) {
|
|
|
|
|
this.$confirm('检测到弹窗拦截,请允许打开PDF', '提示', {
|
|
|
|
|
confirmButtonText: '立即允许',
|
|
|
|
|
cancelButtonText: '取消'
|
|
|
|
|
}).then(() => {
|
|
|
|
|
window.open(fullUrl, '_blank', 'noopener');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
newWindow.focus();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 分时打开策略
|
|
|
|
|
pdfs.forEach((file, index) => {
|
|
|
|
|
setTimeout(() => openPdfWindow(file, index), index * 300);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 增强型滚动控制
|
|
|
|
|
lockScroll() {
|
|
|
|
|
document.documentElement.style.overflow = 'hidden';
|
|
|
|
|
document.documentElement.style.touchAction = 'none';
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
unlockScroll() {
|
|
|
|
|
document.documentElement.style.overflow = '';
|
|
|
|
|
document.documentElement.style.touchAction = '';
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
closeImgViewer() {
|
|
|
|
|
this.imgViewerVisible = false;
|
|
|
|
|
const m = (e) => {
|
|
|
|
|