Commit 40495102 authored by liujiangnan's avatar liujiangnan
parents e8b463de b1602877
import {initAir} from './air';
import { initAir } from './air';
cc.Class({
extends: cc.Component,
properties: {
......@@ -88,14 +88,14 @@ cc.Class({
preloadBundle() {
let platform = "web_desktop";
if(cc.sys.os == cc.sys.OS_IOS){
if (cc.sys.os == cc.sys.OS_IOS) {
platform = "ios";
} else if (cc.sys.os == cc.sys.OS_ANDROID){
} else if (cc.sys.os == cc.sys.OS_ANDROID) {
platform = "android";
}
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/syllabus/v1/allbundles`, {orgid: 507, platform}, (datastr) => {
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/syllabus/v1/allbundles`, { orgid: 507, platform }, (datastr) => {
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.batchPreloadScene(data.rows);
}
......@@ -104,27 +104,27 @@ cc.Class({
batchPreloadScene(scenes) {
const _this = this;
let i = 0;
const load = function(){
const load = function () {
const scene = scenes[i];
if(["OP11", "op_09_plus", "OP10_online", "OP12", "OPW25", "OP_03_2"].includes(scene.sceneName)){
_this.loadedCount ++;
if (["OP11", "op_09_plus", "OP10_online", "OP12", "OPW25", "OP_03_2"].includes(scene.sceneName)) {
_this.loadedCount++;
_this.updateProcessBar();
i++;
if(i<scenes.length){
if (i < scenes.length) {
setTimeout(() => {
load();
}, 1);
}
return;
}
cc.assetManager.loadBundle(scene.bondleUrl, {version: scene.version}, (err, bundle) => {
cc.assetManager.loadBundle(scene.bondleUrl, { version: scene.version }, (err, bundle) => {
console.log(`${scene.bondleUrl}---场景开始loadBundle----`);
bundle.preloadScene(scene.sceneName, ()=>{}, ()=>{
bundle.preloadScene(scene.sceneName, () => { }, () => {
console.log(`${scene.sceneName}场景预加载结束`);
_this.loadedCount ++;
_this.loadedCount++;
_this.updateProcessBar();
i++;
if(i<scenes.length){
if (i < scenes.length) {
setTimeout(() => {
load();
}, 1);
......@@ -132,29 +132,29 @@ cc.Class({
});
});
}
if(scenes && scenes.length>0){
load();
if (scenes && scenes.length > 0) {
load();
}
},
preloadSource() {
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/syllabus/v1/allresources`, {orgid: 507}, (datastr) => {
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/syllabus/v1/allresources`, { orgid: 507 }, (datastr) => {
const data = JSON.parse(datastr);
const rows = data.rows;
if(rows&&rows.length>0){
if (rows && rows.length > 0) {
this.preloadCount += rows.length;
const batchLoad = () => {
let tempArr = rows.splice(0, 10);
let len = tempArr.length;
for (let i = 0; i < tempArr.length; i++) {
cc.assetManager.loadRemote(tempArr[i], (err, texture) => {
if(err){
if (err) {
console.log(err)
}
this.loadedCount ++;
this.loadedCount++;
this.updateProcessBar();
if (i === len-1) {
if (i === len - 1) {
batchLoad();
}
});
......@@ -168,7 +168,7 @@ cc.Class({
updateProcessBar() {
const label = cc.find("middleLayer/ui/ProgressLabel").getComponent(cc.Label);
label.string = `正在加载:${this.loadedCount} / ${this.preloadCount}`;
if(this.loadedCount > this.preloadCount * 0.99){
if (this.loadedCount > this.preloadCount * 0.99) {
cc.find("middleLayer/ui/ProgressLabel").active = false;
}
},
......@@ -201,19 +201,19 @@ cc.Class({
.start();
});
cc.find('middleLayer/BtnRight').on('click', ()=>{
cc.find('middleLayer/BtnRight').on('click', () => {
this.goNextPage();
});
cc.find('middleLayer/BtnLeft').on('click', ()=>{
cc.find('middleLayer/BtnLeft').on('click', () => {
this.goPrePage();
});
cc.find('middleLayer/ui/BtnOpenOsmo').on('click', ()=>{
cc.find('middleLayer/ui/BtnOpenOsmo').on('click', () => {
window.courseware.openOsmo();
});
cc.find('middleLayer/ui/BtnCloseOsmo').on('click', ()=>{
cc.find('middleLayer/ui/BtnCloseOsmo').on('click', () => {
window.courseware.closeOsmo();
});
......@@ -279,19 +279,19 @@ cc.Class({
this.goTarIndexPage(this.courseIndex + 1);
},
goTarIndexPage(index) {
if(!this.courses || index == this.courseIndex || index < 0 || index > this.courses.length-1){
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){
if (this.courseIndex == 0) {
cc.find('middleLayer/BtnLeft').active = false;
}else{
} else {
cc.find('middleLayer/BtnLeft').active = true;
}
if(this.courseIndex==this.courses.length-1){
if (this.courseIndex == this.courses.length - 1) {
cc.find('middleLayer/BtnRight').active = false;
}else{
} else {
cc.find('middleLayer/BtnRight').active = true;
}
this.loadPageBundle();
......@@ -314,9 +314,9 @@ cc.Class({
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/template/v1/${bundleName}`, {}, (datastr) => {
const data = JSON.parse(datastr);
let configData = null;
if(cc.sys.os == cc.sys.OS_IOS){
if (cc.sys.os == cc.sys.OS_IOS) {
configData = data.data.conf.ios;
} else if (cc.sys.os == cc.sys.OS_ANDROID){
} else if (cc.sys.os == cc.sys.OS_ANDROID) {
configData = data.data.conf.android;
} else {
configData = data.data.conf.web_desktop;
......@@ -332,20 +332,20 @@ cc.Class({
courseItem: null,
loadOnlineCourseWare(courseId, linkFlag) {
let api = `/api/courseware/v1/${courseId}/list`;
if(linkFlag === true) {
if (linkFlag === true) {
api = `/api/courseware/v1/${courseId}/eq/level/list`;
}
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, api, {}, (datastr) => {
const data = JSON.parse(datastr);
if(data.rows&&data.rows.length>0){
if (data.rows && data.rows.length > 0) {
this.courses = data.rows;
this.courseIndex = data.index || 0;
this.courseItem = data.rows[this.courseIndex];
}
if(this.courses && this.courses.length>1 && this.courseIndex <= this.courses.length-1){
if (this.courses && this.courses.length > 1 && this.courseIndex <= this.courses.length - 1) {
cc.find('middleLayer/BtnRight').active = true;
}
if(this.courseIndex > 0){
if (this.courseIndex > 0) {
cc.find('middleLayer/BtnLeft').active = true;
}
this.reWriteAir();
......@@ -358,11 +358,11 @@ cc.Class({
let sceneName = '';
let version = '';
let bondleUrl = '';
if(cc.sys.os == cc.sys.OS_IOS){
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){
} else if (cc.sys.os == cc.sys.OS_ANDROID) {
sceneName = data.android.sceneName;
version = data.android.version;
bondleUrl = `http://${address}:${port}/dist/android/${sceneName}/`;
......@@ -376,11 +376,11 @@ cc.Class({
},
loadPageBundle() {
let sceneName, version, bondleUrl = "";
if(cc.sys.os == cc.sys.OS_IOS){
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){
} 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;
......@@ -389,7 +389,7 @@ cc.Class({
version = this.courseItem.conf.web_desktop.version;
bondleUrl = this.courseItem.conf.web_desktop.bondleUrl;
}
this.loadBundle(sceneName, version, bondleUrl);
},
loadBundle(sceneName, version, bondleUrl) {
......@@ -412,7 +412,7 @@ cc.Class({
reWriteAir() {
window.courseware.getData = (callback) => {
let data = null;
if(this.courseItem.data){
if (this.courseItem.data) {
data = JSON.parse(this.courseItem.data);
}
callback && callback(data);
......
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