代码优化
This commit is contained in:
parent
914fb04175
commit
dd58b8cb95
|
|
@ -205,6 +205,30 @@ const getPdfPreviewUrl = (url) => {
|
||||||
|
|
||||||
// 使用 pdf.js viewer 方案(适用于微信内置浏览器无法直接预览的场景)
|
// 使用 pdf.js viewer 方案(适用于微信内置浏览器无法直接预览的场景)
|
||||||
if (props.previewService === 'pdfjs') {
|
if (props.previewService === 'pdfjs') {
|
||||||
|
// #ifdef H5
|
||||||
|
// H5环境下,如果是内网地址(http://)或相对路径,直接使用原URL避免CORS问题
|
||||||
|
// 只有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)}`
|
return `https://mozilla.github.io/pdf.js/web/viewer.html?file=${encodeURIComponent(fullUrl)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -572,13 +572,13 @@ const attachments = ref([
|
||||||
url: 'http://192.168.0.38:18080/bnscloud/realnameapp/gzRealName/contract/pdf/施工人员安全告知书.pdf',
|
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,
|
isSign: false,
|
||||||
fileType: '5',
|
fileType: '5',
|
||||||
title: '签订用工协议承诺书',
|
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,
|
isSign: false,
|
||||||
fileType: '4',
|
fileType: '4',
|
||||||
title: '安全承诺书',
|
title: '安全承诺书',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue