PDF插件上线

This commit is contained in:
朱浩 2024-09-25 15:27:41 +08:00
parent 7a978ddf55
commit 9d18bb2cdf
2 changed files with 18 additions and 5 deletions

View File

@ -6,6 +6,7 @@
<script setup>
import { onMounted, ref } from 'vue';
import { getAppInstallUrl } from '@/utils/tool'
const props = defineProps({
url: {
type: String,
@ -16,7 +17,7 @@ const props = defineProps({
/**pdf文件地址 */
const pdfUrl = ref('');
/**pdfjs文件地址 */
const fileUrl = '/pdfjs-dist/web/viewer.html?file=';
const fileUrl = getAppInstallUrl('pdfjs-dist/web/viewer.html', 'user', '\\out\\renderer', true) + "?file=" //
onMounted(() => {
/** 将传入的pdf地址进行编码防止中文识别错误 */
pdfUrl.value = fileUrl + encodeURIComponent(props.url)

View File

@ -49,6 +49,18 @@ export const getStaticUrl = (url = '', type = 'app', exitPath = '', isFile = fal
}
}
}
export const getAppInstallUrl = (url = '', type = 'app', exitPath = '', isFile = false) => {
if (isDev) return url
else { // 生产环境获取-url
switch(type) {
case 'app': return path.join(__dirname, url) // 应用目录
case 'user': return (isFile?'file://':'')+path.join(Remote.app.getAppPath(),exitPath, url) // 用户目录
// case 'user': return (isFile?'file://':'')+path.join(Remote.app.getPath('userData'),exitPath, url) // 用户目录
default: return ''
}
}
}
/**
* @description 消息发送-nodejs 消息发送
* @form src/main/tool.js 来源