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
53db40e7
Commit
53db40e7
authored
Mar 31, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 账户信息
parent
8a77f86a
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
327 additions
and
124 deletions
+327
-124
auth.ts
src/api/auth.ts
+15
-112
answer-blank.tsx
src/pages/game/play/components/answer-blank.tsx
+8
-1
modal-continue.module.scss
src/pages/game/play/components/modal-continue.module.scss
+131
-0
modal-continue.tsx
src/pages/game/play/components/modal-continue.tsx
+64
-0
question-vertical-division.tsx
...e/play/components/question/question-vertical-division.tsx
+0
-1
index.tsx
src/pages/game/play/index.tsx
+6
-1
index.ts
src/pages/game/play/model/index.ts
+17
-5
utils.ts
src/pages/game/play/model/utils.ts
+35
-1
header.tsx
src/pages/main/components/header.tsx
+6
-2
stage.tsx
src/pages/main/components/scene/stage.tsx
+7
-1
main.tsx
src/pages/main/main.tsx
+2
-0
user.ts
src/store/modules/user.ts
+34
-0
store-model.ts
src/store/store-model.ts
+2
-0
No files found.
src/api/auth.ts
View file @
53db40e7
import
{
request
,
requestAfterSilentLogin
}
from
'@/utils/request'
import
{
request
,
requestAfterSilentLogin
}
from
'@/utils/request'
import
{
getStorage
,
StorageKeys
}
from
'@/utils/storage'
import
{
getStorage
,
StorageKeys
}
from
'@/utils/storage'
import
qs
from
'qs'
type
LoginResult
=
{
type
LoginResult
=
{
phone
?:
string
|
null
;
phone
?:
string
|
null
;
...
@@ -27,123 +26,27 @@ export function silentLoginApi (code: string) {
...
@@ -27,123 +26,27 @@ export function silentLoginApi (code: string) {
})
})
}
}
export
type
LoginOption
=
{
type
AccountType
=
'POINT'
|
'CARD'
;
code
:
string
;
iv
:
string
;
encryptedData
:
string
;
errMsg
?:
string
;
channel
:
number
,
channelExtra
:{[
key
:
string
]:
string
}
}
/** 绑定用户手机 */
export
function
login
(
opts
:
LoginOption
)
{
return
request
<
LoginResult
,
LoginOption
>
({
method
:
'POST'
,
url
:
'/service-activity-pbl/user/bind/phone'
,
data
:
opts
})
}
export
type
UpdateUserInfoOption
=
{
type
AccountIn
=
{
nickname
:
string
;
accountId
?:
number
;
avatarUrl
:
string
;
accountType
?:
AccountType
;
gender
?:
2
|
1
|
0
;
userId
?:
number
;
province
:
string
;
city
:
string
;
}
}
/** 更新用户信息 */
export
type
AccountOut
=
{
export
function
updateUserInfo
(
opts
:
UpdateUserInfoOption
)
{
accountId
:
number
;
return
request
<
LoginResult
,
UpdateUserInfoOption
>
({
accountType
:
AccountType
;
method
:
'POST'
,
amount
:
number
;
url
:
'/service-activity-pbl/user/info/update'
,
data
:
opts
})
}
export
type
AuthRelationUser
=
{
avatarUrl
:
string
;
nickname
:
string
,
phone
:
string
,
id
:
number
,
}
export
type
AuthRelationItem
=
{
createTime
:
string
;
fromUser
:
AuthRelationUser
;
fromUserId
:
number
;
id
:
number
;
mark
:
string
;
toUser
:
AuthRelationUser
;
toUserId
:
number
;
}
const
baseUrl
=
'/service-activity-pbl'
export
function
getMyAuthRelationList
(
userId
:
number
)
{
return
request
<
{
authMeList
:
AuthRelationItem
[],
myAuthList
:
AuthRelationItem
[]
},
{
userId
:
number
}
>
({
method
:
'POST'
,
url
:
`
${
baseUrl
}
/auth_relation/list?userId=
${
userId
}
`
,
data
:
{
userId
}
})
}
type
DeleteAuthRelationOptions
=
{
userId
:
number
;
userId
:
number
;
relationId
:
number
;
}
}
export
function
deleteAuthRelation
(
opt
:
DeleteAuthRelationOptions
)
{
export
function
getAccountInfo
(
)
{
return
request
<
null
,
DeleteAuthRelationOptions
>
({
return
request
AfterSilentLogin
<
AccountOut
[],
AccountIn
>
({
method
:
'POST'
,
method
:
'POST'
,
url
:
`
${
baseUrl
}
/auth_relation/delete?
${
qs
.
stringify
(
opt
)}
`
,
url
:
'/service-idea/account/selectAccounts'
,
data
:
opt
data
:
{
})
userId
:
getStorage
(
StorageKeys
.
userInfo
)?.
userId
,
}
}
type
AddAuthRelationOption
=
{
fromId
:
number
;
mark
:
string
;
toPhone
:
string
;
}
export
function
addAuthRelation
(
opt
:
AddAuthRelationOption
)
{
return
request
<
null
,
AddAuthRelationOption
>
({
method
:
'POST'
,
url
:
`
${
baseUrl
}
/auth_relation/add?
${
qs
.
stringify
(
opt
)}
`
,
data
:
opt
})
}
type
CreateCodeRet
=
{
code
:
string
;
expireTime
:
string
id
:
string
userId
:
string
|
number
}
export
function
createLoginCode
(
userId
:
number
)
{
return
request
<
CreateCodeRet
,
{
userId
:
number
}
>
({
method
:
'POST'
,
url
:
`
${
baseUrl
}
/auth_relation/code/create?userId=
${
userId
}
`
,
data
:
{
userId
}
})
}
type
TemporaryCodeLoginRet
=
CreateCodeRet
&
{
userDTO
?:
{
avatarUrl
:
string
;
nickname
:
string
;
phone
:
string
;
id
:
number
;
}
}
export
function
loginByTemporaryCode
(
code
:
string
)
{
return
request
<
TemporaryCodeLoginRet
,
{
code
:
string
}
>
({
method
:
'POST'
,
url
:
`
${
baseUrl
}
/auth_relation/code/get?code=
${
code
}
`
,
data
:
{
code
}
})
})
}
}
src/pages/game/play/components/answer-blank.tsx
View file @
53db40e7
...
@@ -4,6 +4,7 @@ import classNames from 'classnames'
...
@@ -4,6 +4,7 @@ import classNames from 'classnames'
import
{
useStoreActions
,
useStoreState
}
from
'@/store/hooks'
import
{
useStoreActions
,
useStoreState
}
from
'@/store/hooks'
import
styles
from
'./answer-blank.module.scss'
import
styles
from
'./answer-blank.module.scss'
import
{
isVerticalDivisionQuestion
}
from
'../types'
type
AnswerBlankProps
=
{
type
AnswerBlankProps
=
{
index
:
number
;
index
:
number
;
...
@@ -23,10 +24,16 @@ const AnswerBlank = (props: AnswerBlankProps) => {
...
@@ -23,10 +24,16 @@ const AnswerBlank = (props: AnswerBlankProps) => {
const
isCurrent
=
useMemo
(()
=>
index
===
currentInputIndex
,
[
index
,
currentInputIndex
])
const
isCurrent
=
useMemo
(()
=>
index
===
currentInputIndex
,
[
index
,
currentInputIndex
])
const
isSimple
=
useMemo
(()
=>
{
return
currentQuestion
&&
(
isVerticalDivisionQuestion
(
currentQuestion
)
||
currentQuestion
.
simpleType
)
},
[
currentQuestion
])
return
(
return
(
<
CustomWrapper
>
<
CustomWrapper
>
<
View
<
View
className=
{
classNames
(
styles
.
blank
,
currentQuestion
?.
simpleTyp
e
&&
styles
.
is_simple
,
isCompare
&&
styles
.
is_compare
,
currentInput
&&
styles
.
has_answer
,
isCurrent
&&
styles
.
is_active
)
}
className=
{
classNames
(
styles
.
blank
,
isSimpl
e
&&
styles
.
is_simple
,
isCompare
&&
styles
.
is_compare
,
currentInput
&&
styles
.
has_answer
,
isCurrent
&&
styles
.
is_active
)
}
onClick=
{
()
=>
updateCurrentInputIndex
(
index
)
}
onClick=
{
()
=>
updateCurrentInputIndex
(
index
)
}
>
{
currentInput
}
</
View
>
>
{
currentInput
}
</
View
>
</
CustomWrapper
>
</
CustomWrapper
>
...
...
src/pages/game/play/components/modal-continue.module.scss
0 → 100644
View file @
53db40e7
.mask
{
position
:
fixed
;
left
:
0
;
top
:
0
;
bottom
:
0
;
right
:
0
;
background
:
rgba
(
0
,
0
,
0
,
0
.5
);
z-index
:
2000
;
opacity
:
0
;
pointer-events
:
none
;
transition
:
opacity
.5s
cubic-bezier
(
0
.175
,
0
.885
,
0
.32
,
1
.0
);
&
.is_show
{
opacity
:
1
;
pointer-events
:
all
;
}
}
.modal
{
position
:
fixed
;
bottom
:
0
;
left
:
0
;
right
:
0
;
z-index
:
2001
;
background-color
:
#fff
;
transform
:
translateY
(
100%
);
transition
:
transform
.5s
cubic-bezier
(
0
.175
,
0
.885
,
0
.32
,
1
.0
);
border-radius
:
32px
32px
0px
0px
;
&
.is_show
{
transform
:
translateY
(
0
);
}
}
.tips
{
font-size
:
36px
;
font-weight
:
400
;
color
:
#586170
;
line-height
:
50px
;
text-align
:
center
;
}
.title
{
padding
:
64px
0
32px
0
;
text-align
:
center
;
font-size
:
48px
;
font-weight
:
600
;
color
:
#586170
;
line-height
:
66px
;
}
@supports
(
padding-bottom
:
constant
(
safe-area-inset-bottom
))
or
(
padding-bottom
:
env
(
safe-area-inset-bottom
))
{
.modal
{
padding-bottom
:
constant
(
safe-area-inset-bottom
);
padding-bottom
:
env
(
safe-area-inset-bottom
);
}
}
.footer
{
display
:
flex
;
align-items
:
center
;
padding
:
32px
34px
80px
34px
;
.btn_right
{
flex
:
1
;
height
:
112px
;
background-image
:
url(../assets/btn-next.png)
;
background-size
:
100%
100%
;
display
:
flex
;
align-items
:
center
;
justify-content
:
center
;
font-size
:
40px
;
font-weight
:
500
;
color
:
#FFFFFF
;
line-height
:
56px
;
position
:
relative
;
&
.is_active
{
background-image
:
url(../assets//btn-next-active.png)
;
}
&
.disabled
{
background-image
:
none
;
background-color
:
#E2E6ED
;
color
:
#C2C8D1
;
border-radius
:
32px
;
}
}
.btn_left
{
margin-right
:
20px
;
width
:
260px
;
height
:
112px
;
background-image
:
url(../assets/btn-clear.png)
;
background-size
:
100%
100%
;
font-size
:
40px
;
font-weight
:
500
;
color
:
#FFFFFF
;
line-height
:
56px
;
display
:
flex
;
align-items
:
center
;
justify-content
:
center
;
&
.is_active
{
background-image
:
url(../assets//btn-clear-active.png)
;
}
}
}
.account_left
{
position
:
absolute
;
bottom
:
-48px
;
left
:
0
;
right
:
0
;
text-align
:
center
;
font-size
:
28px
;
font-weight
:
400
;
color
:
#586170
;
line-height
:
40px
;
}
.account_num
{
color
:
#1786F7
;
}
.icon
{
width
:
64px
;
height
:
64px
;
margin-right
:
10px
;
}
src/pages/game/play/components/modal-continue.tsx
0 → 100644
View file @
53db40e7
import
{
View
,
RootPortal
,
Image
,
Text
}
from
'@tarojs/components'
import
{
useCallback
,
useEffect
}
from
'react'
import
classNames
from
'classnames'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
import
styles
from
'./modal-continue.module.scss'
type
ModalContinueProps
=
{
closeOnClickModal
:
boolean
;
onClose
?:
()
=>
void
;
}
const
canGoNext
=
true
const
ModalContinue
=
(
props
:
ModalContinueProps
)
=>
{
const
{
closeOnClickModal
,
onClose
}
=
props
const
modalContinueVisible
=
useStoreState
(
state
=>
state
.
gameModel
.
modalContinueVisible
)
const
cardNum
=
useStoreState
(
state
=>
state
.
userModel
.
cardNum
)
const
fetchAccount
=
useStoreActions
(
actions
=>
actions
.
userModel
.
fetchAccount
)
const
handleClick
=
useCallback
(()
=>
{
if
(
closeOnClickModal
)
{
onClose
?.()
}
},
[
closeOnClickModal
,
onClose
])
useEffect
(()
=>
{
if
(
modalContinueVisible
)
{
fetchAccount
()
}
},
[
fetchAccount
,
modalContinueVisible
])
return
(
<
RootPortal
>
<
View
className=
{
classNames
(
styles
.
mask
,
modalContinueVisible
&&
styles
.
is_show
)
}
onClick=
{
handleClick
}
>
</
View
>
<
View
className=
{
classNames
(
styles
.
modal
,
modalContinueVisible
&&
styles
.
is_show
)
}
>
<
View
className=
{
styles
.
title
}
>
是否继续闯关?
</
View
>
<
View
className=
{
styles
.
tips
}
>
消耗1张答题卡,复活继续闯关
</
View
>
<
View
className=
{
styles
.
footer
}
>
<
View
className=
{
styles
.
btn_left
}
hoverClass=
{
styles
.
is_active
}
>
放弃
</
View
>
<
View
className=
{
classNames
(
styles
.
btn_right
,
!
canGoNext
&&
styles
.
disabled
)
}
hoverClass=
{
canGoNext
?
styles
.
is_active
:
null
}
>
<
Image
src=
{
require
(
'@/pages/main/assets/ph.png'
)
}
className=
{
styles
.
icon
}
></
Image
>
<
Text
>
-1 继续
</
Text
>
<
View
className=
{
styles
.
account_left
}
>
剩余
<
Text
className=
{
styles
.
account_num
}
>
{
cardNum
}
</
Text
>
张
</
View
>
</
View
>
</
View
>
</
View
>
</
RootPortal
>
)
}
export
default
ModalContinue
src/pages/game/play/components/question/question-vertical-division.tsx
View file @
53db40e7
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
import
{
View
,
Text
}
from
'@tarojs/components'
import
{
View
,
Text
}
from
'@tarojs/components'
import
{
useMemo
}
from
'react'
import
{
useMemo
}
from
'react'
import
classNames
from
'classnames'
import
classNames
from
'classnames'
import
{
useStoreActions
}
from
'@/store/hooks'
import
type
{
VerticalDivisionQuestion
}
from
'../../types'
import
type
{
VerticalDivisionQuestion
}
from
'../../types'
import
styles
from
'./question-vertical-division.module.scss'
import
styles
from
'./question-vertical-division.module.scss'
...
...
src/pages/game/play/index.tsx
View file @
53db40e7
import
{
View
,
ScrollView
}
from
'@tarojs/components'
import
{
View
,
ScrollView
,
Button
}
from
'@tarojs/components'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
import
{
useEffect
}
from
'react'
import
{
useEffect
}
from
'react'
import
{
useRouter
}
from
'@tarojs/taro'
import
{
useRouter
}
from
'@tarojs/taro'
import
{
useBoolean
}
from
'@/hooks/use-boolean'
import
ModalContinue
from
'./components/modal-continue'
import
PageHead
from
'./components/page-head'
import
PageHead
from
'./components/page-head'
import
PageFooter
from
'./components/page-footer'
import
PageFooter
from
'./components/page-footer'
...
@@ -15,6 +17,7 @@ const GamePlay = () => {
...
@@ -15,6 +17,7 @@ const GamePlay = () => {
const
currentQuestion
=
useStoreState
(
states
=>
states
.
gameModel
.
currentQuestion
)
const
currentQuestion
=
useStoreState
(
states
=>
states
.
gameModel
.
currentQuestion
)
const
getQuestionList
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
getQuestionList
)
const
getQuestionList
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
getQuestionList
)
const
stageDetail
=
useStoreState
(
state
=>
state
.
gameModel
.
stageDetail
)
const
stageDetail
=
useStoreState
(
state
=>
state
.
gameModel
.
stageDetail
)
const
[
val
,
actions
]
=
useBoolean
(
false
)
const
router
=
useRouter
<
{
id
:
string
}
>
()
const
router
=
useRouter
<
{
id
:
string
}
>
()
...
@@ -34,6 +37,7 @@ const GamePlay = () => {
...
@@ -34,6 +37,7 @@ const GamePlay = () => {
{
currentQuestion
&&
(
{
currentQuestion
&&
(
<
Question
question=
{
currentQuestion
}
/>
<
Question
question=
{
currentQuestion
}
/>
)
}
)
}
<
Button
onClick=
{
actions
.
toggle
}
>
23xxxxx4
</
Button
>
</
ScrollView
>
</
ScrollView
>
{
currentQuestion
&&
(
{
currentQuestion
&&
(
<>
<>
...
@@ -43,6 +47,7 @@ const GamePlay = () => {
...
@@ -43,6 +47,7 @@ const GamePlay = () => {
<
PageFooter
/>
<
PageFooter
/>
</>
</>
)
}
)
}
<
ModalContinue
closeOnClickModal
onClose=
{
actions
.
setFalse
}
/>
</
View
>
</
View
>
)
)
}
}
...
...
src/pages/game/play/model/index.ts
View file @
53db40e7
import
{
action
,
Action
,
computed
,
Computed
,
State
,
Thunk
,
thunk
}
from
'easy-peasy'
import
{
action
,
Action
,
computed
,
Computed
,
State
,
Thunk
,
thunk
}
from
'easy-peasy'
import
{
AppStoreModel
}
from
'@/store/store-model'
import
{
AppStoreModel
}
from
'@/store/store-model'
import
{
getQuestionList
,
type
StageDetail
,
getStageDetail
,
completeStage
}
from
'@/api'
import
{
getQuestionList
,
type
StageDetail
,
getStageDetail
,
completeStage
,
StageType
}
from
'@/api'
import
{
showLoading
,
hideLoading
,
showModal
}
from
'@tarojs/taro'
import
{
showLoading
,
hideLoading
,
showModal
}
from
'@tarojs/taro'
import
{
import
{
QuestionType
,
QuestionType
,
...
@@ -8,7 +8,7 @@ import {
...
@@ -8,7 +8,7 @@ import {
isSelectionQuestion
,
isSelectionQuestion
,
// QuestionOption,
// QuestionOption,
}
from
'../types'
}
from
'../types'
import
{
buildCompleteStageParam
}
from
'./utils'
import
{
buildCompleteStageParam
,
convertQuestion
,
determinQuestion
}
from
'./utils'
// import questionListJson from './test.json'
// import questionListJson from './test.json'
...
@@ -46,11 +46,14 @@ export interface GameModel {
...
@@ -46,11 +46,14 @@ export interface GameModel {
handleGoNext
:
Thunk
<
GameModel
,
void
,
void
,
AppStoreModel
>
;
handleGoNext
:
Thunk
<
GameModel
,
void
,
void
,
AppStoreModel
>
;
isSubmit
:
boolean
;
isSubmit
:
boolean
;
modalContinueVisible
:
boolean
;
submit
:
Thunk
<
GameModel
,
void
,
void
,
AppStoreModel
>
;
submit
:
Thunk
<
GameModel
,
void
,
void
,
AppStoreModel
>
;
}
}
const
gameModel
:
GameModel
=
{
const
gameModel
:
GameModel
=
{
questionList
:
[],
questionList
:
[],
modalContinueVisible
:
true
,
gameStartTime
:
0
,
gameStartTime
:
0
,
isSubmit
:
false
,
isSubmit
:
false
,
...
@@ -103,7 +106,7 @@ const gameModel: GameModel = {
...
@@ -103,7 +106,7 @@ const gameModel: GameModel = {
const
answers
=
state
.
questionList
[
state
.
currentQuestionIndex
]?.
answers
const
answers
=
state
.
questionList
[
state
.
currentQuestionIndex
]?.
answers
const
val
=
answers
?.[
index
]
const
val
=
answers
?.[
index
]
if
(
answers
&&
val
)
{
if
(
answers
&&
val
)
{
val
.
userAnswer
=
`
${
val
.
userAnswer
||
''
}${
char
}
`
val
.
userAnswer
=
`
${
val
.
userAnswer
===
'0'
?
''
:
(
val
.
userAnswer
||
''
)
}${
char
}
`
const
maxLen
=
answers
.
length
const
maxLen
=
answers
.
length
state
.
questionList
=
state
.
questionList
.
slice
()
state
.
questionList
=
state
.
questionList
.
slice
()
if
(
answers
.
length
>
1
&&
index
<
maxLen
-
1
)
{
if
(
answers
.
length
>
1
&&
index
<
maxLen
-
1
)
{
...
@@ -138,7 +141,7 @@ const gameModel: GameModel = {
...
@@ -138,7 +141,7 @@ const gameModel: GameModel = {
}),
}),
handleGoNext
:
thunk
(
async
(
actions
,
_
,
helpers
)
=>
{
handleGoNext
:
thunk
(
async
(
actions
,
_
,
helpers
)
=>
{
const
{
canGoNext
,
currentQuestionIndex
,
questionList
}
=
helpers
.
getState
()
const
{
canGoNext
,
currentQuestionIndex
,
questionList
,
stageDetail
,
currentQuestion
}
=
helpers
.
getState
()
if
(
!
canGoNext
)
return
if
(
!
canGoNext
)
return
if
(
questionList
.
length
===
currentQuestionIndex
+
1
)
{
if
(
questionList
.
length
===
currentQuestionIndex
+
1
)
{
console
.
log
(
'submit'
)
console
.
log
(
'submit'
)
...
@@ -146,6 +149,15 @@ const gameModel: GameModel = {
...
@@ -146,6 +149,15 @@ const gameModel: GameModel = {
return
return
}
}
if
(
stageDetail
?.
type
===
StageType
.
OneStop
)
{
if
(
currentQuestion
&&
!
determinQuestion
(
currentQuestion
))
{
actions
.
updateState
({
modalContinueVisible
:
true
,
})
return
}
}
actions
.
updateCurrentIndex
(
currentQuestionIndex
+
1
)
actions
.
updateCurrentIndex
(
currentQuestionIndex
+
1
)
}),
}),
...
@@ -157,7 +169,7 @@ const gameModel: GameModel = {
...
@@ -157,7 +169,7 @@ const gameModel: GameModel = {
getStageDetail
(
round
)
getStageDetail
(
round
)
])
])
actions
.
updateState
({
actions
.
updateState
({
questionList
,
questionList
:
questionList
.
map
(
convertQuestion
)
,
stageDetail
,
stageDetail
,
gameStartTime
:
Date
.
now
(),
gameStartTime
:
Date
.
now
(),
})
})
...
...
src/pages/game/play/model/utils.ts
View file @
53db40e7
import
{
type
CompleteStageParam
,
type
StageDetail
,
StageLevel
,
type
CompleteQuestion
}
from
'@/api'
import
{
type
CompleteStageParam
,
type
StageDetail
,
StageLevel
,
type
CompleteQuestion
}
from
'@/api'
import
{
type
QuestionType
,
isBlankQuestion
,
isVerticalDivisionQuestion
,
isSelectionQuestion
}
from
'../types'
import
{
type
QuestionType
,
isBlankQuestion
,
isVerticalDivisionQuestion
,
isSelectionQuestion
}
from
'../types'
export
function
convertQuestion
(
question
:
QuestionType
):
QuestionType
{
if
(
isVerticalDivisionQuestion
(
question
))
{
const
{
questionItems
}
=
question
const
dividend
=
+
questionItems
[
0
].
contentText
const
divisor
=
+
questionItems
[
1
].
contentText
const
val
=
Math
.
floor
(
dividend
/
divisor
)
const
text
=
`
${(
val
*
divisor
)}
`
.
split
(
''
)
const
remainder
=
dividend
%
divisor
return
{
...
question
,
answers
:
[
{
contentText
:
`
${
val
}
`
,
sort
:
0
,
},
...
text
.
map
((
t
,
index
)
=>
({
contentText
:
t
,
sort
:
index
+
1
,
})),
{
contentText
:
`
${
remainder
}
`
,
sort
:
text
.
length
+
1
,
},
]
}
}
return
question
}
export
function
buildCompleteStageParam
(
questionList
:
QuestionType
[],
stageDetail
:
StageDetail
,
gameStartTime
:
number
):
CompleteStageParam
{
export
function
buildCompleteStageParam
(
questionList
:
QuestionType
[],
stageDetail
:
StageDetail
,
gameStartTime
:
number
):
CompleteStageParam
{
const
correctNum
=
questionList
.
map
(
c
=>
determinQuestion
(
c
)).
filter
(
Boolean
).
length
const
correctNum
=
questionList
.
map
(
c
=>
determinQuestion
(
c
)).
filter
(
Boolean
).
length
...
@@ -58,7 +92,7 @@ function convert (inQuestion: QuestionType): CompleteQuestion {
...
@@ -58,7 +92,7 @@ function convert (inQuestion: QuestionType): CompleteQuestion {
}
}
/** 判题 */
/** 判题 */
function
determinQuestion
(
question
:
QuestionType
)
{
export
function
determinQuestion
(
question
:
QuestionType
)
{
if
(
isBlankQuestion
(
question
))
{
if
(
isBlankQuestion
(
question
))
{
return
question
.
answers
.
every
(
c
=>
c
.
userAnswer
===
c
.
contentText
)
return
question
.
answers
.
every
(
c
=>
c
.
userAnswer
===
c
.
contentText
)
}
}
...
...
src/pages/main/components/header.tsx
View file @
53db40e7
import
{
View
,
Text
,
Image
}
from
'@tarojs/components'
import
{
View
,
Text
,
Image
}
from
'@tarojs/components'
import
{
getMenuButtonBoundingClientRect
,
getSystemInfoSync
}
from
'@tarojs/taro'
import
{
getMenuButtonBoundingClientRect
,
getSystemInfoSync
}
from
'@tarojs/taro'
import
{
useMemo
,
useState
}
from
'react'
import
{
useMemo
,
useState
}
from
'react'
import
{
useStoreState
}
from
'@/store/hooks'
import
styles
from
'./header.module.scss'
import
styles
from
'./header.module.scss'
...
@@ -14,6 +15,9 @@ const MainHeader = () => {
...
@@ -14,6 +15,9 @@ const MainHeader = () => {
}
}
},
[
sys
,
nav
])
},
[
sys
,
nav
])
const
cardNum
=
useStoreState
(
state
=>
state
.
userModel
.
cardNum
)
const
point
=
useStoreState
(
state
=>
state
.
userModel
.
point
)
return
(
return
(
<
View
className=
{
styles
.
header
}
>
<
View
className=
{
styles
.
header
}
>
<
Image
src=
{
require
(
'../assets/head-bg.png'
)
}
className=
{
styles
.
bg
}
mode=
"widthFix"
></
Image
>
<
Image
src=
{
require
(
'../assets/head-bg.png'
)
}
className=
{
styles
.
bg
}
mode=
"widthFix"
></
Image
>
...
@@ -30,11 +34,11 @@ const MainHeader = () => {
...
@@ -30,11 +34,11 @@ const MainHeader = () => {
</
View
>
</
View
>
<
View
className=
{
styles
.
score
}
>
<
View
className=
{
styles
.
score
}
>
<
Image
src=
{
require
(
'../assets/score.png'
)
}
className=
{
styles
.
icon
}
/>
<
Image
src=
{
require
(
'../assets/score.png'
)
}
className=
{
styles
.
icon
}
/>
<
Text
>
271
</
Text
>
<
Text
>
{
point
}
</
Text
>
</
View
>
</
View
>
<
View
className=
{
styles
.
ph
}
>
<
View
className=
{
styles
.
ph
}
>
<
Image
src=
{
require
(
'../assets/ph.png'
)
}
className=
{
styles
.
icon
}
/>
<
Image
src=
{
require
(
'../assets/ph.png'
)
}
className=
{
styles
.
icon
}
/>
<
Text
>
10
</
Text
>
<
Text
>
{
cardNum
}
</
Text
>
</
View
>
</
View
>
</
View
>
</
View
>
</
View
>
</
View
>
...
...
src/pages/main/components/scene/stage.tsx
View file @
53db40e7
...
@@ -139,6 +139,12 @@ const StageComp = (props: StageProps) => {
...
@@ -139,6 +139,12 @@ const StageComp = (props: StageProps) => {
)
)
}
}
const
handleClick
=
()
=>
{
if
(
stage
.
status
!==
StageStatus
.
DISABLED
)
{
navigateTo
({
url
:
`/pages/game/play/index?id=
${
stage
.
id
}
`
})
}
}
return
(
return
(
<
SceneContext
.
Consumer
>
<
SceneContext
.
Consumer
>
{
({
ready
})
=>
(
{
({
ready
})
=>
(
...
@@ -146,7 +152,7 @@ const StageComp = (props: StageProps) => {
...
@@ -146,7 +152,7 @@ const StageComp = (props: StageProps) => {
className=
{
classNames
(
props
.
className
,
cs
.
bounce_btn
)
}
className=
{
classNames
(
props
.
className
,
cs
.
bounce_btn
)
}
hoverClass=
{
cs
.
bounce_btn_hover
}
hoverClass=
{
cs
.
bounce_btn_hover
}
id=
{
stage
.
status
===
StageStatus
.
CURRENT
?
CurrentRoundId
:
undefined
}
id=
{
stage
.
status
===
StageStatus
.
CURRENT
?
CurrentRoundId
:
undefined
}
onClick=
{
()
=>
navigateTo
({
url
:
`/pages/game/play/index?id=${stage.id}`
})
}
onClick=
{
handleClick
}
>
>
{
renderRound
(
ready
)
}
{
renderRound
(
ready
)
}
<
View
className=
{
styles
.
roundName
}
>
{
stage
.
name
}
</
View
>
<
View
className=
{
styles
.
roundName
}
>
{
stage
.
name
}
</
View
>
...
...
src/pages/main/main.tsx
View file @
53db40e7
...
@@ -15,8 +15,10 @@ const MainPage = () => {
...
@@ -15,8 +15,10 @@ const MainPage = () => {
const
[
isReady
,
setIsReady
]
=
useState
(
false
)
const
[
isReady
,
setIsReady
]
=
useState
(
false
)
const
fetchStage
=
useStoreActions
(
actions
=>
actions
.
mainModel
.
fetchStage
)
const
fetchStage
=
useStoreActions
(
actions
=>
actions
.
mainModel
.
fetchStage
)
const
stageList
=
useStoreState
(
state
=>
state
.
mainModel
.
stageList
)
const
stageList
=
useStoreState
(
state
=>
state
.
mainModel
.
stageList
)
const
fetchAccount
=
useStoreActions
(
actions
=>
actions
.
userModel
.
fetchAccount
)
useDidShow
(()
=>
{
useDidShow
(()
=>
{
fetchAccount
()
const
tabbar
=
getTabBar
(
page
)
as
any
const
tabbar
=
getTabBar
(
page
)
as
any
tabbar
?.
setSelected
(
0
)
tabbar
?.
setSelected
(
0
)
})
})
...
...
src/store/modules/user.ts
0 → 100644
View file @
53db40e7
import
{
action
,
Action
,
Thunk
,
thunk
}
from
'easy-peasy'
import
{
getAccountInfo
}
from
'@/api'
import
{
AppStoreModel
}
from
'../store-model'
export
interface
UserModel
{
cardNum
:
number
;
point
:
number
;
updateState
:
Action
<
UserModel
,
{
cardNum
:
number
;
point
:
number
}
>
;
fetchAccount
:
Thunk
<
UserModel
,
void
,
void
,
AppStoreModel
>
;
}
const
userModel
:
UserModel
=
{
cardNum
:
0
,
point
:
0
,
updateState
:
action
((
state
,
{
cardNum
,
point
})
=>
{
state
.
cardNum
=
cardNum
state
.
point
=
point
}),
fetchAccount
:
thunk
(
async
(
actions
)
=>
{
try
{
const
{
data
:
list
}
=
await
getAccountInfo
()
const
cardNum
=
list
.
find
(
c
=>
c
.
accountType
===
'CARD'
)?.
amount
??
0
const
point
=
list
.
find
(
c
=>
c
.
accountType
===
'POINT'
)?.
amount
??
0
actions
.
updateState
({
cardNum
,
point
})
}
catch
(
err
)
{
actions
.
updateState
({
cardNum
:
0
,
point
:
0
})
}
})
}
export
default
userModel
src/store/store-model.ts
View file @
53db40e7
...
@@ -3,6 +3,7 @@ import mainModel from '@/pages/main/model'
...
@@ -3,6 +3,7 @@ import mainModel from '@/pages/main/model'
import
cartModel
from
'./modules/cart'
import
cartModel
from
'./modules/cart'
import
counterModel
from
'./modules/counter'
import
counterModel
from
'./modules/counter'
import
prepareModel
from
'./modules/prepare'
import
prepareModel
from
'./modules/prepare'
import
userModel
from
'./modules/user'
const
appStoreModel
=
{
const
appStoreModel
=
{
cartModel
,
cartModel
,
...
@@ -10,6 +11,7 @@ const appStoreModel = {
...
@@ -10,6 +11,7 @@ const appStoreModel = {
prepareModel
,
prepareModel
,
gameModel
,
gameModel
,
mainModel
,
mainModel
,
userModel
}
}
export
default
appStoreModel
export
default
appStoreModel
...
...
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