Commit fb2d8590 authored by 李维's avatar 李维

优化首屏展示

parent 1da8f366
import { asyncCallNetworkApiGet, asyncCallNetworkApiPost, getSpriteFrimeByUrl, playLocalAudio, playAudioByUrl, getSprNodeByUrl, asyncDelay } from "./util"; import { asyncCallNetworkApiGet, asyncCallNetworkApiPost, getSpriteFrimeByUrl, playLocalAudio, playAudioByUrl, getSprNodeByUrl, asyncDelay } from "./util";
const {ccclass, property} = cc._decorator; import PageComponentBaseClass from "./PageComponentBase"
const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class HomePageClass extends cc.Component { export default class HomePageClass extends PageComponentBaseClass {
@property(cc.Node) @property(cc.Node)
Viewer: cc.Node = null; Viewer: cc.Node = null;
...@@ -97,8 +99,8 @@ export default class HomePageClass extends cc.Component { ...@@ -97,8 +99,8 @@ export default class HomePageClass extends cc.Component {
// 点击课程 // 点击课程
handleClickCourseItem(pid, pData) { handleClickCourseItem(pid, pData) {
const vc = this.Viewer.getComponent("PageViewer"); const vc = this.Viewer.getComponent("PageViewer");
vc.unitPage.attr({syllabus_pid: pid}); vc.unitPage.attr({ syllabus_pid: pid });
vc.unitPage.attr({pData: pData}); vc.unitPage.attr({ pData: pData });
vc.toView({ vc.toView({
name: "UnitPage", name: "UnitPage",
animation: "rightIn" animation: "rightIn"
...@@ -110,12 +112,12 @@ export default class HomePageClass extends cc.Component { ...@@ -110,12 +112,12 @@ export default class HomePageClass extends cc.Component {
this.SvContent.removeAllChildren(); this.SvContent.removeAllChildren();
this.loading.active = true; this.loading.active = true;
const userInfo = this.userInfo; const userInfo = this.userInfo;
const {rows} = await asyncCallNetworkApiGet('/api/kyxq/v1/user/jclist', { const { rows } = await asyncCallNetworkApiGet('/api/kyxq/v1/user/jclist', {
jc_arr: userInfo.jc_arr, jc_arr: userInfo.jc_arr,
}); });
// 无数据 // 无数据
if(rows && rows.length == 0) { if (rows && rows.length == 0) {
this.loading.active = false; this.loading.active = false;
return return
} }
...@@ -125,11 +127,11 @@ export default class HomePageClass extends cc.Component { ...@@ -125,11 +127,11 @@ export default class HomePageClass extends cc.Component {
if (!this.SvContent['baseH']) { if (!this.SvContent['baseH']) {
this.SvContent['baseH'] = this.SvContent.height; this.SvContent['baseH'] = this.SvContent.height;
this.SvContent.height *= canvas.height / 1080 * 1.1; this.SvContent.height *= canvas.height / 1080 * 1.1;
this.SvContent.parent.height = this.SvContent.height* 1.2; this.SvContent.parent.height = this.SvContent.height * 1.2;
} }
let loadEndCount = 0; let loadEndCount = 0;
for(let i=0; i<rows.length; i++) { for (let i = 0; i < rows.length; i++) {
const row = rows[i]; const row = rows[i];
const ci = cc.instantiate(this.CourseItem); const ci = cc.instantiate(this.CourseItem);
cc.find(`progressText`, ci).getComponent(cc.Label).string = `学习进度:${row.process}`; cc.find(`progressText`, ci).getComponent(cc.Label).string = `学习进度:${row.process}`;
...@@ -139,10 +141,10 @@ export default class HomePageClass extends cc.Component { ...@@ -139,10 +141,10 @@ export default class HomePageClass extends cc.Component {
if (b == 0) { if (b == 0) {
cc.find(`progress`, ci).getComponent(cc.ProgressBar).progress = 0; cc.find(`progress`, ci).getComponent(cc.ProgressBar).progress = 0;
} else { } else {
cc.find(`progress`, ci).getComponent(cc.ProgressBar).progress = Math.floor(a/b*10)/10; cc.find(`progress`, ci).getComponent(cc.ProgressBar).progress = Math.floor(a / b * 10) / 10;
} }
getSprNodeByUrl(row.cover, async(resSpr) => { getSprNodeByUrl(row.cover, async (resSpr) => {
const coverNode = cc.find(`bg`, ci); const coverNode = cc.find(`bg`, ci);
const spr = coverNode.getComponent(cc.Sprite); const spr = coverNode.getComponent(cc.Sprite);
...@@ -152,19 +154,18 @@ export default class HomePageClass extends cc.Component { ...@@ -152,19 +154,18 @@ export default class HomePageClass extends cc.Component {
spr.spriteFrame = resSpr.spriteFrame; spr.spriteFrame = resSpr.spriteFrame;
ci.active = true; ci.active = true;
ci.attr({syllabus_id: row.id}); ci.attr({ syllabus_id: row.id });
ci.on("click", ()=>{ ci.on("click", () => {
this.handleClickCourseItem(ci[`syllabus_id`], row); this.handleClickCourseItem(ci[`syllabus_id`], row);
}) })
loadEndCount ++; loadEndCount++;
if (loadEndCount == rows.length) { if (loadEndCount == rows.length) {
await asyncDelay(0.01); await asyncDelay(0.01);
this.SvContent.opacity = 255; this.SvContent.opacity = 255;
const contentW = this.SvContent.getContentSize().width; const contentW = this.SvContent.getContentSize().width;
if (contentW < canvas.width) { if (contentW < canvas.width) {
// this.SvContent.x = 0;
this.SvContent.x = -contentW / 2; this.SvContent.x = -contentW / 2;
} else { } else {
this.SvContent.x = -canvas.width / 2; this.SvContent.x = -canvas.width / 2;
...@@ -182,7 +183,6 @@ export default class HomePageClass extends cc.Component { ...@@ -182,7 +183,6 @@ export default class HomePageClass extends cc.Component {
} }
// onLoad () {} // onLoad () {}
userInfo; userInfo;
async getUserInfo() { async getUserInfo() {
this.userInfo = null; this.userInfo = null;
...@@ -232,16 +232,14 @@ export default class HomePageClass extends cc.Component { ...@@ -232,16 +232,14 @@ export default class HomePageClass extends cc.Component {
bg.scale = Math.max(sx, sy); bg.scale = Math.max(sx, sy);
} }
async start () { async start() {
// 调用父类中的初始化页面生命周期钩子方法
super.initPageHook(this.node);
this.initBg(); this.initBg();
// 注册PageViwer发来的beforeMounted事件 [页面即将被显示]
this.node.on("beforeMounted", this.beforeMounted.bind(this));
// 注册PageViwer发来的mounted事件 [页面已经切换完毕]
this.node.on("mounted", this.mounted.bind(this));
} }
async beforeMounted() { async beforeMount() {
this.SvContent.removeAllChildren();
} }
async mounted() { async mounted() {
......
import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet } from "./util"; import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet } from "./util";
import PageComponentBaseClass from "./PageComponentBase"
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class LibraryAudioPageClass extends cc.Component { export default class LibraryAudioPageClass extends PageComponentBaseClass {
@property(cc.Node) @property(cc.Node)
Viewer: cc.Node = null; Viewer: cc.Node = null;
...@@ -30,6 +31,8 @@ export default class LibraryAudioPageClass extends cc.Component { ...@@ -30,6 +31,8 @@ export default class LibraryAudioPageClass extends cc.Component {
// onLoad () {} // onLoad () {}
async start() { async start() {
// 调用父类中的初始化页面生命周期钩子方法
super.initPageHook(this.node);
this.initUI() this.initUI()
this.loading.active = true; this.loading.active = true;
await this.initData(); await this.initData();
......
import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet } from "./util"; import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet } from "./util";
import PageComponentBaseClass from "./PageComponentBase"
const {ccclass, property} = cc._decorator; const {ccclass, property} = cc._decorator;
@ccclass @ccclass
export default class LibraryPageClass extends cc.Component { export default class LibraryPageClass extends PageComponentBaseClass {
@property(cc.Node) @property(cc.Node)
Viewer: cc.Node = null; Viewer: cc.Node = null;
...@@ -49,6 +50,8 @@ export default class LibraryPageClass extends cc.Component { ...@@ -49,6 +50,8 @@ export default class LibraryPageClass extends cc.Component {
// onLoad () {} // onLoad () {}
async start () { async start () {
// 调用父类中的初始化页面生命周期钩子方法
super.initPageHook(this.node);
this.loading.active = true; this.loading.active = true;
await this.initView(); await this.initView();
this.loading.active = false; this.loading.active = false;
......
import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet } from "./util"; import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet } from "./util";
import PageComponentBaseClass from "./PageComponentBase"
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class LibraryReadDetailPageClass extends cc.Component { export default class LibraryReadDetailPageClass extends PageComponentBaseClass {
@property(cc.Node) @property(cc.Node)
Viewer: cc.Node = null; Viewer: cc.Node = null;
...@@ -48,15 +49,12 @@ export default class LibraryReadDetailPageClass extends cc.Component { ...@@ -48,15 +49,12 @@ export default class LibraryReadDetailPageClass extends cc.Component {
// onLoad () {} // onLoad () {}
// async start() { async start() {
// this.loading.active = true; // 调用父类中的初始化页面生命周期钩子方法
// await this.initData(); super.initPageHook(this.node);
// this.initView(); }
// this.loading.active = false;
// }
async onEnable() { async mounted() {
// if (!this.m_isLoadData){
this.loading.active = true; this.loading.active = true;
this.scrollView.opacity = 0; this.scrollView.opacity = 0;
...@@ -64,8 +62,6 @@ export default class LibraryReadDetailPageClass extends cc.Component { ...@@ -64,8 +62,6 @@ export default class LibraryReadDetailPageClass extends cc.Component {
this.initView(); this.initView();
this.scrollView.opacity = 255; this.scrollView.opacity = 255;
this.loading.active = false;
// }
} }
async initData() { async initData() {
......
import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet } from "./util"; import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet } from "./util";
import PageComponentBaseClass from "./PageComponentBase"
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class LibraryReadPageClass extends cc.Component { export default class LibraryReadPageClass extends PageComponentBaseClass {
@property(cc.Node) @property(cc.Node)
Viewer: cc.Node = null; Viewer: cc.Node = null;
...@@ -28,6 +29,7 @@ export default class LibraryReadPageClass extends cc.Component { ...@@ -28,6 +29,7 @@ export default class LibraryReadPageClass extends cc.Component {
// onLoad () {} // onLoad () {}
async start() { async start() {
super.initPageHook(this.node)
this.loading.active = true; this.loading.active = true;
this.scrollView.opacity = 0; this.scrollView.opacity = 0;
......
import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet } from "./util"; import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet } from "./util";
import PageComponentBaseClass from "./PageComponentBase"
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class LibraryVideoPageClass extends cc.Component { export default class LibraryVideoPageClass extends PageComponentBaseClass {
@property(cc.Node) @property(cc.Node)
Viewer: cc.Node = null; Viewer: cc.Node = null;
...@@ -38,6 +39,8 @@ export default class LibraryVideoPageClass extends cc.Component { ...@@ -38,6 +39,8 @@ export default class LibraryVideoPageClass extends cc.Component {
// onLoad () {} // onLoad () {}
async start() { async start() {
// 调用父类中的初始化页面生命周期钩子方法
super.initPageHook(this.node);
this.initUI() this.initUI()
this.loading.active = true; this.loading.active = true;
await this.initData(); await this.initData();
......
...@@ -6,11 +6,12 @@ ...@@ -6,11 +6,12 @@
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { asyncCallNetworkApiPost } from "./util"; import { asyncCallNetworkApiPost } from "./util";
import PageComponentBaseClass from "./PageComponentBase"
const {ccclass, property} = cc._decorator; const {ccclass, property} = cc._decorator;
@ccclass @ccclass
export default class LoginPageClass extends cc.Component { export default class LoginPageClass extends PageComponentBaseClass {
@property(cc.Node) @property(cc.Node)
Viewer: cc.Node = null; Viewer: cc.Node = null;
...@@ -42,7 +43,7 @@ export default class LoginPageClass extends cc.Component { ...@@ -42,7 +43,7 @@ export default class LoginPageClass extends cc.Component {
isAgreement: boolean = false; isAgreement: boolean = false;
start () { start () {
super.initPageHook(this.node)
this.initData(); this.initData();
this.initListener(); this.initListener();
this.initAnonymous(); this.initAnonymous();
......
...@@ -6,11 +6,12 @@ ...@@ -6,11 +6,12 @@
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet, asyncCallNetworkApiPost, getSpriteFrimeByUrl, asyncDelay } from "./util"; import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet, asyncCallNetworkApiPost, getSpriteFrimeByUrl, asyncDelay } from "./util";
import PageComponentBaseClass from "./PageComponentBase"
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class MissionPageClass extends cc.Component { export default class MissionPageClass extends PageComponentBaseClass {
@property(cc.Node) @property(cc.Node)
Viewer: cc.Node = null; Viewer: cc.Node = null;
...@@ -59,15 +60,13 @@ export default class MissionPageClass extends cc.Component { ...@@ -59,15 +60,13 @@ export default class MissionPageClass extends cc.Component {
// onLoad () {} // onLoad () {}
async start() { async start() {
// 调用父类中的初始化页面生命周期钩子方法
super.initPageHook(this.node);
this.initBg() this.initBg()
this.userInfo = await this.Viewer.getComponent("PageViewer").getUserInfo(); this.userInfo = await this.Viewer.getComponent("PageViewer").getUserInfo();
// 注册PageViwer发来的beforeMounted事件[页面即将被显示]
this.node.on("beforeMounted", this.beforeMounted.bind(this));
// 注册PageViwer发来的mounted事件[页面已经切换完毕]
this.node.on("mounted", this.mounted.bind(this));
} }
async beforeMounted() { async beforeMount() {
const sv = this.scrollView.getComponent(cc.ScrollView); const sv = this.scrollView.getComponent(cc.ScrollView);
const content = sv.content; const content = sv.content;
content.removeAllChildren(); content.removeAllChildren();
......
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class PageComponentBaseClass extends cc.Component {
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start () {
}
initPageHook(node: cc.Node) {
// 注册PageViwer发来的beforeMount事件 [页面即将被显示]
node.on("beforeMount", ()=>this.beforeMount());
// 注册PageViwer发来的mounted事件 [页面已经切换完毕]
node.on("mounted", ()=>this.mounted());
// 注册PageViwer发来的unmounted事件 [页面已经切换完毕]
node.on("unmounted", ()=>this.unmounted());
}
// 页面即将被显示
beforeMount() {}
mounted() {}
unmounted() {}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "36d4682e-43c1-43aa-b84a-15435434d62a",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
...@@ -151,8 +151,8 @@ export default class PageViewerClass extends cc.Component { ...@@ -151,8 +151,8 @@ export default class PageViewerClass extends cc.Component {
return return
} }
// 触发页面beforeMounted生命周期 // 触发页面beforeMount生命周期
this[PageMap[viewName]].emit("beforeMounted"); this[PageMap[viewName]].emit("beforeMount");
// 切换页面 // 切换页面
await this.switchView(this[PageMap[viewName]], this._currentViewNode, animation); await this.switchView(this[PageMap[viewName]], this._currentViewNode, animation);
this._currentViewName = viewName; this._currentViewName = viewName;
......
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet, asyncDelay } from "./util"; import { getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet, asyncDelay } from "./util";
import PageComponentBaseClass from "./PageComponentBase"
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class UnitPageClass extends cc.Component { export default class UnitPageClass extends PageComponentBaseClass {
@property(cc.Node) @property(cc.Node)
Viewer: cc.Node = null; Viewer: cc.Node = null;
...@@ -42,19 +43,16 @@ export default class UnitPageClass extends cc.Component { ...@@ -42,19 +43,16 @@ export default class UnitPageClass extends cc.Component {
// onLoad () {} // onLoad () {}
async start() { async start() {
// 调用父类中的初始化页面生命周期钩子方法
super.initPageHook(this.node);
this.initBg(); this.initBg();
this.listItem = cc.find("view/content/item", this.unitScrollView); this.listItem = cc.find("view/content/item", this.unitScrollView);
this.node.on("beforeMounted", this.beforeMounted.bind(this))
// 注册PageViwer发来的beforeMounted事件 [页面即将被显示]
this.node.on("beforeMounted", this.beforeMounted.bind(this));
// 注册PageViwer发来的mounted事件 [页面已经切换完毕]
this.node.on("mounted", this.mounted.bind(this));
// 注册PageViwer发来的unmounted事件 [页面已经切换完毕]
this.node.on("unmounted", this.unmounted.bind(this));
} }
async beforeMounted() { // 页面即将显示
async beforeMount() {
this.isDestory = false; this.isDestory = false;
const svNode = this.unitScrollView; const svNode = this.unitScrollView;
const sv = svNode.getComponent(cc.ScrollView); const sv = svNode.getComponent(cc.ScrollView);
...@@ -62,12 +60,12 @@ export default class UnitPageClass extends cc.Component { ...@@ -62,12 +60,12 @@ export default class UnitPageClass extends cc.Component {
content.removeAllChildren(); content.removeAllChildren();
} }
// 监听页面挂载时间 // 页面显示
async mounted() { async mounted() {
await this.initView(); await this.initView();
} }
// 页面切换走 // 页面隐藏
isDestory = false; isDestory = false;
async unmounted() { async unmounted() {
const sv = cc.find("middleLayer/Views/UnitPage/unit_list_node/scrollView") const sv = cc.find("middleLayer/Views/UnitPage/unit_list_node/scrollView")
......
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