打开外部日志的功能

This commit is contained in:
刘嘉伟 2024-12-04 16:19:17 +08:00
parent 5ac69de59a
commit 6c4a052bf6
3 changed files with 40 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import { app, ipcMain } from "electron";
import { app, ipcMain, shell } from "electron";
const fs = require("fs");
const path = require("path");
@ -28,4 +28,17 @@ export const initLoggerApi = () => {
}
});
});
ipcMain.on("logger.openLog", (event, args) => {
console.log('正在打开日志');
shell.openPath(logPath).then((errorMessage) => {
if (errorMessage) {
console.error('Failed to open Logger:', errorMessage);
event.reply("Logger.openLog.hook", false);
} else {
console.log('Logger opened successfully');
event.reply("Logger.openLog.hook", true);
}
});
});
};

View File

@ -1,10 +1,5 @@
import {addIcon} from "@iconify/vue/dist/offline";
/**
* src/layout/index.vue
*/
// 本地菜单图标后端在路由的icon中返回对应的图标字符串并且前端在此处使用addIcon添加即可渲染菜单图标
import Cloud from "@iconify-icons/material-symbols/cloud";
import RocketLaunchRounded from "@iconify-icons/material-symbols/rocket-launch-rounded";
import Download from "@iconify-icons/material-symbols/download-2";
@ -36,6 +31,7 @@ import deviceReset from "@iconify-icons/material-symbols/device-reset";
import switchAccessOutlineRounded from "@iconify-icons/material-symbols/switch-access-outline-rounded";
import switchAccessRounded from "@iconify-icons/material-symbols/switch-access-rounded";
import chargerRounded from "@iconify-icons/material-symbols/charger-rounded";
import fileOpenRounded from "@iconify-icons/material-symbols/file-open-rounded";
addIcon("cloud", Cloud);
addIcon("rocket-launch-rounded", RocketLaunchRounded);
@ -67,5 +63,6 @@ addIcon("downloadRounded", downloadRounded);
addIcon("deviceReset", deviceReset);
addIcon("switchAccessOutlineRounded", switchAccessOutlineRounded);
addIcon("switchAccessRounded", switchAccessRounded);
addIcon("file-open-rounded", fileOpenRounded);

View File

@ -2,6 +2,9 @@
import { defineComponent, onMounted, onUnmounted, ref } from "vue";
import Breadcrumb from "@/layout/compoenets/Breadcrumb.vue";
import { ipcRenderer } from "electron";
import IconifyIconOffline from "@/components/IconifyIcon/src/iconifyIconOffline";
import { useDebounce, useDebounceFn } from "@vueuse/core";
import { ElMessage } from "element-plus";
defineComponent({
name: "Logger"
@ -46,7 +49,21 @@ onMounted(() => {
loggerContent.value = handleLog2Html(args);
}
});
ipcRenderer.on("Logger.openLog.hook", (event, args) => {
if (args) {
ElMessage({
type: "success",
message: "打开日志成功"
});
}
});
});
const openLocalLog = useDebounceFn(() => {
console.log('打开啊日志');
ipcRenderer.send("logger.openLog");
}, 300);
onUnmounted(() => {
ipcRenderer.removeAllListeners("Logger.getLog.hook");
@ -54,7 +71,11 @@ onUnmounted(() => {
</script>
<template>
<div class="main">
<breadcrumb />
<breadcrumb>
<el-button plain type="primary" @click="openLocalLog">
<IconifyIconOffline icon="file-open-rounded" />
</el-button>
</breadcrumb>
<div class="app-container-breadcrumb">
<div
class="w-full h-full p-2 bg-[#2B2B2B] rounded drop-shadow-lg overflow-y-auto"