|
|
@@ -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(() => {
|