|
@@ -9,6 +9,18 @@ export const api_sysExceptionLogSave = (params: any): Promise<any> => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+type uploadType = {
|
|
|
+ clientType?: string;
|
|
|
+ phone?: string | undefined | null;
|
|
|
+ userAgent?: string;
|
|
|
+ appType?: string;
|
|
|
+ content?: string;
|
|
|
+ exceptionType?: string;
|
|
|
+ exceptionTime?: string;
|
|
|
+ deviceType?: string | null;
|
|
|
+ deviceVersion?: string | null
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* 页面有报错时上传错误日志
|
|
|
* @params
|
|
@@ -36,51 +48,64 @@ export default function useErrorLog() {
|
|
|
'/creation'
|
|
|
];
|
|
|
|
|
|
+ let _defaultParams = {
|
|
|
+ clientType: 'STUDENT',
|
|
|
+ phone: '',
|
|
|
+ userAgent: '',
|
|
|
+ appType: 'WEB',
|
|
|
+ content: '',
|
|
|
+ exceptionType: 'ERROR',
|
|
|
+ exceptionTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
+ deviceType: null,
|
|
|
+ deviceVersion: null
|
|
|
+ }
|
|
|
+
|
|
|
const _uploadErrorLog = async (event: any) => {
|
|
|
try {
|
|
|
state.user.data.phone;
|
|
|
|
|
|
- /**
|
|
|
- 日志上报:1.手机号、应用端 iOS|安卓 App类型(老师端|学生端|web)、App版本、系统信息(系统版本|web userAgent)、错误信息(什么位置出现,错误内容) 错误时间 上报类型(错误、埋点)
|
|
|
- Phone、 type 、content
|
|
|
- 手机号|上报类型 (error、record)|content 内容jsonString (应用端 iOS|安卓 App类型(老师端|学生端|web)、App版本、系统信息(系统版本|web userAgent)、错误信息(什么位置出现,错误内容) 错误时间)
|
|
|
+ /*
|
|
|
+ 日志上报:1.手机号、应用端 iOS|安卓 App类型(老师端|学生端|web)、App版本、系统信息(系统版本|web userAgent)、错误信息(什么位置出现,错误内容) 错误时间 上报类型(错误、埋点)
|
|
|
+ Phone、 type 、content
|
|
|
+ 手机号|上报类型 (error、record)|content 内容jsonString (应用端 iOS|安卓 App类型(老师端|学生端|web)、App版本、系统信息(系统版本|web userAgent)、错误信息(什么位置出现,错误内容) 错误时间)
|
|
|
|
|
|
- 手机号 |上报类型 |业务平台|应用端(iOS|安卓)|
|
|
|
+ 手机号 |上报类型 |业务平台|应用端(iOS|安卓)|
|
|
|
*/
|
|
|
- console.log(state.user, window.location.href);
|
|
|
const href = window.location.href;
|
|
|
const index = _whiteBlanks.findIndex(
|
|
|
(item: string) => href.indexOf(item) !== -1
|
|
|
);
|
|
|
|
|
|
- if (window.location.hash === '#/' || index !== -1) {
|
|
|
+ const whiteIp = ['kt.colexiu.com', 'test.kt.colexiu.com', 'dev.kt.colexiu.com']
|
|
|
+ console.log(window.location.hash, index, 'errorLog')
|
|
|
+ if (!whiteIp.includes(window.location.host)) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!(window.location.hash === '#/' || index !== -1)) {
|
|
|
+ return
|
|
|
}
|
|
|
// 错误信息
|
|
|
// 资源加载失败,可以在这里处理错误
|
|
|
- const contentError = `Error message: ${event.target.tagName || ''},${
|
|
|
+ const contentError = `Error message: ${event.target.tagName || ''};${
|
|
|
event.target.src || event.target.href || ''
|
|
|
- }、lineno: ${event.target.lineno || ''}、message: ${
|
|
|
- event.target.message || ''
|
|
|
- }、filename: ${event.target.filename || ''}、fileUrl: ${
|
|
|
+ };lineno: ${event.lineno || ''};message: ${
|
|
|
+ event.message || ''
|
|
|
+ };filename: ${event.filename || ''};fileUrl: ${
|
|
|
window.location.href
|
|
|
}`;
|
|
|
// }
|
|
|
|
|
|
const params = [
|
|
|
{
|
|
|
- clientType: 'STUDENT',
|
|
|
+ ..._defaultParams,
|
|
|
phone: state.user.data?.phone,
|
|
|
userAgent: window.navigator.userAgent,
|
|
|
- appType: 'WEB',
|
|
|
content: contentError,
|
|
|
- exceptionType: 'ERROR',
|
|
|
exceptionTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
- deviceType: null,
|
|
|
- deviceVersion: null
|
|
|
}
|
|
|
];
|
|
|
- console.log('errorLog', params);
|
|
|
- // await api_sysExceptionLogSave(params);
|
|
|
+ // console.log(params)
|
|
|
+ await api_sysExceptionLogSave(params);
|
|
|
} catch {
|
|
|
//
|
|
|
}
|
|
@@ -88,7 +113,8 @@ export default function useErrorLog() {
|
|
|
/**
|
|
|
* 开始监听错误日志并上传
|
|
|
*/
|
|
|
- const startListenErrorLog = () => {
|
|
|
+ const startListenErrorLog = (params?: uploadType) => {
|
|
|
+ _defaultParams = Object.assign(_defaultParams, params);
|
|
|
console.log('mount useErrorLog');
|
|
|
window.addEventListener('error', _uploadErrorLog);
|
|
|
};
|