dedsudiyu 5 days ago
parent
commit
aa0f0ca090

+ 8 - 0
pages_safetyEducationExamination/api/index.js

@@ -204,4 +204,12 @@ export const examUserCoursewareLearningRestart = (data) => {
 		method: 'get',
 		method: 'get',
 		data: { ...data }
 		data: { ...data }
 	})
 	})
+};
+//确认考试承诺书
+export const examUserExamCommitmentConfirm = (data) => {
+	return apiResquest({
+		url: `/exam/user/exam/commitment/confirm`,
+		method: 'POST',
+		data: { ...data }
+	})
 };
 };

+ 3 - 1
pages_safetyEducationExamination/utils/index.js

@@ -128,9 +128,11 @@ export async function confirmCommitmentAndStart(preData, onClose) {
 	}
 	}
 
 
 	try {
 	try {
+		console.log('确认1')
 		const { data } = await examUserExamCommitmentConfirm({ attemptId });
 		const { data } = await examUserExamCommitmentConfirm({ attemptId });
+		console.log('确认2')
 		if (data.code === 200) {
 		if (data.code === 200) {
-			if (typeof onClose === 'function') onClose();
+			console.log('确认3')
 			navigateToExamPlay(preData.examId, attemptId, preData.examKind);
 			navigateToExamPlay(preData.examId, attemptId, preData.examKind);
 		} else {
 		} else {
 			uni.showToast({ title: data.message || '确认失败', icon: 'none' });
 			uni.showToast({ title: data.message || '确认失败', icon: 'none' });

+ 24 - 6
pages_safetyEducationExamination/views/exam/mockExamInfo.vue

@@ -54,6 +54,9 @@
 		goToExamPage,
 		goToExamPage,
 	} from '@/pages_safetyEducationExamination/utils/index.js'
 	} from '@/pages_safetyEducationExamination/utils/index.js'
 	import {
 	import {
+		examUserExamStart,
+	} from '@/pages_safetyEducationExamination/api/index.js'
+	import {
 		parseTime
 		parseTime
 	} from '@/component/public.js'
 	} from '@/component/public.js'
 
 
@@ -87,11 +90,26 @@
 					this.examData.endTime = parseTime(this.examData.endTime, '{y}-{m}-{d} {h}:{i}');
 					this.examData.endTime = parseTime(this.examData.endTime, '{y}-{m}-{d} {h}:{i}');
 				}
 				}
 			},
 			},
-			startMockExam() {
-				goToExamPage(this.examData);
-				// uni.navigateTo({
-				// 	url: `/pages_safetyEducationExamination/views/exam/mockExamPlay?examId=${this.examData.examId}&mockExamId=${this.examData.mockExamId || ''}&attemptId=${this.examData.attemptId || ''}`
-				// });
+			async startMockExam() {
+				if (this.examData.needStudy || this.examData.examStudy) {
+					goToExamPage(this.examData);
+					return;
+				}
+				try {
+					uni.showLoading({ title: '加载中...', mask: true });
+					const { data } = await examUserExamStart({ examId: this.examData.examId, examScene: 2 });
+					uni.hideLoading();
+					if (data.code === 200 && data.data && data.data.attemptId) {
+						uni.navigateTo({
+							url: `/pages_safetyEducationExamination/views/exam/mockExamPlay?examId=${this.examData.examId}&attemptId=${data.data.attemptId}`
+						});
+					} else {
+						uni.showToast({ title: data.message || '获取模拟试卷失败', icon: 'none' });
+					}
+				} catch (e) {
+					uni.hideLoading();
+					uni.showToast({ title: '获取模拟试卷失败', icon: 'none' });
+				}
 			}
 			}
 		}
 		}
 	}
 	}
@@ -107,7 +125,7 @@
 	.scroll-content
 	.scroll-content
 		flex 1
 		flex 1
 		overflow hidden
 		overflow hidden
-		padding-bottom 160rpx
+		padding-bottom 220rpx
 
 
 	.card
 	.card
 		margin 24rpx
 		margin 24rpx

+ 13 - 15
pages_safetyEducationExamination/views/exam/mockExamPlay.vue

@@ -100,7 +100,7 @@
 						:key="oi"
 						:key="oi"
 						class="q-option"
 						class="q-option"
 						:class="{ selected: isSelected(opt.optionLabel) }"
 						:class="{ selected: isSelected(opt.optionLabel) }"
-						@click="selectAnswer(opt)"
+						@click="selectAnswer(oi)"
 					>
 					>
 						<view class="q-option-label">{{ opt.optionLabel }}</view>
 						<view class="q-option-label">{{ opt.optionLabel }}</view>
 						<view class="q-option-content">
 						<view class="q-option-content">
@@ -250,18 +250,18 @@
 		},
 		},
 		onHide() {
 		onHide() {
 			this.clearTimer()
 			this.clearTimer()
-			this.saveCurrentAnswer()
+			if (!this.hasSubmitted) this.saveCurrentAnswer()
 		},
 		},
 		onUnload() {
 		onUnload() {
 			this.clearTimer()
 			this.clearTimer()
-			this.saveCurrentAnswer()
+			if (!this.hasSubmitted) this.saveCurrentAnswer()
 		},
 		},
 		methods: {
 		methods: {
 			// 加载左侧题号导航
 			// 加载左侧题号导航
 			async loadSidebar() {
 			async loadSidebar() {
 				try {
 				try {
 					const response = await examElExamAttemptReviewSidebar({ attemptId: this.attemptId })
 					const response = await examElExamAttemptReviewSidebar({ attemptId: this.attemptId })
-					const data = response.data
+					const data = response.data.data
 					this.examInfo = {
 					this.examInfo = {
 						examTypeName: data.examTypeName || '',
 						examTypeName: data.examTypeName || '',
 						examName: data.examName || '',
 						examName: data.examName || '',
@@ -291,7 +291,7 @@
 						snapshotQuestionId: snapshotQuestionId,
 						snapshotQuestionId: snapshotQuestionId,
 						examScene: 2,
 						examScene: 2,
 					})
 					})
-					this.$set(this, 'currentQuestion', response.data)
+					this.$set(this, 'currentQuestion', response.data.data)
 					this.$set(this, 'viewAnswerShowType', false)
 					this.$set(this, 'viewAnswerShowType', false)
 				} catch (e) {
 				} catch (e) {
 					uni.showToast({ title: '题目加载失败', icon: 'none' })
 					uni.showToast({ title: '题目加载失败', icon: 'none' })
@@ -301,7 +301,7 @@
 			async syncRemainingTime() {
 			async syncRemainingTime() {
 				try {
 				try {
 					const response = await examUserExamGetExamSurplusTime({ attemptId: this.attemptId })
 					const response = await examUserExamGetExamSurplusTime({ attemptId: this.attemptId })
-					this.remainingSeconds = Number(response.data) || 0
+					this.remainingSeconds = Number(response.data.data) || 0
 					this.clearTimer()
 					this.clearTimer()
 					this.startTimer()
 					this.startTimer()
 				} catch (e) {
 				} catch (e) {
@@ -330,16 +330,15 @@
 				}
 				}
 			},
 			},
 			// 选择答案
 			// 选择答案
-			selectAnswer(opt) {
-				if (!this.currentQuestion.snapshotQuestionId) return
+			selectAnswer(optIndex) {
+				const opt = (this.currentQuestion.options || [])[optIndex]
+				if (!opt || !this.currentQuestion.snapshotQuestionId) return
 				let tags = Array.isArray(this.currentQuestion.answerTags) ? [...this.currentQuestion.answerTags] : []
 				let tags = Array.isArray(this.currentQuestion.answerTags) ? [...this.currentQuestion.answerTags] : []
 				const qType = this.currentQuestion.questionType
 				const qType = this.currentQuestion.questionType
 				if (qType == 2) {
 				if (qType == 2) {
-					// 多选
 					const idx = tags.indexOf(opt.optionLabel)
 					const idx = tags.indexOf(opt.optionLabel)
 					if (idx === -1) { tags.push(opt.optionLabel) } else { tags.splice(idx, 1) }
 					if (idx === -1) { tags.push(opt.optionLabel) } else { tags.splice(idx, 1) }
 				} else {
 				} else {
-					// 单选 / 判断
 					tags = [opt.optionLabel]
 					tags = [opt.optionLabel]
 				}
 				}
 				this.$set(this.currentQuestion, 'answerTags', tags)
 				this.$set(this.currentQuestion, 'answerTags', tags)
@@ -359,10 +358,9 @@
 					snapshotQuestionId: q.snapshotQuestionId,
 					snapshotQuestionId: q.snapshotQuestionId,
 					userAnswer: tags.join(','),
 					userAnswer: tags.join(','),
 				}).then(response => {
 				}).then(response => {
-					// response.data 是 isCorrect 值(1正确 0错误)
 					const groups = this.questionTypeGroups
 					const groups = this.questionTypeGroups
 					if (groups[this.groupIndex] && groups[this.groupIndex].questions[this.questionIndex]) {
 					if (groups[this.groupIndex] && groups[this.groupIndex].questions[this.questionIndex]) {
-						this.$set(groups[this.groupIndex].questions[this.questionIndex], 'isCorrect', response.data)
+						this.$set(groups[this.groupIndex].questions[this.questionIndex], 'isCorrect', response.data.data)
 					}
 					}
 				}).catch(e => {
 				}).catch(e => {
 					console.error('保存答案失败', e)
 					console.error('保存答案失败', e)
@@ -453,7 +451,7 @@
 					const response = await examUserExamSubmit({ attemptId: this.attemptId })
 					const response = await examUserExamSubmit({ attemptId: this.attemptId })
 					this.hasSubmitted = true
 					this.hasSubmitted = true
 					this.clearTimer()
 					this.clearTimer()
-					this.buildResult(response.data)
+					this.buildResult(response.data.data)
 					this.showResult = true
 					this.showResult = true
 				} catch (e) {
 				} catch (e) {
 					uni.showToast({ title: '交卷失败', icon: 'none' })
 					uni.showToast({ title: '交卷失败', icon: 'none' })
@@ -481,7 +479,7 @@
 			async retakeExam() {
 			async retakeExam() {
 				try {
 				try {
 					const response = await examUserExamStart({ examId: this.examId, examScene: 2 })
 					const response = await examUserExamStart({ examId: this.examId, examScene: 2 })
-					const data = response.data
+					const data = response.data.data
 					if (data && data.attemptId) {
 					if (data && data.attemptId) {
 						this.attemptId = data.attemptId
 						this.attemptId = data.attemptId
 						this.showResult = false
 						this.showResult = false
@@ -497,7 +495,7 @@
 						this.pageLoading = true
 						this.pageLoading = true
 						this.loadSidebar()
 						this.loadSidebar()
 					} else {
 					} else {
-						uni.showToast({ title: response.message || '重新考试失败', icon: 'none' })
+						uni.showToast({ title: response.data.message || '重新考试失败', icon: 'none' })
 						uni.navigateBack()
 						uni.navigateBack()
 					}
 					}
 				} catch (e) {
 				} catch (e) {

+ 6 - 5
pages_safetyEducationExamination/views/exam/onlineExamPlay.vue

@@ -79,7 +79,7 @@
 						:key="oi"
 						:key="oi"
 						class="q-option"
 						class="q-option"
 						:class="{ selected: isSelected(opt.optionLabel) }"
 						:class="{ selected: isSelected(opt.optionLabel) }"
-						@click="selectAnswer(opt)"
+						@click="selectAnswer(oi)"
 					>
 					>
 						<view class="q-option-label">{{ opt.optionLabel }}</view>
 						<view class="q-option-label">{{ opt.optionLabel }}</view>
 						<view class="q-option-content">
 						<view class="q-option-content">
@@ -200,11 +200,11 @@
 		},
 		},
 		onHide() {
 		onHide() {
 			this.clearTimer();
 			this.clearTimer();
-			this.saveCurrentAnswer();
+			if (!this.hasSubmitted) this.saveCurrentAnswer();
 		},
 		},
 		onUnload() {
 		onUnload() {
 			this.clearTimer();
 			this.clearTimer();
-			this.saveCurrentAnswer();
+			if (!this.hasSubmitted) this.saveCurrentAnswer();
 		},
 		},
 		methods: {
 		methods: {
 			async loadSidebar() {
 			async loadSidebar() {
@@ -285,8 +285,9 @@
 					this.timer = null;
 					this.timer = null;
 				}
 				}
 			},
 			},
-			selectAnswer(opt) {
-				if (!this.currentQuestion.snapshotQuestionId) return;
+			selectAnswer(optIndex) {
+				const opt = (this.currentQuestion.options || [])[optIndex];
+				if (!opt || !this.currentQuestion.snapshotQuestionId) return;
 				let tags = Array.isArray(this.currentQuestion.answerTags) ? [...this.currentQuestion.answerTags] : [];
 				let tags = Array.isArray(this.currentQuestion.answerTags) ? [...this.currentQuestion.answerTags] : [];
 				if (this.currentQuestion.questionType === 2) {
 				if (this.currentQuestion.questionType === 2) {
 					const idx = tags.indexOf(opt.optionLabel);
 					const idx = tags.indexOf(opt.optionLabel);