pdf.js 707 B

123456789101112131415161718
  1. import Config from '@/config/index'
  2. const { Host80 } = Config
  3. import getWebBase from '@/utils/webBase'
  4. const webBase = getWebBase()
  5. // utils/pdf.js 或直接在组件 methods 中定义
  6. export function openLocalPdf(fileName, title) {
  7. // #ifdef H5
  8. // H5 端直接打开相对路径,会被浏览器渲染或下载(取决于浏览器配置)
  9. window.open(`${Host80}${webBase}static/${fileName}`);
  10. // #endif
  11. // #ifdef APP-PLUS
  12. // App 端:将静态资源路径转为系统绝对路径,再用 uni.openDocument 调用系统阅读器打开
  13. uni.navigateTo({
  14. url: `/pages/common/webview?url=${encodeURIComponent(`${Host80}${webBase}static/${fileName}`)}&title=${title}`
  15. });
  16. // #endif
  17. }