Commit 07ceaf58 authored by liujiangnan's avatar liujiangnan

feat: 防止重复加载模板

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