pdf.js 830 B

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