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> <script setup>
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { getAppInstallUrl } from '@/utils/tool'
const props = defineProps({ const props = defineProps({
url: { url: {
type: String, type: String,
@ -16,7 +17,7 @@ const props = defineProps({
/**pdf文件地址 */ /**pdf文件地址 */
const pdfUrl = ref(''); const pdfUrl = ref('');
/**pdfjs文件地址 */ /**pdfjs文件地址 */
const fileUrl = '/pdfjs-dist/web/viewer.html?file='; const fileUrl = getAppInstallUrl('pdfjs-dist/web/viewer.html', 'user', '\\out\\renderer', true) + "?file=" //
onMounted(() => { onMounted(() => {
/** 将传入的pdf地址进行编码防止中文识别错误 */ /** 将传入的pdf地址进行编码防止中文识别错误 */
pdfUrl.value = fileUrl + encodeURIComponent(props.url) 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 消息发送 * @description 消息发送-nodejs 消息发送
* @form src/main/tool.js 来源 * @form src/main/tool.js 来源
@ -137,7 +149,7 @@ export const createWindow = async (type, data) => {
winPdf.focus(); winPdf.focus();
// toolState.isPdfWin=true // toolState.isPdfWin=true
} }
return return
} }
const option = data.option||{} const option = data.option||{}
@ -272,7 +284,7 @@ const eventHandles = (type, win) => {
winPdf=null winPdf=null
win&&win.destroy() win&&win.destroy()
}) })
// 监听窗口的激活事件 // 监听窗口的激活事件
win.on('focus', async () => { win.on('focus', async () => {
console.log('激活窗口') console.log('激活窗口')
@ -299,8 +311,8 @@ const eventHandles = (type, win) => {
/** /**
* @description 外部跳转-web网页 * @description 外部跳转-web网页
* @param {*} path * @param {*} path
* @param {*} params * @param {*} params
*/ */
export const toLinkWeb = (path) => { export const toLinkWeb = (path) => {
const config = baseConfig() const config = baseConfig()