Commit e00cc59e authored by 李维's avatar 李维

添加路由缓存,防止连续跳转导致的页面堆积

parent c0cb1702
...@@ -133,6 +133,8 @@ export default class PageViewerClass extends cc.Component { ...@@ -133,6 +133,8 @@ export default class PageViewerClass extends cc.Component {
_currentViewName = "" _currentViewName = ""
_currentViewNode = null _currentViewNode = null
isLoadingPage = false;
_routerArr = []
async toView(param, data = null) { async toView(param, data = null) {
let viewName = ""; let viewName = "";
let animation = ""; let animation = "";
...@@ -149,6 +151,16 @@ export default class PageViewerClass extends cc.Component { ...@@ -149,6 +151,16 @@ export default class PageViewerClass extends cc.Component {
return return
} }
if(this.isLoadingPage) {
this._routerArr.push({
param,
data
})
cc.log(`页面跳转中,稍后处理: ${viewName}`);
return
}
this.isLoadingPage = true;
// if(!this[PageMap[viewName]]) { // if(!this[PageMap[viewName]]) {
// cc.log(`没有找到viewName: ${viewName}`) // cc.log(`没有找到viewName: ${viewName}`)
// return // return
...@@ -163,6 +175,14 @@ export default class PageViewerClass extends cc.Component { ...@@ -163,6 +175,14 @@ export default class PageViewerClass extends cc.Component {
global.middleLayer.loadPrefabByBundleName("middleLayer_for_kyxq", prefabPath[viewName], async (err, prefab) => { global.middleLayer.loadPrefabByBundleName("middleLayer_for_kyxq", prefabPath[viewName], async (err, prefab) => {
// this[PageMap[viewName]] = cc.instantiate(this[`p_${PageMap[viewName]}`]); // this[PageMap[viewName]] = cc.instantiate(this[`p_${PageMap[viewName]}`]);
this.isLoadingPage = false;
if(this._routerArr.length > 0) {
const lastToView = this._routerArr[this._routerArr.length -1];
console.log(`有路由缓存,跳转到最新页面`)
this._routerArr.length = 0;
this.toView(lastToView.param, lastToView.data);
return;
}
console.log(`创建页面: ${prefab.name}`) console.log(`创建页面: ${prefab.name}`)
this[PageMap[viewName]] = cc.instantiate(prefab); this[PageMap[viewName]] = cc.instantiate(prefab);
this[PageMap[viewName]].attr({ this[PageMap[viewName]].attr({
......
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