lex-xin преди 6 месеца
родител
ревизия
dedbc5c6c7

+ 6 - 0
src/components/the-video-tcplayer/index.tsx

@@ -2,6 +2,8 @@ import { defineComponent, PropType } from 'vue'
 import styles from './index.module.less'
 import TCPlayer from 'tcplayer.js'
 import 'tcplayer.js/dist/tcplayer.css'
+import useErrorLog from '@/hooks/useErrorLog';
+const errorLog = useErrorLog();
 export default defineComponent({
   name: 'o-video',
   props: {
@@ -125,6 +127,10 @@ export default defineComponent({
             i && i.remove()
           }
         })
+
+        this.player.on('error', (e: any) => {
+          errorLog._uploadErrorLog(e)
+        })
       }
     },
     // 操作功能

+ 24 - 10
src/hooks/useErrorLog/index.ts

@@ -59,7 +59,7 @@ export default function useErrorLog() {
   }
 
   const _uploadErrorLog = async (event: any) => {
-    console.log('onerror message -----------------')
+    console.log('onerror message -----------------', event)
     try {
       /*
         日志上报:1.手机号、应用端 iOS|安卓 App类型(老师端|学生端|web)、App版本、系统信息(系统版本|web userAgent)、错误信息(什么位置出现,错误内容) 错误时间 上报类型(错误、埋点)
@@ -72,17 +72,17 @@ export default function useErrorLog() {
         (item: string) => href.indexOf(item) !== -1
       );
 
-      const whiteIp = ['online.lexiaoya.cn', 'test.lexiaoya.cn', 'dev.lexiaoya.cn']
-      console.log(window.location.host, index, 'errorLog')
-      if (!whiteIp.includes(window.location.host)) {
-        return
-      }
+      // const whiteIp = ['online.lexiaoya.cn', 'test.lexiaoya.cn', 'dev.lexiaoya.cn']
+      // console.log(window.location.host, index, 'errorLog')
+      // if (!whiteIp.includes(window.location.host)) {
+      //   return
+      // }
       if (!(window.location.hash === '#/' || index !== -1)) {
         return
       }
       // 错误信息
       // 资源加载失败,可以在这里处理错误
-      const contentError = `Error message: ${event.target.tagName || ''};${event.target.src || event.target.href || ''
+      const contentError = `Error message: ${event.target.tagName || ''};${event.data ? JSON.stringify(event.data) : ''};${event.target.src || event.target.href || ''
         };lineno: ${event.lineno || ''};message: ${event.message || ''
         };filename: ${event.filename || ''};fileUrl: ${window.location.href
         }`;
@@ -97,15 +97,16 @@ export default function useErrorLog() {
           exceptionTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
         }
       ];
-      // console.log(params)
+      console.log(params, state.user.status)
       // 如果不是登录则存在缓存里面
       if (state.user.status !== "login") {
         operationErrorLog('set', params)
         return
       }
       await api_sysExceptionLogSave(params);
-    } catch {
+    } catch (e) {
       //
+      console.log(e)
     }
   };
 
@@ -161,6 +162,10 @@ export default function useErrorLog() {
               tempRouteSchool.push(child.path)
             }
           });
+        } else {
+          if (route.meta?.errorLog) {
+            tempRouteSchool.push(route.path)
+          }
         }
       })
     }
@@ -175,6 +180,10 @@ export default function useErrorLog() {
               tempRouteSchool.push(child.path)
             }
           });
+        }else {
+          if (route.meta?.errorLog) {
+            tempRouteSchool.push(route.path)
+          }
         }
       })
     }
@@ -189,6 +198,10 @@ export default function useErrorLog() {
               tempRouteSchool.push(child.path)
             }
           });
+        }else {
+          if (route.meta?.errorLog) {
+            tempRouteSchool.push(route.path)
+          }
         }
       })
     }
@@ -201,6 +214,7 @@ export default function useErrorLog() {
 
   return {
     startListenErrorLog,
-    stopListenErrorLog
+    stopListenErrorLog,
+    _uploadErrorLog
   };
 }

+ 1 - 0
src/router/routes-common.ts

@@ -316,6 +316,7 @@ export const rootRouter = [
     path: '/shareCreation',
     component: () => import('@/views/creation/index-share'),
     meta: {
+      errorLog: true, // 是否报错时记录信息
       title: '作品详情'
     }
   },

+ 3 - 0
src/views/coursewarePlay/component/video-play.tsx

@@ -15,6 +15,7 @@ import TCPlayer from 'tcplayer.js'
 import 'tcplayer.js/dist/tcplayer.min.css'
 import { Slider } from 'vant'
 import { state } from '@/state'
+import useErrorLog from '@/hooks/useErrorLog';
 
 // 秒转分
 export const getSecondRPM = (second: number, type?: string) => {
@@ -69,6 +70,7 @@ export default defineComponent({
     'timeupdate'
   ],
   setup(props, { emit, expose }) {
+    const errorLog = useErrorLog();
     const { item, isEmtry } = toRefs(props)
     const data = reactive({
       timer: null as any,
@@ -226,6 +228,7 @@ export default defineComponent({
           handleErrorVideo()
           emit('error')
           console.log(e, 'error')
+          errorLog._uploadErrorLog(e)
         })
       }
     }

+ 6 - 0
src/views/creation/index-share.tsx

@@ -24,10 +24,12 @@ import { setLogout } from '@/state'
 import MWxTip from '@/components/o-wx-tip'
 import { usePageVisibility } from '@vant/use'
 import videoBg from './images/video-bg.png'
+import useErrorLog from '@/hooks/useErrorLog';
 
 export default defineComponent({
   name: 'creation-detail',
   setup() {
+    const errorLog = useErrorLog();
     const route = useRoute()
     const router = useRouter()
     const audioId = 'a' + +Date.now() + Math.floor(Math.random() * 100)
@@ -65,6 +67,10 @@ export default defineComponent({
     audioDom.style.width = '100%'
     audioDom.className = styles.audio
 
+    audioDom.onerror = (e: any) =>{
+      errorLog._uploadErrorLog(e)
+    }
+
     /** 改变播放时间 */
     const handleChangeTime = (val: number) => {
       state.currentTime = val

+ 6 - 0
src/views/creation/index.tsx

@@ -23,10 +23,12 @@ import MVideo from '@/components/the-video-tcplayer'
 import ShareModel from './share-model'
 import { usePageVisibility } from '@vant/use'
 import videoBg from './images/video-bg.png'
+import useErrorLog from '@/hooks/useErrorLog';
 
 export default defineComponent({
   name: 'creation-detail',
   setup() {
+    const errorLog = useErrorLog();
     const route = useRoute()
     const router = useRouter()
     const audioId = 'a' + +Date.now() + Math.floor(Math.random() * 100)
@@ -61,6 +63,10 @@ export default defineComponent({
     audioDom.style.width = '100%'
     audioDom.className = styles.audio
 
+    audioDom.onerror = (e: any) =>{
+      errorLog._uploadErrorLog(e)
+    }
+
     /** 改变播放时间 */
     const handleChangeTime = (val: number) => {
       state.currentTime = val