Commit 8c419b95 authored by 李维's avatar 李维

优化解锁逻辑

parent 40a71f27
......@@ -466,7 +466,7 @@ export function initAir(_this) {
} else {
console.error(`非源生环境,网页版不支持${method}方法,将返回此方法的Mock数据以便于网页版调试使用`);
if(method == 'getEngineInfo'){
window.air.getEngineInfoCallback({isDev: 1, uuid: 'debug-xxxxxx-xxxxxx', version: '1.0.2'});
window.air.getEngineInfoCallback({isDev: 0, uuid: 'debug-xxxxxx-xxxxxx', version: '1.0.2'});
} else if(method == 'logUpload'){
window.air.logFileUploadCallback({"fileUrl":"abcedfgh","error":""});
} else if (method == 'startTest') {
......
......@@ -80,54 +80,117 @@ export default class MiddleLayerClass extends middleLayerBase {
// }, 2000);
}
saveAnswer(data, callback = null) {
this.callNetworkApiPost(`/api/kyxq/v1/user/saveanswer`, {
syllabus_id: this.courseItem.course_id,
courseware_id: this.courseItem.id,
template_name: this.courseItem.template_name,
score: data ? data.score : 0,
total_count: data ? data.total_count : 0,
right_count: data ? data.right_count : 0,
wrong_count: data ? data.wrong_count : 0,
result: JSON.stringify(data),
study_duration: Date.now() - this.courseOpenTimeStamp
}, (res) => {
if (res.code != 200) {
this.showTips(`保存学情数据失败 [${res.msg}]`);
return;
}
this.saveEnd(callback);
});
saveAnswer(data) {
return new Promise(resovle => {
this.callNetworkApiPost(`/api/kyxq/v1/user/saveanswer`, {
syllabus_id: this.courseItem.course_id,
courseware_id: this.courseItem.id,
template_name: this.courseItem.template_name,
score: data ? data.score : 0,
total_count: data ? data.total_count : 0,
right_count: data ? data.right_count : 0,
wrong_count: data ? data.wrong_count : 0,
result: JSON.stringify(data),
study_duration: Date.now() - this.courseOpenTimeStamp
}, (res) => {
if (res.code != 200) {
this.showTips(`保存学情数据失败 [${res.msg}]`);
resovle({
ok: false,
msg: `保存学情数据失败 [${res.msg}]`
})
return;
}
resovle({
ok: true,
msg: ""
})
});
})
}
saveEnd(callback) {
if (this.courseIndex < this.courses.length - 1) {
callback && callback();
return;
}
this.callNetworkApiPost(`/api/kyxq/v1/user/saveend`, {
syllabus_id: this.courseItem.course_id,
}, (res) => {
if (res.code != 200) {
this.showTips(`保存结束状态失败 [${res.msg}]`);
saveEnd() {
return new Promise(resovle => {
if (this.courseIndex < this.courses.length - 1) {
resovle({
ok: false,
msg: `${this.courseIndex}<${this.courses.length - 1} 返回`
})
return;
}
callback && callback();
});
this.callNetworkApiPost(`/api/kyxq/v1/user/saveend`, {
syllabus_id: this.courseItem.course_id,
}, (res) => {
if (res.code != 200) {
this.showTips(`保存结束状态失败 [${res.msg}]`);
resovle({
ok: false,
msg: `保存结束状态失败 [${res.msg}]`
})
return;
}
resovle({
ok: true,
msg: ""
})
});
})
}
unlockNext(nextSyllabusId) {
this.callNetworkApiPost(`/api/kyxq/v1/user/unlock`, {
syllabus_id: nextSyllabusId,
}, (res) => {
if (res.code != 200) {
this.showTips(`解锁下一关卡失败 [${res.msg}]`);
return;
unlockNext() {
return new Promise(resovle => {
if (this.courseIndex == this.courses.length - 1) {
const lastCurse = this.crossArray[this.crossArray.length - 1];
if (this.courseItem.course_id != lastCurse.id) {
// 上报解锁下一关
const currentIndex = this.crossArray.findIndex(item => item.id == this.courseItem.course_id);
const nextCourse = this.crossArray[currentIndex + 1];
this.callNetworkApiPost(`/api/kyxq/v1/user/unlock`, {
syllabus_id: nextCourse.id,
}, (res) => {
if (res.code != 200) {
this.showTips(`解锁下一关卡失败 [${res.msg}]`);
resovle({
ok: false,
msg: `解锁下一关卡失败 [${res.msg}]`
})
return;
}
resovle({
ok: true,
msg: "上报解锁下一关"
})
});
} else {
// 上报一个本节课完成
this.callNetworkApiPost(`/api/kyxq/v1/user/saveend`, {
syllabus_id: lastCurse.pid,
}, (res) => {
if (res.code != 200) {
this.showTips(`保存结束状态失败 [${res.msg}]`);
resovle({
ok: false,
msg: `保存结束状态失败 [${res.msg}]`
})
return;
}
});
resovle({
ok: true,
msg: `上报一个本节课完成`
})
}
} else {
resovle({
ok: false,
msg: `${this.courseIndex} < ${this.courses.length - 1} 部署最后一个课件,不需要解锁`
})
}
});
})
}
onHomeworkFinish(d1 = null, d2 = null) {
async onHomeworkFinish(d1 = null, d2 = null) {
let data = null;
let callback = null;
if (typeof (d1) == 'function') {
......@@ -138,7 +201,15 @@ export default class MiddleLayerClass extends middleLayerBase {
callback = d2;
}
console.log('onHomeworkFinish: ' + JSON.stringify(data));
this.saveAnswer(data, callback);
const ok1 = await this.saveAnswer(data);
const ok2 = await this.saveEnd();
const ok3 = await this.unlockNext();
ok1.ok?console.log("saveAnswer成功") : console.log(ok1.msg);
ok2.ok?console.log("saveEnd成功") : console.log(ok2.msg);
ok3.ok?console.log("unlockNext成功") : console.log(ok3.msg);
callback && callback()
}
_designSize = null; // 设计分辨率
......@@ -269,25 +340,8 @@ export default class MiddleLayerClass extends middleLayerBase {
this.goTarIndexPage(this.courseIndex + 1);
});
} else {
const lastCurse = this.crossArray[this.crossArray.length - 1];
// 课件完成的庆祝画面
this.showFinish();
if (this.courseItem.course_id != lastCurse.id) {
// 上报解锁下一关
const currentIndex = this.crossArray.findIndex(item => item.id == this.courseItem.course_id);
const nextCourse = this.crossArray[currentIndex + 1];
this.unlockNext(nextCourse.id);
} else {
// 上报一个本节课完成
this.callNetworkApiPost(`/api/kyxq/v1/user/saveend`, {
syllabus_id: lastCurse.pid,
}, (res) => {
if (res.code != 200) {
this.showTips(`保存结束状态失败 [${res.msg}]`);
return;
}
});
}
}
}
......
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