优化 重构错误监控架构,移除tool.js中的错误监控代码,改为使用uniapp-error-monitor外部库,实现职责分离和代码简化

This commit is contained in:
yuantao
2025-12-02 10:28:16 +08:00
parent 1ca6e6c77a
commit cd2b838647
3 changed files with 17 additions and 285 deletions

21
main.js
View File

@@ -2,9 +2,9 @@ import App from './App'
import uviewPlus from '/uview-plus'
import globalMixin from './mixins/global'
import store from './store'
import tool from './common/utils/tool'
import { createSSRApp } from 'vue'
import './uni.promisify.adaptor'
import { initErrorMonitor } from 'uniapp-error-monitor'
uni.$zp = {
config: {
@@ -18,16 +18,15 @@ export function createApp() {
app.use(uviewPlus)
app.use(globalMixin)
app.use(store)
// 初始化全局错误监控
// 注意只有在生产环境下才会启用错误监控和WebHook上报
// 开发环境和体验版会自动禁用错误监控
tool.initErrorMonitor({
enableGlobalError: true,
enablePromiseError: true,
enableConsoleError: false, // 可选开启console错误监控
// forceEnable: true, // 如需强制启用,可取消注释此行
// 初始化错误监控
initErrorMonitor({
webhookUrl: import.meta.env.VITE_WEBHOOK, // 必填
enableGlobalError: true, // 启用全局错误捕获
enablePromiseError: true, // 启用 Promise 错误捕获
enableConsoleError: false, // 禁用 console.error 捕获
// forceEnable: true,
})
return { app }
}