You've already forked template-MP
新增 错误上报功能增加项目名称和版本号信息
This commit is contained in:
@@ -29,6 +29,15 @@ class Tool {
|
|||||||
|
|
||||||
// Promise包装方法
|
// Promise包装方法
|
||||||
this.wrapPromise = null
|
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
|
* @private
|
||||||
@@ -819,6 +848,8 @@ class Tool {
|
|||||||
const timestamp = new Date(errorInfo.timestamp).toLocaleString('zh-CN')
|
const timestamp = new Date(errorInfo.timestamp).toLocaleString('zh-CN')
|
||||||
|
|
||||||
let message = `🚨 JavaScript错误报告\n`
|
let message = `🚨 JavaScript错误报告\n`
|
||||||
|
message += `📦 项目: ${this.projectInfo.name}\n`
|
||||||
|
message += `🏷️ 版本: ${this.projectInfo.version}\n`
|
||||||
message += `⏰ 时间: ${timestamp}\n`
|
message += `⏰ 时间: ${timestamp}\n`
|
||||||
message += `📱 页面: ${errorInfo.page || '未知页面'}\n`
|
message += `📱 页面: ${errorInfo.page || '未知页面'}\n`
|
||||||
message += `🌐 链接: ${errorInfo.url || '未知链接'}\n\n`
|
message += `🌐 链接: ${errorInfo.url || '未知链接'}\n\n`
|
||||||
|
|||||||
Reference in New Issue
Block a user