perf: 上传日志通知

dev/2025b
Lei OT 2 months ago
parent 5c5d10ef27
commit 7abeef5c1e

@ -1,7 +1,29 @@
import { loadScript } from '@/utils/commons';
import { PROJECT_NAME, BUILD_VERSION } from '@/config';
import { fetchJSON } from '@/utils/request'
let spyTitle = '';
const sendNotify = async () => {
const notifyUrl = 'https://p9axztuwd7x8a7.mycht.cn/dingtalk/dingtalkwork/SendMDMsgByDingRobotToGroup';
const params = {
groupid: 'cidFtzcIzNwNoiaGU9Q795CIg==',
msgTitle: '有人求助',
msgText: `${spyTitle}上传了${PROJECT_NAME} (${BUILD_VERSION})的日志`,
};
return fetchJSON(notifyUrl, params).then((json) => {
if (json.errcode === 0) {
console.info('发送通知成功');
} else {
throw new Error(json?.errmsg + ': ' + json.errcode);
}
});
};
export const loadPageSpy = (title) => {
spyTitle = title;
if (import.meta.env.DEV || window.$pageSpy) return
@ -20,19 +42,44 @@ export const loadPageSpy = (title) => {
PageSpy.registerPlugin(p)
})
window.$pageSpy = new PageSpy(PageSpyConfig);
window.onerror = async function (msg, url, lineNo, columnNo, error) {
// 3
const now = Date.now()
await window.$harbor.uploadPeriods({
startTime: now - 3 * 60000,
endTime: now,
remark: `\`onerror\`自动上传. ${msg}`,
})
}
});
};
export const uploadPageSpyLog = async () => {
// window.$pageSpy.triggerPlugins('onOfflineLog', 'upload');
if (window.$pageSpy) {
await window.$harbor.upload() // { clearCache: true, remark: '' }
alert('Success')
try {
// await window.$harbor.upload() // { clearCache: true, remark: '' }
// 1 , upload : 413 Payload Too Large
const now = Date.now();
await window.$harbor.uploadPeriods({
startTime: now - 60 * 60000,
endTime: now,
});
alert('Success');
sendNotify()
} catch (error) {
alert('Failure');
}
} else {
alert('Failure')
}
}
/**
* @deprecated
* @outdated
*/
export const PageSpyLog = () => {
return (
<>

Loading…
Cancel
Save