Commit f5085024 authored by liujiangnan's avatar liujiangnan

feat: 打开课件功能

parent 26e64ddd
...@@ -205,7 +205,7 @@ export function initAir(_this) { ...@@ -205,7 +205,7 @@ export function initAir(_this) {
} else { } else {
console.error('非源生环境'); console.error('非源生环境');
if(method == 'getEngineInfo'){ if(method == 'getEngineInfo'){
window.air.getEngineInfoCallback({isDev: 1}); window.air.getEngineInfoCallback({isDev: 1, engine_code: 'debug-test-0001'});
} }
} }
}, },
......
...@@ -30,7 +30,7 @@ cc.Class({ ...@@ -30,7 +30,7 @@ cc.Class({
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => { xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) { if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
callBack(xhr.responseText); callBack(JSON.parse(xhr.responseText));
} }
}; };
const url = `${baseUrl}${uri}${queryStr}`; const url = `${baseUrl}${uri}${queryStr}`;
...@@ -65,6 +65,13 @@ cc.Class({ ...@@ -65,6 +65,13 @@ cc.Class({
// 统计已加载的数量 // 统计已加载的数量
loadedCount: null, loadedCount: null,
baseApiUrl: null, // API地址
engineCode: null, // 机器唯一编码
userCode: null, // 用户唯一编码
name: null, // 用户取的英文名
birthday: null, // 用户的生日
courseIds: null, // 根据推荐生成的课件ID数组
// 统一释放异步资源的方法 // 统一释放异步资源的方法
onLoad() { onLoad() {
this.preloadCount = 0; this.preloadCount = 0;
...@@ -76,7 +83,48 @@ cc.Class({ ...@@ -76,7 +83,48 @@ cc.Class({
this.node.zIndex = 9999; this.node.zIndex = 9999;
cc.game.addPersistRootNode(this.node); cc.game.addPersistRootNode(this.node);
this.initListener(); this.initListener();
this.initPageInfo();
this.hideUI();
this.showWaitingLetters();
this.initTerminalInfo(() => {
this.loadGame();
});
},
initTerminalInfo(callback) {
window.courseware.getEngineInfo(res => {
const { isDev, engine_code } = JSON.parse(res);
if (isDev) {
// 这里后面给个测试环境地址
this.baseApiUrl = `https://api.iplayabc.com/`;
} else {
this.baseApiUrl = `https://api.iplayabc.com/`;
}
this.engineCode = engine_code;
this.getUserCode(callback);
});
},
getUserCode(callback) {
this.callNetworkApiPost(this.baseApiUrl, "v1/terminal/store", {
engine_code: this.engineCode,
name: 'default_name',
birthday: '20200202'
}, res => {
if (res.code === 200) {
this.userCode = res.data.user_code;
this.name = res.data.name;
this.birthday = res.data.birthday;
callback && callback();
}else{
console.log("-----error------");
console.log(res.msg);
// TODO 提示错误和上报错误
}
});
},
initPageInfo() {
const addressText = cc.find('middleLayer/ui/address'); const addressText = cc.find('middleLayer/ui/address');
const str = cc.sys.localStorage.getItem('ip'); const str = cc.sys.localStorage.getItem('ip');
console.log('str = ' + str); console.log('str = ' + str);
...@@ -98,9 +146,23 @@ cc.Class({ ...@@ -98,9 +146,23 @@ cc.Class({
global.middleLayer = cc.find('middleLayer').getComponent('middleLayer'); global.middleLayer = cc.find('middleLayer').getComponent('middleLayer');
middleLayer.log("middleLayer.log('像这样在这里打log')"); middleLayer.log("middleLayer.log('像这样在这里打log')");
},
// TODO 查询推荐接口 loadGame() {
this.loadOnlineCourseWare(33562, true); this.callNetworkApiGet(this.baseApiUrl, `v1/preference/courseware`, { user_code: this.userCode }, res => {
if (res.code !== 200) {
console.log("-----error------");
console.log(res.msg);
// TODO 提示错误和上报错误
return;
}
this.courseIds = res.data;
this.loadOnlineCourseWare(this.courseIds[0], false);
});
},
addStar(count, animationFlag) {
// TODO 添加星星的动画并且保存星星到后台
}, },
preloadAll() { preloadAll() {
...@@ -117,13 +179,11 @@ cc.Class({ ...@@ -117,13 +179,11 @@ cc.Class({
} else if (cc.sys.os == cc.sys.OS_ANDROID) { } else if (cc.sys.os == cc.sys.OS_ANDROID) {
platform = "android"; platform = "android";
} }
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/syllabus/v1/allbundles`, { orgid: 483, platform }, (datastr) => { this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/syllabus/v1/allbundles`, { orgid: 488, platform }, (data) => {
const data = JSON.parse(datastr);
if (data.rows && data.rows.length > 0) { if (data.rows && data.rows.length > 0) {
this.preloadCount += data.rows.length; this.preloadCount += data.rows.length;
} }
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/syllabus/v1/allresources`, { orgid: 483 }, (datastr1) => { this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/syllabus/v1/allresources`, { orgid: 488 }, (data1) => {
const data1 = JSON.parse(datastr1);
if (data1.rows && data1.rows.length > 0) { if (data1.rows && data1.rows.length > 0) {
this.preloadCount += data1.rows.length; this.preloadCount += data1.rows.length;
} }
...@@ -138,8 +198,7 @@ cc.Class({ ...@@ -138,8 +198,7 @@ cc.Class({
// 测试用 // 测试用
cc.find("middleLayer/ui/ProgressLabel").active = true; cc.find("middleLayer/ui/ProgressLabel").active = true;
cc.find('middleLayer/ui/loadingProgress').active = true; cc.find('middleLayer/ui/loadingProgress').active = true;
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/courseware/v1/getresources`, { courseid: 20894 }, (datastr1) => { this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/courseware/v1/getresources`, { courseid: 20894 }, (data1) => {
const data1 = JSON.parse(datastr1);
if (data1.rows && data1.rows.length > 0) { if (data1.rows && data1.rows.length > 0) {
this.preloadCount += data1.rows.length; this.preloadCount += data1.rows.length;
} }
...@@ -408,10 +467,8 @@ cc.Class({ ...@@ -408,10 +467,8 @@ cc.Class({
cc.find('middleLayer/ui').active = false; cc.find('middleLayer/ui').active = false;
}, },
loadOnlineBundle(bundleName) { loadOnlineBundle(bundleName) {
this.hideUI();
this.showWaitingLetters(); this.showWaitingLetters();
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/template/v1/${bundleName}`, {}, (datastr) => { this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/template/v1/${bundleName}`, {}, (data) => {
const data = JSON.parse(datastr);
let configData = null; let configData = null;
if (cc.sys.os == cc.sys.OS_IOS) { if (cc.sys.os == cc.sys.OS_IOS) {
configData = data.data.conf.ios; configData = data.data.conf.ios;
...@@ -430,7 +487,6 @@ cc.Class({ ...@@ -430,7 +487,6 @@ cc.Class({
courseIndex: 0, courseIndex: 0,
courseItem: null, courseItem: null,
loadOnlineCourseWare(courseId, linkFlag) { loadOnlineCourseWare(courseId, linkFlag) {
console.log("======================", courseId, linkFlag);
this.hideUI(); this.hideUI();
this.showWaitingLetters(); this.showWaitingLetters();
...@@ -438,8 +494,7 @@ cc.Class({ ...@@ -438,8 +494,7 @@ cc.Class({
if (linkFlag === true) { if (linkFlag === true) {
api = `/api/courseware/v1/${courseId}/eq/level/list`; api = `/api/courseware/v1/${courseId}/eq/level/list`;
} }
this.callNetworkApiGet(`http://iteachabc.com`, api, {}, (datastr) => { this.callNetworkApiGet(`http://iteachabc.com`, api, {}, (data) => {
const data = JSON.parse(datastr);
if (data.rows && data.rows.length > 0) { if (data.rows && data.rows.length > 0) {
this.courses = data.rows; this.courses = data.rows;
this.courseIndex = data.index || 0; this.courseIndex = data.index || 0;
...@@ -573,8 +628,7 @@ cc.Class({ ...@@ -573,8 +628,7 @@ cc.Class({
} }
window.courseware.getAnswer = (queryObj, callback) => { window.courseware.getAnswer = (queryObj, callback) => {
this.log("===成功调用getAnswer===" + JSON.stringify(queryObj)); this.log("===成功调用getAnswer===" + JSON.stringify(queryObj));
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/oxford/courseware/v1/${this.courseItem.id}/getanswer`, queryObj, (datastr) => { this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/oxford/courseware/v1/${this.courseItem.id}/getanswer`, queryObj, (data) => {
const data = JSON.parse(datastr);
callback && callback(JSON.stringify(data.rows)); callback && callback(JSON.stringify(data.rows));
}); });
} }
......
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