|
@@ -1,8 +1,4 @@
|
|
|
-import dayjs from 'dayjs';
|
|
|
-import { sysExceptionLogSave } from '/src/utils/baseApi'
|
|
|
-import { storeData } from "/src/store";
|
|
|
-import { browser } from "/src/utils";
|
|
|
-import state from "/src/state";
|
|
|
+import { uploadErrorLog } from "./uploadLog";
|
|
|
|
|
|
type uploadType = {
|
|
|
clientType?: string;
|
|
@@ -22,51 +18,16 @@ type uploadType = {
|
|
|
*/
|
|
|
export default function useErrorLog() {
|
|
|
const _uploadErrorLog = async (event: any) => {
|
|
|
- let defaultParams = {
|
|
|
- appKey: 'GYM',
|
|
|
- appType: browser().android ? 'ANDROID' : browser().ios && storeData.isApp ? 'IOS' : 'WEB',
|
|
|
- clientType: '',
|
|
|
- content: '',
|
|
|
- deviceType: null,
|
|
|
- deviceVersion: null,
|
|
|
- exceptionTime: null,
|
|
|
- exceptionType: 'ERROR',
|
|
|
- phone: null,
|
|
|
- userAgent: window.navigator.userAgent,
|
|
|
-
|
|
|
- }
|
|
|
- console.log('errorLog','错误',event)
|
|
|
- try {
|
|
|
- const href = window.location.href;
|
|
|
-
|
|
|
- console.log(window.location.hash, 'errorLog')
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- const contentError = `Error message: ${event.target.tagName || ''};${
|
|
|
- event.target.src || event.target.href || ''
|
|
|
- };lineno: ${event.lineno || ''};message: ${
|
|
|
- event.message || ''
|
|
|
- };filename: ${event.filename || ''};fileUrl: ${
|
|
|
- window.location.href
|
|
|
- };reason: ${event.reason?.toString() || ''};`;
|
|
|
-
|
|
|
-
|
|
|
- const params = [
|
|
|
- {
|
|
|
- ...defaultParams,
|
|
|
- clientType: state.systemType === 'teacher' ? 'TEACHER' : state.systemType === 'student' ? 'STUDENT' : 'BACKEND',
|
|
|
- content: contentError,
|
|
|
- exceptionTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
- phone: storeData.user?.phone,
|
|
|
- userAgent: window.navigator.userAgent,
|
|
|
- }
|
|
|
- ];
|
|
|
- console.log(params, '错误信息', 'errorLog')
|
|
|
- await sysExceptionLogSave(params);
|
|
|
- } catch {
|
|
|
-
|
|
|
- }
|
|
|
+
|
|
|
+ const contentError = `Error message: ${event.target.tagName || ''};${
|
|
|
+ event.target.src || event.target.href || ''
|
|
|
+ };lineno: ${event.lineno || ''};message: ${
|
|
|
+ event.message || ''
|
|
|
+ };filename: ${event.filename || ''};fileUrl: ${
|
|
|
+ window.location.href
|
|
|
+ };reason: ${event.reason?.message || ''};
|
|
|
+ stack: ${event.reason?.stack || ''};`;
|
|
|
+ uploadErrorLog(contentError)
|
|
|
};
|
|
|
|
|
|
* 开始监听错误日志并上传
|