Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GeekLearnMathWeapp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
frontend
GeekLearnMathWeapp
Commits
2cfcb8fd
Commit
2cfcb8fd
authored
Apr 05, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: preload assets
parent
d3061f51
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
4 deletions
+38
-4
index.tsx
src/pages/game/play/index.tsx
+19
-4
constants.ts
src/pages/main/components/scene/constants.ts
+7
-0
preload-image.ts
src/utils/preload-image.ts
+12
-0
No files found.
src/pages/game/play/index.tsx
View file @
2cfcb8fd
import
{
View
,
ScrollView
}
from
'@tarojs/components'
import
{
useStoreState
}
from
'@/store/hooks'
// import { useEffect } from 'react'
// import { useRouter } from '@tarojs/taro'
import
{
useBoolean
}
from
'@/hooks/use-boolean'
import
ModalContinue
from
'./components/modal-continue'
import
{
preloadImage
}
from
'@/utils/preload-image'
import
{
useEffect
}
from
'react'
import
assets
from
'@/assets/oss/assets-complete'
import
ModalContinue
from
'./components/modal-continue'
import
PageHead
from
'./components/page-head'
import
PageFooter
from
'./components/page-footer'
import
Question
from
'./components/question'
...
...
@@ -13,10 +13,25 @@ import NumberKeyboard from './components/number-keyboard'
import
styles
from
'./index.module.scss'
let
isLoad
=
false
const
preloadCompleteImages
=
()
=>
{
if
(
isLoad
)
return
isLoad
=
true
const
items
:
string
[]
=
[]
for
(
const
key
in
assets
)
{
items
.
push
(
assets
[
key
].
u
)
}
preloadImage
(
items
)
}
const
GamePlay
=
()
=>
{
const
currentQuestion
=
useStoreState
(
states
=>
states
.
gameModel
.
currentQuestion
)
const
stageDetail
=
useStoreState
(
state
=>
state
.
gameModel
.
stageDetail
)
useEffect
(()
=>
{
preloadCompleteImages
()
},
[])
return
(
<>
<
View
className=
{
styles
.
viewport
}
>
...
...
src/pages/main/components/scene/constants.ts
View file @
2cfcb8fd
...
...
@@ -2,6 +2,7 @@ import assets from '@/assets/oss/assets-main'
import
{
createContext
}
from
'react'
import
{
type
Stage
,
StageStatus
,
StageLevel
,
StageType
}
from
'@/api'
import
type
{
ImageSource
}
from
'@/types'
import
{
preloadImage
}
from
'@/utils/preload-image'
export
const
SceneContext
=
createContext
<
{
ready
:
boolean
}
>
({
ready
:
false
})
...
...
@@ -25,6 +26,12 @@ const NomalPartBgPool = [
assets
[
'round-center-6.png'
],
]
preloadImage
([
...
NomalPartBgPool
.
map
(
c
=>
c
.
u
),
...
SpeicalPartBgPool
.
map
(
c
=>
c
.
u
),
...
PartBgPool
.
map
(
c
=>
c
.
u
)
])
export
{
StageStatus
,
StageLevel
,
Stage
,
StageType
}
export
const
CurrentRoundId
=
'__current_round__'
...
...
src/utils/preload-image.ts
0 → 100644
View file @
2cfcb8fd
declare
const
wx
:
any
export
function
preloadImage
(
urls
:
string
[])
{
if
(
wx
!==
undefined
&&
typeof
wx
.
preloadAssets
===
'function'
)
{
wx
.
preloadAssets
({
data
:
urls
.
map
(
src
=>
({
type
:
'image'
,
src
,
}))
})
}
}
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