yangg 2 месяцев назад
Родитель
Сommit
53240a3650

+ 4 - 1
api/user.js

@@ -129,4 +129,7 @@ export const submitAnswer = (params) => {
   return http.post('/api/job/submit_answer', params);
 };
 
-
+/* 申请职位 */
+export const applyJob = (params) => {
+  return http.post('/api/job/apply', params);
+};

+ 84 - 39
pages/camera/camera.vue

@@ -88,7 +88,7 @@
 						<text class="timer-text">本题剩余时间 {{remainingTime}}</text>
 					</view> -->
 					
-					<button class="next-button" @click="nextQuestion" 
+					<button class="next-button" @click="nextQuestion(option)" 
 						:disabled="
 							(currentQuestion.questionType === 0 && openQuestionAnswer.trim() === '') || 
 							(currentQuestion.questionType === 1 && selectedOption === null) || 
@@ -182,6 +182,8 @@
 				currentQuestionDetail: null, // 当前题目详情
 				isSubmitting: false, // 是否正在提交答案
 				openQuestionAnswer: '', // 存储开放问题的答案
+				currentAnswer: null, // 存储当前答案以便提交
+				questionStartTime: null, // 存储问题开始时间
 			}
 		},
 		computed: {
@@ -321,6 +323,9 @@
 				// 确保问题已加载
 				if (this.questions.length === 0) return;
 				
+				// 记录开始时间
+				this.questionStartTime = new Date();
+				
 				// 模拟倒计时
 				let seconds = 30; // 每题30秒
 				this.timerInterval = setInterval(() => {
@@ -393,25 +398,31 @@
 				this.showResult = true;
 			},
 
-			nextQuestion() {
+			nextQuestion(data) {
 				// 如果还没有显示结果,先检查答案
 				if (!this.showResult) {
 					this.checkAnswer();
 					return;
 				}
 				
-				// 保存当前题目的答案
-				this.saveAnswer();
-				
-				// 如果是最后一题,提交所有答案
-				if (this.currentQuestionIndex >= this.questions.length - 1) {
-					// 显示结果页面
-					this.showEndModal = true;
-					return;
-				}
-				
-				// 前往下一题
-				this.goToNextQuestion();
+				// 保存当前题目的答案并提交
+				this.saveAnswer(data);
+				this.submitCurrentAnswer(data).then(() => {
+					// 如果是最后一题,显示结果页面
+					if (this.currentQuestionIndex >= this.questions.length - 1) {
+						this.showEndModal = true;
+						return;
+					}
+					
+					// 前往下一题
+					this.goToNextQuestion();
+				}).catch(error => {
+					console.error('提交答案失败:', error);
+					uni.showToast({
+						title: '提交答案失败,请重试',
+						icon: 'none'
+					});
+				});
 			},
 
 			// 保存当前题目的答案
@@ -422,14 +433,16 @@
 					answer = {
 						questionId: this.currentQuestion.id,
 						questionType: this.currentQuestion.questionType,
-						answer: this.openQuestionAnswer
+						answer: this.openQuestionAnswer,
+						answerDuration: this.getAnswerDuration() // 添加答题时长
 					};
 				} else { // 单选或多选
 					answer = {
 						questionId: this.currentQuestion.id,
 						questionType: this.currentQuestion.questionType,
 						answer: this.currentQuestion.questionType === 1 ? 
-							this.selectedOption : this.selectedOptions
+							this.selectedOption : this.selectedOptions,
+						answerDuration: this.getAnswerDuration() // 添加答题时长
 					};
 				}
 				
@@ -441,55 +454,87 @@
 					this.answers.push(answer);
 				}
 				
+				// 保存当前答案以便提交
+				this.currentAnswer = answer;
+				
 				console.log('已保存答案:', this.answers);
 			},
 			
-			// 提交所有答案
-			async submitAllAnswers() {
-				if (this.isSubmitting) return;
+			// 获取答题时长(秒)
+			getAnswerDuration() {
+				// 这里假设每题默认30秒,根据剩余时间计算用时
+				// 您可以根据实际情况调整计算逻辑
+				const remainingTimeArr = this.remainingTime.split(':');
+				const remainingSeconds = parseInt(remainingTimeArr[0]) * 60 + parseInt(remainingTimeArr[1]);
+				return 30 - remainingSeconds; // 假设每题30秒
+			},
+
+			// 提交当前答案
+			async submitCurrentAnswer() {
+				if (!this.currentAnswer) return;
 				
 				try {
-					this.isSubmitting = true;
-					
 					// 显示提交中提示
 					uni.showLoading({
 						title: '正在提交答案...'
 					});
 					
 					// 构建提交数据
+					let answerContent = '';
+					
+					if (this.currentAnswer.questionType === 0) {
+						// 开放题直接使用文本答案
+						answerContent = this.currentAnswer.answer;
+					} else if (this.currentAnswer.questionType === 1) {
+						// 单选题,获取选项ID而不是索引
+						const selectedIndex = this.currentAnswer.answer;
+						const selectedOption = this.currentQuestion.options[selectedIndex];
+						// 使用选项的ID或其他唯一标识符
+						answerContent = selectedOption.id ? selectedOption.id.toString() : selectedIndex.toString();
+					} else if (this.currentAnswer.questionType === 2) {
+						// 多选题,将选项ID数组转为逗号分隔的字符串
+						const selectedIndices = this.currentAnswer.answer;
+						const selectedOptionIds = selectedIndices.map(index => {
+							const option = this.currentQuestion.options[index];
+							// 使用选项的ID或其他唯一标识符
+							return option.id ? option.id : index;
+						});
+						answerContent = selectedOptionIds.join(',');
+					}
+					
 					const submitData = {
-						interviewId: this.interviewId,
-						answers: this.answers
+						application_id: 1, // 或者使用其他合适的ID
+						question_id: this.currentAnswer.questionId,
+						answer_content: answerContent,
+						answer_duration: this.currentAnswer.answerDuration || 0,
+						// 如果需要tenant_id,请在这里添加
+						tenant_id: 1
 					};
 					
-					// 这里需要添加您的API调用
-					// const res = await submitInterviewAnswers(submitData);
+					console.log('提交数据:', submitData);
 					
-					// 模拟API调用
-					await new Promise(resolve => setTimeout(resolve, 1000));
+					// 调用API提交答案
+					const res = await this.$http.post('http://192.168.66.187:8083/api/job/submit_answer', submitData);
+					
+					console.log('提交答案响应:', res);
 					
 					// 隐藏加载提示
 					uni.hideLoading();
 					
-					// 显示成功提示
-					uni.showToast({
-						title: '提交成功',
-						icon: 'success'
-					});
-					
-					// 关闭结果页面,可以选择跳转到其他页面
-					setTimeout(() => {
-						this.back();
-					}, 1500);
+					return res;
 					
 				} catch (error) {
 					console.error('提交答案失败:', error);
+					// 隐藏加载提示
+					uni.hideLoading();
+					
+					// 显示错误提示
 					uni.showToast({
 						title: '提交答案失败,请重试',
 						icon: 'none'
 					});
-				} finally {
-					this.isSubmitting = false;
+					
+					throw error;
 				}
 			},
 			

+ 12 - 2
pages/index/index.vue

@@ -110,7 +110,8 @@
 	import {
 		fillUserInfo,
 		getUserInfo,
-		getJobList
+		getJobList,
+		applyJob
 	} from '@/api/user';
 	export default {
 		data() {
@@ -247,7 +248,12 @@
 
 				// 保存所选职位信息
 				uni.setStorageSync('selectedJob', JSON.stringify(this.selectedJob));
-				uni.navigateTo({
+				applyJob({
+					job_id: this.selectedJobId,
+					tenant_id: 1,
+					openid: JSON.parse(uni.getStorageSync('userInfo')).openid
+				}).then(res => {
+					uni.navigateTo({
 				  url: '/pages/interview-notice/interview-notice',
 				  fail: (err) => {
 				    console.error('页面跳转失败:', err);
@@ -257,6 +263,10 @@
 				    });
 				  }
 				});
+				}).catch(err => {
+					console.error('申请职位失败:', err);
+				});
+				
 				// 显示填写个人信息表单
 				// this.userInfoFilled = true;
 			},

+ 4 - 0
unpackage/dist/dev/mp-weixin/api/user.js

@@ -54,6 +54,10 @@ const fillUserInfo = (params) => {
 const getInterviewList = (params) => {
   return utils_request.http.get("/system/interview_question/list", params);
 };
+const applyJob = (params) => {
+  return utils_request.http.post("/api/job/apply", params);
+};
+exports.applyJob = applyJob;
 exports.fillUserInfo = fillUserInfo;
 exports.getInterviewList = getInterviewList;
 exports.getJobList = getJobList;

+ 66 - 27
unpackage/dist/dev/mp-weixin/pages/camera/camera.js

@@ -41,8 +41,12 @@ const _sfc_main = {
       // 当前题目详情
       isSubmitting: false,
       // 是否正在提交答案
-      openQuestionAnswer: ""
+      openQuestionAnswer: "",
       // 存储开放问题的答案
+      currentAnswer: null,
+      // 存储当前答案以便提交
+      questionStartTime: null
+      // 存储问题开始时间
     };
   },
   computed: {
@@ -152,6 +156,7 @@ const _sfc_main = {
     startTimer() {
       if (this.questions.length === 0)
         return;
+      this.questionStartTime = /* @__PURE__ */ new Date();
       let seconds = 30;
       this.timerInterval = setInterval(() => {
         seconds--;
@@ -206,17 +211,25 @@ const _sfc_main = {
       }
       this.showResult = true;
     },
-    nextQuestion() {
+    nextQuestion(data) {
       if (!this.showResult) {
         this.checkAnswer();
         return;
       }
-      this.saveAnswer();
-      if (this.currentQuestionIndex >= this.questions.length - 1) {
-        this.showEndModal = true;
-        return;
-      }
-      this.goToNextQuestion();
+      this.saveAnswer(data);
+      this.submitCurrentAnswer(data).then(() => {
+        if (this.currentQuestionIndex >= this.questions.length - 1) {
+          this.showEndModal = true;
+          return;
+        }
+        this.goToNextQuestion();
+      }).catch((error) => {
+        console.error("提交答案失败:", error);
+        common_vendor.index.showToast({
+          title: "提交答案失败,请重试",
+          icon: "none"
+        });
+      });
     },
     // 保存当前题目的答案
     saveAnswer() {
@@ -225,13 +238,17 @@ const _sfc_main = {
         answer = {
           questionId: this.currentQuestion.id,
           questionType: this.currentQuestion.questionType,
-          answer: this.openQuestionAnswer
+          answer: this.openQuestionAnswer,
+          answerDuration: this.getAnswerDuration()
+          // 添加答题时长
         };
       } else {
         answer = {
           questionId: this.currentQuestion.id,
           questionType: this.currentQuestion.questionType,
-          answer: this.currentQuestion.questionType === 1 ? this.selectedOption : this.selectedOptions
+          answer: this.currentQuestion.questionType === 1 ? this.selectedOption : this.selectedOptions,
+          answerDuration: this.getAnswerDuration()
+          // 添加答题时长
         };
       }
       const existingIndex = this.answers.findIndex((a) => a.questionId === answer.questionId);
@@ -240,38 +257,60 @@ const _sfc_main = {
       } else {
         this.answers.push(answer);
       }
+      this.currentAnswer = answer;
       console.log("已保存答案:", this.answers);
     },
-    // 提交所有答案
-    async submitAllAnswers() {
-      if (this.isSubmitting)
+    // 获取答题时长(秒)
+    getAnswerDuration() {
+      const remainingTimeArr = this.remainingTime.split(":");
+      const remainingSeconds = parseInt(remainingTimeArr[0]) * 60 + parseInt(remainingTimeArr[1]);
+      return 30 - remainingSeconds;
+    },
+    // 提交当前答案
+    async submitCurrentAnswer() {
+      if (!this.currentAnswer)
         return;
       try {
-        this.isSubmitting = true;
         common_vendor.index.showLoading({
           title: "正在提交答案..."
         });
+        let answerContent = "";
+        if (this.currentAnswer.questionType === 0) {
+          answerContent = this.currentAnswer.answer;
+        } else if (this.currentAnswer.questionType === 1) {
+          const selectedIndex = this.currentAnswer.answer;
+          const selectedOption = this.currentQuestion.options[selectedIndex];
+          answerContent = selectedOption.id ? selectedOption.id.toString() : selectedIndex.toString();
+        } else if (this.currentAnswer.questionType === 2) {
+          const selectedIndices = this.currentAnswer.answer;
+          const selectedOptionIds = selectedIndices.map((index) => {
+            const option = this.currentQuestion.options[index];
+            return option.id ? option.id : index;
+          });
+          answerContent = selectedOptionIds.join(",");
+        }
         const submitData = {
-          interviewId: this.interviewId,
-          answers: this.answers
+          application_id: 1,
+          // 或者使用其他合适的ID
+          question_id: this.currentAnswer.questionId,
+          answer_content: answerContent,
+          answer_duration: this.currentAnswer.answerDuration || 0,
+          // 如果需要tenant_id,请在这里添加
+          tenant_id: 1
         };
-        await new Promise((resolve) => setTimeout(resolve, 1e3));
+        console.log("提交数据:", submitData);
+        const res2 = await this.$http.post("http://192.168.66.187:8083/api/job/submit_answer", submitData);
+        console.log("提交答案响应:", res2);
         common_vendor.index.hideLoading();
-        common_vendor.index.showToast({
-          title: "提交成功",
-          icon: "success"
-        });
-        setTimeout(() => {
-          this.back();
-        }, 1500);
+        return res2;
       } catch (error) {
         console.error("提交答案失败:", error);
+        common_vendor.index.hideLoading();
         common_vendor.index.showToast({
           title: "提交答案失败,请重试",
           icon: "none"
         });
-      } finally {
-        this.isSubmitting = false;
+        throw error;
       }
     },
     // 修改 goToNextQuestion 方法,添加 async 关键字
@@ -446,7 +485,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
     o: common_vendor.t($options.currentQuestion.questionType === 1 ? "●" : "☐")
   }, {
     p: common_vendor.t($data.showResult ? "下一题" : "提交答案"),
-    q: common_vendor.o((...args) => $options.nextQuestion && $options.nextQuestion(...args)),
+    q: common_vendor.o(($event) => $options.nextQuestion(_ctx.option)),
     r: $options.currentQuestion.questionType === 0 && $data.openQuestionAnswer.trim() === "" || $options.currentQuestion.questionType === 1 && $data.selectedOption === null || $options.currentQuestion.questionType === 2 && $data.selectedOptions.length === 0,
     s: $data.showEndModal
   }, $data.showEndModal ? {

+ 17 - 9
unpackage/dist/dev/mp-weixin/pages/index/index.js

@@ -113,15 +113,23 @@ const _sfc_main = {
         return;
       }
       common_vendor.index.setStorageSync("selectedJob", JSON.stringify(this.selectedJob));
-      common_vendor.index.navigateTo({
-        url: "/pages/interview-notice/interview-notice",
-        fail: (err) => {
-          console.error("页面跳转失败:", err);
-          common_vendor.index.showToast({
-            title: "页面跳转失败",
-            icon: "none"
-          });
-        }
+      api_user.applyJob({
+        job_id: this.selectedJobId,
+        tenant_id: 1,
+        openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid
+      }).then((res) => {
+        common_vendor.index.navigateTo({
+          url: "/pages/interview-notice/interview-notice",
+          fail: (err) => {
+            console.error("页面跳转失败:", err);
+            common_vendor.index.showToast({
+              title: "页面跳转失败",
+              icon: "none"
+            });
+          }
+        });
+      }).catch((err) => {
+        console.error("申请职位失败:", err);
       });
     },
     submitForm() {