diff --git a/src/utils/commons.js b/src/utils/commons.js index 7c027d6..90217b2 100644 --- a/src/utils/commons.js +++ b/src/utils/commons.js @@ -592,18 +592,27 @@ export const logWebsocket = (message, direction) => { } }; export const readWebsocketLog = () => { - let openRequest = indexedDB.open('LogWebsocketData') - openRequest.onsuccess = function (e) { - let db = e.target.result - let transaction = db.transaction('LogStore') - let store = transaction.objectStore('LogStore') - let request = store.getAll() - request.onsuccess = function (e) { - let data = e.target.result - console.log(JSON.stringify(data)) - sessionStorage.setItem('websocketLogData', JSON.stringify(data)) + return new Promise((resolve, reject) => { + let openRequest = indexedDB.open('LogWebsocketData') + openRequest.onerror = function (e) { + reject('Error opening database.') } - } + openRequest.onsuccess = function (e) { + let db = e.target.result + let transaction = db.transaction('LogStore') + let store = transaction.objectStore('LogStore') + let request = store.getAll() + request.onerror = function (e) { + reject('Error getting all records.') + } + request.onsuccess = function (e) { + let data = e.target.result + sessionStorage.setItem('websocketLogData', JSON.stringify(data)) + console.log(JSON.stringify(data)) + resolve(data) + } + } + }) }; export const clearWebsocketLog = () => { let openRequest = indexedDB.open('LogWebsocketData') diff --git a/src/utils/pagespy.js b/src/utils/pagespy.js index 04fb7a0..a0bfb20 100644 --- a/src/utils/pagespy.js +++ b/src/utils/pagespy.js @@ -5,21 +5,27 @@ 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}`, + '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({ maximum: 0.2 * 1024 * 1024 }); - // PageSpy.registerPlugin(window.$harbor); + // 注册插件 + 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.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, }); + // 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); }); }; diff --git a/src/views/AuthApp.jsx b/src/views/AuthApp.jsx index 3491589..e89a58c 100644 --- a/src/views/AuthApp.jsx +++ b/src/views/AuthApp.jsx @@ -90,15 +90,14 @@ function AuthApp() { return fetchEmailWorker; } - const uploadLog = () => { - // sendNotify() - readWebsocketLog() + const uploadLog = async () => { + sendNotify() + await readWebsocketLog() if (window.$pageSpy) { - setTimeout(() => { - window.$pageSpy.triggerPlugins('onOfflineLog', 'upload') + // window.$pageSpy.triggerPlugins('onOfflineLog', 'upload') + await window.$harbor.upload() // 上传日志 { clearCache: true, remark: '' } messageApi.info('Success') - clearWebsocketLog() - }, 200); + clearWebsocketLog() } else { messageApi.error('Failure') }