diff --git a/src/pageSpy/index.jsx b/src/pageSpy/index.jsx index 10c4c03..a0918e5 100644 --- a/src/pageSpy/index.jsx +++ b/src/pageSpy/index.jsx @@ -1,26 +1,36 @@ import { loadScript } from '@/utils/commons'; -import { PROJECT_NAME } from '@/config'; +import { PROJECT_NAME, BUILD_VERSION } from '@/config'; export const loadPageSpy = (title) => { if (import.meta.env.DEV || window.$pageSpy) return + const PageSpyConfig = { api: 'page-spy.mycht.cn', project: PROJECT_NAME, title: title, autoRender: false }; const PageSpySrc = [ - 'https://page-spy.mycht.cn/page-spy/index.min.js', - 'https://page-spy.mycht.cn/plugin/data-harbor/index.min.js', - 'https://page-spy.mycht.cn/plugin/rrweb/index.min.js', + 'https://page-spy.mycht.cn/page-spy/index.min.js'+`?${BUILD_VERSION}`, + 'https://page-spy.mycht.cn/plugin/data-harbor/index.min.js'+`?${BUILD_VERSION}`, + 'https://page-spy.mycht.cn/plugin/rrweb/index.min.js'+`?${BUILD_VERSION}`, ]; Promise.all(PageSpySrc.map((src) => loadScript(src))).then(() => { // 注册插件 - PageSpy.registerPlugin(new DataHarborPlugin({ maximum: 2 * 1024 * 1024 })); - // 实例化 PageSpy - window.$pageSpy = new PageSpy({ api: 'page-spy.mycht.cn', project: PROJECT_NAME, title: title, autoRender: false }); + window.$harbor = new DataHarborPlugin(); + window.$rrweb = new RRWebPlugin(); + [window.$harbor, window.$rrweb].forEach(p => { + PageSpy.registerPlugin(p) + }) + window.$pageSpy = new PageSpy(PageSpyConfig); }); }; -export const uploadPageSpyLog = () => { - window.$pageSpy.triggerPlugins('onOfflineLog', 'upload'); +export const uploadPageSpyLog = async () => { + // window.$pageSpy.triggerPlugins('onOfflineLog', 'upload'); + if (window.$pageSpy) { + await window.$harbor.upload() // 上传日志 { clearCache: true, remark: '' } + alert('Success') + } else { + alert('Failure') + } } export const PageSpyLog = () => { diff --git a/src/stores/Auth.js b/src/stores/Auth.js index 07e0554..8828884 100644 --- a/src/stores/Auth.js +++ b/src/stores/Auth.js @@ -87,7 +87,7 @@ const useAuthStore = create(devtools((set, get) => ({ } })) - loadPageSpy(userJson.real_name) + loadPageSpy(`${userJson.real_name}-${userJson.VName}`) }, authenticate: async (usr, pwd) => { diff --git a/src/views/App.jsx b/src/views/App.jsx index 4665957..8428689 100644 --- a/src/views/App.jsx +++ b/src/views/App.jsx @@ -18,6 +18,7 @@ import { useThemeContext } from '@/stores/ThemeContext' import { usingStorage } from '@/hooks/usingStorage' import { useDefaultLgc } from '@/i18n/LanguageSwitcher' import { appendRequestParams } from '@/utils/request' +import { uploadPageSpyLog } from '@/pageSpy'; import { PERM_ACCOUNT_MANAGEMENT, PERM_ROLE_NEW, PERM_OVERSEA, PERM_AIR_TICKET, PERM_PRODUCTS_MANAGEMENT } from '@/config' @@ -92,7 +93,7 @@ function App() { insetInlineEnd: 94, }} > - } onClick={() => uploadLog()} /> + } onClick={() => uploadPageSpyLog()} /> {contextHolder}