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
c31dcf8a
Commit
c31dcf8a
authored
Apr 05, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 优化代码
parent
2d413a31
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
50 additions
and
51 deletions
+50
-51
game.ts
src/api/game.ts
+1
-0
index.js
src/native-components/count-up/index.js
+2
-3
complete-head.tsx
src/pages/game/complete/components/complete-head.tsx
+1
-1
count-up.module.scss
src/pages/game/play/components/count-up.module.scss
+9
-2
count-up.tsx
src/pages/game/play/components/count-up.tsx
+28
-27
modal-continue.tsx
src/pages/game/play/components/modal-continue.tsx
+2
-15
index.tsx
src/pages/game/play/index.tsx
+1
-2
index.ts
src/pages/game/play/model/index.ts
+2
-0
utils.ts
src/pages/game/play/model/utils.ts
+4
-1
No files found.
src/api/game.ts
View file @
c31dcf8a
...
@@ -101,6 +101,7 @@ export interface CompleteStageParam {
...
@@ -101,6 +101,7 @@ export interface CompleteStageParam {
correctNum
:
number
;
correctNum
:
number
;
level
:
StageLevel
|
null
;
level
:
StageLevel
|
null
;
levelTime
:
number
;
levelTime
:
number
;
isTimeout
:
boolean
;
num
:
number
;
num
:
number
;
questions
:
CompleteQuestion
[];
questions
:
CompleteQuestion
[];
resultTime
:
number
;
resultTime
:
number
;
...
...
src/native-components/count-up/index.js
View file @
c31dcf8a
...
@@ -81,9 +81,8 @@ Component({
...
@@ -81,9 +81,8 @@ Component({
}
}
}
else
{
}
else
{
this
.
_tick
+=
1
this
.
_tick
+=
1
if
(
this
.
_tick
>=
this
.
data
.
maxValue
)
{
if
(
this
.
_tick
===
this
.
data
.
maxValue
)
{
this
.
stop
()
this
.
triggerEvent
(
'exceed'
)
this
.
triggerEvent
(
'timeup'
)
}
}
}
}
const
{
minutes
,
seconds
}
=
this
.
data
const
{
minutes
,
seconds
}
=
this
.
data
...
...
src/pages/game/complete/components/complete-head.tsx
View file @
c31dcf8a
...
@@ -122,7 +122,7 @@ const GameCompleteHead = () => {
...
@@ -122,7 +122,7 @@ const GameCompleteHead = () => {
</
View
>
</
View
>
<
View
className=
{
styles
.
item
}
>
<
View
className=
{
styles
.
item
}
>
<
Image
src=
{
require
(
'../assets/time.png'
)
}
className=
{
styles
.
icon
}
></
Image
>
<
Image
src=
{
require
(
'../assets/time.png'
)
}
className=
{
styles
.
icon
}
></
Image
>
<
View
className=
{
classNames
(
styles
.
item_text
,
gameResult
.
errNum
<=
0
&&
!
gameResult
.
level
&&
styles
.
err
)
}
>
{
time
.
minutes
}
:
{
time
.
seconds
}
</
View
>
<
View
className=
{
classNames
(
styles
.
item_text
,
gameResult
.
isTimeout
&&
styles
.
err
)
}
>
{
time
.
minutes
}
:
{
time
.
seconds
}
</
View
>
</
View
>
</
View
>
</
View
>
</
View
>
</
View
>
</
View
>
...
...
src/pages/game/play/components/count-up.module.scss
View file @
c31dcf8a
...
@@ -42,14 +42,21 @@
...
@@ -42,14 +42,21 @@
}
}
}
}
.roleWrap
{
position
:
absolute
;
left
:
0
;
top
:
0
;
right
:
0
;
width
:
100%
;
transform
:
translateX
(
0px
);
}
.role
{
.role
{
position
:
absolute
;
position
:
absolute
;
left
:
0
;
left
:
0
;
top
:
-8px
;
top
:
-8px
;
margin-left
:
-40px
;
margin-left
:
-40px
;
transform
:
translateX
(
0px
);
.tick
{
.tick
{
width
:
6px
;
width
:
6px
;
border-radius
:
3px
;
border-radius
:
3px
;
...
...
src/pages/game/play/components/count-up.tsx
View file @
c31dcf8a
import
{
View
,
Image
}
from
'@tarojs/components'
import
{
View
,
Image
}
from
'@tarojs/components'
import
{
use
State
,
useEffect
,
use
Callback
,
useMemo
}
from
'react'
import
{
useCallback
,
useMemo
}
from
'react'
import
{
createSelectorQuery
}
from
'@tarojs/taro'
import
{
useDidShow
,
nextTick
}
from
'@tarojs/taro'
import
classNames
from
'classnames'
import
classNames
from
'classnames'
import
{
useBoolean
}
from
'@/hooks'
import
{
useBoolean
}
from
'@/hooks'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
...
@@ -8,8 +8,6 @@ import { type StageDetail, StageType } from '@/api'
...
@@ -8,8 +8,6 @@ import { type StageDetail, StageType } from '@/api'
import
styles
from
'./count-up.module.scss'
import
styles
from
'./count-up.module.scss'
const
id
=
'_process__'
type
CountUpProps
=
{
type
CountUpProps
=
{
stageDetail
:
StageDetail
stageDetail
:
StageDetail
}
}
...
@@ -21,24 +19,13 @@ const CountUp = (props: CountUpProps) => {
...
@@ -21,24 +19,13 @@ const CountUp = (props: CountUpProps) => {
const
questionList
=
useStoreState
(
state
=>
state
.
gameModel
.
questionList
)
const
questionList
=
useStoreState
(
state
=>
state
.
gameModel
.
questionList
)
const
isSubmit
=
useStoreState
(
state
=>
state
.
gameModel
.
isSubmit
)
const
isSubmit
=
useStoreState
(
state
=>
state
.
gameModel
.
isSubmit
)
const
submit
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
submit
)
const
submit
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
submit
)
const
[
width
,
setWidth
]
=
useState
(
0
)
const
[
isExceed
,
exceedActions
]
=
useBoolean
(
false
)
const
[
isExceed
,
exceedActions
]
=
useBoolean
(
false
)
const
[
isStarted
,
startActions
]
=
useBoolean
(
false
)
const
questionLength
=
useMemo
(()
=>
{
const
questionLength
=
useMemo
(()
=>
{
return
questionList
.
length
return
questionList
.
length
},
[
questionList
])
},
[
questionList
])
useEffect
(()
=>
{
createSelectorQuery
().
select
(
`#
${
id
}
`
)
.
boundingClientRect
()
.
exec
((
res
)
=>
{
console
.
log
(
res
)
if
(
res
[
0
])
{
setWidth
(
res
[
0
].
width
)
}
})
},
[])
const
isOneStop
=
useMemo
(()
=>
{
const
isOneStop
=
useMemo
(()
=>
{
return
stageDetail
.
type
===
StageType
.
OneStop
return
stageDetail
.
type
===
StageType
.
OneStop
},
[
stageDetail
])
},
[
stageDetail
])
...
@@ -50,12 +37,24 @@ const CountUp = (props: CountUpProps) => {
...
@@ -50,12 +37,24 @@ const CountUp = (props: CountUpProps) => {
return
0
return
0
},
[
stageDetail
])
},
[
stageDetail
])
useDidShow
(()
=>
{
nextTick
(()
=>
{
startActions
.
setTrue
()
})
})
const
roleStyle
=
useMemo
(()
=>
{
const
roleStyle
=
useMemo
(()
=>
{
if
(
isStarted
)
{
return
{
transform
:
'translateX(100%)'
,
transition
:
`transform
${
stageDetail
.
bTime
}
s linear`
,
}
}
return
{
return
{
transform
:
`translateX(
${
width
}
px)`
,
transform
:
'translateX(0)'
,
transition
:
`transform
${
stageDetail
.
bTime
}
s linear`
,
transition
:
`transform
${
stageDetail
.
bTime
}
s linear`
,
}
}
},
[
width
,
stageDetail
.
bTime
])
},
[
stageDetail
,
isStarted
])
const
processInnerStyle
=
useMemo
(()
=>
{
const
processInnerStyle
=
useMemo
(()
=>
{
if
(
isSubmit
)
{
if
(
isSubmit
)
{
...
@@ -77,15 +76,17 @@ const CountUp = (props: CountUpProps) => {
...
@@ -77,15 +76,17 @@ const CountUp = (props: CountUpProps) => {
return
(
return
(
<
View
className=
{
classNames
(
styles
.
count
,
isOneStop
&&
styles
.
is_stop
)
}
>
<
View
className=
{
classNames
(
styles
.
count
,
isOneStop
&&
styles
.
is_stop
)
}
>
<
View
className=
{
styles
.
process
}
id=
{
id
}
>
<
View
className=
{
styles
.
process
}
>
<
View
className=
{
styles
.
process_inner
}
style=
{
processInnerStyle
}
></
View
>
<
View
className=
{
styles
.
process_inner
}
style=
{
processInnerStyle
}
></
View
>
{
!
isOneStop
&&
(
{
!
isOneStop
&&
(
<
View
className=
{
styles
.
role
}
style=
{
roleStyle
}
>
<
View
className=
{
styles
.
roleWrap
}
style=
{
roleStyle
}
>
<
View
className=
{
styles
.
tick
}
></
View
>
<
View
className=
{
styles
.
role
}
>
<
Image
src=
{
require
(
'../assets/count-cat.png'
)
}
className=
{
styles
.
cat
}
></
Image
>
<
View
className=
{
styles
.
tick
}
></
View
>
<
View
className=
{
styles
.
tips
}
>
通关要求
</
View
>
<
Image
src=
{
require
(
'../assets/count-cat.png'
)
}
className=
{
styles
.
cat
}
></
Image
>
</
View
>
<
View
className=
{
styles
.
tips
}
>
通关要求
</
View
>
)
}
</
View
>
</
View
>
)
}
</
View
>
</
View
>
<
View
className=
{
classNames
(
styles
.
time
,
isExceed
&&
styles
.
red
)
}
>
<
View
className=
{
classNames
(
styles
.
time
,
isExceed
&&
styles
.
red
)
}
>
{
isExceed
{
isExceed
...
@@ -95,7 +96,7 @@ const CountUp = (props: CountUpProps) => {
...
@@ -95,7 +96,7 @@ const CountUp = (props: CountUpProps) => {
<
count
-
up
-
time
<
count
-
up
-
time
exceedTime=
{
20
}
exceedTime=
{
20
}
onExceed=
{
exceedActions
.
setTrue
}
onExceed=
{
exceedActions
.
setTrue
}
maxValue=
{
60
*
60
}
maxValue=
{
stageDetail
.
bTime
}
startValue=
{
startTick
}
startValue=
{
startTick
}
isDown=
{
isOneStop
}
isDown=
{
isOneStop
}
onTimeup=
{
handleTimeUp
}
onTimeup=
{
handleTimeUp
}
...
...
src/pages/game/play/components/modal-continue.tsx
View file @
c31dcf8a
...
@@ -5,16 +5,9 @@ import { useStoreState, useStoreActions } from '@/store/hooks'
...
@@ -5,16 +5,9 @@ import { useStoreState, useStoreActions } from '@/store/hooks'
import
styles
from
'./modal-continue.module.scss'
import
styles
from
'./modal-continue.module.scss'
type
ModalContinueProps
=
{
closeOnClickModal
:
boolean
;
onClose
?:
()
=>
void
;
}
const
canGoNext
=
true
const
canGoNext
=
true
const
ModalContinue
=
(
props
:
ModalContinueProps
)
=>
{
const
ModalContinue
=
()
=>
{
const
{
closeOnClickModal
,
onClose
}
=
props
const
modalContinueVisible
=
useStoreState
(
state
=>
state
.
gameModel
.
modalContinueVisible
)
const
modalContinueVisible
=
useStoreState
(
state
=>
state
.
gameModel
.
modalContinueVisible
)
const
cardNum
=
useStoreState
(
state
=>
state
.
userModel
.
cardNum
)
const
cardNum
=
useStoreState
(
state
=>
state
.
userModel
.
cardNum
)
...
@@ -22,12 +15,6 @@ const ModalContinue = (props: ModalContinueProps) => {
...
@@ -22,12 +15,6 @@ const ModalContinue = (props: ModalContinueProps) => {
const
submit
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
submit
)
const
submit
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
submit
)
const
reborn
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
reborn
)
const
reborn
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
reborn
)
const
handleClick
=
useCallback
(()
=>
{
if
(
closeOnClickModal
)
{
onClose
?.()
}
},
[
closeOnClickModal
,
onClose
])
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
modalContinueVisible
)
{
if
(
modalContinueVisible
)
{
fetchAccount
()
fetchAccount
()
...
@@ -40,7 +27,7 @@ const ModalContinue = (props: ModalContinueProps) => {
...
@@ -40,7 +27,7 @@ const ModalContinue = (props: ModalContinueProps) => {
return
(
return
(
<
RootPortal
>
<
RootPortal
>
<
View
className=
{
classNames
(
styles
.
mask
,
modalContinueVisible
&&
styles
.
is_show
)
}
onClick=
{
handleClick
}
>
<
View
className=
{
classNames
(
styles
.
mask
,
modalContinueVisible
&&
styles
.
is_show
)
}
>
</
View
>
</
View
>
<
View
className=
{
classNames
(
styles
.
modal
,
modalContinueVisible
&&
styles
.
is_show
)
}
>
<
View
className=
{
classNames
(
styles
.
modal
,
modalContinueVisible
&&
styles
.
is_show
)
}
>
<
View
className=
{
styles
.
title
}
>
是否继续闯关?
</
View
>
<
View
className=
{
styles
.
title
}
>
是否继续闯关?
</
View
>
...
...
src/pages/game/play/index.tsx
View file @
c31dcf8a
...
@@ -16,7 +16,6 @@ import styles from './index.module.scss'
...
@@ -16,7 +16,6 @@ import styles from './index.module.scss'
const
GamePlay
=
()
=>
{
const
GamePlay
=
()
=>
{
const
currentQuestion
=
useStoreState
(
states
=>
states
.
gameModel
.
currentQuestion
)
const
currentQuestion
=
useStoreState
(
states
=>
states
.
gameModel
.
currentQuestion
)
const
stageDetail
=
useStoreState
(
state
=>
state
.
gameModel
.
stageDetail
)
const
stageDetail
=
useStoreState
(
state
=>
state
.
gameModel
.
stageDetail
)
const
[
val
,
actions
]
=
useBoolean
(
false
)
return
(
return
(
<>
<>
...
@@ -41,7 +40,7 @@ const GamePlay = () => {
...
@@ -41,7 +40,7 @@ const GamePlay = () => {
</>
</>
)
}
)
}
</
View
>
</
View
>
<
ModalContinue
closeOnClickModal
onClose=
{
actions
.
setFalse
}
/>
<
ModalContinue
/>
</>
</>
)
)
}
}
...
...
src/pages/game/play/model/index.ts
View file @
c31dcf8a
...
@@ -13,6 +13,7 @@ import { buildCompleteStageParam, convertQuestion, determinQuestion } from './ut
...
@@ -13,6 +13,7 @@ import { buildCompleteStageParam, convertQuestion, determinQuestion } from './ut
interface
CompleteStageDetail
extends
CompleteStageOut
{
interface
CompleteStageDetail
extends
CompleteStageOut
{
errNum
:
number
;
errNum
:
number
;
levelTime
:
number
;
levelTime
:
number
;
isTimeout
:
boolean
;
}
}
const
COUNTER_ID
=
'z__countdown__'
const
COUNTER_ID
=
'z__countdown__'
...
@@ -277,6 +278,7 @@ const gameModel: GameModel = {
...
@@ -277,6 +278,7 @@ const gameModel: GameModel = {
actions
.
updateState
({
actions
.
updateState
({
gameResult
:
{
gameResult
:
{
...
gameResult
,
...
gameResult
,
isTimeout
:
params
.
isTimeout
,
errNum
:
params
.
num
-
params
.
correctNum
,
errNum
:
params
.
num
-
params
.
correctNum
,
levelTime
:
params
.
levelTime
levelTime
:
params
.
levelTime
}
}
...
...
src/pages/game/play/model/utils.ts
View file @
c31dcf8a
...
@@ -40,7 +40,7 @@ export function convertQuestion (question: QuestionType): QuestionType {
...
@@ -40,7 +40,7 @@ export function convertQuestion (question: QuestionType): QuestionType {
}
}
export
function
buildCompleteStageParam
(
questionList
:
QuestionType
[],
stageDetail
:
StageDetail
,
resultTime
:
number
):
CompleteStageParam
{
export
function
buildCompleteStageParam
(
questionList
:
QuestionType
[],
stageDetail
:
StageDetail
,
resultTime
:
number
):
CompleteStageParam
{
const
wrongList
=
questionList
.
map
(
c
=>
!
determinQuestion
(
c
)).
filter
(
Boolean
)
const
wrongList
=
questionList
.
filter
(
c
=>
!
determinQuestion
(
c
)
)
const
wrongLength
=
wrongList
.
length
const
wrongLength
=
wrongList
.
length
if
(
wrongLength
>
0
)
{
if
(
wrongLength
>
0
)
{
...
@@ -55,6 +55,8 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta
...
@@ -55,6 +55,8 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta
const
num
=
questionList
.
length
const
num
=
questionList
.
length
let
levelTime
:
number
=
0
let
levelTime
:
number
=
0
const
isTimeout
=
resultTime
>
bTime
const
correctNum
=
num
-
wrongLength
const
correctNum
=
num
-
wrongLength
if
(
correctNum
===
num
)
{
if
(
correctNum
===
num
)
{
...
@@ -73,6 +75,7 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta
...
@@ -73,6 +75,7 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta
return
{
return
{
correctNum
,
correctNum
,
level
,
level
,
isTimeout
,
levelTime
,
levelTime
,
stageId
:
stageDetail
.
id
,
stageId
:
stageDetail
.
id
,
questions
:
questionList
.
map
(
convert
),
questions
:
questionList
.
map
(
convert
),
...
...
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