代码优化

This commit is contained in:
BianLzhaoMin 2025-12-25 10:11:25 +08:00
parent 914fb04175
commit dd58b8cb95
2 changed files with 26 additions and 2 deletions

View File

@ -205,6 +205,30 @@ const getPdfPreviewUrl = (url) => {
// 使 pdf.js viewer
if (props.previewService === 'pdfjs') {
// #ifdef H5
// H5http://使URLCORS
// https使pdfjs viewer
const isLocalOrHttp = fullUrl.startsWith('http://') || fullUrl.startsWith('/')
//
let isSameOrigin = false
try {
if (typeof window !== 'undefined' && window.location) {
const urlObj = new URL(fullUrl, window.location.origin)
isSameOrigin = urlObj.origin === window.location.origin
}
} catch (e) {
// URL
}
if (isLocalOrHttp || isSameOrigin) {
// 使URL
console.log('检测到内网/同源地址使用直接预览模式避免CORS问题')
return fullUrl
}
// #endif
// https使pdfjs viewer
return `https://mozilla.github.io/pdf.js/web/viewer.html?file=${encodeURIComponent(fullUrl)}`
}

View File

@ -572,13 +572,13 @@ const attachments = ref([
url: 'http://192.168.0.38:18080/bnscloud/realnameapp/gzRealName/contract/pdf/施工人员安全告知书.pdf',
},
{
url: 'https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf',
url: 'http://bns-cloud.oss-cn-beijing.aliyuncs.com/upload/app/lsdPhoto/pdf/2025/12/24/01d319cb-a09f-4fe6-a16e-b34491913c94.pdf?Expires=1766631029&OSSAccessKeyId=TMP.3KnER1yK3SmuHqhpR7cyButgj9YipTKQazvma5ESj1VAHwJDZY83yvgyMFjra1SWYEFcbrmrQhRcoSD65kfTzuPQrkGPzY&Signature=qRCf3f4qPiWbmKDZu5%2BdVoL5ZCU%3D',
isSign: false,
fileType: '5',
title: '签订用工协议承诺书',
},
{
url: 'https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf',
url: 'https://bns-cloud.oss-cn-beijing.aliyuncs.com/upload/app/lsdPhoto/pdf/2025/12/24/01d319cb-a09f-4fe6-a16e-b34491913c94.pdf?Expires=1766630782&OSSAccessKeyId=TMP.3KnER1yK3SmuHqhpR7cyButgj9YipTKQazvma5ESj1VAHwJDZY83yvgyMFjra1SWYEFcbrmrQhRcoSD65kfTzuPQrkGPzY&Signature=Lg%2FHxLITIMnaQnWfjGOb1h5rcxc%3D',
isSign: false,
fileType: '4',
title: '安全承诺书',