diff --git a/src/views/dev/DeviceCheckEditDialog.vue b/src/views/dev/DeviceCheckEditDialog.vue index 52a07462..382ffd43 100644 --- a/src/views/dev/DeviceCheckEditDialog.vue +++ b/src/views/dev/DeviceCheckEditDialog.vue @@ -295,7 +295,7 @@ export default { }, //预览照片 showImgViewer(row) { - this.certFileUrl = this.BASE_URL + '/udiwms/image/register/file/getImage?type=image2&name=' + this.certFileUrl = this.BASE_URL + '/udiwms/image/register/file/getImage?type=device&name=' this.imgList = [] previewImage({ imageUrl: row.filePath, certFileUrl: this.certFileUrl }).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/DeviceInspectMyTake.vue b/src/views/dev/DeviceInspectMyTake.vue index b328725f..267f2db2 100644 --- a/src/views/dev/DeviceInspectMyTake.vue +++ b/src/views/dev/DeviceInspectMyTake.vue @@ -586,7 +586,7 @@ export default { if (row.inspectImage.substr(-1) == ',') { row.inspectImage = row.inspectImage.slice(0, row.inspectImage.length - 1); } - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; this.imgList = []; previewImage({imageUrl: row.inspectImage, certFileUrl: this.certFileUrl}).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/DeviceInspectTake.vue b/src/views/dev/DeviceInspectTake.vue index d53fab5c..b0c2bf56 100644 --- a/src/views/dev/DeviceInspectTake.vue +++ b/src/views/dev/DeviceInspectTake.vue @@ -586,7 +586,7 @@ export default { if (row.inspectImage.substr(-1) == ',') { row.inspectImage = row.inspectImage.slice(0, row.inspectImage.length - 1); } - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; this.imgList = []; previewImage({imageUrl: row.inspectImage, certFileUrl: this.certFileUrl}).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/DeviceInspectTakeAdd.vue b/src/views/dev/DeviceInspectTakeAdd.vue index d6e14b2f..abf8a852 100644 --- a/src/views/dev/DeviceInspectTakeAdd.vue +++ b/src/views/dev/DeviceInspectTakeAdd.vue @@ -690,7 +690,7 @@ export default { if (row.inspectImage.substr(-1) == ',') { row.inspectImage = row.inspectImage.slice(0, row.inspectImage.length - 1); } - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; this.imgList = []; previewImage({imageUrl: row.inspectImage, certFileUrl: this.certFileUrl}).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/DeviceInspectTakeAuditModify.vue b/src/views/dev/DeviceInspectTakeAuditModify.vue index d80eb078..d3ea17b0 100644 --- a/src/views/dev/DeviceInspectTakeAuditModify.vue +++ b/src/views/dev/DeviceInspectTakeAuditModify.vue @@ -460,7 +460,7 @@ export default { if (row.inspectImage.substr(-1) == ',') { row.inspectImage = row.inspectImage.slice(0, row.inspectImage.length - 1); } - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; this.imgList = []; previewImage({imageUrl: row.inspectImage, certFileUrl: this.certFileUrl}).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/DeviceInspectTakeSelect.vue b/src/views/dev/DeviceInspectTakeSelect.vue index 2248f166..fa362638 100644 --- a/src/views/dev/DeviceInspectTakeSelect.vue +++ b/src/views/dev/DeviceInspectTakeSelect.vue @@ -533,7 +533,7 @@ export default { if (row.inspectImage.substr(-1) == ',') { row.inspectImage = row.inspectImage.slice(0, row.inspectImage.length - 1); } - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; this.imgList = []; previewImage({imageUrl: row.inspectImage, certFileUrl: this.certFileUrl}).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/DeviceRepairOrderAudit.vue b/src/views/dev/DeviceRepairOrderAudit.vue index 8a51e986..2f2ccdac 100644 --- a/src/views/dev/DeviceRepairOrderAudit.vue +++ b/src/views/dev/DeviceRepairOrderAudit.vue @@ -438,7 +438,7 @@ export default { if(row.uploadImage.substr(-1) == ','){ row.uploadImage=row.uploadImage.slice(0, row.uploadImage.length-1); } - this.certFileUrl = this.BASE_URL +"/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL +"/udiwms/image/register/file/getImage?type=device&name="; console.log(this.certFileUrl + "========"); this.imgList = []; previewImage({imageUrl: row.uploadImage, certFileUrl: this.certFileUrl}).then(response => { diff --git a/src/views/dev/DeviceRepairOrderCompleted.vue b/src/views/dev/DeviceRepairOrderCompleted.vue index b33d4a75..b810b1a4 100644 --- a/src/views/dev/DeviceRepairOrderCompleted.vue +++ b/src/views/dev/DeviceRepairOrderCompleted.vue @@ -415,7 +415,7 @@ export default { if (row.substr(-1) == ',') { row = row.slice(0, row.length - 1); } - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; console.log(this.certFileUrl + "========"); this.imgList = []; previewImage({imageUrl: row, certFileUrl: this.certFileUrl}).then(response => { diff --git a/src/views/dev/DeviceRepairOrderNew.vue b/src/views/dev/DeviceRepairOrderNew.vue index 6cc442fa..f39ac5ce 100644 --- a/src/views/dev/DeviceRepairOrderNew.vue +++ b/src/views/dev/DeviceRepairOrderNew.vue @@ -400,7 +400,7 @@ export default { if (row.uploadImage.substr(-1) == ',') { row.uploadImage = row.uploadImage.slice(0, row.uploadImage.length - 1); } - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; console.log(this.certFileUrl + "========"); this.imgList = []; previewImage({imageUrl: row.uploadImage, certFileUrl: this.certFileUrl}).then(response => { diff --git a/src/views/dev/DeviceRepairOrderhandle.vue b/src/views/dev/DeviceRepairOrderhandle.vue index 6d653d7a..cd8b82f4 100644 --- a/src/views/dev/DeviceRepairOrderhandle.vue +++ b/src/views/dev/DeviceRepairOrderhandle.vue @@ -346,7 +346,7 @@ export default { if (row.substr(-1) == ',') { row = row.slice(0, row.length - 1); } - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; console.log(this.certFileUrl + "========"); this.imgList = []; previewImage({imageUrl: row, certFileUrl: this.certFileUrl}).then(response => { diff --git a/src/views/dev/DeviceTemperamentDialog.vue b/src/views/dev/DeviceTemperamentDialog.vue index 90ecc5cd..c10358af 100644 --- a/src/views/dev/DeviceTemperamentDialog.vue +++ b/src/views/dev/DeviceTemperamentDialog.vue @@ -307,7 +307,7 @@ export default { }, //预览照片 showImgViewer(row) { - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; this.imgList = []; previewImage({imageUrl: row.filePath, certFileUrl: this.certFileUrl}).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/invContractDialog.vue b/src/views/dev/invContractDialog.vue index 75dfc1c9..e29f08e8 100644 --- a/src/views/dev/invContractDialog.vue +++ b/src/views/dev/invContractDialog.vue @@ -294,7 +294,7 @@ export default { //预览照片 showImgViewer(row) { // 假设你的图片URL基础路径 - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; this.imgList = []; // 检查文件是否为PDF diff --git a/src/views/dev/invDeviceCheckEditDialog.vue b/src/views/dev/invDeviceCheckEditDialog.vue index 8d3902fc..6b60dcc0 100644 --- a/src/views/dev/invDeviceCheckEditDialog.vue +++ b/src/views/dev/invDeviceCheckEditDialog.vue @@ -289,9 +289,71 @@ export default { this.getDeviceCertList() }, + async showImgViewer(row) { + const BASE_API = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; + this.imgList = []; + + // 分割文件路径并过滤空值 + const files = row.filePath.split(',') + .map(path => path.trim()) + .filter(Boolean); + + // 分离文件类型 + const fileGroups = files.reduce((acc, file) => { + const type = file.split('.').pop().toLowerCase(); + type === 'pdf' ? acc.pdf.push(file) : acc.images.push(file); + return acc; + }, { pdf: [], images: [] }); + + // 并行处理图片预览数据获取 + const imagePreviews = await Promise.all( + fileGroups.images.map(file => + previewImage({ + imageUrl: file, + certFileUrl: this.certFileUrl + }).then(res => res.code === 20000 ? res.data : null) + ) + ); + + // 更新图片列表并显示查看器(如果有图片) + const validImages = imagePreviews.filter(Boolean); + if (validImages.length > 0) { + this.imgList = validImages; + this.imgViewerVisible = true; + this.lockScroll(); + } + + // 打开所有PDF文件(每个PDF独立标签页) + fileGroups.pdf.forEach(pdf => { + const pdfUrl = `${BASE_API}${encodeURIComponent(pdf)}`; + window.open(pdfUrl, '_blank', 'noopener'); + }); + }, + +// 滚动锁定/解锁方法 + lockScroll() { + document.body.style.overflow = 'hidden'; + const preventDefault = e => e.preventDefault(); + document.addEventListener('touchmove', preventDefault, { passive: false }); + this.__scrollHandler = preventDefault; + }, + + unlockScroll() { + document.body.style.overflow = ''; + if (this.__scrollHandler) { + document.removeEventListener('touchmove', this.__scrollHandler); + } + }, + +// 在查看器关闭时调用 + closeImageViewer() { + this.imgViewerVisible = false; + this.unlockScroll(); + }, + //预览照片 - showImgViewer(row) { - this.certFileUrl = this.BASE_URL + '/udiwms/image/register/file/getImage?type=image2&name=' + showImgViewer2(row) { + this.certFileUrl = this.BASE_URL + '/udiwms/image/register/file/getImage?type=device&name=' this.imgList = [] previewImage({ imageUrl: row.filePath, certFileUrl: this.certFileUrl }).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/invDeviceEditDialog.vue b/src/views/dev/invDeviceEditDialog.vue index 73f725ca..3dc6ba54 100644 --- a/src/views/dev/invDeviceEditDialog.vue +++ b/src/views/dev/invDeviceEditDialog.vue @@ -297,41 +297,89 @@ 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) => { diff --git a/src/views/dev/invDeviceInspectEditDialog.vue b/src/views/dev/invDeviceInspectEditDialog.vue index 1ae06bff..0693bb42 100644 --- a/src/views/dev/invDeviceInspectEditDialog.vue +++ b/src/views/dev/invDeviceInspectEditDialog.vue @@ -287,7 +287,7 @@ export default { }, //预览照片 showImgViewer(row) { - this.certFileUrl = this.BASE_URL + '/udiwms/image/register/file/getImage?type=image2&name=' + this.certFileUrl = this.BASE_URL + '/udiwms/image/register/file/getImage?type=device&name=' this.imgList = [] previewImage({ imageUrl: row.filePath, certFileUrl: this.certFileUrl }).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/invDeviceRepairEditDialog.vue b/src/views/dev/invDeviceRepairEditDialog.vue index b1a4afb8..28c39842 100644 --- a/src/views/dev/invDeviceRepairEditDialog.vue +++ b/src/views/dev/invDeviceRepairEditDialog.vue @@ -299,7 +299,7 @@ export default { }, //预览照片 showImgViewer(row) { - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; this.imgList = []; previewImage({imageUrl: row.filePath, certFileUrl: this.certFileUrl}).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/invDeviceUpkeepEditDialog.vue b/src/views/dev/invDeviceUpkeepEditDialog.vue index 36703b4e..88578539 100644 --- a/src/views/dev/invDeviceUpkeepEditDialog.vue +++ b/src/views/dev/invDeviceUpkeepEditDialog.vue @@ -329,7 +329,7 @@ export default { }, //预览照片 showImgViewer(row) { - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; this.imgList = []; previewImage({imageUrl: row.filePath, certFileUrl: this.certFileUrl}).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/invDeviceUsageEditDialog.vue b/src/views/dev/invDeviceUsageEditDialog.vue index 1b76f87a..21c19c3e 100644 --- a/src/views/dev/invDeviceUsageEditDialog.vue +++ b/src/views/dev/invDeviceUsageEditDialog.vue @@ -287,7 +287,7 @@ export default { }, //预览照片 showImgViewer(row) { - this.certFileUrl = this.BASE_URL + '/udiwms/image/register/file/getImage?type=image2&name=' + this.certFileUrl = this.BASE_URL + '/udiwms/image/register/file/getImage?type=device&name=' this.imgList = [] previewImage({ imageUrl: row.filePath, certFileUrl: this.certFileUrl }).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/invDeviceUserEditDialog.vue b/src/views/dev/invDeviceUserEditDialog.vue index b5034e96..ceec0e31 100644 --- a/src/views/dev/invDeviceUserEditDialog.vue +++ b/src/views/dev/invDeviceUserEditDialog.vue @@ -287,7 +287,7 @@ export default { }, //预览照片 showImgViewer(row) { - this.certFileUrl = this.BASE_URL + '/udiwms/image/register/file/getImage?type=image2&name=' + this.certFileUrl = this.BASE_URL + '/udiwms/image/register/file/getImage?type=device&name=' this.imgList = [] previewImage({ imageUrl: row.filePath, certFileUrl: this.certFileUrl }).then(response => { if (response.code === 20000) { diff --git a/src/views/dev/invTechniclDialog.vue b/src/views/dev/invTechniclDialog.vue index fef1b3ce..5f7ad7b2 100644 --- a/src/views/dev/invTechniclDialog.vue +++ b/src/views/dev/invTechniclDialog.vue @@ -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) => { diff --git a/src/views/inventory/cert/depCertAddDialog.vue b/src/views/inventory/cert/depCertAddDialog.vue index 75f362aa..cd7e208b 100644 --- a/src/views/inventory/cert/depCertAddDialog.vue +++ b/src/views/inventory/cert/depCertAddDialog.vue @@ -119,7 +119,7 @@ :on-success="uploadHandleSuccess" :on-error="uploadHandleError" :file-list="fileList" - :data="{type:'image2'}" + :data="{type:'device'}" :auto-upload="true"> {{ choiceFile }} @@ -351,7 +351,7 @@ export default { }, toViewCompanyCert() { - this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name="; + this.certFileUrl = this.BASE_URL + "/udiwms/image/register/file/getImage?type=device&name="; window.open(this.certFileUrl + this.formData.filePath); }, },