|
|
|
|
import { loadScript } from '@haina/utils-commons'
|
|
|
|
|
import { fetchJSON } from '@/utils/request'
|
|
|
|
|
import { readWebsocketLog } from '@/utils/indexedDB'
|
|
|
|
|
import { BUILD_VERSION, BUILD_DATE } from '@/config'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
// export const loadPageSpy = (title) => {
|
|
|
|
|
// if (import.meta.env.DEV || window.$pageSpy) return
|
|
|
|
|
|
|
|
|
|
// const PageSpyConfig = { api: 'page-spy.mycht.cn', project: 'Sales CRM', title: title + '(v' + BUILD_VERSION + ')', autoRender: false, offline: true }
|
|
|
|
|
|
|
|
|
|
// const PageSpySrc = [
|
|
|
|
|
// 'https://page-spy.mycht.cn/page-spy/index.min.js' + `?${BUILD_DATE}`,
|
|
|
|
|
// 'https://page-spy.mycht.cn/plugin/data-harbor/index.min.js' + `?${BUILD_DATE}`,
|
|
|
|
|
// 'https://page-spy.mycht.cn/plugin/rrweb/index.min.js' + `?${BUILD_DATE}`,
|
|
|
|
|
// ]
|
|
|
|
|
// Promise.all(PageSpySrc.map((src) => loadScript(src))).then(() => {
|
|
|
|
|
// // 注册插件
|
|
|
|
|
// window.$harbor = new DataHarborPlugin()
|
|
|
|
|
// window.$rrweb = new RRWebPlugin()
|
|
|
|
|
// ;[window.$harbor, window.$rrweb].forEach((p) => {
|
|
|
|
|
// PageSpy.registerPlugin(p)
|
|
|
|
|
// })
|
|
|
|
|
// window.$pageSpy = new PageSpy(PageSpyConfig)
|
|
|
|
|
|
|
|
|
|
// // PageSpy.registerPlugin(new DataHarborPlugin());
|
|
|
|
|
// // PageSpy.registerPlugin(new RRWebPlugin());
|
|
|
|
|
// // 实例化 PageSpy
|
|
|
|
|
// // window.$pageSpy = new PageSpy({ api: 'page-spy.mycht.cn', project: 'Sales CRM', title: title + '(v' + BUILD_VERSION + ')', autoRender: false, offline: true, });
|
|
|
|
|
// console.log('[PageSpy]', window.$pageSpy.version)
|
|
|
|
|
// // window.addEventListener('beforeunload', (e) => {
|
|
|
|
|
// // e.preventDefault() // If you prevent default behavior in Mozilla Firefox
|
|
|
|
|
// // e.returnValue = '' // Chrome requires returnValue to be set
|
|
|
|
|
|
|
|
|
|
// // window.$harbor.upload({ clearCache: false, remark: '自动上传' }) // 上传日志 { clearCache: true, remark: '' }
|
|
|
|
|
// // })
|
|
|
|
|
// window.onerror = async function (msg, url, lineNo, columnNo, error) {
|
|
|
|
|
// await readWebsocketLog()
|
|
|
|
|
// // 上传最近 3 分钟的日志
|
|
|
|
|
// const now = Date.now()
|
|
|
|
|
// await window.$harbor.uploadPeriods({
|
|
|
|
|
// startTime: now - 3 * 60000,
|
|
|
|
|
// endTime: now,
|
|
|
|
|
// remark: `\`onerror\`自动上传. ${msg}`,
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
// export const uploadPageSpyLog = async () => {
|
|
|
|
|
// // window.$pageSpy.triggerPlugins('onOfflineLog', 'upload');
|
|
|
|
|
// // if (window.$pageSpy) {
|
|
|
|
|
// // await window.$harbor.upload() // 上传日志 { clearCache: true, remark: '' }
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
|
|
// if (import.meta.env.DEV) return true;
|
|
|
|
|
|
|
|
|
|
// if (window.$pageSpy) {
|
|
|
|
|
// try {
|
|
|
|
|
// await readWebsocketLog()
|
|
|
|
|
// // 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,
|
|
|
|
|
// });
|
|
|
|
|
// return true;
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
export const sendNotify = async (message) => {
|
|
|
|
|
|
|
|
|
|
const notifyUrl = 'https://p9axztuwd7x8a7.mycht.cn/dingtalk/dingtalkwork/SendMDMsgByDingRobotToGroup';
|
|
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
|
groupid: 'cidFtzcIzNwNoiaGU9Q795CIg==',
|
|
|
|
|
msgTitle: '有人求助',
|
|
|
|
|
msgText: `${message}\\n\\nSales CRM (${BUILD_VERSION})`,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return fetchJSON(notifyUrl, params).then((json) => {
|
|
|
|
|
if (json.errcode === 0) {
|
|
|
|
|
console.info('发送通知成功');
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(json?.errmsg + ': ' + json.errcode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
// const uploadLog = async () => {
|
|
|
|
|
// await readWebsocketLog()
|
|
|
|
|
// if (window.$pageSpy) {
|
|
|
|
|
// // window.$pageSpy.triggerPlugins('onOfflineLog', 'upload')
|
|
|
|
|
// 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,
|
|
|
|
|
// })
|
|
|
|
|
// messageApi.info('Success')
|
|
|
|
|
// // clearWebsocketLog()
|
|
|
|
|
// sendNotify()
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// messageApi.error('Failure')
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// messageApi.error('Failure')
|
|
|
|
|
// }
|
|
|
|
|
// }
|