Browse Source

Merge branch 'feature-patch' into ktyq-online-new

TIANYONG 2 weeks ago
parent
commit
25f6903c7c

+ 60 - 0
src/hooks/errorLog/index.ts

@@ -0,0 +1,60 @@
+import { uploadErrorLog } from "./uploadLog";
+import state from "/src/state";
+import { getQuery } from "/src/utils/queryString";
+
+type uploadType = {
+  clientType?: string;
+  phone?: string | undefined | null;
+  userAgent?: string;
+  appType?: string;
+  content?: string;
+  exceptionType?: string;
+  exceptionTime?: string;
+  deviceType?: string | null;
+  deviceVersion?: string | null
+}
+
+const query: any = getQuery();
+
+/**
+ * 页面有报错时上传错误日志
+ * @params
+ */
+export default function useErrorLog() {
+  const _uploadErrorLog = async (event: any) => {
+    // 错误信息
+    const contentError = `Error message: ${event.target.tagName || ''};${
+      event.target.src || event.target.href || ''
+    };lineno: ${event.lineno || ''};colno: ${event.colno || ''};message: ${
+      event.message || ''
+    };filename: ${event.filename || ''};fileUrl: ${
+      window.location.href
+    };reason: ${event.reason?.message || ''};
+    stack: ${event.reason?.stack || ''};
+    bizId: ${state.examSongId || query.id || ''};
+    partIndex: ${query["part-index"] || state.partIndex || 0}
+    partName: ${decodeURIComponent(query["part-name"] || '') || ''};`;
+    uploadErrorLog(contentError)
+  };
+  /**
+   * 开始监听错误日志并上传
+   */
+  const startListenErrorLog = () => {
+    console.log('mount useErrorLog');
+    window.addEventListener('error', _uploadErrorLog);
+    window.addEventListener('unhandledrejection', _uploadErrorLog);
+  };
+
+  /**
+   * 停止监听
+   */
+  const stopListenErrorLog = () => {
+    window.removeEventListener('error', _uploadErrorLog);
+    window.removeEventListener('unhandledrejection', _uploadErrorLog);
+  };
+
+  return {
+    startListenErrorLog,
+    stopListenErrorLog
+  };
+}

+ 44 - 0
src/hooks/errorLog/uploadLog.ts

@@ -0,0 +1,44 @@
+import state from "/src/state";
+import dayjs from 'dayjs';
+import { sysExceptionLogSave } from '/src/utils/baseApi'
+import { browser } from "/src/utils";
+import { storeData } from "/src/store";
+
+// 上传错误日志
+export const uploadErrorLog = async (contentError: string) => {
+	//
+    let defaultParams = {
+		appKey: 'KT', // 应用标识(GYT,GYM,KT,KLX,CBS),可用值:GYM,GYT,KLX,KLX_JG,KT,CBS
+		appType: browser().android ? 'ANDROID' : browser().ios && storeData.isApp ? 'IOS' : 'WEB', // 应用类型(IOS,ANDROID,HARMONY),可用值:IOS,ANDROID,HARMONY,WEB
+		clientType: '', // 客户端类型(TEACHER,STUDENT,SCHOOL,BACKEND),可用值:BACKEND,SCHOOL,TEACHER,STUDENT,TENANT	
+		content: '', // 内容
+		deviceType: null, // 设备类型
+		deviceVersion: null, // 设备版本
+		exceptionTime: null, // 异常时间
+		exceptionType: 'ERROR', // 异常类型(ERROR,RECORD),可用值:ERROR,RECORD	
+		phone: null, // 手机号
+		userAgent: window.navigator.userAgent, // 客户端信息
+		
+	  }
+	console.log('errorLog','错误',event)
+	try {
+	console.log(window.location.hash, 'errorLog', storeData)
+
+	const params = [
+		{
+		...defaultParams,
+		appKey: state.isCbsView ? 'CBS' : 'KT',
+		// clientType: state.systemType === 'teacher' ? 'TEACHER' : state.systemType === 'student' ? 'STUDENT' : 'BACKEND',
+		clientType: storeData.isApp ? 'STUDENT' : storeData.user?.clientType ? storeData.user?.clientType : '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 {
+	//
+	}
+}

+ 10 - 1
src/page-instrument/main.ts

@@ -12,6 +12,7 @@ import router from "./router";
 import "./theme.css";
 import "./custom-plugins/guide-driver/index.less"
 import { getQuery } from "/src/utils/queryString";
+import useErrorLog from "/src/hooks/errorLog"
 
 (function () {
 	const query = getQuery();
@@ -32,4 +33,12 @@ import { getQuery } from "/src/utils/queryString";
 	});
 })();
 
-createApp(App).use(router).mount("#app");
+// createApp(App).use(router).mount("#app");
+const app = createApp(App)
+app.use(router)
+
+// 监听错误信息
+const errorLog = useErrorLog();
+errorLog.startListenErrorLog();
+
+app.mount("#app")  

+ 6 - 1
src/page-instrument/view-detail/index.tsx

@@ -41,6 +41,7 @@ import { position } from "html2canvas/dist/types/css/property-descriptors/positi
 import Loading from "./loading"
 import LoadingCss from "./loadingCss"
 import { getSvgPngToSize } from "/src/helpers/svgToPng"
+import { uploadErrorLog } from '/src/hooks/errorLog/uploadLog'
 // import bgJson from "./images/index.json";
 
 // const DelayCheck = defineAsyncComponent(() =>
@@ -180,8 +181,10 @@ export default defineComponent({
       loadJson('data');
       try { 
         await getMusicDetail(id);
-      } catch (err) {
+      } catch (err: any) {
         console.error(err);
+        const contentError = `reason: ${err?.message || ''};stack: ${err?.stack || ''};bizId: ${state.examSongId || query.id || ''};partIndex: ${query["part-index"] || state.partIndex || 0};partName: ${decodeURIComponent(query["part-name"] || '') || ''};`;
+        uploadErrorLog(contentError)
         state.isLoading = false;
         isEmptyMusicShow.value = true
         // 需要向外面(iframe)派发计时器数据的时候触发
@@ -359,6 +362,8 @@ export default defineComponent({
         handleRendered(osmd)
       }catch(err:any){
         console.log(err, "err")
+        const contentError = `reason: ${err?.message || ''};stack: ${err?.stack || ''};bizId: ${state.examSongId || query.id || ''};partIndex: ${query["part-index"] || state.partIndex || 0};partName: ${decodeURIComponent(query["part-name"] || '') || ''};`;
+        uploadErrorLog(contentError)
         // 需要向外面(iframe)派发计时器数据的时候触发
         if(query.isbeatTimes){
           console.log("webApi_beatTimes",err)

+ 3 - 63
src/page-instrument/view-evaluat-report/index.tsx

@@ -101,69 +101,7 @@ export default defineComponent({
       api_setStatusBarVisibility();
     });
     // console.log(route.params, query)
-    /** 获取曲谱数据 */
-    const getMusicInfo = (res: any) => {
-      const index = state.partIndex;
-      const musicInfo = {
-        ...res.data,
-        ...res.data.background[index],
-      };
-      // console.log("🚀 ~ musicInfo:", musicInfo);
-      setState(musicInfo, index);
-      setCustom();
-      detailData.isLoading = false;
-    };
-
-    const setState = (data: any, index: number) => {
-      // console.log("🚀 ~ data:", data)
-      state.scrollContainer = "scrollContainer";
-      state.detailId = data.id;
-      state.xmlUrl = data.xmlFileUrl;
-      state.partIndex = index;
-      state.subjectId = data.musicSubject;
-      state.categoriesId = data.categoriesId;
-      state.categoriesName = data.musicTagNames;
-      state.enableEvaluation = data.canEvaluate ? true : false;
-      state.examSongId = data.id + "";
-      state.examSongName = data.musicSheetName;
-      // 解析扩展字段
-      if (data.extConfigJson) {
-        try {
-          state.extConfigJson = JSON.parse(data.extConfigJson as string);
-        } catch (error) {
-          console.error("解析扩展字段错误:", error);
-        }
-      }
-      state.isOpenMetronome = data.mp3Type === "MP3_METRONOME" ? true : false;
-      state.needTick = data.isOpenMetronome;
-      state.isShowFingering = data.showFingering ? true : false;
-      state.music = data.audioFileUrl;
-      state.accompany = data.metronomeUrl || data.metronomeUrl;
-      state.midiUrl = data.midiUrl;
-      state.parentCategoriesId = data.musicTag;
-      state.playMode = data.audioType === "MP3" ? "MP3" : "MIDI";
-      state.originSpeed = state.speed = data.speed;
-      // console.log('速度',10,state.speed)
-      state.track = data.track;
-      state.enableNotation = data.notation ? true : false;
 
-      // 映射声部ID
-      state.subjectId = mappingVoicePart(state.subjectId as any, "ORCHESTRA");
-      // console.log("🚀 ~ state.subjectId:", state.subjectId);
-      // 是否打击乐
-      state.isPercussion = state.subjectId == 23 || state.subjectId == 113 || state.subjectId == 121 || isRhythmicExercises();
-
-      // 设置指法
-      state.fingeringInfo = subjectFingering(state.subjectId);
-      // console.log("🚀 ~ state.fingeringInfo:", state.fingeringInfo, state.subjectId, state.track)
-      // state.isOpenPrepare = true
-    };
-
-    const setCustom = () => {
-      if (state.extConfigJson.multitrack) {
-        setGlobalData("multitrack", state.extConfigJson.multitrack);
-      }
-    };
 
     onMounted(async () => {
       state.isEvaluatReport = true;
@@ -197,6 +135,8 @@ export default defineComponent({
       // 评测报告展示什么类型的谱面
       state.isSingleLine = false;
       scoreData.musicType = query.musicRenderType ? query.musicRenderType : resultData.musicType ? resultData.musicType : state.musicRenderType;
+      // 如果是打击乐,只显示节奏一栏,itemType需要修改为'cadence'
+      scoreData.itemType = state.isPercussion ? 'cadence' : 'intonation';
       // @ts-ignore
       state.musicRenderType = scoreData.musicType;
       detailData.isLoading = false;
@@ -276,7 +216,7 @@ export default defineComponent({
           active = allNote.value.find((item: any) => item.i === idx)
         }        
         setTimeout(() => {
-          if (useedid.value.includes(active.id)) {
+          if ( !active || useedid.value.includes(active.id) ) {
             return;
           }
           useedid.value.push(active.id);

+ 9 - 0
src/utils/baseApi.ts

@@ -25,4 +25,13 @@ export const creatMusicSheetImg = (data: any) => {
 export const getInstrumentCode = () => {
   const url = `/musicSheet/instrumentCode`;
   return request.get(url);
+};
+
+/** 上传错误信息 */
+export const sysExceptionLogSave = (data: any): Promise<any> => {
+  return request.post('/sysExceptionLog/save', {
+    requestType: 'json',
+    isExceptionLog: true, // js异常收集,需要使用edu-app
+    data
+  });
 };

+ 1 - 0
src/utils/request.ts

@@ -28,6 +28,7 @@ request.interceptors.request.use(
 		// console.log(9999,storeData.proxy,storeData.platformApi,options)
 		// 内容平台的前缀为cbs-app
 		const platformApi = options.isContentCenter ? '/cbs-app' : storeData.platformApi
+		// const platformApi = options.isContentCenter ? '/cbs-app' : options.isExceptionLog ? '/edu-app' : storeData.platformApi
 		const _prefix = storeData.proxy + platformApi;
 		/** 
 		 * 只有后台才去设置