Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
middleLayer_for_kyxq
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
middleLayer_for_kyxq
Commits
918f99ca
Commit
918f99ca
authored
Nov 10, 2023
by
李维
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加页面生命周期,优化页面加载性能
beforeMounted,mounted
parent
e609166a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
73 deletions
+46
-73
middleLayer_for_kyxq.fire
assets/middleLayer_for_kyxq/scene/middleLayer_for_kyxq.fire
+4
-4
HomePage.ts
assets/middleLayer_for_kyxq/script/HomePage.ts
+0
-1
MissionPage.ts
assets/middleLayer_for_kyxq/script/MissionPage.ts
+4
-2
PageViewer.ts
assets/middleLayer_for_kyxq/script/PageViewer.ts
+26
-65
UnitPage.ts
assets/middleLayer_for_kyxq/script/UnitPage.ts
+12
-1
No files found.
assets/middleLayer_for_kyxq/scene/middleLayer_for_kyxq.fire
View file @
918f99ca
...
@@ -13731,7 +13731,7 @@
...
@@ -13731,7 +13731,7 @@
"node": {
"node": {
"__id__": 298
"__id__": 298
},
},
"_enabled":
fals
e,
"_enabled":
tru
e,
"alignMode": 1,
"alignMode": 1,
"_target": {
"_target": {
"__id__": 296
"__id__": 296
...
@@ -13857,7 +13857,7 @@
...
@@ -13857,7 +13857,7 @@
"node": {
"node": {
"__id__": 301
"__id__": 301
},
},
"_enabled":
fals
e,
"_enabled":
tru
e,
"alignMode": 1,
"alignMode": 1,
"_target": {
"_target": {
"__id__": 296
"__id__": 296
...
@@ -18416,7 +18416,7 @@
...
@@ -18416,7 +18416,7 @@
"node": {
"node": {
"__id__": 403
"__id__": 403
},
},
"_enabled":
fals
e,
"_enabled":
tru
e,
"alignMode": 1,
"alignMode": 1,
"_target": {
"_target": {
"__id__": 401
"__id__": 401
...
@@ -18542,7 +18542,7 @@
...
@@ -18542,7 +18542,7 @@
"node": {
"node": {
"__id__": 406
"__id__": 406
},
},
"_enabled":
fals
e,
"_enabled":
tru
e,
"alignMode": 1,
"alignMode": 1,
"_target": {
"_target": {
"__id__": 401
"__id__": 401
...
...
assets/middleLayer_for_kyxq/script/HomePage.ts
View file @
918f99ca
...
@@ -187,7 +187,6 @@ export default class NewClass extends cc.Component {
...
@@ -187,7 +187,6 @@ export default class NewClass extends cc.Component {
userInfo
;
userInfo
;
async
getUserInfo
()
{
async
getUserInfo
()
{
const
userInfo
=
await
this
.
Viewer
.
getComponent
(
"
PageViewer
"
).
getUserInfo
();
const
userInfo
=
await
this
.
Viewer
.
getComponent
(
"
PageViewer
"
).
getUserInfo
();
console
.
log
(
userInfo
)
this
.
userInfo
=
userInfo
.
detail
;
this
.
userInfo
=
userInfo
.
detail
;
// 如果是匿名登录 隐藏右上角头像按钮
// 如果是匿名登录 隐藏右上角头像按钮
cc
.
find
(
"
/UserInfo
"
,
this
.
node
).
active
=
this
.
userInfo
.
isAnonymous
?
true
:
false
;
cc
.
find
(
"
/UserInfo
"
,
this
.
node
).
active
=
this
.
userInfo
.
isAnonymous
?
true
:
false
;
...
...
assets/middleLayer_for_kyxq/script/MissionPage.ts
View file @
918f99ca
...
@@ -58,9 +58,11 @@ export default class NewClass extends cc.Component {
...
@@ -58,9 +58,11 @@ export default class NewClass extends cc.Component {
async
start
()
{
async
start
()
{
this
.
initBg
()
this
.
initBg
()
this
.
userInfo
=
await
this
.
Viewer
.
getComponent
(
"
PageViewer
"
).
getUserInfo
();
this
.
userInfo
=
await
this
.
Viewer
.
getComponent
(
"
PageViewer
"
).
getUserInfo
();
// 注册PageViwer发来的mounted事件[页面已经切换完毕]
this
.
node
.
on
(
"
mounted
"
,
this
.
mounted
.
bind
(
this
))
}
}
async
onEnable
()
{
async
mounted
()
{
this
.
loading
.
active
=
true
;
this
.
loading
.
active
=
true
;
this
.
scrollView
.
opacity
=
0
;
this
.
scrollView
.
opacity
=
0
;
...
...
assets/middleLayer_for_kyxq/script/PageViewer.ts
View file @
918f99ca
...
@@ -6,6 +6,17 @@
...
@@ -6,6 +6,17 @@
// - 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
{
asyncCallNetworkApiGet
}
from
"
./util
"
;
import
{
asyncCallNetworkApiGet
}
from
"
./util
"
;
const
PageMap
=
{
LoginPage
:
"
loginPage
"
,
HomePage
:
"
homePage
"
,
LibraryPage
:
"
libraryPage
"
,
LibraryReadPage
:
"
libraryReadPage
"
,
LibraryAudioPage
:
"
libraryAudioPage
"
,
LibraryVideoPage
:
"
libraryVideoPage
"
,
LibraryReadDetailPage
:
"
libraryReadDetailPage
"
,
UnitPage
:
"
unitPage
"
,
MissionPage
:
"
missionPage
"
,
}
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
...
@@ -114,24 +125,8 @@ export default class NewClass extends cc.Component {
...
@@ -114,24 +125,8 @@ export default class NewClass extends cc.Component {
async
start
()
{
async
start
()
{
const
userInfo
=
await
this
.
getUserInfo
();
const
userInfo
=
await
this
.
getUserInfo
();
if
(
!
userInfo
.
phone
)
{
// 初始化页面
this
.
_currentViewNode
=
this
.
loginPage
;
!
userInfo
.
phone
?
this
.
toView
(
"
LoginPage
"
)
:
this
.
toView
(
"
HomePage
"
)
this
.
_currentViewName
=
"
LoginPage
"
}
else
{
this
.
_currentViewNode
=
this
.
homePage
;
this
.
_currentViewName
=
"
HomePage
"
;
}
// this._currentViewNode = this.missionPage;
// this._currentViewName = "MissionPage"
this
.
_currentViewNode
.
active
=
true
;
if
(
userInfo
.
phone
){
this
.
justShowView
(
"
homePage
"
)
}
else
{
this
.
justShowView
(
"
LoginPage
"
)
}
}
}
_currentViewName
=
""
_currentViewName
=
""
...
@@ -141,54 +136,20 @@ export default class NewClass extends cc.Component {
...
@@ -141,54 +136,20 @@ export default class NewClass extends cc.Component {
cc
.
log
(
`重复跳转页面:
${
this
.
_currentViewName
}
`
);
cc
.
log
(
`重复跳转页面:
${
this
.
_currentViewName
}
`
);
return
return
}
}
switch
(
viewName
)
{
case
'
LoginPage
'
:
if
(
!
this
[
PageMap
[
viewName
]])
{
await
this
.
switchView
(
this
.
loginPage
,
this
.
_currentViewNode
,
aniType
);
cc
.
log
(
`没有找到viewName:
${
viewName
}
`
)
this
.
_currentViewName
=
'
LoginPage
'
;
return
this
.
_currentViewNode
=
this
.
loginPage
;
break
;
case
'
HomePage
'
:
await
this
.
switchView
(
this
.
homePage
,
this
.
_currentViewNode
,
aniType
);
this
.
_currentViewName
=
'
HomePage
'
;
this
.
_currentViewNode
=
this
.
homePage
;
break
;
case
'
LibraryPage
'
:
await
this
.
switchView
(
this
.
libraryPage
,
this
.
_currentViewNode
,
aniType
);
this
.
_currentViewName
=
'
LibraryPage
'
;
this
.
_currentViewNode
=
this
.
libraryPage
;
break
;
case
'
LibraryReadPage
'
:
await
this
.
switchView
(
this
.
libraryReadPage
,
this
.
_currentViewNode
,
aniType
);
this
.
_currentViewName
=
'
LibraryReadPage
'
;
this
.
_currentViewNode
=
this
.
libraryReadPage
;
break
;
case
'
LibraryAudioPage
'
:
await
this
.
switchView
(
this
.
libraryAudioPage
,
this
.
_currentViewNode
,
aniType
);
this
.
_currentViewName
=
'
LibraryAudioPage
'
;
this
.
_currentViewNode
=
this
.
libraryAudioPage
;
break
;
case
'
LibraryVideoPage
'
:
await
this
.
switchView
(
this
.
libraryVideoPage
,
this
.
_currentViewNode
,
aniType
);
this
.
_currentViewName
=
'
LibraryVideoPage
'
;
this
.
_currentViewNode
=
this
.
libraryVideoPage
;
break
;
case
'
LibraryReadDetailPage
'
:
await
this
.
switchView
(
this
.
libraryReadDetailPage
,
this
.
_currentViewNode
,
aniType
);
this
.
_currentViewName
=
'
LibraryReadDetailPage
'
;
this
.
_currentViewNode
=
this
.
libraryReadDetailPage
;
break
;
case
'
UnitPage
'
:
await
this
.
switchView
(
this
.
unitPage
,
this
.
_currentViewNode
,
aniType
);
this
.
_currentViewName
=
'
UnitPage
'
;
this
.
_currentViewNode
=
this
.
unitPage
;
break
;
case
'
MissionPage
'
:
await
this
.
switchView
(
this
.
missionPage
,
this
.
_currentViewNode
,
aniType
);
this
.
_currentViewName
=
'
MissionPage
'
;
this
.
_currentViewNode
=
this
.
missionPage
;
break
;
}
}
// 触发页面beforeMounted生命周期
this
[
PageMap
[
viewName
]].
emit
(
"
beforeMounted
"
);
// 切换页面
await
this
.
switchView
(
this
[
PageMap
[
viewName
]],
this
.
_currentViewNode
,
aniType
);
this
.
_currentViewName
=
viewName
;
this
.
_currentViewName
=
viewName
;
this
.
_currentViewNode
=
this
[
PageMap
[
viewName
]];
// mounted
this
.
_currentViewNode
.
emit
(
"
mounted
"
)
}
}
switchView
(
inPage
,
outPage
,
aniType
)
{
switchView
(
inPage
,
outPage
,
aniType
)
{
...
@@ -259,7 +220,7 @@ export default class NewClass extends cc.Component {
...
@@ -259,7 +220,7 @@ export default class NewClass extends cc.Component {
}
}
justShowView
(
viewName
)
{
justShowView
(
viewName
)
{
this
.
loginPage
.
active
=
viewName
==
"
L
oginPage
"
this
.
loginPage
.
active
=
viewName
==
"
l
oginPage
"
this
.
homePage
.
active
=
viewName
==
"
homePage
"
this
.
homePage
.
active
=
viewName
==
"
homePage
"
this
.
libraryPage
.
active
=
viewName
==
"
libraryPage
"
this
.
libraryPage
.
active
=
viewName
==
"
libraryPage
"
this
.
libraryReadPage
.
active
=
viewName
==
"
libraryReadPage
"
this
.
libraryReadPage
.
active
=
viewName
==
"
libraryReadPage
"
...
...
assets/middleLayer_for_kyxq/script/UnitPage.ts
View file @
918f99ca
...
@@ -42,9 +42,20 @@ export default class NewClass extends cc.Component {
...
@@ -42,9 +42,20 @@ export default class NewClass extends cc.Component {
async
start
()
{
async
start
()
{
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发来的mounted事件[页面已经切换完毕]
this
.
node
.
on
(
"
mounted
"
,
this
.
mounted
.
bind
(
this
))
}
}
async
onEnable
()
{
async
beforeMounted
()
{
const
svNode
=
this
.
unitScrollView
;
const
sv
=
svNode
.
getComponent
(
cc
.
ScrollView
);
const
content
=
sv
.
content
;
content
.
removeAllChildren
();
}
// 监听页面挂载时间
async
mounted
()
{
await
this
.
initView
();
await
this
.
initView
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment