Commit 96f9670f authored by liujiangnan's avatar liujiangnan

feat: 加载课件等

parent 00cbacfd
{
"ver": "1.0.8",
"uuid": "5db4ac00-dc44-44aa-a996-19aefa0955c5",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
......@@ -8,32 +8,6 @@ cc.Class({
initAir(this);
},
getData(callBack) {
callBack(null);
return;
const uri = 'courseware/v1/getdata';
const syllabus_id = this.bundleInfoList[this.currentBundleIndex].syllabus_id;
const data = {
courseid: syllabus_id
};
this.callNetworkApiGet(uri, data, callBack);
},
onHomeworkFinish(callBack) {
return;
if (this.role == 'teacher') {
return;
}
const uri = 'app_source/v1/student/homework/finished';
const data = {
syllabus_id: this.syllabus_id,
homework_id: this.homework_id,
token: this.token,
score: 100
};
console.log('data = ' + JSON.stringify(data));
this.callNetworkApiPost(uri, data, callBack);
},
callNetworkApiPost(uri, data, callBack) {
const xhr = new XMLHttpRequest();
const url = `${this.baseUrl}${uri}`;
......@@ -49,12 +23,9 @@ cc.Class({
start() {
this.node.zIndex = 9999;
cc.game.addPersistRootNode(this.node);
this.initListener();
const addressText = cc.find('middleLayer/ui/address');
const str = cc.sys.localStorage.getItem('ip');
console.log('str = ' + str);
......@@ -68,6 +39,12 @@ cc.Class({
nameText.getComponent(cc.EditBox).string = bundleName;
}
const courseIdNode = cc.find('middleLayer/ui/courseId');
const courseId = cc.sys.localStorage.getItem('courseId');
if (courseId) {
courseIdNode.getComponent(cc.EditBox).string = courseId;
}
global.middleLayer = cc.find('middleLayer').getComponent('middleLayer');
middleLayer.log("middleLayer.log('像这样在这里打log')");
......@@ -103,21 +80,32 @@ cc.Class({
},
initListener() {
const exitBtn = this.node.getChildByName('ExitBtn');
const exitBtn = cc.find('middleLayer/ExitBtn');
exitBtn.on('click', () => {
cc.find('middleLayer/BtnRight').active = false;
cc.find('middleLayer/BtnLeft').active = false;
cc.tween(exitBtn)
.to(0.1, { scaleX: 0.9, scaleY: 1.1 })
.to(0.1, { scaleX: 1.1, scaleY: 0.9 })
.to(0.1, { scaleX: 1, scaleY: 1 })
.call(() => {
exitBtn.active = false;
cc.game.removePersistRootNode(this.node);
cc.director.loadScene("middleLayer_for_debug", () => {
exitBtn.active = false;
});
})
.start();
});
cc.find('middleLayer/BtnRight').on('click', ()=>{
this.goNextPage();
});
cc.find('middleLayer/BtnLeft').on('click', ()=>{
this.goPrePage();
});
const BtnStartLocal = cc.find('middleLayer/ui/BtnStartLocal');
BtnStartLocal.on('click', () => {
const addressText = cc.find('middleLayer/ui/address');
......@@ -143,6 +131,17 @@ cc.Class({
exitBtn.active = true;
});
const BtnStartCourseWare = cc.find('middleLayer/ui/BtnStartCourseWare');
BtnStartCourseWare.on('click', () => {
this.showWaitingLetters();
this.hideUI();
const courseIdNode = cc.find('middleLayer/ui/courseId');
const courseId = courseIdNode.getComponent(cc.EditBox).string;
cc.sys.localStorage.setItem('courseId', courseId);
this.loadOnlineCourseWare(courseId);
exitBtn.active = true;
});
const btnClose = cc.find('middleLayer/ConsoleNode/BtnClose');
const btnOpen = cc.find('middleLayer/ConsoleNode/BtnOpen');
const consoleNode = cc.find('middleLayer/ConsoleNode/Console');
......@@ -162,6 +161,30 @@ cc.Class({
});
},
goPrePage() {
this.goTarIndexPage(this.courseIndex - 1);
},
goNextPage() {
this.goTarIndexPage(this.courseIndex + 1);
},
goTarIndexPage(index) {
if(!this.courses || index == this.courseIndex || index < 0 || index > this.courses.length-1){
return;
}
this.courseIndex = index;
this.courseItem = this.courses[this.courseIndex];
if(this.courseIndex==0){
cc.find('middleLayer/BtnLeft').active = false;
}else{
cc.find('middleLayer/BtnLeft').active = true;
}
if(this.courseIndex==this.courses.length-1){
cc.find('middleLayer/BtnRight').active = false;
}else{
cc.find('middleLayer/BtnRight').active = true;
}
this.loadPageBundle();
},
log(str) {
const logStr = `${new Date().toLocaleString()}: ${str}`;
console.log(logStr);
......@@ -173,33 +196,84 @@ cc.Class({
consoleContent.addChild(content);
consoleContent.getComponent(cc.Layout).updateLayout();
},
hideUI() {
cc.find('middleLayer/ui').active = false;
},
loadOnlineBundle(bundleName) {
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/template/v1/${bundleName}`, {}, (datastr) => {
const data = JSON.parse(datastr);
const configData = data.data.conf.android;
let configData = null;
if(cc.sys.os == cc.sys.OS_IOS){
configData = data.data.conf.ios;
} else if (cc.sys.os == cc.sys.OS_ANDROID){
configData = data.data.conf.android;
} else {
configData = data.data.conf.web_desktop;
}
const sceneName = configData.sceneName;
const version = configData.version;
const bondleUrl = configData.bondleUrl;
this.loadBundle(sceneName, version, bondleUrl);
});
},
courses: null,
courseIndex: 0,
courseItem: null,
loadOnlineCourseWare(courseId) {
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/courseware/v1/${courseId}/list`, {}, (datastr) => {
const data = JSON.parse(datastr);
if(data.rows&&data.rows.length>0){
this.courses = data.rows;
this.courseIndex = 0;
this.courseItem = data.rows[0];
}
if(this.courses && this.courses.length>1){
cc.find('middleLayer/BtnRight').active = true;
}
this.reWriteAir();
this.loadPageBundle();
});
},
loadLocalBundle(address, port) {
this.callNetworkApiGet(`http://${address}:${port}`, '/dist/config.json', {}, (datastr) => {
const data = JSON.parse(datastr);
console.log(JSON.stringify(data));
const sceneName = data.android.sceneName;
const version = data.android.version;
const bondleUrl = `http://${address}:${port}/dist/android/${sceneName}/`;
let sceneName = '';
let version = '';
let bondleUrl = '';
if(cc.sys.os == cc.sys.OS_IOS){
sceneName = data.ios.sceneName;
version = data.ios.version;
bondleUrl = `http://${address}:${port}/dist/ios/${sceneName}/`;
} else if (cc.sys.os == cc.sys.OS_ANDROID){
sceneName = data.android.sceneName;
version = data.android.version;
bondleUrl = `http://${address}:${port}/dist/android/${sceneName}/`;
} else {
sceneName = data.android.sceneName;
version = "";
bondleUrl = `http://${address}:${port}/dist/web_desktop/`;
}
this.loadBundle(sceneName, version, bondleUrl);
});
},
loadPageBundle() {
let sceneName, version, bondleUrl = "";
if(cc.sys.os == cc.sys.OS_IOS){
sceneName = this.courseItem.conf.ios.sceneName;
version = this.courseItem.conf.ios.version;
bondleUrl = this.courseItem.conf.ios.bondleUrl;
} else if (cc.sys.os == cc.sys.OS_ANDROID){
sceneName = this.courseItem.conf.android.sceneName;
version = this.courseItem.conf.android.version;
bondleUrl = this.courseItem.conf.android.bondleUrl;
} else {
sceneName = this.courseItem.conf.web_desktop.sceneName;
version = this.courseItem.conf.web_desktop.version;
bondleUrl = this.courseItem.conf.web_desktop.bondleUrl;
}
this.loadBundle(sceneName, version, bondleUrl);
},
loadBundle(sceneName, version, bondleUrl) {
cc.assetManager.loadBundle(bondleUrl, { version: version }, async (err, bundle) => {
if (err) {
......@@ -215,6 +289,22 @@ cc.Class({
});
},
reWriteAir() {
window.courseware.getData = (callback) => {
let data = null;
if(this.courseItem.data){
data = JSON.parse(this.courseItem.data);
}
callback && callback(data);
}
window.courseware.nextPage = () => {
this.goNextPage();
}
window.courseware.beforePage = () => {
this.goPrePage();
}
},
callNativeFunction(param) {
const paramStr = JSON.stringify(param);
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
......
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