Преглед на файлове

增加上报事件类型

shmily1213 преди 1 месец
родител
ревизия
a1ae8fce60

+ 2 - 0
src/common/report.ts

@@ -4,7 +4,9 @@ export const events = {
   examStartLoadError: 'exam-start-load-error',
   examStartGetPaperSuccess: 'exam-start-get-paper-success',
   examStartGetPaperError: 'exam-start-get-paper-error',
+  examStartInitError: 'exam-start-init-error',
   ExamStartLoadSlow: 'exam-start-load-slow',
+  ExamStartGetPaperSlow: 'exam-start-get-paper-slow',
   examStartSubmitSuccess: 'exam-start-submit-success',
   examStartSubmitError: 'exam-start-submit-error',
   examStartExit: 'exam-start-exit',

+ 1 - 1
src/pagesMain/pages/index/index.vue

@@ -79,7 +79,7 @@ const checkInfo = async () => {
 }
 const reloadUserInfo = async () => {
   if (userStore.isLogin) {
-    await userStore.getUserInfo();
+    await userStore.reloadInfo();
   }
 }
 const handleChangeLocation = () => {

+ 63 - 12
src/pagesStudy/pages/exam-start/exam-start.vue

@@ -203,8 +203,10 @@ const handleSubmit = (tempSave: boolean = false) => {
       duration: practiceDuration.value
     };
     console.log('提交试卷参数', params)
+    const start = Date.now();
     await commitExamineePaper(params);
-    uni.report(events.examStartSubmitSuccess, getReportData());
+    const costTime = Date.now() - start;
+    uni.report(events.examStartSubmitSuccess, getReportData({ time: costTime }));
     if (isSimulationExam.value || isTestExam.value) {
       if (!tempSave) {
         setTimeout(async () => {
@@ -311,8 +313,7 @@ const getOpenExamineeWithTimeoutCheck = async (params: Study.OpenExamineeRequest
       // 上报超时数据,超时时间单位为秒
       // 每个时间点如果请求还未返回,都会上报一次
       uni.report(events.ExamStartLoadSlow, getReportData({
-        timeout: timeout / 1000, // 转换为秒
-        timeoutLevel: timeout,
+        time: timeout
       }));
     }, timeout) as unknown as number;
     timers.push(timer);
@@ -334,6 +335,51 @@ const getOpenExamineeWithTimeoutCheck = async (params: Study.OpenExamineeRequest
   }
 };
 
+/**
+ * 带超时检测的 getPaper 请求
+ * 在 3s, 5s, 10s, 15s, 20s 这 5 个时间点检测超时并上报
+ * 每个时间点如果请求还未返回,都会上报一次
+ */
+const getPaperWithTimeoutCheck = async (params: Study.GetExamPaperRequestDTO) => {
+  // 超时时间档次(单位:毫秒)
+  const timeoutLevels = [3000, 5000, 10000, 15000, 20000];
+  // 存储所有定时器ID,用于清理
+  const timers: number[] = [];
+  // 请求是否已完成
+  let isCompleted = false;
+
+  // 创建超时检测定时器
+  timeoutLevels.forEach((timeout) => {
+    const timer = setTimeout(() => {
+      // 如果请求已完成,不进行上报
+      if (isCompleted) {
+        return;
+      }
+      // 上报超时数据,超时时间单位为秒
+      // 每个时间点如果请求还未返回,都会上报一次
+      uni.report(events.ExamStartGetPaperSlow, getReportData({
+        time: timeout
+      }));
+    }, timeout) as unknown as number;
+    timers.push(timer);
+  });
+
+  try {
+    // 执行请求
+    const result = await getPaper(params);
+    // 标记请求已完成
+    isCompleted = true;
+    // 清除所有定时器
+    timers.forEach((timer) => clearTimeout(timer));
+    return result;
+  } catch (error) {
+    // 请求失败时也要清除定时器
+    isCompleted = true;
+    timers.forEach((timer) => clearTimeout(timer));
+    throw error;
+  }
+};
+
 // 1、加载知识点练习数据
 const loadPracticeData = async () => {
   const { paperType, readonly, practiceInfo } = prevData.value;
@@ -354,13 +400,13 @@ const loadPracticeData = async () => {
       } else {
         params.directed = practiceInfo?.directed || false;
       }
-      const startTime = Date.now();
+      const start = Date.now();
       const res = await getOpenExamineeWithTimeoutCheck(params);
       data = res.data || {};
-      const endTime = Date.now() - startTime;
-      console.log('开卷用时:', endTime);
+      const costTime = Date.now() - start;
+      console.log('开卷用时:', costTime);
       uni.report(events.examStartLoadSuccess, getReportData({
-        time: Date.now() - startTime
+        time: costTime
       }));
     } catch (error) {
       uni.report(events.examStartLoadError, getReportData({
@@ -427,16 +473,21 @@ const loadExamData = async () => {
 const combinePaperData = async (examinee: Study.Examinee, paperType: EnumPaperType) => {
   examineeId.value = examinee.examineeId;
   if (examinee.paperId) {
-    const res = await getPaper({
+    const start = Date.now();
+    const res = await getPaperWithTimeoutCheck({
       type: paperType,
       id: examinee.paperId
     });
+    const costTime = Date.now() - start;
     paperData.value = res.data;
     paperData.value.questions = restoreQuestion(examinee.questions, res.data.questions);
     console.log('初始化数据', paperData.value.questions)
     setQuestionList(paperData.value.questions);
     setDuration(examinee.duration || 0);
-    uni.report(events.examStartGetPaperSuccess, getReportData());
+
+    uni.report(events.examStartGetPaperSuccess, getReportData({
+      time: costTime
+    }));
     await nextTick();
     const targetQuestion = flatQuestionList.value.find(item => item.id === prevData.value.questionId);
     if (targetQuestion) {
@@ -468,7 +519,6 @@ const combinePaperData = async (examinee: Study.Examinee, paperType: EnumPaperTy
         startTime();
       }
     }
-    uni.report(events.examStartGetPaperSuccess, getReportData());
   } else {
     uni.report(events.examStartGetPaperError, getReportData({
       error: '获取试卷数据失败,没有paperId'
@@ -495,7 +545,7 @@ const loadData = async () => {
       loadExamData();
     }
   } catch (error) {
-    uni.report(events.examStartLoadError, getReportData(error));
+    uni.report(events.examStartInitError, getReportData(error));
   }
 };
 const getReportData = (extraData: any = {}) => {
@@ -506,7 +556,8 @@ const getReportData = (extraData: any = {}) => {
       phonenumber: userStore.userInfo.phonenumber,
     },
     platform: platform.value,
-    extraData
+    extraData,
+    createTime: Date.now()
   }
 }
 onLoad(() => {

+ 7 - 3
src/pagesStudy/pages/knowledge-practice/knowledge-practice.vue

@@ -77,10 +77,14 @@ const loadKnowledgeList = async () => {
   }
   try {
     uni.$ie.showLoading();
-    const { data } = await getKnowledgeList({
+    const params: Study.KnowledgeListRequestDTO = {
       subjectId: currentSubjectId.value,
-      directed: prevData.value.directed
-    });
+      directed: prevData.value.directed,
+    };
+    if (userStore.isVHS) {
+      params.questionType = prevData.value.questionType;
+    }
+    const { data } = await getKnowledgeList(params);
     treeData.value = data as Study.KnowledgeNode[];
     pagingRef.value?.complete(data);
   } catch (error) {

+ 6 - 0
src/store/userStore.ts

@@ -147,6 +147,12 @@ export const useUserStore = defineStore('ie-user', {
         });
       }
     },
+    async reloadInfo() {
+      try {
+        await this.getUserInfo();
+        await oldUserStore.SyncToken(this.accessToken);
+      } catch (error) { }
+    },
     checkLogin({ askToLogin = true }: CheckLoginOptions = {}): Promise<boolean> {
       if (this.isLogin) {
         return Promise.resolve(true);

+ 1 - 0
src/types/study.ts

@@ -311,6 +311,7 @@ export interface SubjectListRequestDTO {
 export interface KnowledgeListRequestDTO {
   subjectId: number;
   directed: boolean;
+  questionType?: number;
 }
 
 export interface OpenExamineeRequestDTO {