Commit dfbda67a authored by 范雪寒's avatar 范雪寒

style: 格式化

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