From 31566408d38ae9350ad3a9e3f5037bb29e178e5c Mon Sep 17 00:00:00 2001 From: yuantao Date: Mon, 1 Dec 2025 15:11:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E5=8A=9F=E8=83=BD=E5=A2=9E=E5=8A=A0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=90=8D=E7=A7=B0=E5=92=8C=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/utils/tool.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/common/utils/tool.js b/common/utils/tool.js index 929ae2c..a393ffd 100644 --- a/common/utils/tool.js +++ b/common/utils/tool.js @@ -29,6 +29,15 @@ class Tool { // Promise包装方法 this.wrapPromise = null + + // 项目信息 + this.projectInfo = { + name: 'template', + version: '1.0.0' + } + + // 尝试从 manifest.json 加载项目信息 + this._loadProjectInfo() } /** @@ -811,6 +820,26 @@ class Tool { } } + /** + * 加载项目信息 + * @private + */ + _loadProjectInfo() { + try { + // 尝试加载 manifest.json 信息 + const manifest = require('../../manifest.json') + if (manifest.name) { + this.projectInfo.name = manifest.name + } + if (manifest.versionName) { + this.projectInfo.version = manifest.versionName + } + } catch (error) { + // 如果加载失败,使用默认信息 + console.warn('无法加载项目信息,使用默认值') + } + } + /** * 格式化错误消息 * @private @@ -819,6 +848,8 @@ class Tool { const timestamp = new Date(errorInfo.timestamp).toLocaleString('zh-CN') let message = `🚨 JavaScript错误报告\n` + message += `📦 项目: ${this.projectInfo.name}\n` + message += `🏷️ 版本: ${this.projectInfo.version}\n` message += `⏰ 时间: ${timestamp}\n` message += `📱 页面: ${errorInfo.page || '未知页面'}\n` message += `🌐 链接: ${errorInfo.url || '未知链接'}\n\n`