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