Commit ef721862 authored by 李维's avatar 李维

修复一些可能导致爆闪的问题

parent fb969153
......@@ -240,13 +240,19 @@ export default class HomePageClass extends PageComponentBaseClass {
}
async mounted() {
if(this.isDestroy) {
return
}
await this.getUserInfo();
await this.getCourseList();
this.initTopUserPanel();
}
isDestroy = false;
async beforeDestroy() {
this.isDestroy = true;
this.SvContent.removeAllChildren();
}
// update (dt) {}
}
......@@ -37,6 +37,9 @@ export default class LibraryAudioPageClass extends PageComponentBaseClass {
}
async mounted(data: any) {
if(this.isDestroy) {
return;
}
this.syllabus_pid = this.setPageRouterData(this.syllabus_pid, data.syllabus_pid);
this.initUI()
this.loading.active = true;
......@@ -45,6 +48,11 @@ export default class LibraryAudioPageClass extends PageComponentBaseClass {
this.loading.active = false;
}
isDestroy = false;
async beforeDestroy() {
this.isDestroy = true;
}
initUI(){
this.svItem.active=false
}
......
......@@ -34,6 +34,9 @@ export default class LibraryReadPageClass extends PageComponentBaseClass {
}
async mounted(data: any) {
if(this.isDestroy) {
return;
}
this.syllabus_pid = this.setPageRouterData(this.syllabus_pid, data.syllabus_pid)
this.pData = this.setPageRouterData(this.pData, data.pData);
......@@ -47,6 +50,11 @@ export default class LibraryReadPageClass extends PageComponentBaseClass {
this.loading.active = false;
}
isDestroy = false;
async beforeDestroy() {
this.isDestroy = true;
}
async initData() {
const { rows } = await asyncCallNetworkApiGet(`/api/syllabus/v1/list`, { pid: this.syllabus_pid });
this.data = rows;
......
......@@ -58,18 +58,26 @@ export default class LibraryReadDetailPageClass extends PageComponentBaseClass {
}
async mounted(data) {
this.syllabus_pid = this.setPageRouterData(this.syllabus_pid, data.syllabus_pid);
this.pData = this.setPageRouterData(this.pData, data.pData)
this.loading.active = true;
this.scrollView.opacity = 0;
if(this.isDestroy) {
return;
}
this.syllabus_pid = this.setPageRouterData(this.syllabus_pid, data.syllabus_pid);
this.pData = this.setPageRouterData(this.pData, data.pData)
this.loading.active = true;
this.scrollView.opacity = 0;
await this.initData();
this.initView();
await this.initData();
this.initView();
this.scrollView.opacity = 255;
this.scrollView.opacity = 255;
}
isDestroy = false;
async beforeDestroy() {
this.isDestroy = true;
}
async initData() {
const {rows} = await asyncCallNetworkApiGet(`/api/syllabus/v1/list`, {pid: this.syllabus_pid});
this.levelData = rows;
......
......@@ -40,6 +40,9 @@ export default class LibraryVideoPageClass extends PageComponentBaseClass {
syllabus_pid = ""
showMyWork = null;
async mounted(data) {
if(this.isDestroy) {
return;
}
this.pageTitle = this.setPageRouterData(this.pageTitle, data.pageTitle);
this.fromPage = this.setPageRouterData(this.fromPage, data.fromPage);
this.syllabus_pid = this.setPageRouterData(this.syllabus_pid, data.syllabus_pid);
......@@ -59,6 +62,11 @@ export default class LibraryVideoPageClass extends PageComponentBaseClass {
sv.content.removeAllChildren();
}
isDestroy = false;
async beforeDestroy() {
this.isDestroy = true;
}
initUI() {
this.svItem.active = false
}
......
......@@ -79,6 +79,9 @@ export default class MissionPageClass extends PageComponentBaseClass {
syllabus_pid = ""
pData = null;
async mounted(data) {
if(this.isDestroy) {
return;
}
const unitConfigData = data.configData;
this.syllabus_pid = this.setPageRouterData(this.syllabus_pid, data.syllabus_pid);
this.pData = this.setPageRouterData(this.pData, data.pData);
......@@ -99,6 +102,11 @@ export default class MissionPageClass extends PageComponentBaseClass {
this.updatePageData();
}
isDestroy = false;
async beforeDestroy() {
this.isDestroy = true;
}
initBg() {
const canvas = cc.find("Canvas");
const bg = cc.find("bg/bg_default", this.node);
......@@ -287,6 +295,10 @@ export default class MissionPageClass extends PageComponentBaseClass {
const coverNode = cc.find("pic_layer", itemNode);
getSprNodeByUrl(data.cover, (spr) => {
if(!coverNode.isValid){
console.log(`节点销毁了`)
}
coverNode.addChild(spr.node);
spr.srcBlendFactor = cc.macro.BlendFactor.ONE
setSprNodeMaxLen(spr.node, coverNode.width, coverNode.height);
......
......@@ -54,6 +54,9 @@ export default class UnitPageClass extends PageComponentBaseClass {
// 页面显示
async mounted(data) {
if(this.isDestroy) {
return
}
this.syllabus_pid = data.syllabus_pid;
this.pData = data.pData;
console.log(this.syllabus_pid, this.pData)
......
......@@ -49,9 +49,16 @@ export default class LoginPageClass extends PageComponentBaseClass {
}
mounted(data: any): void {
if(this.isDestroy) {
return;
}
this.initEnteredPhone();
}
async beforeDestroy() {
this.isDestroy = true;
}
initEnteredPhone() {
const enteredPhone = cc.sys.localStorage.getItem('_entered_phone');
if(this.checkPhone(enteredPhone)) {
......@@ -280,9 +287,5 @@ export default class LoginPageClass extends PageComponentBaseClass {
this.showPanel();
}
onDestroy() {
this.isDestroy = true;
}
// update (dt) {}
}
......@@ -25,11 +25,20 @@ export default class PageComponentBaseClass extends cc.Component {
node.on("mounted", (data)=>this.mounted(data));
}
// 页面即将被显示
/**
* 页面即将被显示前调用 【异步调用】
*/
beforeMount(data) {}
/**
* 页面显示后调用 【异步调用】
*/
mounted(data) {}
// 页面即将被销毁
/**
* 页面即将被销毁前调用 【实时调用】
* 可以操作节点,执行一些节点销毁处理
*/
beforeDestroy() {}
// 设置页面数据
......
......@@ -303,11 +303,7 @@ export default class PageViewerClass extends cc.Component {
// 执行垃圾回收
runGC() {
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS || cc.sys.os == cc.sys.OS_ANDROID) {
setTimeout(() => {
cc.sys.garbageCollect()
}, 5000)
}
global.middleLayer.runGC()
}
courseBackViewName = "";
......@@ -318,7 +314,16 @@ export default class PageViewerClass extends cc.Component {
// 执行垃圾回收
this.runGC();
this.courseBackViewName = viewName;
this[PageMap[viewName]].active = false;
// 未传移除页面 则全部移除
this.node.children.forEach(child => {
child.removeFromParent();
child.destroy();
})
// 清空当前页面名字
this._currentViewName = ""
// 清空当前页面节点
this._currentViewNode = null
}
courseClose() {
......@@ -328,15 +333,8 @@ export default class PageViewerClass extends cc.Component {
}
// 执行垃圾回收
this.runGC();
// 触发页面beforeMount生命周期
this[PageMap[this.courseBackViewName]].emit("beforeMount");
this[PageMap[this.courseBackViewName]].active = true;
this._currentViewName = this.courseBackViewName;
this._currentViewNode = this[PageMap[this.courseBackViewName]];
// mounted
this._currentViewNode.emit("mounted", {})
this.toView(this.courseBackViewName);
}
// update (dt) {}
}
......@@ -262,10 +262,8 @@ export abstract class middleLayerBase extends cc.Component {
const destroyer = cc.instantiate(cc.find('middleLayer/Destroyer'));
destroyer.parent = cc.find('Canvas');
destroyer.active = true;
// 手机端强制垃圾回收
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS || cc.sys.os == cc.sys.OS_ANDROID) {
cc.sys.garbageCollect();
}
// 垃圾回收
this.runGC();
//显示退出按钮
this.showExitBtn(sceneName);
callback && callback();
......@@ -276,6 +274,29 @@ export abstract class middleLayerBase extends cc.Component {
});
}
/**
* 主动调用垃圾回收方法
* 防止用户多次主动调用造成的卡顿,延时执行
*/
gcTimeoutId = null;
runGC() {
if(this.gcTimeoutId) {
this.log(`上次垃圾回收还未执行,重置回收计划时间`)
clearTimeout(this.gcTimeoutId);
this.gcTimeoutId = null;
}
this.gcTimeoutId = setTimeout(() => {
this.gcTimeoutId = null;
// 手机端强制垃圾回收
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS || cc.sys.os == cc.sys.OS_ANDROID) {
cc.sys.garbageCollect();
this.log(`垃圾回收完毕!`)
} else {
this.log(`非移动端,未执行垃圾回收`)
}
}, 2000);
}
progressTextCom = null;
progressBarScript = null;
setLoadingProgressBar(pInt) {
......
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