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`