Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
middleLayer_for_debug
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_debug
Commits
603b660d
Commit
603b660d
authored
Dec 04, 2021
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 预加载相关
parent
b0d768b7
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
200 additions
and
93 deletions
+200
-93
middleLayer_for_debug.fire
...ts/middleLayer_for_debug/scene/middleLayer_for_debug.fire
+174
-76
middleLayer.js
assets/middleLayer_for_debug/script/middleLayer.js
+26
-17
No files found.
assets/middleLayer_for_debug/scene/middleLayer_for_debug.fire
View file @
603b660d
This diff is collapsed.
Click to expand it.
assets/middleLayer_for_debug/script/middleLayer.js
View file @
603b660d
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
import
{
initAir
}
from
'
./air
'
;
import
{
initAir
}
from
'
./air
'
;
cc
.
Class
({
cc
.
Class
({
extends
:
cc
.
Component
,
extends
:
cc
.
Component
,
properties
:
{},
properties
:
{
},
callNetworkApiPost
(
uri
,
data
,
callBack
)
{
callNetworkApiPost
(
uri
,
data
,
callBack
)
{
const
xhr
=
new
XMLHttpRequest
();
const
xhr
=
new
XMLHttpRequest
();
...
@@ -38,10 +39,22 @@ cc.Class({
...
@@ -38,10 +39,22 @@ cc.Class({
xhr
.
send
();
xhr
.
send
();
},
},
// 需要预加载的数量
preloadCount
:
null
,
// 统计已加载的数量
loadedCount
:
null
,
onLoad
()
{
onLoad
()
{
this
.
preloadCount
=
0
;
this
.
loadedCount
=
0
;
initAir
(
this
);
initAir
(
this
);
if
(
!
window
.
preloadBundleAndSourcesFlag
){
// 只加载一次就行了
window
.
preloadBundleAndSourcesFlag
=
true
;
cc
.
find
(
"
middleLayer/ui/ProgressLabel
"
).
active
=
true
;
this
.
preloadBundle
();
this
.
preloadBundle
();
this
.
preloadSource
();
this
.
preloadSource
();
}
},
},
start
()
{
start
()
{
...
@@ -73,16 +86,7 @@ cc.Class({
...
@@ -73,16 +86,7 @@ cc.Class({
middleLayer
.
log
(
"
middleLayer.log('像这样在这里打log')
"
);
middleLayer
.
log
(
"
middleLayer.log('像这样在这里打log')
"
);
},
},
// 需要预加载的数量
preloadCount
:
0
,
// 统计已加载的数量
loadedCount
:
0
,
preloadBundle
()
{
preloadBundle
()
{
if
(
window
.
air
.
bundleLoaded
){
// 限制只加载一次
return
;
}
window
.
air
.
bundleLoaded
=
true
;
let
platform
=
"
web_desktop
"
;
let
platform
=
"
web_desktop
"
;
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_IOS
){
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_IOS
){
platform
=
"
ios
"
;
platform
=
"
ios
"
;
...
@@ -107,6 +111,7 @@ cc.Class({
...
@@ -107,6 +111,7 @@ cc.Class({
bundle
.
preloadScene
(
scene
.
sceneName
,
()
=>
{},
()
=>
{
bundle
.
preloadScene
(
scene
.
sceneName
,
()
=>
{},
()
=>
{
console
.
log
(
`
${
scene
.
sceneName
}
场景预加载结束`
);
console
.
log
(
`
${
scene
.
sceneName
}
场景预加载结束`
);
_this
.
loadedCount
++
;
_this
.
loadedCount
++
;
_this
.
updateProcessBar
();
i
++
;
i
++
;
if
(
i
<
scenes
.
length
){
if
(
i
<
scenes
.
length
){
setTimeout
(()
=>
{
setTimeout
(()
=>
{
...
@@ -123,11 +128,6 @@ cc.Class({
...
@@ -123,11 +128,6 @@ cc.Class({
},
},
preloadSource
()
{
preloadSource
()
{
if
(
window
.
air
.
sourceLoaded
){
// 限制只加载一次
return
;
}
window
.
air
.
sourceLoaded
=
true
;
this
.
callNetworkApiGet
(
`http://staging-teach.ireadabc.com`
,
`/api/syllabus/v1/allresources`
,
{
orgid
:
507
},
(
datastr
)
=>
{
this
.
callNetworkApiGet
(
`http://staging-teach.ireadabc.com`
,
`/api/syllabus/v1/allresources`
,
{
orgid
:
507
},
(
datastr
)
=>
{
const
data
=
JSON
.
parse
(
datastr
);
const
data
=
JSON
.
parse
(
datastr
);
const
rows
=
data
.
rows
;
const
rows
=
data
.
rows
;
...
@@ -142,6 +142,7 @@ cc.Class({
...
@@ -142,6 +142,7 @@ cc.Class({
console
.
log
(
err
)
console
.
log
(
err
)
}
}
this
.
loadedCount
++
;
this
.
loadedCount
++
;
this
.
updateProcessBar
();
if
(
i
===
len
-
1
)
{
if
(
i
===
len
-
1
)
{
batchLoad
();
batchLoad
();
}
}
...
@@ -153,6 +154,14 @@ cc.Class({
...
@@ -153,6 +154,14 @@ cc.Class({
});
});
},
},
updateProcessBar
()
{
const
label
=
cc
.
find
(
"
middleLayer/ui/ProgressLabel
"
).
getComponent
(
cc
.
Label
);
label
.
string
=
`正在加载:
${
this
.
loadedCount
}
/
${
this
.
preloadCount
}
`
;
if
(
this
.
loadedCount
>
this
.
preloadCount
*
0.99
){
cc
.
find
(
"
middleLayer/ui/ProgressLabel
"
).
active
=
false
;
}
},
asyncDelayLog
(
str
)
{
asyncDelayLog
(
str
)
{
console
.
log
(
str
);
console
.
log
(
str
);
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
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