Commit aa28dc73 authored by liujiangnan's avatar liujiangnan

feat: 预加载

parent 200e919e
......@@ -372,6 +372,61 @@ export default class NewClass extends middleLayerBase {
}
preloadAll(onProgress, onComplete) {
let platform = "web_desktop";
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
platform = "ios";
}
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_ANDROID) {
platform = "android";
}
this.callNetworkApiGet(`/api/syllabus/v1/allbundles`, { orgid: this.ORG_ID, platform }, (datastr) => {
const data = JSON.parse(datastr);
this.callNetworkApiGet(`/api/syllabus/v1/allresources`, { orgid: this.ORG_ID }, (datastr1) => {
const data1 = JSON.parse(datastr1);
this.batchPreloadScene(data.rows);
this.preloadSource(data1.rows, onProgress, onComplete);
});
});
}
batchPreloadScene(scenes = [], expects = []) {
let i = 0;
const load = function () {
const scene = scenes[i];
if (expects.includes(scene.sceneName)) {
i++;
if (i < scenes.length) {
setTimeout(() => {
load();
}, 1);
}
return;
}
cc.assetManager.loadBundle(scene.bondleUrl, { version: scene.version }, (err, bundle) => {
console.log(`${scene.bondleUrl}---场景开始loadBundle----`);
i++;
if (i < scenes.length) {
setTimeout(() => {
load();
}, 1);
}
});
}
if (scenes && scenes.length > 0) {
load();
}
}
preloadSource(array, onProgress, onComplete) {
const rows = array || [];
let tempArr = rows.map(item => {
return {url: item};
});
cc.assetManager.preloadAny(tempArr, null, onProgress, onComplete);
}
saveRecordResult(recordResult) {
if (this.isLogin == false) {
// 游客
......@@ -646,6 +701,7 @@ export default class NewClass extends middleLayerBase {
cc.find('middleLayer/BtnRight').active = false;
cc.find('middleLayer/BtnLeft').active = false;
cc.find('middleLayer/ExitBtn').active = false;
cc.find('middleLayer/ram').active = (bundleName == 'NJ_YouLeChang');
if (bundleName == 'NJ_login') {
// 如果跳到登录页,则清理一些缓存的使用数据
this.data = {};
......@@ -835,6 +891,7 @@ export default class NewClass extends middleLayerBase {
cc.find('middleLayer/BtnRight').active = false;
cc.find('middleLayer/BtnLeft').active = false;
cc.find('middleLayer/ExitBtn').active = false;
cc.find('middleLayer/ram').active = false;
if (this.type == "aixuebao") {
await this.asyncCallNetworkApiGet(`/api/aixuebao/v1/engine/active`, {
......@@ -1221,6 +1278,45 @@ export default class NewClass extends middleLayerBase {
this.goPrePage();
});
buttonOnClick(cc.find('middleLayer/downloadSourceLayer/close'), () => {
cc.find('middleLayer/downloadSourceLayer').active = false;
cc.find('middleLayer/downloadSourceLayer/loading').getComponent(cc.Animation).stop("loading");
cc.find('middleLayer/downloadSourceLayer/progress/desc').getComponent(cc.Label).string = `0 / 0`;
cc.find('middleLayer/downloadSourceLayer/progress/bar').width = 0;
cc.find('middleLayer/downloadSourceLayer/per').getComponent(cc.Label).string = `0%`;
});
buttonOnClick(cc.find('middleLayer/ram'), () => {
this.showConfirm("缓存资源大概需要十分钟左右,网速好缓存时间更短哟~", ()=>{
const laodingLayer = cc.find('middleLayer/downloadSourceLayer');
laodingLayer.active = true;
const loading = cc.find('middleLayer/downloadSourceLayer/loading');
const anim = loading.getComponent(cc.Animation)
anim.play('loading');
cc.find('middleLayer/downloadSourceLayer/progress/bar').width = 0;
this.preloadAll((finished, total) => {
const percent = Math.floor(finished/total*100);
cc.find('middleLayer/downloadSourceLayer/progress/desc').getComponent(cc.Label).string = `${finished} / ${total}`;
cc.find('middleLayer/downloadSourceLayer/progress/bar').width = Math.floor(490 * percent / 100);
cc.find('middleLayer/downloadSourceLayer/per').getComponent(cc.Label).string = `${percent}%`;
if (!laodingLayer.active) {
return false;
throw Error("===取消加载===");
}
}, () => {
laodingLayer.active = false;
anim.stop('loading');
cc.find('middleLayer/downloadSourceLayer/progress/desc').getComponent(cc.Label).string = `0 / 0`;
cc.find('middleLayer/downloadSourceLayer/progress/bar').width = 0;
cc.find('middleLayer/downloadSourceLayer/per').getComponent(cc.Label).string = `0%`;
this.showTips(`资源缓存完成啦,开始去学习吧~~`);
});
}, ()=>{});
});
buttonOnClick(cc.find('middleLayer/activeLayer/close'), () => {
cc.find('middleLayer/activeLayer').active = false;
});
......
......@@ -302,6 +302,8 @@ export abstract class middleLayerBase extends cc.Component {
this.showWaitingLetters();
cc.find('middleLayer/ram').active = false;
let api = `/api/courseware/v2/${courseId}/list`;
if (linkFlag === true) {
api = `/api/courseware/v2/${courseId}/eq/level/list`;
......
......@@ -28,8 +28,8 @@
"rawHeight": 45,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"borderLeft": 11,
"borderRight": 9,
"subMetas": {}
}
}
......
{
"ver": "2.3.5",
"uuid": "1d23ed90-c480-4799-bb29-5492ae7a84f1",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 150,
"height": 150,
"platformSettings": {},
"subMetas": {
"ram": {
"ver": "1.0.4",
"uuid": "2c2bf7a6-d993-434c-a726-9fb943e497e0",
"rawTextureUuid": "1d23ed90-c480-4799-bb29-5492ae7a84f1",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 60,
"height": 60,
"rawWidth": 60,
"rawHeight": 60,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
......@@ -10,7 +10,15 @@
"services": [
{
"service_id": "351",
"enable": true
"enable": false
},
{
"service_id": "305",
"enable": false
},
{
"service_id": "302",
"enable": false
}
]
}
......
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