pdf.js 811 B

12345678910111213141516171819202122232425262728293031
  1. import Config from '@/config/index'
  2. import getWebBase from '@/utils/webBase'
  3. const webBase = getWebBase()
  4. // 打开 PDF 文件(修复 URL 编码问题)
  5. export function openLocalPdf(fileName, title, type = 'pdf') {
  6. // 最终要跳转的 url
  7. let targetUrl = ''
  8. // 拼接地址
  9. if (type === 'pdf') {
  10. targetUrl = `${Config.Host80}/${fileName}`
  11. } else if (type === 'pdf1') {
  12. targetUrl = fileName
  13. }
  14. // 传递给 webview(只编码一次,正确格式)
  15. const webviewUrl = `/pages/common/webview?url=${encodeURIComponent(targetUrl)}&title=${encodeURIComponent(title)}`
  16. // #ifdef H5
  17. if (type === 'pdf') {
  18. window.open(targetUrl)
  19. } else if (type === 'pdf1') {
  20. window.open(targetUrl)
  21. }
  22. // #endif
  23. // #ifdef APP-PLUS
  24. uni.navigateTo({ url: webviewUrl })
  25. // #endif
  26. }