Commit 40f49912 authored by linwenqing's avatar linwenqing

fix:考试bug修复

parent 6cc5e8e5
...@@ -18,8 +18,12 @@ let learnApiFun = function(vm){ ...@@ -18,8 +18,12 @@ let learnApiFun = function(vm){
/* 获取考试结果 */ /* 获取考试结果 */
let getExamResult = async (examId, params = {}) => await vm.$u.post(sysApiUrl + '/wxh-worker-rest/rest/exam/serviceRule/userExamInfo/' + vm.vuex_token + '?examId=' + examId, params); let getExamResult = async (examId, params = {}) => await vm.$u.post(sysApiUrl + '/wxh-worker-rest/rest/exam/serviceRule/userExamInfo/' + vm.vuex_token + '?examId=' + examId, params);
/* 申请考试 */
let applyExam = async (examId, params = {}) => await vm.$u.post(sysApiUrl + '/wxh-worker-rest/rest/exam/serviceRule/' + vm.vuex_token + '?examId=' + examId, params);
/* 获取下一题 */
let getNextQuestion = async (userExamId, questionId, userAnswerIds, params = {}) => await vm.$u.post(sysApiUrl + '/wxh-worker-rest/rest/exam/serviceRule/next/' + vm.vuex_token + '?userExamId=' + userExamId + '&questionId=' + questionId + '&userAnswerIds=' + (userAnswerIds || "9999"), params);
const learnApi = { const learnApi = {
getTrainingNoticeList,CourseList,ChapterDetails,CourseSection,updateLearnCourses,getExamResult getTrainingNoticeList,CourseList,ChapterDetails,CourseSection,updateLearnCourses,getExamResult,applyExam,getNextQuestion
} }
return learnApi return learnApi
} }
......
...@@ -695,8 +695,7 @@ export default { ...@@ -695,8 +695,7 @@ export default {
let length = this.examList.length; let length = this.examList.length;
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
let examId = this.examList[i].id; let examId = this.examList[i].id;
this.$u.api this.$u.api.getExamResult(examId)
.getExamResult(examId)
.then((res) => { .then((res) => {
if (res.code != 200) { if (res.code != 200) {
console.log("getUserExamInfo 200 err"); console.log("getUserExamInfo 200 err");
......
...@@ -95,7 +95,8 @@ export default { ...@@ -95,7 +95,8 @@ export default {
timer: null, timer: null,
isComplete: false, // 是否已经考试完成判定 isComplete: false, // 是否已经考试完成判定
examInfo: null, examInfo: null,
isLoadQuestion: true isLoadQuestion: true,
isOnLoad: true
}; };
}, },
computed: { computed: {
...@@ -116,9 +117,8 @@ export default { ...@@ -116,9 +117,8 @@ export default {
getApp().trackPage('学习考试答题页') getApp().trackPage('学习考试答题页')
this.examId = e.examId; this.examId = e.examId;
this.userExamId = e.userExamId; this.userExamId = e.userExamId;
this.getNext(); this.getUserExamInfo();
// this.applyExam(); // this.getNext();
// this.getUserExamInfo();
}, },
onUnload() { onUnload() {
clearTimeout(this.timer); clearTimeout(this.timer);
...@@ -176,14 +176,6 @@ export default { ...@@ -176,14 +176,6 @@ export default {
const result = txt.replace(reg, ""); const result = txt.replace(reg, "");
return result; return result;
}, },
//开始考试 点击
startClick: function () {
this.isStart = true;
//this.getData()
//this.applyExam()
this.getUserExamInfo();
},
gotoLogin() { gotoLogin() {
uni.navigateTo({ uni.navigateTo({
url: "/pages/login/wxlogin", url: "/pages/login/wxlogin",
...@@ -197,47 +189,44 @@ export default { ...@@ -197,47 +189,44 @@ export default {
}); });
let that = this; let that = this;
uni.request({ let examId = that.examId;
url: this.$u.api.getExamResult(examId)
systemApiUrl + .then((res) => {
"/wxh-worker-rest/rest/exam" +
"/serviceRule/userExamInfo/" +
that.vuex_token +
"?examId=" +
this.examId,
method: "POST",
data: {
//examId:this.examId,
},
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
success: (res) => {
uni.hideLoading(); uni.hideLoading();
if (!res.data) { if (!res.data) {
return; return;
} }
if (res.data.code == 401 || res.data.code == 403) { if (res.code == 200) {
//提示 提交结果失败 请再次提交
uni.showToast({
icon: "none",
title: "获取考试结果失败,请再次尝试提交",
});
return
}
if (res.data.code == 200) {
//examStatus 用户考试状态 0考试中 1考试完成 2未参与 //examStatus 用户考试状态 0考试中 1考试完成 2未参与
if (res.data.data.examStatus == 2) { if (res.data.examStatus == 2) {
that.applyExam();
return;
}
if (res.data.examStatus == 1) {
if(that.isOnLoad){
that.applyExam(); that.applyExam();
that.isOnLoad = false;
return; return;
} }
if (res.data.data.examStatus == 1) {
that.isComplete = true; that.isComplete = true;
that.examScore = res.data.data.examScore; that.examScore = res.data.examScore;
return; return;
} }
if (res.data.data.examStatus == 0) { if (res.data.examStatus == 0) {
that.userExamId = res.data.data.id; that.userExamId = res.data.id;
let key = 'exma-' + this.examId;
let limitTime = uni.getStorageSync(key);
if(limitTime < 0){
let time = parseInt(
this.timeDefine["time-id-" + this.examId]
);
this.endTime = time;
this.currentTime = parseInt(time * 1000);
}else{
this.endTime = parseInt(limitTime);
this.currentTime = parseInt(limitTime * 1000);
}
that.getNext(); that.getNext();
} }
} else { } else {
...@@ -246,15 +235,14 @@ export default { ...@@ -246,15 +235,14 @@ export default {
title: res.data.message, title: res.data.message,
}); });
} }
}, })
fail: (e) => { // .catch((err) => {
uni.hideLoading(); // uni.hideLoading();
uni.showToast({ // uni.showToast({
icon: "none", // icon: "none",
title: "获取考试信息失败", // title: err,
}); // });
}, // });
});
}, },
//申请考试 //申请考试
...@@ -264,31 +252,13 @@ export default { ...@@ -264,31 +252,13 @@ export default {
}); });
let that = this; let that = this;
uni.request({ let examId = this.examId;
url: this.$u.api.applyExam(examId)
systemApiUrl + .then((res) => {
"/wxh-worker-rest/rest/exam" +
"/serviceRule/" +
that.vuex_token +
"?examId=" +
this.examId,
method: "POST",
data: {
//examId:this.examId,
},
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
success: (res) => {
uni.hideLoading(); uni.hideLoading();
if (res.statusCode == 401) { if (res.code == 200) {
this.gotoLogin(); if (res.data.userExamId) {
return that.userExamId = res.data.userExamId;
}
if (res.data.code == 200) {
if (res.data.data.userExamId) {
that.userExamId = res.data.data.userExamId;
//申请完考试设置倒计时总时间 //申请完考试设置倒计时总时间
let time = parseInt( let time = parseInt(
...@@ -306,15 +276,14 @@ export default { ...@@ -306,15 +276,14 @@ export default {
title: res.data.message, title: res.data.message,
}); });
} }
}, })
fail: (e) => { // .catch((err) => {
uni.hideLoading(); // uni.hideLoading();
uni.showToast({ // uni.showToast({
icon: "none", // icon: "none",
title: "申请考试 失败", // title: "获取考试信息失败",
}); // });
}, // });
});
}, },
//获取下一题 //获取下一题
...@@ -333,60 +302,34 @@ export default { ...@@ -333,60 +302,34 @@ export default {
}); });
let that = this; let that = this;
uni.request({
url: this.$u.api.getNextQuestion(this.userExamId, questionId, this.userAnswerIds)
systemApiUrl + .then((res) => {
"/wxh-worker-rest/rest/exam" +
"/serviceRule/next/" +
that.vuex_token +
"?userExamId=" +
this.userExamId +
"&questionId=" +
questionId +
"&userAnswerIds=" +
(this.userAnswerIds || "9999") +
",", // 9999超时自动下一题
method: "POST",
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
success: (res) => {
uni.hideLoading(); uni.hideLoading();
if (res.statusCode == 401) { if (res.code == 200) {
this.gotoLogin() that.currentItem = res.data;
return; that.progress = res.data.progress;
} // if(this.isLoadQuestion){
if(res.statusCode == 403){ // this.isLoadQuestion = false;
uni.showToast({ // if(!res.data.isQuestion){
icon: "none", // this.applyExam()
title: "获取考试结果失败,请再次尝试提交", // return
}); // }
return // let key = 'exma-' + this.examId;
} // let limitTime = uni.getStorageSync(key);
if (res.data.code == 200) {
that.currentItem = res.data.data;
that.progress = res.data.data.progress;
if(this.isLoadQuestion){
this.isLoadQuestion = false;
if(!res.data.data.isQuestion){
this.applyExam()
return
}
let key = 'exma-' + this.examId;
let limitTime = uni.getStorageSync(key);
console.log(limitTime);
// let limitTime = this.getLimitTime(that.progress);
// console.log(limitTime); // console.log(limitTime);
this.endTime = parseInt(limitTime); // // let limitTime = this.getLimitTime(that.progress);
this.currentTime = parseInt(limitTime * 1000); // // console.log(limitTime);
} // this.endTime = parseInt(limitTime);
if (res.data.data.isQuestion) { // this.currentTime = parseInt(limitTime * 1000);
let str = res.data.data.question.content; // }
if (res.data.isQuestion) {
let str = res.data.question.content;
var wz = str.indexOf("."); var wz = str.indexOf(".");
let str1 = str.substring(wz + 1); let str1 = str.substring(wz + 1);
that.currentItem.question.content = str1.replace('*', ''); that.currentItem.question.content = str1.replace('*', '');
} }
if (res.data.data.answerList) { if (res.data.answerList) {
that.handleData(); that.handleData();
// that.currentTime = 100 // that.currentTime = 100
this.everyTime = getApp().globalData.questionTime; //每道题100s this.everyTime = getApp().globalData.questionTime; //每道题100s
...@@ -402,21 +345,21 @@ export default { ...@@ -402,21 +345,21 @@ export default {
this.examInfo = that.currentItem; this.examInfo = that.currentItem;
// that.bottomTitle = '完成考试,现在签约' // that.bottomTitle = '完成考试,现在签约'
} }
// debugger
} else { } else {
uni.showToast({ uni.showToast({
icon: "none", icon: "none",
title: res.data.message, title: res.data.message,
}); });
} }
}, })
fail: (e) => { // .catch((err) => {
uni.hideLoading(); // uni.hideLoading();
uni.showToast({ // uni.showToast({
icon: "none", // icon: "none",
title: "获取下一题 失败", // title: "获取考试信息失败",
}); // });
}, // });
});
}, },
getLimitTime(progress){ getLimitTime(progress){
let arr = progress.split('/'); let arr = progress.split('/');
......
...@@ -39,9 +39,11 @@ export default { ...@@ -39,9 +39,11 @@ export default {
onLoad(param) { onLoad(param) {
getApp().trackPage('学习开始考试页') getApp().trackPage('学习开始考试页')
this.examId = param.examId; this.examId = param.examId;
this.getExamResult();
// this.getUserExamInfo(); // this.getUserExamInfo();
}, },
onShow() {
this.getExamResult();
},
onUnload() { onUnload() {
uni.switchTab({ uni.switchTab({
url: '/pages/index/learn' url: '/pages/index/learn'
...@@ -67,23 +69,14 @@ export default { ...@@ -67,23 +69,14 @@ export default {
}); });
}, },
getExamResult() { getExamResult() {
uni.request({ let examId = this.examId;
url: this.$u.api.getExamResult(examId)
process.uniEnv.systemUrl.apiUrl + .then((res) => {
"/wxh-worker-rest/rest/exam/serviceRule/userExamInfo/" +
this.vuex_token +
"?examId=" +
this.examId,
method: "POST",
header: {
"Content-Type": "application/x-www-from-urlencoded",
},
success: (res) => {
uni.hideLoading(); uni.hideLoading();
if (res.data.code == 200) { if (res.code == 200) {
if (res.data.data.ruleDisc) { if (res.data.ruleDisc) {
var str = res.data.data.ruleDisc; var str = res.data.ruleDisc;
this.userExamId = res.data.data.id; this.userExamId = res.data.id;
let strArr = str.split("(")[0].split(","); let strArr = str.split("(")[0].split(",");
this.title = strArr[0]; this.title = strArr[0];
...@@ -92,7 +85,13 @@ export default { ...@@ -92,7 +85,13 @@ export default {
this.ruleDisc = strArr[3]; this.ruleDisc = strArr[3];
} }
} }
}, })
.catch((err) => {
uni.hideLoading();
uni.showToast({
icon: "none",
title: "获取考试信息失败",
});
}); });
}, },
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment