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

优化解锁逻辑

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