From 8a7e53bc97eebfc1022c1665fbd7005feab0bfe4 Mon Sep 17 00:00:00 2001 From: fhysy <1149505133@qq.com> Date: Wed, 25 Jun 2025 18:13:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(main):=20=E6=B7=BB=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BA=94=E7=94=A8=E7=89=88=E6=9C=AC=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在主进程中添加 get-app-version 的 IPC 处理程序,返回应用版本号 - 在预加载脚本中暴露 getAppVersion 方法给渲染进程 - 在 calibration 页面中添加版本信息显示 - 优化日志显示功能,增加日志转置和分页显示 - 添加清空日志功能 - 调整设备卡片样式,增加选中状态 --- electron-builder.yml | 3 + src/main/index.js | 11 +- src/preload/index.js | 20 +- src/renderer/src/views/calibration/index.vue | 749 ++++++++++++++----- 4 files changed, 593 insertions(+), 190 deletions(-) diff --git a/electron-builder.yml b/electron-builder.yml index 13478b8..ce62993 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -8,7 +8,10 @@ directories: # 定义要包含或排除在构建输出中的文件 files: - '!**/.vscode/*' # 排除VSCode配置文件 + - '!**/.cursor/*' # 排除cursor配置文件 + - '!**/.idea/*' # 排除idea配置文件 - '!src/*' # 排除源代码目录 + - '!**/*.log' # 排除日志文件 - '!electron.vite.config.{js,ts,mjs,cjs}' # 排除Electron构建配置文件 - '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}' # 排除开发和文档文件 - '!{.env,.env.*,.npmrc,pnpm-lock.yaml,*.zip,app.log}' # 排除环境和包管理配置文件 diff --git a/src/main/index.js b/src/main/index.js index b5468cc..6ff2476 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -91,9 +91,9 @@ if (!gotTheLock) { } }); - // This method will be called when Electron has finished - // initialization and is ready to create browser windows. - // Some APIs can only be used after this event occurs. + //当Electron完成时,将调用此方法 +//初始化并准备创建浏览器窗口。 +//某些API只能在此事件发生后使用。 const { spawn } = require('child_process'); let child = null; let exePluginsExeList = []; @@ -220,5 +220,10 @@ if (!gotTheLock) { } }); } + // In this file you can include the rest of your app"s specific main process // code. You can also put them in separate files and require them here. + +ipcMain.handle('get-app-version', () => { + return app.getVersion(); +}); diff --git a/src/preload/index.js b/src/preload/index.js index 121f8c3..1717c90 100644 --- a/src/preload/index.js +++ b/src/preload/index.js @@ -1,4 +1,4 @@ -import { contextBridge, ipcRenderer } from 'electron' +import { contextBridge, ipcRenderer } from 'electron' import { electronAPI } from '@electron-toolkit/preload' // Custom APIs for renderer @@ -16,6 +16,10 @@ import { electronAPI } from '@electron-toolkit/preload' // return result; // } // } +// // 暴露获取版本号的方法 +// ipcMain.handle('get-app-version', () => { +// return app.getVersion(); // 返回当前应用版本(来自 package.json) +// }); // Use `contextBridge` APIs to expose Electron APIs to // renderer only if context isolation is enabled, otherwise @@ -23,12 +27,22 @@ import { electronAPI } from '@electron-toolkit/preload' // 使用contextBridge将Electron API和自定义的主进程方法API暴露给渲染进程页面。 if (process.contextIsolated) { try { - contextBridge.exposeInMainWorld('electron', electronAPI) + contextBridge.exposeInMainWorld('electron', { + ...electronAPI, + getAppVersion: async () => { + return await ipcRenderer.invoke('get-app-version'); + } + }) // contextBridge.exposeInMainWorld('api', api) } catch (error) { console.error(error) } } else { - window.electron = electronAPI + window.electron = { + ...electronAPI, + getAppVersion: async () => { + return await ipcRenderer.invoke('get-app-version'); + } + } // window.api = api } diff --git a/src/renderer/src/views/calibration/index.vue b/src/renderer/src/views/calibration/index.vue index bd09e57..3654105 100644 --- a/src/renderer/src/views/calibration/index.vue +++ b/src/renderer/src/views/calibration/index.vue @@ -2,7 +2,7 @@
设备码: {{ device.deviceSN || '无' }}
+芯片ID: {{ device.deviceSN || '无' }}
设备端口: {{ device.devicePort || '无' }}
标定结果: {{ device.result || '无' }}
- 失败描述:
+ 结果描述: