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,55 +695,54 @@ export default { ...@@ -695,55 +695,54 @@ 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");
uni.showToast({
icon: "none",
title: "获取考试信息失败",
});
}
this.examList[i].examId = res.data.id;
this.examList[i].examStatus = res.data.examStatus; //i;//
this.examList[i].questionTime = res.data.questionTime;
let examResult = res.data.examLevelResult;
this.examList[i].status =
examResult != "" ? examResult : "未通过";
//动态获取条件
let ruleDisc = res.data.ruleDisc;
let targetIndex = ruleDisc.indexOf("(");
if (targetIndex) {
this.examList[i].condition = ruleDisc
.substr(targetIndex + 1)
.replace(")", "");
}
// examStatus 用户考试状态 0考试中 1考试完成 2未参与
that.exam = res.data;
if (res.data.examStatus == 2) {
return;
}
if (res.data.examStatus == 1) {
that.examList[i].isComplete =
this.examList[i].status == "已通过";
that.examScore = res.data.examScore;
return;
}
if (res.data.examStatus == 0) {
that.userExamId = res.data.id;
}
})
.catch((err) => {
uni.hideLoading();
uni.showToast({ uni.showToast({
icon: "none", icon: "none",
title: "获取考试信息失败", title: "获取考试信息失败",
}); });
}
this.examList[i].examId = res.data.id;
this.examList[i].examStatus = res.data.examStatus; //i;//
this.examList[i].questionTime = res.data.questionTime;
let examResult = res.data.examLevelResult;
this.examList[i].status =
examResult != "" ? examResult : "未通过";
//动态获取条件
let ruleDisc = res.data.ruleDisc;
let targetIndex = ruleDisc.indexOf("(");
if (targetIndex) {
this.examList[i].condition = ruleDisc
.substr(targetIndex + 1)
.replace(")", "");
}
// examStatus 用户考试状态 0考试中 1考试完成 2未参与
that.exam = res.data;
if (res.data.examStatus == 2) {
return;
}
if (res.data.examStatus == 1) {
that.examList[i].isComplete =
this.examList[i].status == "已通过";
that.examScore = res.data.examScore;
return;
}
if (res.data.examStatus == 0) {
that.userExamId = res.data.id;
}
})
.catch((err) => {
uni.hideLoading();
uni.showToast({
icon: "none",
title: "获取考试信息失败",
}); });
});
} }
}, },
//跳转到assessment页面 //跳转到assessment页面
......
...@@ -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,64 +189,60 @@ export default { ...@@ -197,64 +189,60 @@ 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" + uni.hideLoading();
"/serviceRule/userExamInfo/" + if (!res.data) {
that.vuex_token + return;
"?examId=" + }
this.examId, if (res.code == 200) {
method: "POST", //examStatus 用户考试状态 0考试中 1考试完成 2未参与
data: { if (res.data.examStatus == 2) {
//examId:this.examId, that.applyExam();
},
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
success: (res) => {
uni.hideLoading();
if (!res.data) {
return; return;
} }
if (res.data.code == 401 || res.data.code == 403) { if (res.data.examStatus == 1) {
//提示 提交结果失败 请再次提交 if(that.isOnLoad){
uni.showToast({
icon: "none",
title: "获取考试结果失败,请再次尝试提交",
});
return
}
if (res.data.code == 200) {
//examStatus 用户考试状态 0考试中 1考试完成 2未参与
if (res.data.data.examStatus == 2) {
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.examScore;
that.examScore = res.data.data.examScore; return;
return; }
} if (res.data.examStatus == 0) {
if (res.data.data.examStatus == 0) { that.userExamId = res.data.id;
that.userExamId = res.data.data.id;
that.getNext(); 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);
} }
} else { that.getNext();
uni.showToast({
icon: "none",
title: res.data.message,
});
} }
}, } else {
fail: (e) => {
uni.hideLoading();
uni.showToast({ uni.showToast({
icon: "none", icon: "none",
title: "获取考试信息失败", title: res.data.message,
}); });
}, }
}); })
// .catch((err) => {
// uni.hideLoading();
// uni.showToast({
// icon: "none",
// title: err,
// });
// });
}, },
//申请考试 //申请考试
...@@ -264,57 +252,38 @@ export default { ...@@ -264,57 +252,38 @@ 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" + uni.hideLoading();
"/serviceRule/" + if (res.code == 200) {
that.vuex_token + if (res.data.userExamId) {
"?examId=" + that.userExamId = res.data.userExamId;
this.examId,
method: "POST", //申请完考试设置倒计时总时间
data: { let time = parseInt(
//examId:this.examId, this.timeDefine["time-id-" + this.examId]
}, );
header: { this.endTime = time;
"Content-Type": "application/x-www-form-urlencoded", // let timestamp = new Date().getTime();
}, // this.endTime = timestamp + time * 1000;
success: (res) => { this.currentTime = parseInt(time * 1000); //this.formatTimeToMini(timestamp);//endTime-currentTime再格式化时间显示
uni.hideLoading(); that.getNext();
if (res.statusCode == 401) {
this.gotoLogin();
return
}
if (res.data.code == 200) {
if (res.data.data.userExamId) {
that.userExamId = res.data.data.userExamId;
//申请完考试设置倒计时总时间
let time = parseInt(
this.timeDefine["time-id-" + this.examId]
);
this.endTime = time;
// let timestamp = new Date().getTime();
// this.endTime = timestamp + time * 1000;
this.currentTime = parseInt(time * 1000); //this.formatTimeToMini(timestamp);//endTime-currentTime再格式化时间显示
that.getNext();
}
} else {
uni.showToast({
icon: "none",
title: res.data.message,
});
} }
}, } else {
fail: (e) => {
uni.hideLoading();
uni.showToast({ uni.showToast({
icon: "none", icon: "none",
title: "申请考试 失败", title: res.data.message,
}); });
}, }
}); })
// .catch((err) => {
// uni.hideLoading();
// uni.showToast({
// icon: "none",
// title: "获取考试信息失败",
// });
// });
}, },
//获取下一题 //获取下一题
...@@ -333,90 +302,64 @@ export default { ...@@ -333,90 +302,64 @@ 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" + uni.hideLoading();
"/serviceRule/next/" + if (res.code == 200) {
that.vuex_token + that.currentItem = res.data;
"?userExamId=" + that.progress = res.data.progress;
this.userExamId + // if(this.isLoadQuestion){
"&questionId=" + // this.isLoadQuestion = false;
questionId + // if(!res.data.isQuestion){
"&userAnswerIds=" + // this.applyExam()
(this.userAnswerIds || "9999") + // return
",", // 9999超时自动下一题 // }
method: "POST", // let key = 'exma-' + this.examId;
header: { // let limitTime = uni.getStorageSync(key);
"Content-Type": "application/x-www-form-urlencoded", // console.log(limitTime);
}, // // let limitTime = this.getLimitTime(that.progress);
success: (res) => { // // console.log(limitTime);
uni.hideLoading(); // this.endTime = parseInt(limitTime);
if (res.statusCode == 401) { // this.currentTime = parseInt(limitTime * 1000);
this.gotoLogin() // }
return; if (res.data.isQuestion) {
} let str = res.data.question.content;
if(res.statusCode == 403){ var wz = str.indexOf(".");
uni.showToast({ let str1 = str.substring(wz + 1);
icon: "none", that.currentItem.question.content = str1.replace('*', '');
title: "获取考试结果失败,请再次尝试提交",
});
return
} }
if (res.data.code == 200) { if (res.data.answerList) {
that.currentItem = res.data.data; that.handleData();
that.progress = res.data.data.progress; // that.currentTime = 100
if(this.isLoadQuestion){ this.everyTime = getApp().globalData.questionTime; //每道题100s
this.isLoadQuestion = false; that.isSelect = false;
if(!res.data.data.isQuestion){ clearTimeout(this.timer);
this.applyExam() that.startCounting();
return
}
let key = 'exma-' + this.examId;
let limitTime = uni.getStorageSync(key);
console.log(limitTime);
// let limitTime = this.getLimitTime(that.progress);
// console.log(limitTime);
this.endTime = parseInt(limitTime);
this.currentTime = parseInt(limitTime * 1000);
}
if (res.data.data.isQuestion) {
let str = res.data.data.question.content;
var wz = str.indexOf(".");
let str1 = str.substring(wz + 1);
that.currentItem.question.content = str1.replace('*', '');
}
if (res.data.data.answerList) {
that.handleData();
// that.currentTime = 100
this.everyTime = getApp().globalData.questionTime; //每道题100s
that.isSelect = false;
clearTimeout(this.timer);
that.startCounting();
} else {
that.isSelect = true;
that.getUserExamInfo();
clearTimeout(this.timer);
this.isComplete = true;
//用来考完试判断跳转
this.examInfo = that.currentItem;
// that.bottomTitle = '完成考试,现在签约'
}
} else { } else {
uni.showToast({ that.isSelect = true;
icon: "none", that.getUserExamInfo();
title: res.data.message, clearTimeout(this.timer);
}); this.isComplete = true;
//用来考完试判断跳转
this.examInfo = that.currentItem;
// that.bottomTitle = '完成考试,现在签约'
} }
}, // debugger
fail: (e) => { } else {
uni.hideLoading();
uni.showToast({ uni.showToast({
icon: "none", icon: "none",
title: "获取下一题 失败", title: res.data.message,
}); });
}, }
}); })
// .catch((err) => {
// uni.hideLoading();
// uni.showToast({
// icon: "none",
// 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,32 +69,29 @@ export default { ...@@ -67,32 +69,29 @@ 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/" + uni.hideLoading();
this.vuex_token + if (res.code == 200) {
"?examId=" + if (res.data.ruleDisc) {
this.examId, var str = res.data.ruleDisc;
method: "POST", this.userExamId = res.data.id;
header: {
"Content-Type": "application/x-www-from-urlencoded", let strArr = str.split("(")[0].split(",");
}, this.title = strArr[0];
success: (res) => { this.score = strArr[1];
uni.hideLoading(); this.time = strArr[2];
if (res.data.code == 200) { this.ruleDisc = strArr[3];
if (res.data.data.ruleDisc) {
var str = res.data.data.ruleDisc;
this.userExamId = res.data.data.id;
let strArr = str.split("(")[0].split(",");
this.title = strArr[0];
this.score = strArr[1];
this.time = strArr[2];
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