Commit 07ceaf58 authored by liujiangnan's avatar liujiangnan

feat: 防止重复加载模板

parent 71739925
......@@ -398,6 +398,7 @@ export default class NewClass extends middleLayerBase {
});
} else {
this.showTips("用户信息过期,请重新登录!");
this.IS_BUNDLE_LOADING = false;
this.loadOnlineBundle('NJ_login');
callback && callback(false);
}
......@@ -406,6 +407,10 @@ export default class NewClass extends middleLayerBase {
// 重写loadOnlineBundle方法;主要是对一些必要的页面跳转做一些拦截处理
loadOnlineBundle(bundleName, callback = null) {
if (this.IS_BUNDLE_LOADING) {
return;
}
this.IS_BUNDLE_LOADING = true;
console.log(" in loadOnlineBundle")
cc.find('middleLayer/BtnRight').active = false;
cc.find('middleLayer/BtnLeft').active = false;
......
......@@ -8,6 +8,8 @@ export abstract class middleLayerBase extends cc.Component {
abstract hideWaitingLetters(): void;
abstract showWaitingLetters(): void;
IS_BUNDLE_LOADING = false;
onMiddleLayerLoadingFinish() {
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
jsb.reflection.callStaticMethod(
......@@ -123,6 +125,10 @@ export abstract class middleLayerBase extends cc.Component {
}
loadOnlineBundle(bundleName, callback = null) {
if (this.IS_BUNDLE_LOADING) {
return;
}
this.IS_BUNDLE_LOADING = true;
console.log(' in loadOnlineBundle')
cc.find('middleLayer/BtnRight').active = false;
cc.find('middleLayer/BtnLeft').active = false;
......@@ -155,12 +161,10 @@ export abstract class middleLayerBase extends cc.Component {
currentBundleInfo = null;
loadBundleBuffer = {}; // 缓冲load bundle请求 同时多个请求导致异常
loadBundleLock = false; // 未加载完成禁止新的加载
addToLoadBundleBuffer(sceneName, version, bondleUrl, callback) {
console.log("[middleLayer_for_NJ_lite]-[addToLoadBundleBuffer] sceneName=", sceneName)
this.loadBundleBuffer[this.getUUID()] = {sceneName, version, bondleUrl, callback}
}
getLoadBundleFromBuffer() {
let keys = Object.keys(this.loadBundleBuffer)
if(keys.length > 0) {
......@@ -173,14 +177,16 @@ export abstract class middleLayerBase extends cc.Component {
}
reloadBundle() {
if (this.IS_BUNDLE_LOADING) {
return;
}
this.IS_BUNDLE_LOADING = true;
console.log(' in reloadBundle');
const { sceneName, version, bondleUrl } = this.currentBundleInfo;
this.loadBundle(sceneName, version, bondleUrl);
}
async loadBundle(sceneName, version, bondleUrl, callback = null) {
this.assetList = [];
this.textureList = [];
this.assetObj = {};
......@@ -239,6 +245,7 @@ export abstract class middleLayerBase extends cc.Component {
}
callback && callback();
this.IS_BUNDLE_LOADING = false;
});
});
......@@ -306,6 +313,11 @@ export abstract class middleLayerBase extends cc.Component {
courseItem = null;
courseOpenTimeStamp = null;
loadOnlineCourseWare(courseId, linkFlag = false, coursewareId = null) {
if (this.IS_BUNDLE_LOADING) {
return;
}
this.IS_BUNDLE_LOADING = true;
this.showWaitingLetters();
let api = `/api/courseware/v2/${courseId}/list`;
......@@ -326,6 +338,7 @@ export abstract class middleLayerBase extends cc.Component {
} else {
this.hideWaitingLetters();
this.showTips(`内容还未制作`);
this.IS_BUNDLE_LOADING = false;
return;
}
this.loadPageBundle(() => {
......@@ -373,7 +386,12 @@ export abstract class middleLayerBase extends cc.Component {
this.goTarIndexPage(this.courseIndex + 1);
}
goTarIndexPage(index) {
if (this.IS_BUNDLE_LOADING) {
return;
}
this.IS_BUNDLE_LOADING = true;
if (!this.courses || index == this.courseIndex || index < 0 || index > this.courses.length - 1) {
this.IS_BUNDLE_LOADING = false;
return;
}
......@@ -422,27 +440,13 @@ export abstract class middleLayerBase extends cc.Component {
.start();
}
async clearDragonDisplayAssetList() {
console.log('喵喵喵: clearDragonDisplayAssetList');
console.log('喵喵喵: ' + this.nodeList.length);
console.log('喵喵喵: ' + this.atlasList.length);
console.log('喵喵喵: ' + this.assetList.length);
console.log('喵喵喵: ' + this.textureList.length);
if (this.atlasList.length == 0) {
return;
}
this.setNodeListVisible();
console.log("this.atlasList.length: ", this.atlasList.length);
for (let i=0; i<this.atlasList.length; i++) {
const atlas = this.atlasList[i];
const asset = this.assetList[i];
......@@ -464,8 +468,6 @@ export abstract class middleLayerBase extends cc.Component {
texture.decRef();
console.log('aaaaa~');
}
......@@ -474,12 +476,6 @@ export abstract class middleLayerBase extends cc.Component {
// 原始方法
clearDragonDisplayAssetList3() {
console.log('喵喵喵: clearDragonDisplayAssetList');
console.log('喵喵喵: ' + this.nodeList.length);
console.log('喵喵喵: ' + this.atlasList.length);
console.log('喵喵喵: ' + this.assetList.length);
console.log('喵喵喵: ' + this.textureList.length);
[ ...this.atlasList , ...this.assetList].forEach(asset => {
asset.decRef();
cc.assetManager.releaseAsset(asset);
......
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