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
a8d1dc29
Commit
a8d1dc29
authored
Mar 31, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 题目
parent
6676d379
Show whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
590 additions
and
216 deletions
+590
-216
auth.ts
src/api/auth.ts
+8
-7
game.ts
src/api/game.ts
+53
-0
index.ts
src/api/index.ts
+1
-0
app.tsx
src/app.tsx
+3
-0
skynet.ts
src/config/skynet.ts
+1
-1
page-head.tsx
src/pages/game/play/components/page-head.tsx
+0
-1
question-blank.module.scss
.../game/play/components/question/question-blank.module.scss
+8
-1
question-blank.tsx
src/pages/game/play/components/question/question-blank.tsx
+2
-0
question-vertical-division.module.scss
...omponents/question/question-vertical-division.module.scss
+5
-1
question-vertical-division.tsx
...e/play/components/question/question-vertical-division.tsx
+1
-1
index.tsx
src/pages/game/play/index.tsx
+16
-1
index.ts
src/pages/game/play/model/index.ts
+14
-7
test-4.json
src/pages/game/play/model/test-4.json
+278
-0
test.json
src/pages/game/play/model/test.json
+68
-0
constants.ts
src/pages/main/components/scene/constants.ts
+6
-25
index.tsx
src/pages/main/components/scene/index.tsx
+27
-108
part.tsx
src/pages/main/components/scene/part.tsx
+4
-6
small-part.tsx
src/pages/main/components/scene/small-part.tsx
+2
-2
stage-tag.tsx
src/pages/main/components/scene/stage-tag.tsx
+3
-3
stage.module.scss
src/pages/main/components/scene/stage.module.scss
+0
-0
stage.tsx
src/pages/main/components/scene/stage.tsx
+45
-45
main.tsx
src/pages/main/main.tsx
+7
-2
model.ts
src/pages/main/model.ts
+28
-0
store-model.ts
src/store/store-model.ts
+2
-0
silent-login.ts
src/utils/silent-login.ts
+8
-5
No files found.
src/api/auth.ts
View file @
a8d1dc29
import
{
request
}
from
'@/utils/request'
import
{
request
,
requestAfterSilentLogin
}
from
'@/utils/request'
import
{
getStorage
,
StorageKeys
}
from
'@/utils/storage'
import
qs
from
'qs'
type
LoginResult
=
{
...
...
@@ -12,17 +13,17 @@ type LoginResult = {
/** 登录token */
token
:
string
;
/** 用户ID */
i
d
:
number
;
userI
d
:
number
;
/** */
unionId
:
string
;
}
/** 静默登录 */
export
function
silentLoginApi
(
code
:
string
,
recommendId
:
string
)
{
return
request
<
LoginResult
,
{
code
:
string
,
recommendId
:
string
,
}
>
({
method
:
'
POS
T'
,
url
:
'/service-
activity-pbl/user/l
ogin'
,
data
:
{
code
,
recommendId
}
export
function
silentLoginApi
(
code
:
string
)
{
return
request
<
LoginResult
,
{
code
:
string
}
>
({
method
:
'
GE
T'
,
url
:
'/service-
idea/stage/user/userL
ogin'
,
data
:
{
code
}
})
}
...
...
src/api/game.ts
0 → 100644
View file @
a8d1dc29
import
{
requestAfterSilentLogin
}
from
'@/utils/request'
import
{
getStorage
,
StorageKeys
}
from
'@/utils/storage'
import
{
type
QuestionType
}
from
'@/pages/game/play/types'
export
const
getQuestionList
=
(
stageId
:
number
)
=>
{
return
requestAfterSilentLogin
<
QuestionType
[],
{
stageId
:
number
,
userId
?:
number
}
>
({
url
:
'/service-idea/stage/startStage'
,
method
:
'GET'
,
data
:
{
stageId
,
userId
:
getStorage
(
StorageKeys
.
userInfo
)?.
userId
}
})
}
export
const
enum
StageStatus
{
CURRENT
=
'CURRENT'
,
DISABLED
=
'DISABLED'
,
PASSED
=
'PASSED'
,
}
export
const
enum
StageType
{
Strong
=
'强化'
,
Enhance
=
'应用'
,
OneStop
=
'一站到底'
,
}
export
const
enum
StageLevel
{
S
=
'S'
,
A
=
'A'
,
B
=
'B'
}
export
type
Stage
=
{
content
:
string
;
gear
:
number
;
id
:
number
;
label
:
string
;
level
:
StageLevel
;
name
:
string
;
stageLabel
:
string
;
status
?:
StageStatus
;
type
?:
StageType
;
upGear
:
boolean
;
part
?:
number
;
}
/** 获取关卡列表 */
export
function
getStageList
()
{
return
requestAfterSilentLogin
<
Stage
[],
{
chapter
:
number
;
userId
?:
number
}
>
({
method
:
'GET'
,
url
:
'/service-idea/stage/listStages'
,
data
:
{
chapter
:
1
,
userId
:
getStorage
(
StorageKeys
.
userInfo
)?.
userId
}
})
}
src/api/index.ts
View file @
a8d1dc29
export
*
from
'./auth'
export
*
from
'./game'
src/app.tsx
View file @
a8d1dc29
...
...
@@ -2,6 +2,7 @@ import { Component, PropsWithChildren } from 'react'
import
{
StoreProvider
}
from
'easy-peasy'
import
{
getUpdateManager
,
showModal
}
from
'@tarojs/taro'
import
{
configSkynet
}
from
'@/utils/skynet'
import
{
silentLogin
}
from
'@/utils/silent-login'
import
store
from
'./store'
...
...
@@ -44,6 +45,8 @@ class App extends Component<PropsWithChildren> {
showCancel
:
false
})
}
silentLogin
()
}
componentDidHide
()
{}
...
...
src/config/skynet.ts
View file @
a8d1dc29
import
{
baseUrl
}
from
'./server'
const
_baseUrl
=
process
.
env
.
SERVER_ENDPOINT
===
'https://geek.jkwljy.com'
?
baseUrl
:
'http://172.10.6
2
.134'
const
_baseUrl
=
process
.
env
.
SERVER_ENDPOINT
===
'https://geek.jkwljy.com'
?
baseUrl
:
'http://172.10.6
1
.134'
export
const
SkynetConfig
=
{
appId
:
'learn-math'
,
...
...
src/pages/game/play/components/page-head.tsx
View file @
a8d1dc29
...
...
@@ -9,7 +9,6 @@ const PageHead = () => {
const
[
nav
]
=
useState
(
getMenuButtonBoundingClientRect
())
const
questionList
=
useStoreState
(
states
=>
states
.
gameModel
.
questionList
)
const
currentQuestionIndex
=
useStoreState
(
states
=>
states
.
gameModel
.
currentQuestionIndex
)
console
.
log
(
'rr'
)
return
(
<
View
className=
{
styles
.
header
}
>
...
...
src/pages/game/play/components/question/question-blank.module.scss
View file @
a8d1dc29
...
...
@@ -14,6 +14,13 @@
display
:
flex
;
line-height
:
112px
;
align-items
:
center
;
justify-content
:
center
;
flex-direction
:
column
;
.top
{
flex
:
2
;
}
.bottom
{
flex
:
4
;
}
}
}
src/pages/game/play/components/question/question-blank.tsx
View file @
a8d1dc29
...
...
@@ -21,9 +21,11 @@ const QuestionBlank = (props: QuestionBlankProps) => {
return
(
<
View
className=
{
classNames
(
styles
.
content
,
question
.
simpleType
&&
styles
.
is_sample
)
}
>
<
View
className=
{
styles
.
top
}
></
View
>
<
View
>
{
tree
.
map
(
item
=>
renderRichText
(
item
))
}
</
View
>
<
View
className=
{
styles
.
bottom
}
></
View
>
</
View
>
)
}
...
...
src/pages/game/play/components/question/question-vertical-division.module.scss
View file @
a8d1dc29
...
...
@@ -7,7 +7,11 @@
}
.gap
{
flex
:
1
;
flex
:
2
;
}
.gap_2
{
flex
:
3
;
}
.top
{
...
...
src/pages/game/play/components/question/question-vertical-division.tsx
View file @
a8d1dc29
...
...
@@ -43,7 +43,7 @@ const QuestionVerticalDivision = (props: QuestionSelectionProps) => {
<
View
className=
{
styles
.
footer
}
>
<
AnswerBlank
index=
{
3
}
></
AnswerBlank
>
</
View
>
<
View
className=
{
styles
.
gap
}
></
View
>
<
View
className=
{
styles
.
gap
_2
}
></
View
>
</
View
>
)
}
...
...
src/pages/game/play/index.tsx
View file @
a8d1dc29
import
{
View
,
ScrollView
}
from
'@tarojs/components'
import
{
useStoreState
}
from
'@/store/hooks'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
import
{
useEffect
}
from
'react'
import
{
useRouter
}
from
'@tarojs/taro'
import
PageHead
from
'./components/page-head'
import
PageFooter
from
'./components/page-footer'
...
...
@@ -11,11 +13,22 @@ import styles from './index.module.scss'
const
GamePlay
=
()
=>
{
const
currentQuestion
=
useStoreState
(
states
=>
states
.
gameModel
.
currentQuestion
)
const
getQuestionList
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
getQuestionList
)
const
router
=
useRouter
<
{
id
:
string
}
>
()
useEffect
(()
=>
{
getQuestionList
(
+
router
.
params
.
id
)
},
[
router
,
getQuestionList
])
return
(
<
View
className=
{
styles
.
viewport
}
>
{
currentQuestion
&&
(
<>
<
PageHead
/>
<
CountUp
/>
</>
)
}
<
ScrollView
className=
{
styles
.
body
}
scrollY
>
{
currentQuestion
&&
(
<
Question
question=
{
currentQuestion
}
/>
...
...
@@ -24,7 +37,9 @@ const GamePlay = () => {
{
currentQuestion
?.
questionType
!==
'选择题'
&&
(
<
NumberKeyboard
/>
)
}
{
currentQuestion
&&
(
<
PageFooter
/>
)
}
</
View
>
)
}
...
...
src/pages/game/play/model/index.ts
View file @
a8d1dc29
import
{
action
,
Action
,
computed
,
Computed
,
Thunk
,
thunk
}
from
'easy-peasy'
import
{
AppStoreModel
}
from
'@/store/store-model'
import
{
getQuestionList
}
from
'@/api'
import
{
showLoading
,
hideLoading
}
from
'@tarojs/taro'
import
{
QuestionType
,
QuestionAnswer
,
isSelectionQuestion
,
QuestionOption
,
//
QuestionOption,
}
from
'../types'
import
questionListJson
from
'./test.json'
//
import questionListJson from './test.json'
export
interface
GameModel
{
/** 题目列表 */
...
...
@@ -41,7 +43,7 @@ export interface GameModel {
}
const
gameModel
:
GameModel
=
{
questionList
:
questionListJson
as
QuestionType
[],
questionList
:
[],
currentInputIndex
:
0
,
currentQuestionIndex
:
0
,
updateCurrentInputIndex
:
action
((
state
,
num
)
=>
{
...
...
@@ -118,8 +120,7 @@ const gameModel: GameModel = {
handleGoNext
:
thunk
(
async
(
actions
,
_
,
helpers
)
=>
{
const
{
canGoNext
,
currentQuestionIndex
,
questionList
}
=
helpers
.
getState
()
if
(
!
canGoNext
)
return
const
len
=
questionList
.
length
if
(
len
===
currentQuestionIndex
+
1
)
{
if
(
questionList
.
length
===
currentQuestionIndex
+
1
)
{
console
.
log
(
'submit'
)
return
}
...
...
@@ -127,10 +128,16 @@ const gameModel: GameModel = {
actions
.
updateCurrentIndex
(
currentQuestionIndex
+
1
)
}),
getQuestionList
:
thunk
(
async
(
actions
,
round
,
helpers
)
=>
{
getQuestionList
:
thunk
(
async
(
actions
,
round
)
=>
{
try
{
showLoading
()
const
{
data
:
questionList
}
=
await
getQuestionList
(
round
)
actions
.
updateList
(
questionList
)
}
catch
(
err
)
{
actions
.
updateList
([])
}
catch
(
err
)
{}
}
finally
{
hideLoading
()
}
}),
}
...
...
src/pages/game/play/model/test-4.json
0 → 100644
View file @
a8d1dc29
[
{
"answers"
:
[
{
"contentText"
:
"69"
,
"sort"
:
0
}
],
"contentText"
:
"28<MathSymbol value=
\"
+
\"
/>41<MathSymbol value=
\"
=
\"
/><AnswerBlank index=
\"
0
\"
/>"
,
"questionItems"
:
[
{
"contentText"
:
"28"
,
"sort"
:
0
},
{
"contentText"
:
"41"
,
"sort"
:
1
},
{
"contentText"
:
"69"
,
"sort"
:
2
}
],
"questionType"
:
"随机填空"
,
"simpleType"
:
true
,
"sort"
:
11
},
{
"answers"
:
[
{
"contentText"
:
"44"
,
"sort"
:
0
}
],
"contentText"
:
"30元钱可以买<AnswerBlank index=
\"
0
\"
/>元笔记本74本"
,
"questionItems"
:
[
{
"contentText"
:
"30"
,
"sort"
:
0
},
{
"contentText"
:
"44"
,
"sort"
:
1
},
{
"contentText"
:
"74"
,
"sort"
:
2
}
],
"questionType"
:
"随机填空"
,
"simpleType"
:
false
,
"sort"
:
13
},
{
"answers"
:
[
{
"contentText"
:
"C"
,
"sort"
:
1
}
],
"contentText"
:
"爸爸把一盘糖果的一半给了弟弟,把剩下的糖果给了一半给姐姐,这时盘里还剩8块,请问盘里原来有几块糖?"
,
"options"
:
[
{
"answer"
:
false
,
"contentText"
:
"16块"
,
"index"
:
"A"
},
{
"answer"
:
false
,
"contentText"
:
"24块"
,
"index"
:
"B"
},
{
"answer"
:
true
,
"contentText"
:
"32块"
,
"index"
:
"C"
},
{
"answer"
:
false
,
"contentText"
:
"64块"
,
"index"
:
"D"
}
],
"questionType"
:
"选择题"
,
"simpleType"
:
false
,
"sort"
:
28
},
{
"answers"
:
[
{
"contentText"
:
"35"
,
"sort"
:
0
}
],
"contentText"
:
"22<MathSymbol value=
\"
+
\"
/>13<MathSymbol value=
\"
=
\"
/><AnswerBlank index=
\"
0
\"
/>"
,
"questionItems"
:
[
{
"contentText"
:
"22"
,
"sort"
:
0
},
{
"contentText"
:
"13"
,
"sort"
:
1
},
{
"contentText"
:
"35"
,
"sort"
:
2
}
],
"questionType"
:
"随机填空"
,
"simpleType"
:
true
,
"sort"
:
49
},
{
"answers"
:
[
{
"contentText"
:
"59"
,
"sort"
:
0
}
],
"contentText"
:
"43元钱可以买16元笔记本<AnswerBlank index=
\"
0
\"
/>本"
,
"questionItems"
:
[
{
"contentText"
:
"43"
,
"sort"
:
0
},
{
"contentText"
:
"16"
,
"sort"
:
1
},
{
"contentText"
:
"59"
,
"sort"
:
2
}
],
"questionType"
:
"随机填空"
,
"simpleType"
:
false
,
"sort"
:
51
},
{
"answers"
:
[
{
"contentText"
:
"13"
,
"sort"
:
0
}
],
"contentText"
:
"<AnswerBlank index=
\"
0
\"
/>元钱可以买21元笔记本34本"
,
"questionItems"
:
[
{
"contentText"
:
"13"
,
"sort"
:
0
},
{
"contentText"
:
"21"
,
"sort"
:
1
},
{
"contentText"
:
"34"
,
"sort"
:
2
}
],
"questionType"
:
"随机填空"
,
"simpleType"
:
false
,
"sort"
:
82
},
{
"answers"
:
[
{
"contentText"
:
"45"
,
"sort"
:
0
}
],
"contentText"
:
"33<MathSymbol value=
\"
+
\"
/>12<MathSymbol value=
\"
=
\"
/><AnswerBlank index=
\"
0
\"
/>"
,
"questionItems"
:
[
{
"contentText"
:
"33"
,
"sort"
:
0
},
{
"contentText"
:
"12"
,
"sort"
:
1
},
{
"contentText"
:
"45"
,
"sort"
:
2
}
],
"questionType"
:
"随机填空"
,
"simpleType"
:
true
,
"sort"
:
83
},
{
"answers"
:
[
{
"contentText"
:
"20"
,
"sort"
:
0
}
],
"contentText"
:
"8<MathSymbol value=
\"
+
\"
/>12<MathSymbol value=
\"
=
\"
/><AnswerBlank index=
\"
0
\"
/>"
,
"questionItems"
:
[
{
"contentText"
:
"8"
,
"sort"
:
0
},
{
"contentText"
:
"12"
,
"sort"
:
1
},
{
"contentText"
:
"20"
,
"sort"
:
2
}
],
"questionType"
:
"随机填空"
,
"simpleType"
:
true
,
"sort"
:
92
},
{
"answers"
:
[
{
"contentText"
:
"18"
,
"sort"
:
0
}
],
"contentText"
:
"7<MathSymbol value=
\"
+
\"
/>11<MathSymbol value=
\"
=
\"
/><AnswerBlank index=
\"
0
\"
/>"
,
"questionItems"
:
[
{
"contentText"
:
"7"
,
"sort"
:
0
},
{
"contentText"
:
"11"
,
"sort"
:
1
},
{
"contentText"
:
"18"
,
"sort"
:
2
}
],
"questionType"
:
"随机填空"
,
"simpleType"
:
true
,
"sort"
:
95
},
{
"answers"
:
[
{
"contentText"
:
"C"
,
"sort"
:
1
}
],
"contentText"
:
"《钢铁是怎样炼成的》是前苏联作家奥斯特洛夫斯基的自传体小说,小说的主人公是()?"
,
"options"
:
[
{
"answer"
:
false
,
"contentText"
:
"格列佛"
,
"index"
:
"A"
},
{
"answer"
:
false
,
"contentText"
:
"汤姆·索亚"
,
"index"
:
"B"
},
{
"answer"
:
true
,
"contentText"
:
"保尔·柯察金"
,
"index"
:
"C"
},
{
"answer"
:
false
,
"contentText"
:
"海伦"
,
"index"
:
"D"
}
],
"questionType"
:
"选择题"
,
"simpleType"
:
false
,
"sort"
:
98
}
]
src/pages/game/play/model/test.json
View file @
a8d1dc29
...
...
@@ -32,6 +32,74 @@
"questionType"
:
"选择题"
,
"simpleType"
:
false
},
{
"contentText"
:
"<p>某班50名学生在一次百米测试中,成绩全部介于13秒与19秒之间,将测试结果分成六组,得到频率分布直方图(如图).设成绩小于16秒的学生人数占全班总人数的百分比为<i>x</i>,成绩大于等于15秒且小于17秒的学生人数为<i>y</i>,则从频率分布直方图中可分析出<i>x</i>和<i>y</i>分别为( )</p><p><img src=
\"
https://profile-1257124244.cos.ap-chengdu.myqcloud.com/question/image/943c1ee2-ed62-42d7-b381-d0e3d31677a7.png
\"
style=
\"
max-width:90vw;max-height:62.005104vw
\"
alt=
\"\"
width=
\"
202.90031
\"
height=
\"
139.78728
\"
></p>"
,
"options"
:
[
{
"contentText"
:
"<p>0.56,35</p>"
,
"answer"
:
true
,
"index"
:
"A"
},
{
"contentText"
:
"<p>0.56,45</p>"
,
"answer"
:
false
,
"index"
:
"B"
},
{
"contentText"
:
"<p>0.44,35</p>"
,
"answer"
:
false
,
"index"
:
"C"
},
{
"contentText"
:
"<p>0.44,45</p>"
,
"answer"
:
false
,
"index"
:
"D"
}
],
"answers"
:
[
{
"contentText"
:
"C"
,
"sort"
:
1
}
],
"questionType"
:
"选择题"
,
"simpleType"
:
false
,
"sort"
:
98
},
{
"answers"
:
[
{
"contentText"
:
"C"
,
"sort"
:
1
}
],
"contentText"
:
"《钢铁是怎样炼成的》是前苏联作家奥斯特洛夫斯基的自传体小说,小说的主人公是()?"
,
"options"
:
[
{
"answer"
:
false
,
"contentText"
:
"格列佛"
,
"index"
:
"A"
},
{
"answer"
:
false
,
"contentText"
:
"汤姆·索亚"
,
"index"
:
"B"
},
{
"answer"
:
true
,
"contentText"
:
"保尔·柯察金"
,
"index"
:
"C"
},
{
"answer"
:
false
,
"contentText"
:
"海伦"
,
"index"
:
"D"
}
],
"questionType"
:
"选择题"
,
"simpleType"
:
false
,
"sort"
:
98
},
{
"answers"
:
[
{
...
...
src/pages/main/components/scene/constants.ts
View file @
a8d1dc29
import
assets
from
'@/assets/oss/assets-main'
import
{
createContext
}
from
'react'
import
{
type
Stage
,
StageStatus
,
StageLevel
,
StageType
}
from
'@/api'
export
const
SceneContext
=
createContext
<
{
ready
:
boolean
}
>
({
ready
:
false
})
...
...
@@ -29,6 +30,8 @@ const NomalPartBgPool = [
assets
[
'round-center-6.png'
],
]
export
{
StageStatus
,
StageLevel
,
Stage
,
StageType
}
export
const
CurrentRoundId
=
'__current_round__'
export
const
getSmallPartBg
=
(
index
:
number
,
type
:
'even'
|
'odd'
|
'special'
):
ImageSource
=>
{
...
...
@@ -49,7 +52,7 @@ let evenIndex = 0
let
oddIndex
=
0
let
specialIndex
=
0
export
function
groupRoundToSmallPart
(
list
:
Round
[]):
SmallPart
[]
{
export
function
groupRoundToSmallPart
(
list
:
Stage
[]):
SmallPart
[]
{
const
ret
:
SmallPart
[]
=
[]
let
flag
:
'even'
|
'odd'
=
'even'
...
...
@@ -102,37 +105,15 @@ export const enum RoundState {
UnLocked
=
3
}
export
const
enum
RoundType
{
Strong
=
'Strong'
,
Enhance
=
'Enhance'
,
OneStop
=
'OneStop'
,
}
export
const
enum
RoundScore
{
S
=
'S'
,
A
=
'A'
,
B
=
'B'
}
export
type
Round
=
{
state
?:
RoundState
;
score
?:
RoundScore
;
type
?:
RoundType
;
id
:
number
;
name
?:
string
;
tag
?:
string
;
upBonus
?:
boolean
;
}
export
type
SmallPart
=
{
rounds
:
Round
[];
rounds
:
Stage
[];
bg
:
ImageSource
;
offset
:
number
;
type
:
'odd'
|
'even'
|
'special'
;
}
export
type
Part
=
{
rounds
:
Round
[];
stages
:
Stage
[];
number
:
number
;
}
...
...
src/pages/main/components/scene/index.tsx
View file @
a8d1dc29
import
{
View
}
from
'@tarojs/components'
import
assets
from
'@/assets/oss/assets-main'
import
{
useMemo
}
from
'react'
import
LazeImage
from
'../lazy-image'
import
{
Part
,
RoundScore
,
RoundState
,
RoundTyp
e
}
from
'./constants'
import
{
Part
,
Stag
e
}
from
'./constants'
import
ScenePart
from
'./part'
import
styles
from
'./scene.module.scss'
type
SceneProps
=
{
stageList
:
Stage
[];
}
const
dataList
:
Part
[]
=
[
{
rounds
:
[
{
state
:
RoundState
.
Clear
,
type
:
RoundType
.
Strong
,
score
:
RoundScore
.
S
,
name
:
'计算达标1'
,
tag
:
'top10'
,
id
:
1
,
},
{
state
:
RoundState
.
Clear
,
type
:
RoundType
.
Enhance
,
score
:
RoundScore
.
A
,
upBonus
:
true
,
tag
:
'top20'
,
name
:
'应用过关1'
,
id
:
2
,
},
{
state
:
RoundState
.
Clear
,
type
:
RoundType
.
Enhance
,
score
:
RoundScore
.
S
,
tag
:
'top30'
,
name
:
'应用过关2'
,
id
:
3
,
},
{
state
:
RoundState
.
Clear
,
type
:
RoundType
.
Strong
,
score
:
RoundScore
.
A
,
upBonus
:
true
,
tag
:
'topn'
,
name
:
'计算达标3'
,
id
:
4
,
},
{
state
:
RoundState
.
Clear
,
type
:
RoundType
.
OneStop
,
score
:
RoundScore
.
B
,
name
:
'一站到底1'
,
id
:
5
,
}
],
number
:
0
},
{
rounds
:
[
{
id
:
6
,
state
:
RoundState
.
Clear
,
type
:
RoundType
.
Enhance
,
name
:
'计算达标1'
,
score
:
RoundScore
.
A
,
},
{
id
:
7
,
state
:
RoundState
.
Clear
,
type
:
RoundType
.
Strong
,
score
:
RoundScore
.
S
,
tag
:
'top20'
,
name
:
'计算达标1'
,
},
{
id
:
8
,
state
:
RoundState
.
Clear
,
type
:
RoundType
.
OneStop
,
score
:
RoundScore
.
S
,
tag
:
'top10'
,
name
:
'计算达标1'
,
},
{
id
:
9
,
state
:
RoundState
.
Clear
,
type
:
RoundType
.
Enhance
,
score
:
RoundScore
.
A
,
name
:
'计算达标1'
,
function
toPart
(
stageList
:
Stage
[]):
Part
[]
{
const
ret
:
Part
[]
=
[]
stageList
.
forEach
(
item
=>
{
const
last
=
ret
.
find
(
c
=>
c
.
number
===
(
item
.
part
||
0
))
if
(
last
)
{
last
.
stages
.
push
(
item
)
}
else
{
ret
.
push
({
number
:
item
.
part
??
0
,
stages
:
[
item
]
})
}
],
number
:
1
},
{
rounds
:
[
{
id
:
10
,
type
:
RoundType
.
Enhance
,
state
:
RoundState
.
UnLocked
,
name
:
'计算达标1'
},
{
id
:
11
},
{
id
:
12
,
type
:
RoundType
.
OneStop
,
},
{
id
:
13
,
type
:
RoundType
.
Enhance
,
},
{
id
:
14
},
{
id
:
15
,
type
:
RoundType
.
Enhance
,
}
],
number
:
2
},
{
rounds
:
[{
id
:
16
,
type
:
RoundType
.
Enhance
,
},
{
id
:
17
},
{
id
:
18
,
type
:
RoundType
.
OneStop
}],
number
:
3
},
{
rounds
:
[{
id
:
19
},
{
id
:
20
,
type
:
RoundType
.
OneStop
},
{
id
:
21
},
{
id
:
22
,
type
:
RoundType
.
Enhance
},
{
id
:
23
,
type
:
RoundType
.
OneStop
},
{
id
:
24
},
{
id
:
25
}],
number
:
4
},
]
})
return
ret
}
const
Scene
=
(
props
:
SceneProps
)
=>
{
const
partList
=
useMemo
(()
=>
{
return
toPart
(
props
.
stageList
)
},
[
props
.
stageList
])
const
Scene
=
()
=>
{
return
(
<
View
>
{
data
List
.
map
(
item
=>
{
{
part
List
.
map
(
item
=>
{
return
(
<
ScenePart
part=
{
item
}
key=
{
item
.
number
}
/>
)
...
...
src/pages/main/components/scene/part.tsx
View file @
a8d1dc29
...
...
@@ -19,19 +19,17 @@ const ScenePart = (props: ScenePartProps) => {
},
[
part
.
number
])
const
smallParts
=
useMemo
(()
=>
{
return
groupRoundToSmallPart
(
part
.
round
s
)
},
[
part
])
return
groupRoundToSmallPart
(
part
.
stage
s
)
},
[
part
.
stages
])
return
(
<
View
>
<
LazeImage
source=
{
bg
}
contentClass=
{
classNames
(
cs
.
flex
,
cs
.
align_center
)
}
>
<
View
className=
{
classNames
(
styles
.
partName
,
cs
.
flex
,
cs
.
align_center
)
}
>
Part
{
part
.
number
+
1
}
</
View
>
</
LazeImage
>
{
smallParts
.
map
(
item
=>
{
return
(
{
smallParts
.
map
(
item
=>
(
<
SceneSmallPart
part=
{
item
}
key=
{
item
.
offset
}
/>
)
})
}
))
}
</
View
>
)
}
...
...
src/pages/main/components/scene/small-part.tsx
View file @
a8d1dc29
import
LazeImage
from
'../lazy-image'
import
{
type
SmallPart
,
}
from
'./constants'
import
RoundComp
from
'./
round
'
import
RoundComp
from
'./
stage
'
import
styles
from
'./small-part.module.scss'
...
...
@@ -26,7 +26,7 @@ const SceneSmallPart = (props: SceneSmallPartProps) => {
<
LazeImage
source=
{
part
.
bg
}
>
{
part
.
rounds
.
map
((
item
,
index
)
=>
{
return
(
<
RoundComp
round
=
{
item
}
key=
{
item
.
id
}
className=
{
getClassName
(
index
,
part
.
type
)
}
/>
<
RoundComp
stage
=
{
item
}
key=
{
item
.
id
}
className=
{
getClassName
(
index
,
part
.
type
)
}
/>
)
})
}
</
LazeImage
>
...
...
src/pages/main/components/scene/
round
-tag.tsx
→
src/pages/main/components/scene/
stage
-tag.tsx
View file @
a8d1dc29
...
...
@@ -3,14 +3,14 @@ import { useEffect, useRef, useMemo } from 'react'
import
assets
from
'@/assets/oss/assets-round'
import
{
usePageScroll
,
createIntersectionObserver
,
getCurrentInstance
,
getMenuButtonBoundingClientRect
,
IntersectionObserver
,
nextTick
}
from
'@tarojs/taro'
type
Round
TagProps
=
{
type
Stage
TagProps
=
{
url
?:
string
;
className
:
string
;
id
:
number
|
string
;
ready
:
boolean
;
}
const
RoundTag
=
(
props
:
Round
TagProps
)
=>
{
const
StageTag
=
(
props
:
Stage
TagProps
)
=>
{
const
nav
=
useRef
(
getMenuButtonBoundingClientRect
())
const
{
url
,
className
,
id
,
ready
}
=
props
const
scrollRef
=
useRef
(
0
)
...
...
@@ -104,4 +104,4 @@ const RoundTag = (props: RoundTagProps) => {
)
}
export
default
Round
Tag
export
default
Stage
Tag
src/pages/main/components/scene/
round
.module.scss
→
src/pages/main/components/scene/
stage
.module.scss
View file @
a8d1dc29
File moved
src/pages/main/components/scene/
round
.tsx
→
src/pages/main/components/scene/
stage
.tsx
View file @
a8d1dc29
...
...
@@ -3,25 +3,25 @@ import assets from '@/assets/oss/assets-round'
import
classNames
from
'classnames'
import
{
cs
}
from
'@/styles'
import
{
navigateTo
}
from
'@tarojs/taro'
import
{
RoundState
,
type
Round
,
RoundType
,
type
ImageSource
,
RoundScore
,
CurrentRoundId
,
SceneContext
}
from
'./constants'
import
RoundTag
from
'./round
-tag'
import
{
type
Stage
,
StageType
,
StageStatus
,
type
ImageSource
,
StageLevel
,
CurrentRoundId
,
SceneContext
}
from
'./constants'
import
StageTag
from
'./stage
-tag'
import
styles
from
'./
round
.module.scss'
import
styles
from
'./
stage
.module.scss'
type
Round
Props
=
{
round
:
Round
;
type
Stage
Props
=
{
stage
:
Stage
;
className
?:
string
;
}
const
getLockedIcon
=
(
type
?:
Round
Type
):
ImageSource
=>
{
const
getLockedIcon
=
(
type
?:
Stage
Type
):
ImageSource
=>
{
switch
(
type
)
{
case
Round
Type
.
Strong
:
{
case
Stage
Type
.
Strong
:
{
return
assets
[
'strong-unlock.png'
]
}
case
Round
Type
.
Enhance
:
{
case
Stage
Type
.
Enhance
:
{
return
assets
[
'enhance-unlock.png'
]
}
case
Round
Type
.
OneStop
:
{
case
Stage
Type
.
OneStop
:
{
return
assets
[
'one-stop-unlock.png'
]
}
}
...
...
@@ -29,15 +29,15 @@ const getLockedIcon = (type?: RoundType): ImageSource => {
return
assets
[
'strong-unlock.png'
]
}
const
getTagIcon
=
(
tag
?:
string
):
ImageSource
|
null
=>
{
const
getTagIcon
=
(
tag
?:
number
):
ImageSource
|
null
=>
{
switch
(
tag
)
{
case
'top10'
:
{
case
10
:
{
return
assets
[
'top-10.png'
]
}
case
'top20'
:
{
case
20
:
{
return
assets
[
'top-20.png'
]
}
case
'top30'
:
{
case
30
:
{
return
assets
[
'top-30.png'
]
}
// case 'topn': {
...
...
@@ -48,15 +48,15 @@ const getTagIcon = (tag?: string): ImageSource | null => {
return
null
}
const
getUnlockedIcon
=
(
type
?:
Round
Type
):
ImageSource
=>
{
const
getUnlockedIcon
=
(
type
?:
Stage
Type
):
ImageSource
=>
{
switch
(
type
)
{
case
Round
Type
.
Strong
:
{
case
Stage
Type
.
Strong
:
{
return
assets
[
'strong-current-base.png'
]
}
case
Round
Type
.
Enhance
:
{
case
Stage
Type
.
Enhance
:
{
return
assets
[
'enhance-current-base.png'
]
}
case
Round
Type
.
OneStop
:
{
case
Stage
Type
.
OneStop
:
{
return
assets
[
'one-stop-current.png'
]
}
}
...
...
@@ -64,15 +64,15 @@ const getUnlockedIcon = (type?: RoundType): ImageSource => {
return
assets
[
'strong-current-base.png'
]
}
const
getClearIcon
=
(
type
?:
Round
Type
):
ImageSource
=>
{
const
getClearIcon
=
(
type
?:
Stage
Type
):
ImageSource
=>
{
switch
(
type
)
{
case
Round
Type
.
Strong
:
{
case
Stage
Type
.
Strong
:
{
return
assets
[
'strong-clear-base.png'
]
}
case
Round
Type
.
Enhance
:
{
case
Stage
Type
.
Enhance
:
{
return
assets
[
'enhance-clear-base.png'
]
}
case
Round
Type
.
OneStop
:
{
case
Stage
Type
.
OneStop
:
{
return
assets
[
'one-stop-clear-base.png'
]
}
}
...
...
@@ -80,50 +80,50 @@ const getClearIcon = (type?: RoundType): ImageSource => {
return
assets
[
'strong-clear-base.png'
]
}
const
getScoreIcon
=
(
score
?:
RoundScore
):
ImageSource
=>
{
const
getScoreIcon
=
(
score
?:
StageLevel
):
ImageSource
=>
{
switch
(
score
)
{
case
RoundScore
.
S
:
{
case
StageLevel
.
S
:
{
return
assets
[
'score-s.png'
]
}
case
RoundScore
.
A
:
{
case
StageLevel
.
A
:
{
return
assets
[
'score-a.png'
]
}
case
RoundScore
.
B
:
{
case
StageLevel
.
B
:
{
return
assets
[
'score-b.png'
]
}
}
return
assets
[
'score-b.png'
]
}
const
getIconClassNames
=
(
type
?:
Round
Type
,
extra
:
string
[]
=
[])
=>
{
return
classNames
(
styles
.
icon
,
type
===
Round
Type
.
OneStop
&&
styles
.
isOneStop
,
...
extra
)
const
getIconClassNames
=
(
type
?:
Stage
Type
,
extra
:
string
[]
=
[])
=>
{
return
classNames
(
styles
.
icon
,
type
===
Stage
Type
.
OneStop
&&
styles
.
isOneStop
,
...
extra
)
}
const
RoundComp
=
(
props
:
Round
Props
)
=>
{
const
{
round
}
=
props
const
StageComp
=
(
props
:
Stage
Props
)
=>
{
const
{
stage
}
=
props
const
renderRound
=
(
ready
:
boolean
)
=>
{
switch
(
round
.
state
)
{
case
RoundState
.
Locked
:
{
switch
(
stage
.
status
)
{
case
StageStatus
.
DISABLED
:
{
return
(
<
Image
src=
{
getLockedIcon
(
round
.
type
).
u
}
className=
{
getIconClassNames
(
round
.
type
)
}
/>
<
Image
src=
{
getLockedIcon
(
stage
.
type
).
u
}
className=
{
getIconClassNames
(
stage
.
type
)
}
/>
)
}
case
RoundState
.
UnLocked
:
{
case
StageStatus
.
CURRENT
:
{
return
(
<
Image
src=
{
getUnlockedIcon
(
round
.
type
).
u
}
className=
{
getIconClassNames
(
round
.
type
)
}
/>
<
Image
src=
{
getUnlockedIcon
(
stage
.
type
).
u
}
className=
{
getIconClassNames
(
stage
.
type
)
}
/>
)
}
case
RoundState
.
Clear
:
{
const
tag
=
getTagIcon
(
round
.
tag
)
case
StageStatus
.
PASSED
:
{
const
tag
=
getTagIcon
(
stage
.
gear
)
return
(
<
View
className=
{
styles
.
clear
}
>
<
RoundTag
url=
{
tag
?.
u
}
className=
{
styles
.
tag
}
id=
{
round
.
id
}
ready=
{
ready
}
/>
<
Image
src=
{
getScoreIcon
(
round
.
score
).
u
}
className=
{
styles
.
score
}
/>
<
Image
src=
{
getClearIcon
(
round
.
type
).
u
}
className=
{
getIconClassNames
(
round
.
type
,
[
styles
.
clearIcon
])
}
/>
{
!!
round
.
upBonus
&&
(
<
StageTag
url=
{
tag
?.
u
}
className=
{
styles
.
tag
}
id=
{
stage
.
id
}
ready=
{
ready
}
/>
<
Image
src=
{
getScoreIcon
(
stage
.
level
).
u
}
className=
{
styles
.
score
}
/>
<
Image
src=
{
getClearIcon
(
stage
.
type
).
u
}
className=
{
getIconClassNames
(
stage
.
type
,
[
styles
.
clearIcon
])
}
/>
{
!!
stage
.
upGear
&&
(
<>
<
Image
src=
{
assets
[
'up-bonus.png'
].
u
}
className=
{
styles
.
upname
}
></
Image
>
<
Image
src=
{
assets
[
'up-bonus-arrow.png'
].
u
}
className=
{
styles
.
uparrow
}
></
Image
>
...
...
@@ -135,7 +135,7 @@ const RoundComp = (props: RoundProps) => {
}
return
(
<
Image
src=
{
getLockedIcon
(
round
.
type
).
u
}
className=
{
getIconClassNames
(
round
.
type
)
}
/>
<
Image
src=
{
getLockedIcon
(
stage
.
type
).
u
}
className=
{
getIconClassNames
(
stage
.
type
)
}
/>
)
}
...
...
@@ -145,15 +145,15 @@ const RoundComp = (props: RoundProps) => {
<
View
className=
{
classNames
(
props
.
className
,
cs
.
bounce_btn
)
}
hoverClass=
{
cs
.
bounce_btn_hover
}
id=
{
round
.
state
===
RoundState
.
UnLocked
?
CurrentRoundId
:
undefined
}
onClick=
{
()
=>
navigateTo
({
url
:
'/pages/game/play/index'
})
}
id=
{
stage
.
status
===
StageStatus
.
CURRENT
?
CurrentRoundId
:
undefined
}
onClick=
{
()
=>
navigateTo
({
url
:
`/pages/game/play/index?id=${stage.id}`
})
}
>
{
renderRound
(
ready
)
}
<
View
className=
{
styles
.
roundName
}
>
{
round
.
name
}
</
View
>
<
View
className=
{
styles
.
roundName
}
>
{
stage
.
name
}
</
View
>
</
View
>
)
}
</
SceneContext
.
Consumer
>
)
}
export
default
Round
Comp
export
default
Stage
Comp
src/pages/main/main.tsx
View file @
a8d1dc29
import
{
View
}
from
'@tarojs/components'
import
{
getMenuButtonBoundingClientRect
,
useDidShow
,
getCurrentInstance
,
getTabBar
,
pageScrollTo
,
getSystemInfoSync
}
from
'@tarojs/taro'
import
{
useState
,
useMemo
,
useEffect
,
useCallback
}
from
'react'
import
{
useStoreActions
,
useStoreState
}
from
'@/store/hooks'
import
{
CurrentRoundId
,
SceneContext
}
from
'./components/scene/constants'
import
MainHeader
from
'./components/header'
import
MainChapter
from
'./components/chapter'
...
...
@@ -12,6 +13,8 @@ import styles from './main.module.scss'
const
MainPage
=
()
=>
{
const
page
=
useMemo
(()
=>
getCurrentInstance
().
page
,
[])
const
[
isReady
,
setIsReady
]
=
useState
(
false
)
const
fetchStage
=
useStoreActions
(
actions
=>
actions
.
mainModel
.
fetchStage
)
const
stageList
=
useStoreState
(
state
=>
state
.
mainModel
.
stageList
)
useDidShow
(()
=>
{
const
tabbar
=
getTabBar
(
page
)
as
any
...
...
@@ -29,12 +32,14 @@ const MainPage = () => {
},
[])
useEffect
(()
=>
{
fetchStage
().
then
(()
=>
{
setTimeout
(()
=>
{
scrollToCurrent
(()
=>
{
setIsReady
(
true
)
})
},
1000
)
},
[
scrollToCurrent
])
})
},
[
scrollToCurrent
,
fetchStage
])
return
(
<>
...
...
@@ -42,7 +47,7 @@ const MainPage = () => {
<
View
className=
{
styles
.
body
}
style=
{
{
paddingTop
:
`${nav.height + nav.top + 5}px`
}
}
>
<
MainChapter
/>
<
SceneContext
.
Provider
value=
{
{
ready
:
isReady
}
}
>
<
MainScene
/>
<
MainScene
stageList=
{
stageList
}
/>
</
SceneContext
.
Provider
>
<
View
className=
{
styles
.
gap
}
></
View
>
</
View
>
...
...
src/pages/main/model.ts
0 → 100644
View file @
a8d1dc29
import
{
action
,
Action
,
Thunk
,
thunk
}
from
'easy-peasy'
import
{
AppStoreModel
}
from
'@/store/store-model'
import
{
type
Stage
,
getStageList
}
from
'@/api'
export
interface
MainModel
{
stageList
:
Stage
[];
updateStageList
:
Action
<
MainModel
,
Stage
[]
>
;
fetchStage
:
Thunk
<
MainModel
,
void
,
void
,
AppStoreModel
>
;
}
const
mainModel
:
MainModel
=
{
stageList
:
[],
updateStageList
:
action
((
state
,
stageList
)
=>
{
state
.
stageList
=
stageList
}),
fetchStage
:
thunk
(
async
(
actions
,
_
)
=>
{
try
{
const
{
data
:
stageList
}
=
await
getStageList
()
actions
.
updateStageList
(
stageList
)
}
catch
(
err
)
{
actions
.
updateStageList
([])
}
}),
}
export
default
mainModel
src/store/store-model.ts
View file @
a8d1dc29
import
gameModel
from
'@/pages/game/play/model'
import
mainModel
from
'@/pages/main/model'
import
cartModel
from
'./modules/cart'
import
counterModel
from
'./modules/counter'
import
prepareModel
from
'./modules/prepare'
...
...
@@ -8,6 +9,7 @@ const appStoreModel = {
counterModel
,
prepareModel
,
gameModel
,
mainModel
,
}
export
default
appStoreModel
...
...
src/utils/silent-login.ts
View file @
a8d1dc29
...
...
@@ -9,13 +9,13 @@ import {
const
silentLoginDeferred
=
new
Deferred
<
null
>
()
async
function
silentLogin
(
recommendId
:
string
)
{
async
function
silentLogin
()
{
try
{
await
Taro
.
checkSession
()
const
token
=
getStorage
(
StorageKeys
.
token
)
//
const token = getStorage(StorageKeys.token)
const
openId
=
getStorage
(
StorageKeys
.
openid
)
const
userInfo
=
getStorage
(
StorageKeys
.
userInfo
)
if
(
!
token
||
!
openId
)
{
// 未登录
if
(
!
openId
)
{
// 未登录
throw
new
Error
(
'unlogin'
)
}
setProfile
(
openId
,
`
${
userInfo
?.
userId
}
`)
...
...
@@ -24,13 +24,16 @@ async function silentLogin (recommendId:string) {
try {
const { code } = await Taro.login()
const { data } = await silentLoginApi(code
, recommendId
)
const { data } = await silentLoginApi(code)
updateStorage(StorageKeys.openid, data.openId)
updateStorage(StorageKeys.unionid, data.unionId)
updateStorage(StorageKeys.token, data.token)
updateStorage(StorageKeys.userInfo, {
userId: data.userId,
})
setProfile(data.openId, `
$
{
data
.
i
d
}
`)
setProfile(data.openId, `
$
{
data
.
userI
d
}
`)
} catch (silentLoginError) {
console.log('silent login error', error)
}
...
...
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