Browse Source

添加错误日志

lex 11 months ago
parent
commit
3a19f4ec5a

+ 9 - 6
index.html

@@ -47,12 +47,15 @@
     window._AMapSecurityConfig = {
       serviceHost: 'https://online.dayaedu.com/_AMapService'
     }
-
-      // window._AMapSecurityConfig = {
-      //     serviceHost: 'http://192.168.3.120:8001/_AMapService',
-      //     // 例如 :serviceHost:'http://1.1.1.1:80/_AMapService',
-      //   }
+    window.addEventListener('error', (e) => {
+      console.log(e, '111')
+    });
+    // window._AMapSecurityConfig = {
+    //     serviceHost: 'http://192.168.3.120:8001/_AMapService',
+    //     // 例如 :serviceHost:'http://1.1.1.1:80/_AMapService',
+    //   }
   </script>
+  <script type="text/javascript" src="https://online.dayaedu.com/_AMapService111"></script>
 </body>
 
-</html>
+</html>

+ 3 - 1
src/components/m-empty/index.tsx

@@ -15,7 +15,9 @@ export default defineComponent({
       default: ''
     },
     image: {
-      type: String as PropType<'empty' | 'network' | '404' | 'icon_empty' | 'list'>,
+      type: String as PropType<
+        'empty' | 'network' | '404' | 'icon_empty' | 'list'
+      >,
       default: 'icon_empty'
     },
     showButton: {

+ 79 - 6
src/hooks/useErrorLog/index.ts

@@ -1,22 +1,95 @@
-import { useRoute } from 'vue-router';
+import { state } from '@/state';
+import dayjs from 'dayjs';
+import request from '@/helpers/request';
+
+/** 错误信息列表 */
+export const api_sysExceptionLogSave = (params: any): Promise<any> => {
+  return request.post('/edu-app/sysExceptionLog/save', {
+    data: params
+  });
+};
 
 /**
  * 页面有报错时上传错误日志
  * @params
  */
 export default function useErrorLog() {
-  const _whiteBlanks = [];
+  const _whiteBlanks = [
+    '/student-register',
+    '/register-new',
+    '/school-register',
+    '/teaher-register',
+    '/instrumentDetail',
+    '/famousMusicDetail',
+    '/musicianDetail',
+    '/tempo-practice',
+    '/order-detail',
+    '/member-center',
+    '/unit-detail',
+    '/practice-mode',
+    '/error-question-mode',
+    '/examination-mode',
+    '/courseware-list',
+    '/co-ai',
+    '/co-ai-detail',
+    '/courseware-play',
+    '/creation'
+  ];
+
+  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)、错误信息(什么位置出现,错误内容) 错误时间)
+
+      手机号 |上报类型 |业务平台|应用端(iOS|安卓)|
+     */
+      console.log(state.user, window.location.href);
+      const href = window.location.href;
+      const index = _whiteBlanks.findIndex(
+        (item: string) => href.indexOf(item) !== -1
+      );
 
-  const _uploadErrorLog = async (e: any) => {
-    const route = useRoute();
+      if (window.location.hash === '#/' || index !== -1) {
+      }
+      // 错误信息
+      // 资源加载失败,可以在这里处理错误
+      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: ${
+        window.location.href
+      }`;
+      // }
 
-    console.log(route, e);
+      const params = [
+        {
+          clientType: 'STUDENT',
+          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);
+    } catch {
+      //
+    }
   };
   /**
    * 开始监听错误日志并上传
    */
   const startListenErrorLog = () => {
-    // console.log('mount useErrorLog');
+    console.log('mount useErrorLog');
     window.addEventListener('error', _uploadErrorLog);
   };
 

+ 4 - 4
src/main.ts

@@ -35,10 +35,6 @@ postMessage({ api: 'getNavHeight' }, (res: any) => {
   }
 });
 
-// 监听错误信息
-const errorLog = useErrorLog();
-errorLog.startListenErrorLog();
-
 // import Vconsole from 'vconsole';
 // const vconsole = new Vconsole();
 
@@ -53,4 +49,8 @@ dayjs.locale('zh-ch');
 
 app.use(router);
 
+// 监听错误信息
+const errorLog = useErrorLog();
+errorLog.startListenErrorLog();
+
 app.mount('#app');

+ 4 - 1
src/views/courseware-list/index.tsx

@@ -257,6 +257,9 @@ export default defineComponent({
       } catch {}
     };
     onMounted(async () => {
+      window.addEventListener('error', (e: any) => {
+        console.log(e, 'error');
+      });
       // console.log(browser().isTablet, 'browser().isTablet');
       await getTanentList();
       await getSubjectList();
@@ -465,7 +468,7 @@ export default defineComponent({
                       {...{ id: index == 0 ? 'courseware-0' : '' }}
                       class={[styles.cover, item.load ? styles.loaded : '']}
                       objectFit="cover"
-                      src={item.coverImg}
+                      src={item.coverImg + '1'}
                       onLoad={() => {
                         item.load = true;
                       }}

+ 10 - 1
src/views/knowledge-library/wroing-book/index.tsx

@@ -1,6 +1,6 @@
 import MHeader from '@/components/m-header';
 import MSticky from '@/components/m-sticky';
-import { defineComponent } from 'vue';
+import { defineComponent, onMounted } from 'vue';
 import styles from './index.module.less';
 import { useRouter } from 'vue-router';
 import { Image, showToast } from 'vant';
@@ -46,6 +46,15 @@ export default defineComponent({
         //
       }
     };
+
+    onMounted(() => {
+      // setTimeout(() => {
+      //   const script = document.createElement('script');
+      //   script.type = 'text/javascript';
+      //   script.src = 'https://online.dayaedu.com/_AMapService111';
+      //   document.body.appendChild(script);
+      // }, 1000);
+    });
     return () => (
       <div
         class={[