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
8a77f86a
Commit
8a77f86a
authored
Mar 31, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 联调
parent
7e292b95
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
272 additions
and
34 deletions
+272
-34
global.d.ts
global.d.ts
+4
-2
game.ts
src/api/game.ts
+75
-2
index.js
src/native-components/count-up/index.js
+1
-0
count-up.tsx
src/pages/game/play/components/count-up.tsx
+31
-11
page-head.tsx
src/pages/game/play/components/page-head.tsx
+6
-3
index.tsx
src/pages/game/play/index.tsx
+9
-6
index.ts
src/pages/game/play/model/index.ts
+63
-6
utils.ts
src/pages/game/play/model/utils.ts
+75
-0
types.ts
src/pages/game/play/types.ts
+8
-4
No files found.
global.d.ts
View file @
8a77f86a
...
...
@@ -13,10 +13,12 @@ declare module '*.styl';
type
CountUptime
=
React
.
FC
<
{
maxNum
}
>
type
CountUpTime
=
React
.
DetailedHTMLProps
<
React
.
HTMLAttributes
<
HTMLElement
>
&
{
'max-value'
?:
number
,
onTimeup
?:
()
=>
void
},
HTMLElement
>
declare
namespace
JSX
{
interface
IntrinsicElements
{
interface
IntrinsicElements
{
// 扩展 IntrinsicElements 否则无法识别自定义标签
'count-up-time'
:
React
.
DetailedHTMLProps
<
React
.
HTMLAttributes
<
HTMLElement
>
&
{
'max-value'
?:
number
,
onTimeup
?:
()
=>
void
},
HTMLElement
>
'count-up-time'
:
CountUpTime
}
}
...
...
src/api/game.ts
View file @
8a77f86a
import
{
requestAfterSilentLogin
}
from
'@/utils/request'
import
{
getStorage
,
StorageKeys
}
from
'@/utils/storage'
import
{
type
QuestionType
}
from
'@/pages/game/play/types'
import
{
QuestionItem
,
type
QuestionType
}
from
'@/pages/game/play/types'
export
const
getQuestionList
=
(
stageId
:
number
)
=>
{
return
requestAfterSilentLogin
<
QuestionType
[],
{
stageId
:
number
,
userId
?:
number
}
>
({
...
...
@@ -29,7 +29,7 @@ export const enum StageLevel {
B
=
'B'
}
export
type
Stage
=
{
export
interface
Stage
{
content
:
string
;
gear
:
number
;
id
:
number
;
...
...
@@ -43,6 +43,35 @@ export type Stage = {
part
?:
number
;
}
type
StageRank
=
{
bestResultTime
:
number
;
firstResultTime
:
number
;
me
:
boolean
;
nickName
:
string
;
no
:
number
;
secondName
:
string
;
userId
:
number
;
}
export
interface
StageDetail
extends
Stage
{
aTime
:
number
;
bTime
:
number
;
sTime
:
number
;
firstTime
:
boolean
;
content
:
string
;
bestResultTime
:
number
;
ranks
?:
StageRank
[];
}
/** 获取关卡详情 */
export
function
getStageDetail
(
stageId
:
number
)
{
return
requestAfterSilentLogin
<
StageDetail
,
{
stageId
:
number
,
userId
?:
number
}
>
({
method
:
'GET'
,
url
:
'/service-idea/stage/stageDetail'
,
data
:
{
stageId
,
userId
:
getStorage
(
StorageKeys
.
userInfo
)?.
userId
}
})
}
/** 获取关卡列表 */
export
function
getStageList
()
{
return
requestAfterSilentLogin
<
Stage
[],
{
chapter
:
number
;
userId
?:
number
}
>
({
...
...
@@ -51,3 +80,47 @@ export function getStageList () {
data
:
{
chapter
:
1
,
userId
:
getStorage
(
StorageKeys
.
userInfo
)?.
userId
}
})
}
export
interface
CompleteQuestion
extends
QuestionItem
{
userAnswers
:
string
[];
}
export
interface
CompleteStageParam
{
correctNum
:
number
;
level
:
StageLevel
;
num
:
number
;
questions
:
CompleteQuestion
[];
resultTime
:
number
;
stageId
:
number
;
}
interface
CompleteStageParamIn
extends
CompleteStageParam
{
userId
?:
number
;
}
export
interface
CompleteStageOut
{
averageTime
:
number
;
gear
:
number
;
level
:
StageLevel
;
nextGear
:
number
;
nextGearTime
:
number
;
pointAfter
:
number
;
pointBefore
:
number
;
ranks
:
StageRank
[];
rate
:
number
;
resultTime
:
number
;
sLevelTime
:
number
;
upGear
:
boolean
;
}
/** 完成 */
export
function
completeStage
(
arg
:
CompleteStageParam
)
{
return
requestAfterSilentLogin
<
CompleteStageOut
,
CompleteStageParamIn
>
({
method
:
'POST'
,
url
:
'/service-idea/stage/completeStage'
,
data
:
{
...
arg
,
userId
:
getStorage
(
StorageKeys
.
userInfo
)?.
userId
}
})
}
src/native-components/count-up/index.js
View file @
8a77f86a
...
...
@@ -37,6 +37,7 @@ Component({
attached
()
{
this
.
_tick
=
0
this
.
startCount
()
console
.
log
(
this
)
},
methods
:
{
...
...
src/pages/game/play/components/count-up.tsx
View file @
8a77f86a
import
{
View
,
Image
}
from
'@tarojs/components'
import
{
useState
,
useEffect
,
useCallback
,
useMemo
}
from
'react'
import
{
createSelectorQuery
}
from
'@tarojs/taro'
import
{
useState
,
useEffect
,
useCallback
,
useMemo
,
useRef
}
from
'react'
import
{
createSelectorQuery
,
getCurrentInstance
}
from
'@tarojs/taro'
import
{
useStoreState
}
from
'@/store/hooks'
import
{
type
StageDetail
}
from
'@/api'
import
styles
from
'./count-up.module.scss'
const
speed
=
4
const
id
=
'_process__'
const
CountUp
=
()
=>
{
type
CountUpProps
=
{
stageDetail
:
StageDetail
}
const
CountUp
=
(
props
:
CountUpProps
)
=>
{
const
{
stageDetail
}
=
props
const
currentQuestionIndex
=
useStoreState
(
states
=>
states
.
gameModel
.
currentQuestionIndex
)
const
questionList
=
useStoreState
(
state
=>
state
.
gameModel
.
questionList
)
const
isSubmit
=
useStoreState
(
state
=>
state
.
gameModel
.
isSubmit
)
const
[
width
,
setWidth
]
=
useState
(
0
)
const
countUp
=
useRef
<
any
>
(
null
)
const
questionLength
=
useMemo
(()
=>
{
return
questionList
.
length
},
[
questionList
])
useEffect
(()
=>
{
const
query
=
createSelectorQuery
()
query
.
select
(
`#
${
id
}
`
)
createSelectorQuery
().
select
(
`#
${
id
}
`
)
.
boundingClientRect
()
.
exec
((
res
)
=>
{
console
.
log
(
res
)
...
...
@@ -32,15 +38,29 @@ const CountUp = () => {
const
roleStyle
=
useMemo
(()
=>
{
return
{
transform
:
`translateX(
${
width
}
px)`
,
transition
:
`transform
${
questionLength
*
speed
}
s linear`
,
transition
:
`transform
${
stageDetail
.
bTime
}
s linear`
,
}
},
[
width
,
questionLength
])
},
[
width
,
stageDetail
.
bTime
])
useEffect
(()
=>
{
if
(
isSubmit
&&
countUp
.
current
?.
sid
)
{
console
.
log
(
countUp
.
current
)
const
comp
=
getCurrentInstance
()?.
page
?.
selectComponent
?.(
`#
${
countUp
.
current
?.
sid
}
`) as any
comp?.stop?.()
console.log(comp, 11)
}
}, [isSubmit])
const processInnerStyle = useMemo(() => {
if (isSubmit) {
return {
width: '100%'
}
}
return {
width: `
$
{
currentQuestionIndex
*
100
/
questionLength
}
%
`
}
},
[
currentQuestionIndex
,
questionLength
])
}, [currentQuestionIndex, questionLength
, isSubmit
])
const handleTimeUp = useCallback(() => {
console.log('upd1')
...
...
@@ -58,7 +78,7 @@ const CountUp = () => {
</View>
<View className={styles.time}>
<Image src={require('../assets/count-time.png')} className={styles.icon}></Image>
<
count
-
up
-
time
max
-
value=
{
60
*
60
}
onTimeup=
{
handleTimeUp
}
/>
<count-up-time max-value={60 * 60} onTimeup={handleTimeUp}
ref={countUp}
/>
</View>
</View>
)
...
...
src/pages/game/play/components/page-head.tsx
View file @
8a77f86a
import
{
View
,
Image
,
Text
}
from
'@tarojs/components'
import
{
getMenuButtonBoundingClientRect
}
from
'@tarojs/taro'
import
{
getMenuButtonBoundingClientRect
,
navigateBack
}
from
'@tarojs/taro'
import
{
useState
,
memo
}
from
'react'
import
{
useStoreState
}
from
'@/store/hooks'
...
...
@@ -19,8 +19,11 @@ const PageHead = () => {
}
}
>
<
View
className=
{
styles
.
inner
}
style=
{
{
height
:
`${nav.height + 10}px`
}
}
>
<
Image
src=
{
require
(
'../assets/arrow.png'
)
}
className=
{
styles
.
arrow
}
></
Image
>
<
Text
>
{
currentQuestionIndex
+
1
}
/
{
questionList
.
length
}
</
Text
>
<
Image
src=
{
require
(
'../assets/arrow.png'
)
}
className=
{
styles
.
arrow
}
onClick=
{
()
=>
navigateBack
()
}
></
Image
>
{
questionList
.
length
>
0
?
(<
Text
>
{
currentQuestionIndex
+
1
}
/
{
questionList
.
length
}
</
Text
>)
:
(<
Text
>
出错了
</
Text
>)
}
</
View
>
</
View
>
</
View
>
...
...
src/pages/game/play/index.tsx
View file @
8a77f86a
...
...
@@ -14,6 +14,7 @@ import styles from './index.module.scss'
const
GamePlay
=
()
=>
{
const
currentQuestion
=
useStoreState
(
states
=>
states
.
gameModel
.
currentQuestion
)
const
getQuestionList
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
getQuestionList
)
const
stageDetail
=
useStoreState
(
state
=>
state
.
gameModel
.
stageDetail
)
const
router
=
useRouter
<
{
id
:
string
}
>
()
...
...
@@ -23,10 +24,10 @@ const GamePlay = () => {
return
(
<
View
className=
{
styles
.
viewport
}
>
{
currentQuestion
&&
(
<
PageHead
/>
{
currentQuestion
&&
stageDetail
&&
(
<>
<
PageHead
/>
<
CountUp
/>
<
CountUp
stageDetail=
{
stageDetail
}
/>
</>
)
}
<
ScrollView
className=
{
styles
.
body
}
scrollY
>
...
...
@@ -34,11 +35,13 @@ const GamePlay = () => {
<
Question
question=
{
currentQuestion
}
/>
)
}
</
ScrollView
>
{
currentQuestion
?.
questionType
!==
'选择题'
&&
(
<
NumberKeyboard
/>
)
}
{
currentQuestion
&&
(
<>
{
currentQuestion
?.
questionType
!==
'选择题'
&&
(
<
NumberKeyboard
/>
)
}
<
PageFooter
/>
</>
)
}
</
View
>
)
...
...
src/pages/game/play/model/index.ts
View file @
8a77f86a
import
{
action
,
Action
,
computed
,
Computed
,
Thunk
,
thunk
}
from
'easy-peasy'
import
{
action
,
Action
,
computed
,
Computed
,
State
,
Thunk
,
thunk
}
from
'easy-peasy'
import
{
AppStoreModel
}
from
'@/store/store-model'
import
{
getQuestionList
}
from
'@/api'
import
{
showLoading
,
hideLoading
}
from
'@tarojs/taro'
import
{
getQuestionList
,
type
StageDetail
,
getStageDetail
,
completeStage
}
from
'@/api'
import
{
showLoading
,
hideLoading
,
showModal
}
from
'@tarojs/taro'
import
{
QuestionType
,
QuestionAnswer
,
isSelectionQuestion
,
// QuestionOption,
}
from
'../types'
import
{
buildCompleteStageParam
}
from
'./utils'
// import questionListJson from './test.json'
export
interface
GameModel
{
/** 题目列表 */
questionList
:
QuestionType
[];
stageDetail
:
StageDetail
|
null
;
gameStartTime
:
number
;
updateState
:
Action
<
GameModel
,
Partial
<
State
<
GameModel
>>>
;
/** 当前题目 */
currentQuestion
:
Computed
<
GameModel
,
QuestionType
|
undefined
>
;
/** 当前题目下标 */
...
...
@@ -40,12 +44,27 @@ export interface GameModel {
getQuestionList
:
Thunk
<
GameModel
,
number
,
void
,
AppStoreModel
>
;
handleGoNext
:
Thunk
<
GameModel
,
void
,
void
,
AppStoreModel
>
;
isSubmit
:
boolean
;
submit
:
Thunk
<
GameModel
,
void
,
void
,
AppStoreModel
>
;
}
const
gameModel
:
GameModel
=
{
questionList
:
[],
gameStartTime
:
0
,
isSubmit
:
false
,
stageDetail
:
null
,
updateState
:
action
((
state
,
obj
)
=>
{
for
(
const
key
in
obj
)
{
state
[
key
]
=
obj
[
key
]
}
}),
currentInputIndex
:
0
,
currentQuestionIndex
:
0
,
updateCurrentInputIndex
:
action
((
state
,
num
)
=>
{
state
.
currentInputIndex
=
num
}),
...
...
@@ -68,6 +87,7 @@ const gameModel: GameModel = {
}
return
questionAnswers
?.
every
((
c
)
=>
!!
c
.
userAnswer
)
??
false
}),
updateSelectionAnswer
:
action
((
state
,
index
)
=>
{
const
question
=
state
.
questionList
[
state
.
currentQuestionIndex
]
if
(
isSelectionQuestion
(
question
))
{
...
...
@@ -122,6 +142,7 @@ const gameModel: GameModel = {
if
(
!
canGoNext
)
return
if
(
questionList
.
length
===
currentQuestionIndex
+
1
)
{
console
.
log
(
'submit'
)
actions
.
submit
()
return
}
...
...
@@ -131,10 +152,46 @@ const gameModel: GameModel = {
getQuestionList
:
thunk
(
async
(
actions
,
round
)
=>
{
try
{
showLoading
()
const
{
data
:
questionList
}
=
await
getQuestionList
(
round
)
actions
.
updateList
(
questionList
)
const
[{
data
:
questionList
},
{
data
:
stageDetail
}]
=
await
Promise
.
all
([
getQuestionList
(
round
),
getStageDetail
(
round
)
])
actions
.
updateState
({
questionList
,
stageDetail
,
gameStartTime
:
Date
.
now
(),
})
}
catch
(
err
)
{
showModal
({
title
:
'提示'
,
content
:
err
.
message
||
'出错了'
,
showCancel
:
false
,
})
actions
.
updateState
({
questionList
:
[],
stageDetail
:
null
})
}
finally
{
hideLoading
()
}
}),
submit
:
thunk
(
async
(
actions
,
__
,
helpers
)
=>
{
try
{
showLoading
({
mask
:
true
,
title
:
'提交中'
})
actions
.
updateState
({
isSubmit
:
true
})
const
{
questionList
,
gameStartTime
,
stageDetail
}
=
helpers
.
getState
()
await
completeStage
(
buildCompleteStageParam
(
questionList
,
stageDetail
!
,
gameStartTime
))
}
catch
(
err
)
{
actions
.
updateList
([])
showModal
({
title
:
'提示'
,
content
:
err
.
message
||
'出错了'
,
showCancel
:
false
,
})
console
.
log
(
err
)
}
finally
{
hideLoading
()
}
...
...
src/pages/game/play/model/utils.ts
0 → 100644
View file @
8a77f86a
import
{
type
CompleteStageParam
,
type
StageDetail
,
StageLevel
,
type
CompleteQuestion
}
from
'@/api'
import
{
type
QuestionType
,
isBlankQuestion
,
isVerticalDivisionQuestion
,
isSelectionQuestion
}
from
'../types'
export
function
buildCompleteStageParam
(
questionList
:
QuestionType
[],
stageDetail
:
StageDetail
,
gameStartTime
:
number
):
CompleteStageParam
{
const
correctNum
=
questionList
.
map
(
c
=>
determinQuestion
(
c
)).
filter
(
Boolean
).
length
const
resultTime
=
Math
.
round
((
Date
.
now
()
-
gameStartTime
)
/
1000
)
const
{
sTime
,
aTime
,
bTime
}
=
stageDetail
let
level
=
StageLevel
.
B
const
num
=
questionList
.
length
if
(
correctNum
===
num
)
{
if
(
resultTime
<=
sTime
)
{
level
=
StageLevel
.
S
}
else
if
(
resultTime
<=
aTime
)
{
level
=
StageLevel
.
A
}
else
if
(
resultTime
<=
bTime
)
{
level
=
StageLevel
.
B
}
}
return
{
correctNum
,
level
,
stageId
:
stageDetail
.
id
,
questions
:
questionList
.
map
(
convert
),
num
,
resultTime
:
Math
.
round
((
Date
.
now
()
-
gameStartTime
)
/
1000
),
}
}
function
convert
(
inQuestion
:
QuestionType
):
CompleteQuestion
{
if
(
isBlankQuestion
(
inQuestion
))
{
return
{
...
inQuestion
,
userAnswers
:
inQuestion
.
answers
.
map
(
c
=>
c
.
userAnswer
!
),
}
}
if
(
isSelectionQuestion
(
inQuestion
))
{
return
{
...
inQuestion
,
userAnswers
:
inQuestion
.
options
.
filter
(
c
=>
c
.
userAnswer
).
map
(
c
=>
c
.
index
)
}
}
if
(
isVerticalDivisionQuestion
(
inQuestion
))
{
return
{
...
inQuestion
,
userAnswers
:
inQuestion
.
answers
.
map
(
c
=>
c
.
userAnswer
!
),
}
}
throw
new
Error
(
'question not supported'
)
}
/** 判题 */
function
determinQuestion
(
question
:
QuestionType
)
{
if
(
isBlankQuestion
(
question
))
{
return
question
.
answers
.
every
(
c
=>
c
.
userAnswer
===
c
.
contentText
)
}
if
(
isSelectionQuestion
(
question
))
{
return
question
.
options
.
every
(
c
=>
c
.
answer
===
c
.
userAnswer
)
}
if
(
isVerticalDivisionQuestion
(
question
))
{
return
question
.
answers
.
every
(
c
=>
c
.
userAnswer
===
c
.
contentText
)
}
throw
new
Error
(
'question not supported'
)
}
src/pages/game/play/types.ts
View file @
8a77f86a
...
...
@@ -8,6 +8,10 @@ export interface QuestionItem {
questionType
:
string
;
answers
:
QuestionAnswer
[];
simpleType
?:
boolean
;
contentText
:
string
;
options
:
QuestionOption
[];
questionItems
?:
RandomQuestionItem
[];
sort
:
number
;
}
export
interface
BlankQuestion
extends
QuestionItem
{
...
...
@@ -21,9 +25,9 @@ export interface SelectionQuestion extends QuestionItem {
options
:
QuestionOption
[];
}
export
interface
RandomQuestion
extends
QuestionItem
{
questionItems
?:
RandomQuestionItem
[];
}
//
export interface RandomQuestion extends QuestionItem {
//
questionItems?: RandomQuestionItem[];
//
}
/** 带余除法 */
export
interface
DivisionWithRemainderQuestion
extends
QuestionItem
{
...
...
@@ -42,7 +46,7 @@ export interface MultiplicationQuestion extends QuestionItem {
questionItems
:
[];
}
export
type
QuestionType
=
BlankQuestion
|
SelectionQuestion
|
Random
Question
export
type
QuestionType
=
BlankQuestion
|
SelectionQuestion
|
VerticalDivision
Question
export
function
isBlankQuestion
(
q
:
QuestionType
):
q
is
BlankQuestion
{
return
q
?.
questionType
===
'填空题'
||
q
?.
questionType
===
'随机填空'
...
...
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