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
f457fb4c
Commit
f457fb4c
authored
Nov 11, 2023
by
李维
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化运行内存占用
parent
07ad5cb2
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
188 additions
and
185 deletions
+188
-185
middleLayer_for_kyxq.fire
assets/middleLayer_for_kyxq/scene/middleLayer_for_kyxq.fire
+122
-123
MissionPage.ts
assets/middleLayer_for_kyxq/script/MissionPage.ts
+16
-19
PageComponentBase.ts
assets/middleLayer_for_kyxq/script/PageComponentBase.ts
+6
-6
PageViewer.ts
assets/middleLayer_for_kyxq/script/PageViewer.ts
+19
-9
UnitPage.ts
assets/middleLayer_for_kyxq/script/UnitPage.ts
+19
-24
util.ts
assets/middleLayer_for_kyxq/script/util.ts
+6
-4
No files found.
assets/middleLayer_for_kyxq/scene/middleLayer_for_kyxq.fire
View file @
f457fb4c
This diff is collapsed.
Click to expand it.
assets/middleLayer_for_kyxq/script/MissionPage.ts
View file @
f457fb4c
...
...
@@ -45,7 +45,6 @@ export default class MissionPageClass extends PageComponentBaseClass {
configData
=
[];
userInfo
=
null
nameLblStr
=
""
;
headSprStr
=
""
;
handleClickBackBtn
()
{
const
vc
=
this
.
Viewer
.
getComponent
(
"
PageViewer
"
);
...
...
@@ -76,6 +75,15 @@ export default class MissionPageClass extends PageComponentBaseClass {
// unitConfigData 是从Unit层传进来的config配置参数,如果是从模板返回到Mission层,这个配置文件是没有的
const
customBgUrl
=
unitConfigData
&&
unitConfigData
.
mission_bg_url
?
unitConfigData
.
mission_bg_url
:
""
;
this
.
initCustomBg
(
customBgUrl
);
const
headSprStr
=
unitConfigData
&&
unitConfigData
.
teacher_avatar
?
unitConfigData
.
teacher_avatar
:
""
;
if
(
headSprStr
)
{
getSprNodeByUrl
(
headSprStr
,
(
spr
)
=>
{
this
.
headNode
.
addChild
(
spr
.
node
);
spr
.
srcBlendFactor
=
cc
.
macro
.
BlendFactor
.
ONE
;
setSprNodeMaxLen
(
spr
.
node
,
this
.
headNode
.
width
,
this
.
headNode
.
height
);
this
.
headNode
.
active
=
true
;
});
}
this
.
loading
.
active
=
true
;
this
.
scrollView
.
opacity
=
0
;
...
...
@@ -125,12 +133,17 @@ export default class MissionPageClass extends PageComponentBaseClass {
let
_data
=
JSON
.
parse
(
rows
[
0
].
data
)
this
.
configData
=
_data
.
pages
;
this
.
nameLblStr
=
_data
.
title
;
this
.
headSprStr
=
_data
.
teacher_avatar
;
bgImageUrl
=
_data
.
bg_image_url
;
}
}
this
.
refreshConfig
()
if
(
this
.
configData
&&
this
.
configData
.
length
>
0
)
{
this
.
btn_preview
.
active
=
true
;
this
.
headNode
.
active
=
false
;
}
else
{
this
.
btn_preview
.
active
=
false
;
this
.
headNode
.
active
=
false
;
}
// 数据汇报
if
(
this
.
node
[
"
pData
"
]
&&
this
.
node
[
"
pData
"
].
id
!=
null
)
{
...
...
@@ -147,22 +160,6 @@ export default class MissionPageClass extends PageComponentBaseClass {
}
}
refreshConfig
()
{
if
(
this
.
configData
&&
this
.
configData
.
length
>
0
)
{
this
.
btn_preview
.
active
=
true
;
this
.
headNode
.
active
=
false
;
getSprNodeByUrl
(
this
.
headSprStr
,
(
spr
)
=>
{
this
.
headNode
.
addChild
(
spr
.
node
);
spr
.
srcBlendFactor
=
cc
.
macro
.
BlendFactor
.
ONE
;
setSprNodeMaxLen
(
spr
.
node
,
this
.
headNode
.
width
,
this
.
headNode
.
height
);
this
.
headNode
.
active
=
true
;
});
}
else
{
this
.
btn_preview
.
active
=
false
;
this
.
headNode
.
active
=
false
;
}
}
getConfigData
()
{
return
this
.
configData
}
...
...
assets/middleLayer_for_kyxq/script/PageComponentBase.ts
View file @
f457fb4c
...
...
@@ -20,16 +20,16 @@ export default class PageComponentBaseClass extends cc.Component {
initPageHook
(
node
:
cc
.
Node
)
{
// 注册PageViwer发来的beforeMount事件 [页面即将被显示]
node
.
on
(
"
beforeMount
"
,
(
)
=>
this
.
beforeMount
(
));
node
.
on
(
"
beforeMount
"
,
(
data
)
=>
this
.
beforeMount
(
data
));
// 注册PageViwer发来的mounted事件 [页面已经切换完毕]
node
.
on
(
"
mounted
"
,
(
)
=>
this
.
mounted
(
));
node
.
on
(
"
mounted
"
,
(
data
)
=>
this
.
mounted
(
data
));
// 注册PageViwer发来的unmounted事件 [页面已经切换完毕]
node
.
on
(
"
unmounted
"
,
(
)
=>
this
.
unmounted
(
));
node
.
on
(
"
unmounted
"
,
(
data
)
=>
this
.
unmounted
(
data
));
}
// 页面即将被显示
beforeMount
()
{}
mounted
()
{}
unmounted
()
{}
beforeMount
(
data
)
{}
mounted
(
data
)
{}
unmounted
(
data
)
{}
// update (dt) {}
}
assets/middleLayer_for_kyxq/script/PageViewer.ts
View file @
f457fb4c
...
...
@@ -162,14 +162,23 @@ export default class PageViewerClass extends cc.Component {
}
switchView
(
inPage
,
outPage
,
aniType
)
{
// 页面切换两秒后 执行垃圾回收
if
(
cc
.
sys
.
isNative
&&
cc
.
sys
.
os
==
cc
.
sys
.
OS_IOS
||
cc
.
sys
.
os
==
cc
.
sys
.
OS_ANDROID
)
{
setTimeout
(()
=>
{
cc
.
sys
.
garbageCollect
()
},
2000
)
}
if
(
inPage
.
active
==
false
)
{
inPage
.
active
=
true
}
if
(
aniType
==
"
leftIn
"
||
aniType
==
"
rightIn
"
)
{
let
targetX
=
-
this
.
node
.
width
;
if
(
aniType
==
"
leftIn
"
)
{
targetX
=
-
targetX
}
inPage
.
active
=
true
;
inPage
.
opacity
=
255
;
inPage
.
x
=
-
targetX
;
outPage
.
active
=
true
;
outPage
.
opacity
=
255
;
cc
.
tween
(
inPage
)
.
to
(
0.2
,
{
x
:
0
...
...
@@ -181,7 +190,7 @@ export default class PageViewerClass extends cc.Component {
x
:
targetX
})
.
call
(()
=>
{
outPage
.
active
=
false
;
outPage
.
opacity
=
0
;
outPage
.
emit
(
"
unmounted
"
)
resovle
(
true
)
})
...
...
@@ -193,8 +202,8 @@ export default class PageViewerClass extends cc.Component {
targetY
=
-
targetY
}
inPage
.
y
=
-
targetY
;
inPage
.
active
=
true
;
outPage
.
active
=
true
;
inPage
.
opacity
=
255
;
outPage
.
opacity
=
255
;
cc
.
tween
(
inPage
)
.
to
(
0.2
,
{
y
:
0
...
...
@@ -206,7 +215,7 @@ export default class PageViewerClass extends cc.Component {
y
:
targetY
})
.
call
(()
=>
{
outPage
.
active
=
false
;
outPage
.
opacity
=
0
;
outPage
.
emit
(
"
unmounted
"
)
resovle
(
true
)
})
...
...
@@ -214,16 +223,16 @@ export default class PageViewerClass extends cc.Component {
})
}
else
{
if
(
outPage
)
{
outPage
.
active
=
false
;
outPage
.
opacity
=
0
;
outPage
.
emit
(
"
unmounted
"
)
}
else
{
// 未传移除页面 则全部移除
for
(
let
key
in
PageMap
)
{
this
[
PageMap
[
key
]].
active
=
false
;
this
[
PageMap
[
key
]].
opacity
=
0
;
this
[
PageMap
[
key
]].
emit
(
"
unmounted
"
);
}
}
inPage
.
active
=
true
;
inPage
.
opacity
=
255
;
inPage
.
x
=
0
;
inPage
.
y
=
0
;
return
new
Promise
((
resovle
,
reject
)
=>
{
...
...
@@ -232,6 +241,7 @@ export default class PageViewerClass extends cc.Component {
},
200
)
})
}
}
// update (dt) {}
}
assets/middleLayer_for_kyxq/script/UnitPage.ts
View file @
f457fb4c
...
...
@@ -48,30 +48,34 @@ export default class UnitPageClass extends PageComponentBaseClass {
// 调用父类中的初始化页面生命周期钩子方法
super
.
initPageHook
(
this
.
node
);
this
.
initBg
();
this
.
listItem
=
cc
.
find
(
"
view/content/item
"
,
this
.
unitScrollView
);
this
.
listItem
=
cc
.
find
(
"
view/item
"
,
this
.
unitScrollView
);
}
// 页面即将显示
async
beforeMount
()
{
this
.
isDestory
=
false
;
const
svNode
=
this
.
unitScrollView
;
const
sv
=
svNode
.
getComponent
(
cc
.
ScrollView
);
const
content
=
sv
.
content
;
content
.
removeAllChildren
();
}
// 页面显示
async
mounted
()
{
this
.
listItem
=
cc
.
find
(
"
view/item
"
,
this
.
unitScrollView
);
const
sv
=
this
.
unitScrollView
.
getComponent
(
cc
.
ScrollView
);
this
.
svContent
=
sv
.
content
;
await
this
.
initView
();
}
// 页面隐藏
isDestory
=
false
;
async
unmounted
()
{
const
sv
=
cc
.
find
(
"
middleLayer/Views/UnitPage/unit_list_node/scrollView
"
)
sv
.
off
(
"
scrolling
"
)
const
content
=
this
.
svContent
;
this
.
unitScrollView
.
off
(
"
scrolling
"
)
content
.
destroyAllChildren
();
this
.
isDestory
=
true
;
this
.
lastUpdate
=
0
;
this
.
allListItemNodes
.
forEach
(
node
=>
{
node
&&
node
.
destroy
()
})
this
.
allListItemNodes
=
[];
}
...
...
@@ -187,9 +191,7 @@ export default class UnitPageClass extends PageComponentBaseClass {
this
.
allListItemNodes
=
[];
const
svNode
=
this
.
unitScrollView
;
svNode
.
opacity
=
0
;
const
n1Date
=
new
Date
()
const
resData
=
await
this
.
Viewer
.
getComponent
(
"
PageViewer
"
).
getSyllabusTreeByPid
(
this
.
node
[
'
syllabus_pid
'
])
console
.
log
(
"
接口SyllabusTree`响应时间:
"
,
new
Date
()
-
n1Date
)
let
rows
=
[]
this
.
configData
=
null
let
bgImageUrl
=
null
;
...
...
@@ -206,29 +208,20 @@ export default class UnitPageClass extends PageComponentBaseClass {
}
if
(
rows
.
length
==
0
)
{
const
svNode
=
this
.
unitScrollView
;
const
sv
=
svNode
.
getComponent
(
cc
.
ScrollView
);
const
content
=
sv
.
content
;
content
.
removeAllChildren
();
this
.
svContent
.
destroyAllChildren
();
return
;
}
this
.
initCustomBg
(
bgImageUrl
);
const
n2Date
=
new
Date
()
await
this
.
getAndStoreSyllabusStatus
(
rows
);
console
.
log
(
"
接口SyllabusStatus响应时间:
"
,
new
Date
()
-
n2Date
)
// const svNode = this.unitScrollView;
const
view
=
cc
.
find
(
"
view
"
,
svNode
);
view
.
width
=
svNode
.
width
;
view
.
height
=
svNode
.
height
;
const
nowDate
=
new
Date
();
const
sv
=
svNode
.
getComponent
(
cc
.
ScrollView
);
this
.
getUnitItemDataArr
(
rows
,
sv
);
const
time
=
new
Date
()
-
nowDate
console
.
log
(
"
创建节点时间:
"
,
time
)
svNode
.
opacity
=
255
;
this
.
refreshConfig
()
}
...
...
@@ -243,15 +236,13 @@ export default class UnitPageClass extends PageComponentBaseClass {
}
listItem
;
g_c
ontent
=
null
;
svC
ontent
=
null
;
async
getUnitItemDataArr
(
dataArr
,
sv
)
{
const
content
=
this
.
g_content
=
sv
.
content
;
content
.
removeAllChildren
();
const
content
=
sv
.
content
;
sv
.
scrollToTop
();
content
.
width
=
sv
.
node
.
width
;
content
.
height
=
sv
.
node
.
height
;
content
.
removeAllChildren
();
let
listItem
=
this
.
listItem
;
let
subItem
=
cc
.
find
(
"
/sub_item
"
,
listItem
);
...
...
@@ -263,6 +254,7 @@ export default class UnitPageClass extends PageComponentBaseClass {
}
const
data
=
dataArr
[
i
];
const
itemNode
=
cc
.
instantiate
(
listItem
);
itemNode
.
active
=
true
;
const
cardsContainer
=
cc
.
find
(
"
/cards
"
,
itemNode
)
let
listLabel
=
cc
.
find
(
"
/label
"
,
itemNode
);
itemNode
[
'
data
'
]
=
data
;
...
...
@@ -364,8 +356,11 @@ export default class UnitPageClass extends PageComponentBaseClass {
lastUpdate
=
0
;
update
(
dt
)
{
if
(
this
.
isDestory
)
{
return
}
if
(
this
.
lastUpdate
<
this
.
allListItemNodes
.
length
)
{
this
.
allListItemNodes
[
this
.
lastUpdate
++
].
parent
=
this
.
g_c
ontent
this
.
allListItemNodes
[
this
.
lastUpdate
++
].
parent
=
this
.
svC
ontent
}
}
}
...
...
assets/middleLayer_for_kyxq/script/util.ts
View file @
f457fb4c
...
...
@@ -116,7 +116,6 @@ export function playAudioByUrl(audio_url, cb = null) {
}
}
export
function
btnClickAnima
(
btn
,
time
=
0.15
,
rate
=
1.05
)
{
btn
.
tmpScale
=
btn
.
scale
;
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
...
...
@@ -138,12 +137,15 @@ export function btnClickAnima(btn, time = 0.15, rate = 1.05) {
export
function
getSpriteFrimeByUrl
(
url
,
cb
)
{
cc
.
loader
.
load
({
url
},
(
err
,
img
)
=>
{
const
spriteFrame
=
new
cc
.
SpriteFrame
(
img
)
if
(
!
url
)
{
return
}
cc
.
assetManager
.
loadRemote
(
url
,
(
error
,
texture2D
)
=>
{
const
spriteFrame
=
new
cc
.
SpriteFrame
(
texture2D
)
if
(
cb
)
{
cb
(
spriteFrame
);
}
})
})
;
}
export
function
appearAnim
(
node
,
time
=
1
,
callback
=
null
)
{
...
...
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