refactor: `@/pagespy` --> `@haina/utils-pagespy`;

main
Lei OT 4 months ago
parent 7087954bd3
commit 1608a6049a

@ -13,6 +13,7 @@
"dependencies": {
"@ant-design/icons": "^5.5.1",
"@haina/utils-commons": "http://202.103.68.93:9000/npm/utils-commons-0.1.0.tgz",
"@haina/utils-pagespy": "http://202.103.68.93:9000/npm/utils-pagespy-0.1.1.tgz",
"@haina/utils-request": "http://202.103.68.93:9000/npm/utils-request-0.1.0.tgz",
"@react-pdf/renderer": "^3.4.0",
"antd": "^5.28.0",

@ -2,7 +2,8 @@ import { useState } from "react";
import { Popover, message, FloatButton, Button, Form, Input } from "antd";
import { BugOutlined } from "@ant-design/icons";
import useAuthStore from "@/stores/Auth";
import { uploadPageSpyLog, sendNotify } from "@/pageSpy";
import { sendNotify } from "@/pageSpy";
import { uploadPageSpyLog } from '@haina/utils-pagespy';
function LogUploader() {
const [open, setOpen] = useState(false);

@ -1,6 +1,5 @@
import { loadScript } from '@/utils/commons';
import { PROJECT_NAME, BUILD_VERSION } from '@/config';
import { fetchJSON } from '@/utils/request'
import { fetchJSON } from '@haina/utils-request'
import { usingStorage } from "@/hooks/usingStorage";
export const sendNotify = async (message) => {
@ -22,85 +21,3 @@ export const sendNotify = async (message) => {
}
});
};
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'+`?v=${BUILD_VERSION}`,
'https://page-spy.mycht.cn/plugin/data-harbor/index.min.js'+`?v=${BUILD_VERSION}`,
'https://page-spy.mycht.cn/plugin/rrweb/index.min.js'+`?v=${BUILD_VERSION}`,
];
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);
window.onerror = async function (msg, url, lineNo, columnNo, error) {
// iframe rrweb Cannot set property attributeName of #<MutationRecord> which has only a getter
//
if (url && url.indexOf('https://page-spy.mycht.cn/plugin/rrweb/index.min.js') > -1) {
console.info('ignore rrweb error')
} else {
// 3
const now = Date.now()
await window.$harbor.uploadPeriods({
startTime: now - 3 * 60000,
endTime: now,
remark: `\`onerror\`自动上传. ${msg}`,
})
}
}
});
};
export const uploadPageSpyLog = async () => {
if (import.meta.env.DEV) return true;
if (window.$pageSpy) {
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,
});
return true;
} catch (error) {
return false;
}
} else {
return false;
}
}
/**
* @deprecated
* @outdated
*/
export const PageSpyLog = () => {
return (
<>
{window.$pageSpy && (
<a
className='text-primary'
onClick={() => {
window.$pageSpy.triggerPlugins('onOfflineLog', 'download');
window.$pageSpy.triggerPlugins('onOfflineLog', 'upload');
}}>
上传Debug日志 ({window.$pageSpy.address.substring(0, 4)})
</a>
)}
</>
);
};

@ -1,8 +1,8 @@
import { create } from 'zustand'
import { devtools } from 'zustand/middleware'
import { appendRequestParams, fetchJSON, postForm } from '@haina/utils-request'
import { HT_HOST } from "@/config"
import { loadPageSpy } from '@/pageSpy'
import { HT_HOST, PROJECT_NAME } from "@/config"
import { loadPageSpy } from '@haina/utils-pagespy'
import { usingStorage } from '@/hooks/usingStorage'
import { isEmpty } from "@haina/utils-commons";
@ -86,7 +86,7 @@ const useAuthStore = create(devtools((set, get) => ({
}
}))
loadPageSpy(`${userJson.LoginName}-${userJson.VName}`)
loadPageSpy(`${userJson.LoginName}-${userJson.VName}`, PROJECT_NAME, false)
},
authenticate: async (usr, pwd) => {

Loading…
Cancel
Save