Commit 37b3e1ab by 程默

添加全局js异常监控上报

parent 163775df
<script> <script>
// let mpAnalytics=require('../node_modules/mayi-analytics/dist/');
export default { export default {
created () { created() {
// NODE_ENV // NODE_ENV
let extConfig = wx.getExtConfigSync? wx.getExtConfigSync(): {} let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
if (process.env.NODE_ENV=="development") { if (process.env.NODE_ENV == "development") {
extConfig={mixid:'antgood'} extConfig={mixid:'antgood'}
} }
this.$store.commit("setExtConfig", extConfig.mixid); this.$store.commit("setExtConfig", extConfig.mixid);
// if (wx.getExtConfig) {
// wx.getExtConfig({
// success : (res) => {
// if(res.errMsg == 'getExtConfig: ok'){
// this.$store.commit("setExtConfig", res.extConfig.mixid);
// }
// }
// })
// }
// 调用API从本地缓存中获取数据 // 调用API从本地缓存中获取数据
/* /*
* 平台 api 差异的处理方式: api 方法统一挂载到 mpvue 名称空间, 平台判断通过 mpvuePlatform 特征字符串 * 平台 api 差异的处理方式: api 方法统一挂载到 mpvue 名称空间, 平台判断通过 mpvuePlatform 特征字符串
...@@ -27,24 +17,43 @@ export default { ...@@ -27,24 +17,43 @@ export default {
* 支付宝(蚂蚁):mpvue === my, mpvuePlatform === 'my' * 支付宝(蚂蚁):mpvue === my, mpvuePlatform === 'my'
*/ */
let logs let logs;
if (mpvuePlatform === 'my') { if (mpvuePlatform === "my") {
logs = mpvue.getStorageSync({key: 'logs'}).data || [] logs = mpvue.getStorageSync({ key: "logs" }).data || [];
logs.unshift(Date.now()) logs.unshift(Date.now());
mpvue.setStorageSync({ mpvue.setStorageSync({
key: 'logs', key: "logs",
data: logs data: logs
}) });
} else { } else {
logs = mpvue.getStorageSync('logs') || [] logs = mpvue.getStorageSync("logs") || [];
logs.unshift(Date.now()) logs.unshift(Date.now());
mpvue.setStorageSync('logs', logs) mpvue.setStorageSync("logs", logs);
} }
}, },
log () { onError(err) {
console.log(`log at:${Date.now()}`) console.log(err, "js异常捕获");
wx.request({
url: "https://analytics.mayi888.cn/ma.gif",
data: {
e: "mp_error",
logInfo: {
err
} }
} },
method: "GET",
success: function(res) {
console.log("上报成功", res);
},
fail: function(res) {
console.log("上报失败", res);
}
});
},
log() {
console.log(`log at:${Date.now()}`);
}
};
</script> </script>
<style> <style>
...@@ -66,5 +75,5 @@ export default { ...@@ -66,5 +75,5 @@ export default {
} }
@import url("../static/font/iconfont.css"); @import url("../static/font/iconfont.css");
@import url('../static/css/common.scss'); @import url("../static/css/common.scss");
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment