فهرست منبع

Merge branch 'iteration-20250103' into ponline

lex-xin 1 ماه پیش
والد
کامیت
5420d4bdfc
4فایلهای تغییر یافته به همراه172 افزوده شده و 0 حذف شده
  1. 2 0
      src/helpers/hooks.ts
  2. 133 0
      src/helpers/useErrorLog/index.ts
  3. 19 0
      src/tenant/music/music-detail/new-index.tsx
  4. 18 0
      src/views/music/music-detail/index.tsx

+ 2 - 0
src/helpers/hooks.ts

@@ -145,6 +145,8 @@ export const useStatisticTracking = (params: {
   objectType: 'VIP_COURSE' | 'PRACTICE' | 'GROUP' | 'LIVE' | 'VIDEO' | 'MUSIC'
   objectId: number | string
 }) => {
+  // 埋点统计 没有编号则不统计
+  if(!params.objectId) return
   request.post('/api-student/exposure/record', {
     hideLoading: false,
     data: [{ ...params, platform: browser().ios ? 'ios' : 'android' }]

+ 133 - 0
src/helpers/useErrorLog/index.ts

@@ -0,0 +1,133 @@
+import { state } from '@/state'
+import dayjs from 'dayjs'
+import request from '@/helpers/request'
+
+/** 错误信息列表 */
+export const api_sysExceptionLogSave = (params: any): Promise<any> => {
+  return request.post('/sysExceptionLog/save', {
+    prefix: '/api-auth',
+    data: params
+  })
+}
+
+type uploadType = {
+  clientType?: string
+  appKey: string
+  phone?: string | undefined | null
+  userAgent?: string
+  appType?: string
+  content?: string
+  exceptionType?: string
+  exceptionTime?: string
+  deviceType?: string | null
+  deviceVersion?: string | null
+}
+
+/**
+ * 页面有报错时上传错误日志
+ * @params
+ */
+export default function useErrorLog() {
+  const _whiteBlanks = ['/student-register']
+
+  let _defaultParams = {
+    clientType: 'STUDENT',
+    appKey: 'KLX',
+    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)、错误信息(什么位置出现,错误内容) 错误时间)
+
+        手机号 |上报类型 |业务平台|应用端(iOS|安卓)|
+     */
+      const href = window.location.href
+      const index = _whiteBlanks.findIndex(
+        (item: string) => href.indexOf(item) !== -1
+      )
+
+      const whiteIp = [
+        'online.colexiu.com',
+        'test.colexiu.com',
+        'dev.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 || ''};${
+        event.target.src || event.target.href || ''
+      };lineno: ${event.lineno || ''};message: ${
+        event.message || ''
+      };filename: ${event.filename || ''};fileUrl: ${window.location.href}`
+      // }
+
+      const params = [
+        {
+          ..._defaultParams,
+          phone: state.user.data?.phone,
+          userAgent: window.navigator.userAgent,
+          content: contentError,
+          exceptionTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
+        }
+      ]
+      // console.log(params)
+      await api_sysExceptionLogSave(params)
+    } catch {
+      //
+    }
+  }
+  /**
+   * 开始监听错误日志并上传
+   */
+  const startListenErrorLog = (params?: uploadType) => {
+    _defaultParams = Object.assign(_defaultParams, params)
+    console.log('mount useErrorLog')
+    window.addEventListener('error', _uploadErrorLog)
+  }
+
+  /**
+   * 停止监听
+   */
+  const stopListenErrorLog = () => {
+    window.removeEventListener('error', _uploadErrorLog)
+  }
+
+  /**
+   * 上传错误日志
+   * @param params
+   */
+  const uploadSingleErrorLog = async (params: uploadType) => {
+    const paramsList = [
+      {
+        ..._defaultParams,
+        ...params
+      }
+    ]
+    await api_sysExceptionLogSave(paramsList)
+  }
+
+  return {
+    startListenErrorLog,
+    stopListenErrorLog,
+    uploadSingleErrorLog
+  }
+}

+ 19 - 0
src/tenant/music/music-detail/new-index.tsx

@@ -51,6 +51,8 @@ import inactiveButtonIcon from './images/icon_checkbox_default.png'
 import staffDetafult from './images/staff-default.png'
 import firstDefault from './images/first-default.png'
 import fixedDefault from './images/fixed-default.png'
+import useErrorLog from '@/helpers/useErrorLog'
+import dayjs from 'dayjs'
 
 import Plyr from 'plyr'
 import 'plyr/dist/plyr.css'
@@ -61,6 +63,7 @@ import { svgtopng } from './formatSvgToImg'
 export default defineComponent({
   name: 'new-index',
   setup() {
+    const useErrorLogHook = useErrorLog()
     localStorage.setItem('behaviorId', getRandomKey())
     const router = useRouter()
     const route = useRoute()
@@ -243,6 +246,22 @@ export default defineComponent({
       // }
 
       window.addEventListener('message', showLoading)
+
+      // 判断是否有曲目编号 如果没有则记录日志
+      if(!route.query.id) {
+        const historyState = router.options.history.state
+        const contentError = `Error message: history url:${ historyState.back }、 current url${historyState.current};message: id is undefined;fileUrl: ${
+          window.location.href
+        }`;
+        useErrorLogHook.uploadSingleErrorLog({
+          appKey: 'KLX',
+          clientType: state.platformType,
+          phone: state.user.data?.phone,
+          userAgent: window.navigator.userAgent,
+          content: contentError,
+          exceptionTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
+        })
+      }
     })
     onUnmounted(() => {
       postMessage({

+ 18 - 0
src/views/music/music-detail/index.tsx

@@ -60,6 +60,8 @@ import { getInstrumentName } from '@/constant/instruments'
 import { svgtopng } from '@/tenant/music/music-detail/formatSvgToImg'
 import { useThrottleFn } from '@vueuse/core'
 import { useStatisticTracking } from '@/helpers/hooks'
+import useErrorLog from '@/helpers/useErrorLog'
+import dayjs from 'dayjs'
 // import {
 //   formatXML,
 //   getCustomInfo,
@@ -75,6 +77,7 @@ export const getAssetsHomeFile = (fileName: string) => {
 export default defineComponent({
   name: 'MusicDetail',
   setup() {
+    const useErrorLogHook = useErrorLog()
     const behaviorId = ref(getRandomKey())
     localStorage.setItem('behaviorId', behaviorId.value)
     const router = useRouter()
@@ -357,6 +360,21 @@ export default defineComponent({
       // }
 
       window.addEventListener('message', showLoading)
+      // 判断是否有曲目编号 如果没有则记录日志
+      if(!route.query.id) {
+        const historyState = router.options.history.state
+        const contentError = `Error message: history url:${ historyState.back }、 current url${historyState.current};message: id is undefined;fileUrl: ${
+          window.location.href
+        }`;
+        useErrorLogHook.uploadSingleErrorLog({
+          appKey: 'KLX',
+          clientType: state.platformType,
+          phone: state.user.data?.phone,
+          userAgent: window.navigator.userAgent,
+          content: contentError,
+          exceptionTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
+        })
+      }
     })
     onBeforeUnmount(() => {
       postMessage({