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
91b790cb
Commit
91b790cb
authored
Jun 16, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 发起pk
parent
cc815f9a
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
150 additions
and
41 deletions
+150
-41
game.ts
src/api/game.ts
+8
-0
pk.ts
src/api/pk.ts
+39
-0
index.tsx
src/pages/accept-pk/index.tsx
+18
-3
model.ts
src/pages/battles/model.ts
+2
-8
battle-complete.tsx
src/pages/game/play/components/battle-complete.tsx
+4
-3
index.ts
src/pages/game/play/model/index.ts
+48
-23
types.ts
src/pages/game/play/model/types.ts
+3
-1
utils.ts
src/pages/game/play/model/utils.ts
+14
-1
index.tsx
src/pages/prepare/index.tsx
+2
-2
index.ts
src/utils/index.ts
+12
-0
No files found.
src/api/game.ts
View file @
91b790cb
...
@@ -10,6 +10,14 @@ export const getQuestionList = (stageId: number, normal: boolean = true) => {
...
@@ -10,6 +10,14 @@ export const getQuestionList = (stageId: number, normal: boolean = true) => {
}))
}))
}
}
export
const
getPkQuestionList
=
(
stageId
:
number
)
=>
{
return
requestAfterSilentLogin
<
QuestionType
[],
{
stageId
:
number
}
>
(()
=>
({
url
:
'/service-idea//pk/personal/stage/generateQuestion'
,
method
:
'GET'
,
data
:
{
stageId
}
}))
}
export
const
resumeGame
=
(
stageId
:
number
)
=>
{
export
const
resumeGame
=
(
stageId
:
number
)
=>
{
return
requestAfterSilentLogin
<
null
,
{
stageId
:
number
,
userId
?:
number
}
>
(
userInfo
=>
({
return
requestAfterSilentLogin
<
null
,
{
stageId
:
number
,
userId
?:
number
}
>
(
userInfo
=>
({
method
:
'GET'
,
method
:
'GET'
,
...
...
src/api/pk.ts
View file @
91b790cb
...
@@ -63,3 +63,42 @@ export function fetchUserRecords (data: PkParams) {
...
@@ -63,3 +63,42 @@ export function fetchUserRecords (data: PkParams) {
}
}
}))
}))
}
}
export
type
SubmitPkResultParams
=
{
initiator
:
number
;
initiatorErrNum
:
number
;
initiatorResultTime
:
number
;
recipient
:
number
;
recipientErrNum
:
number
;
recipientResultTime
:
number
;
}
export
async
function
submitPkResult
(
params
:
SubmitPkResultParams
)
{
const
result1
=
await
requestAfterSilentLogin
<
number
,
SubmitPkResultParams
>
(()
=>
({
url
:
'/service-idea/pk/personal/stage/complete'
,
method
:
'POST'
,
data
:
params
}))
return
await
getPkResult
(
result1
.
data
)
}
export
type
PkResult
=
SubmitPkResultParams
&
{
initiatorLevel
:
string
;
initiatorName
:
string
;
initiatorStar
:
number
;
recipientLevel
:
string
;
recipientName
:
string
;
recipientStar
:
number
;
result
:
string
;
stageName
:
string
;
}
export
function
getPkResult
(
params
:
number
)
{
return
requestAfterSilentLogin
<
PkResult
,
{
id
:
number
}
>
(()
=>
({
url
:
'/service-idea/pk/personal/pkDetail'
,
method
:
'GET'
,
data
:
{
id
:
params
}
}))
}
src/pages/accept-pk/index.tsx
View file @
91b790cb
...
@@ -4,6 +4,7 @@ import { useBoolean } from '@/hooks'
...
@@ -4,6 +4,7 @@ import { useBoolean } from '@/hooks'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
import
assetsPk
from
'@/assets/oss/assets-pk'
import
assetsPk
from
'@/assets/oss/assets-pk'
import
assetsMainNext
from
'@/assets/oss/assets-main-next'
import
assetsMainNext
from
'@/assets/oss/assets-main-next'
import
{
useRef
}
from
'react'
import
{
badgeImages
}
from
'../battles/const'
import
{
badgeImages
}
from
'../battles/const'
import
styles
from
'./index.module.scss'
import
styles
from
'./index.module.scss'
import
TopHeader
from
'./components/top-header'
import
TopHeader
from
'./components/top-header'
...
@@ -15,6 +16,8 @@ const AcceptPk = () => {
...
@@ -15,6 +16,8 @@ const AcceptPk = () => {
const
details
=
useStoreState
((
state
)
=>
state
.
battlesModel
.
details
)
const
details
=
useStoreState
((
state
)
=>
state
.
battlesModel
.
details
)
const
userInfo
=
useStoreState
((
state
)
=>
state
.
userModel
.
userInfo
)
const
userInfo
=
useStoreState
((
state
)
=>
state
.
userModel
.
userInfo
)
const
getQuestionList
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
getQuestionList
)
const
getStageDetail
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
getStageDetail
)
const
fetchUserDetails
=
useStoreActions
(
const
fetchUserDetails
=
useStoreActions
(
(
actions
)
=>
actions
.
battlesModel
.
fetchUserDetails
(
actions
)
=>
actions
.
battlesModel
.
fetchUserDetails
...
@@ -29,10 +32,22 @@ const AcceptPk = () => {
...
@@ -29,10 +32,22 @@ const AcceptPk = () => {
}
}
})
})
const
isClickRef
=
useRef
(
false
)
const
toGame
=
()
=>
{
const
toGame
=
()
=>
{
navigateTo
({
if
(
isClickRef
.
current
)
return
url
:
`/pages/game/play/index?id=
${
router
.
params
.
stageId
}
`
isClickRef
.
current
=
true
})
const
stageId
=
+
(
router
.
params
.
stageId
??
-
1
)
Promise
.
all
([
getQuestionList
({
stageId
,
isBattle
:
true
}),
getStageDetail
(
stageId
)
])
.
then
(()
=>
{
isClickRef
.
current
=
false
navigateTo
({
url
:
`/pages/game/play/index?id=
${
stageId
}
&isBattle=true`
})
})
}
}
const
handleClick
=
()
=>
{
const
handleClick
=
()
=>
{
...
...
src/pages/battles/model.ts
View file @
91b790cb
...
@@ -32,10 +32,7 @@ const battlesModel: BattlesModel = {
...
@@ -32,10 +32,7 @@ const battlesModel: BattlesModel = {
fetchUserDetails
:
thunk
(
async
(
actions
,
payload
)
=>
{
fetchUserDetails
:
thunk
(
async
(
actions
,
payload
)
=>
{
try
{
try
{
const
res
=
await
fetchUserDetails
(
payload
)
const
res
=
await
fetchUserDetails
(
payload
)
if
(
res
.
code
===
200
)
{
actions
.
setUserDetails
(
res
.
data
)
console
.
log
(
'res'
,
res
)
actions
.
setUserDetails
(
res
.
data
)
}
}
catch
(
err
)
{
}
catch
(
err
)
{
}
}
}),
}),
...
@@ -43,10 +40,7 @@ const battlesModel: BattlesModel = {
...
@@ -43,10 +40,7 @@ const battlesModel: BattlesModel = {
fetchUserRecords
:
thunk
(
async
(
actions
,
payload
)
=>
{
fetchUserRecords
:
thunk
(
async
(
actions
,
payload
)
=>
{
try
{
try
{
const
res
=
await
fetchUserRecords
(
payload
)
const
res
=
await
fetchUserRecords
(
payload
)
if
(
res
.
code
===
200
)
{
actions
.
setUserRecords
(
res
.
data
.
records
)
console
.
log
(
'res'
,
res
)
actions
.
setUserRecords
(
res
.
data
.
records
)
}
}
catch
(
err
)
{
}
catch
(
err
)
{
}
}
}),
}),
...
...
src/pages/game/play/components/battle-complete.tsx
View file @
91b790cb
...
@@ -3,16 +3,17 @@ import assetsGame from '@/assets/oss/assets-game'
...
@@ -3,16 +3,17 @@ import assetsGame from '@/assets/oss/assets-game'
import
assetsPrepare
from
'@/assets/oss/assets-prepare'
import
assetsPrepare
from
'@/assets/oss/assets-prepare'
import
assetsPk
from
'@/assets/oss/assets-pk'
import
assetsPk
from
'@/assets/oss/assets-pk'
import
classNames
from
'classnames'
import
classNames
from
'classnames'
import
{
useStoreState
}
from
'@/store/hooks'
import
styles
from
'./battle-complete.module.scss'
import
styles
from
'./battle-complete.module.scss'
type
BattleCompleteProps
=
{
type
BattleCompleteProps
=
{
data
?:
{}
}
}
const
BattleComplete
=
(
props
:
BattleCompleteProps
)
=>
{
const
BattleComplete
=
(
props
:
BattleCompleteProps
)
=>
{
const
{
data
}
=
props
const
pkResult
=
useStoreState
(
states
=>
states
.
gameModel
.
pkResult
)
if
(
!
data
)
{
if
(
!
pkResult
)
{
return
null
return
null
}
}
...
...
src/pages/game/play/model/index.ts
View file @
91b790cb
...
@@ -2,7 +2,7 @@ import { action, computed, thunk } from 'easy-peasy'
...
@@ -2,7 +2,7 @@ import { action, computed, thunk } from 'easy-peasy'
import
{
import
{
getQuestionList
,
StageLevel
,
getQuestionList
,
StageLevel
,
getStageDetail
,
completeStage
,
StageType
,
getStageDetail
,
completeStage
,
StageType
,
resumeGame
,
fetchUserDetails
resumeGame
,
getPkQuestionList
,
submitPkResult
}
from
'@/api'
}
from
'@/api'
import
{
import
{
showLoading
,
hideLoading
,
showModal
,
redirectTo
,
showLoading
,
hideLoading
,
showModal
,
redirectTo
,
...
@@ -15,7 +15,7 @@ import {
...
@@ -15,7 +15,7 @@ import {
isSelectionQuestion
,
isSelectionQuestion
,
// QuestionOption,
// QuestionOption,
}
from
'../types'
}
from
'../types'
import
{
buildCompleteStageParam
,
convertQuestion
,
determinQuestion
}
from
'./utils'
import
{
buildCompleteStageParam
,
convertQuestion
,
determinQuestion
,
buildSubmitPkParams
}
from
'./utils'
import
{
GameModel
}
from
'./types'
import
{
GameModel
}
from
'./types'
...
@@ -38,6 +38,7 @@ const gameModel: GameModel = {
...
@@ -38,6 +38,7 @@ const gameModel: GameModel = {
counterId
:
COUNTER_ID
,
counterId
:
COUNTER_ID
,
questionList
:
[],
questionList
:
[],
errList
:
[],
errList
:
[],
isBattle
:
false
,
gameResult
:
{
gameResult
:
{
/** 排名档位 */
/** 排名档位 */
gear
:
10
,
gear
:
10
,
...
@@ -66,6 +67,7 @@ const gameModel: GameModel = {
...
@@ -66,6 +67,7 @@ const gameModel: GameModel = {
stageDetail
:
null
,
stageDetail
:
null
,
stageDetailPre
:
null
,
stageDetailPre
:
null
,
pkResult
:
null
,
updateState
:
action
((
state
,
obj
)
=>
{
updateState
:
action
((
state
,
obj
)
=>
{
for
(
const
key
in
obj
)
{
for
(
const
key
in
obj
)
{
...
@@ -229,19 +231,28 @@ const gameModel: GameModel = {
...
@@ -229,19 +231,28 @@ const gameModel: GameModel = {
}
}
}),
}),
getQuestionList
:
thunk
(
async
(
actions
,
round
,
helpers
)
=>
{
getQuestionList
:
thunk
(
async
(
actions
,
{
isBattle
=
false
,
stageId
}
,
helpers
)
=>
{
try
{
try
{
// showLoading()
// showLoading()
const
stageList
=
helpers
.
getStoreState
().
mainModel
.
stageList
let
questionList
const
isFirstStage
=
stageList
.
findIndex
(
c
=>
String
(
c
.
id
)
===
String
(
round
))
===
0
if
(
!
isBattle
)
{
const
stageDetail
=
helpers
.
getState
().
stageDetail
const
stageList
=
helpers
.
getStoreState
().
mainModel
.
stageList
const
isNormal
=
!
isFirstStage
||
!!
stageDetail
?.
level
const
isFirstStage
=
stageList
.
findIndex
(
c
=>
String
(
c
.
id
)
===
String
(
stageId
))
===
0
const
{
data
:
questionList
}
=
await
getQuestionList
(
round
,
isNormal
)
const
stageDetail
=
helpers
.
getState
().
stageDetail
const
isNormal
=
!
isFirstStage
||
!!
stageDetail
?.
level
const
{
data
:
list
}
=
await
getQuestionList
(
stageId
,
isNormal
)
questionList
=
list
}
else
{
const
{
data
:
list
}
=
await
getPkQuestionList
(
stageId
)
questionList
=
list
}
actions
.
updateState
({
actions
.
updateState
({
questionList
:
questionList
.
map
(
convertQuestion
),
questionList
:
questionList
.
map
(
convertQuestion
),
currentInputIndex
:
0
,
currentInputIndex
:
0
,
currentQuestionIndex
:
0
,
currentQuestionIndex
:
0
,
errList
:
[],
errList
:
[],
isBattle
,
pkResult
:
null
,
modalContinueVisible
:
false
,
modalContinueVisible
:
false
,
bornTimes
:
3
,
bornTimes
:
3
,
gameStartTime
:
Date
.
now
(),
gameStartTime
:
Date
.
now
(),
...
@@ -273,22 +284,36 @@ const gameModel: GameModel = {
...
@@ -273,22 +284,36 @@ const gameModel: GameModel = {
disableAlertBeforeUnload
()
disableAlertBeforeUnload
()
actions
.
updateState
({
isSubmit
:
true
})
actions
.
updateState
({
isSubmit
:
true
})
stopCounter
()
stopCounter
()
const
{
questionList
,
stageDetail
}
=
helpers
.
getState
()
const
{
questionList
,
stageDetail
,
isBattle
}
=
helpers
.
getState
()
const
{
errList
,
errNum
,
...
rest
}
=
buildCompleteStageParam
(
questionList
,
stageDetail
!
,
getCounter
()?.
getCount
()
??
0
)
const
out
=
buildCompleteStageParam
(
questionList
,
stageDetail
!
,
getCounter
()?.
getCount
()
??
0
)
const
{
data
:
gameResult
}
=
await
completeStage
(
rest
)
const
{
errList
,
errNum
,
...
rest
}
=
out
actions
.
updateState
({
if
(
!
isBattle
)
{
errList
,
const
{
data
:
gameResult
}
=
await
completeStage
(
rest
)
gameResult
:
{
actions
.
updateState
({
...
gameResult
,
errList
,
isTimeout
:
rest
.
isTimeout
,
gameResult
:
{
errNum
,
...
gameResult
,
levelTime
:
rest
.
levelTime
isTimeout
:
rest
.
isTimeout
,
errNum
,
levelTime
:
rest
.
levelTime
}
})
hideLoading
()
redirectTo
({
url
:
'/pages/game/complete/index'
,
})
}
else
{
const
pkDetails
=
helpers
.
getStoreState
().
battlesModel
.
details
const
userInfo
=
helpers
.
getStoreState
().
userModel
.
userInfo
if
(
!
pkDetails
)
{
throw
new
Error
(
'提交出错'
)
}
}
})
const
result
=
await
submitPkResult
(
buildSubmitPkParams
(
pkDetails
,
out
,
userInfo
))
hideLoading
()
redirectTo
({
actions
.
updateState
({
url
:
'/pages/game/complete/index'
,
pkResult
:
result
.
data
,
})
})
}
}
catch
(
err
)
{
}
catch
(
err
)
{
hideLoading
()
hideLoading
()
showModal
({
showModal
({
...
...
src/pages/game/play/model/types.ts
View file @
91b790cb
...
@@ -39,6 +39,8 @@ export interface GameModelState {
...
@@ -39,6 +39,8 @@ export interface GameModelState {
counterId
:
string
;
counterId
:
string
;
rightIcon
:
string
|
null
;
rightIcon
:
string
|
null
;
isBattle
:
boolean
;
}
}
export
interface
GameModel
extends
GameModelState
{
export
interface
GameModel
extends
GameModelState
{
...
@@ -61,7 +63,7 @@ export interface GameModel extends GameModelState {
...
@@ -61,7 +63,7 @@ export interface GameModel extends GameModelState {
canGoNext
:
Computed
<
GameModel
,
boolean
>
;
canGoNext
:
Computed
<
GameModel
,
boolean
>
;
updateList
:
Action
<
GameModel
,
QuestionType
[]
>
;
updateList
:
Action
<
GameModel
,
QuestionType
[]
>
;
getQuestionList
:
Thunk
<
GameModel
,
number
,
void
,
AppStoreModel
>
;
getQuestionList
:
Thunk
<
GameModel
,
{
stageId
:
number
;
isBattle
?:
boolean
}
,
void
,
AppStoreModel
>
;
getStageDetail
:
Thunk
<
GameModel
,
number
,
void
,
AppStoreModel
>
;
getStageDetail
:
Thunk
<
GameModel
,
number
,
void
,
AppStoreModel
>
;
handleGoNext
:
Thunk
<
GameModel
,
void
,
void
,
AppStoreModel
>
;
handleGoNext
:
Thunk
<
GameModel
,
void
,
void
,
AppStoreModel
>
;
...
...
src/pages/game/play/model/utils.ts
View file @
91b790cb
import
{
type
CompleteStageParam
,
type
StageDetail
,
StageLevel
,
type
CompleteQuestion
}
from
'@/api'
import
{
type
CompleteStageParam
,
type
StageDetail
,
StageLevel
,
type
CompleteQuestion
,
SubmitPkResultParams
,
PkDetails
}
from
'@/api'
import
{
getLogManager
}
from
'@tarojs/taro'
import
{
getLogManager
}
from
'@tarojs/taro'
import
{
getStorage
,
StorageKeys
}
from
'@/utils/storage'
import
{
getStorage
,
StorageKeys
}
from
'@/utils/storage'
import
{
UserInfo
}
from
'@/types'
import
{
type
QuestionType
,
isBlankQuestion
,
isVerticalDivisionQuestion
,
isSelectionQuestion
}
from
'../types'
import
{
type
QuestionType
,
isBlankQuestion
,
isVerticalDivisionQuestion
,
isSelectionQuestion
}
from
'../types'
const
logger
=
getLogManager
({
level
:
1
})
const
logger
=
getLogManager
({
level
:
1
})
...
@@ -155,3 +156,15 @@ export function determinQuestion (question: QuestionType) {
...
@@ -155,3 +156,15 @@ export function determinQuestion (question: QuestionType) {
throw
new
Error
(
'question type not supported'
)
throw
new
Error
(
'question type not supported'
)
}
}
export
function
buildSubmitPkParams
(
pkDetail
:
PkDetails
,
out
:
BuildParamsOut
,
userInfo
:
UserInfo
):
SubmitPkResultParams
{
return
{
initiator
:
pkDetail
.
userId
,
initiatorErrNum
:
0
,
initiatorResultTime
:
pkDetail
.
resultTime
,
recipient
:
userInfo
.
userId
!
,
recipientErrNum
:
out
.
errNum
,
recipientResultTime
:
out
.
resultTime
,
}
}
src/pages/prepare/index.tsx
View file @
91b790cb
...
@@ -96,7 +96,7 @@ const Prepare = () => {
...
@@ -96,7 +96,7 @@ const Prepare = () => {
throttleDelay: 1000,
throttleDelay: 1000,
onSuccess: () => {
onSuccess: () => {
palyAudio(audio['蹦蹦top出现首页.wav'].u)
palyAudio(audio['蹦蹦top出现首页.wav'].u)
getQuestionList(
+router.params.id || 1
).then(() => {
getQuestionList(
{ stageId: +router.params.id || 1 }
).then(() => {
setFalse()
setFalse()
navigateTo({
navigateTo({
url: `
/
pages
/
game
/
play
/
index
?
id
=
$
{
router
.
params
.
id
}
`
url: `
/
pages
/
game
/
play
/
index
?
id
=
$
{
router
.
params
.
id
}
`
...
@@ -128,7 +128,7 @@ const Prepare = () => {
...
@@ -128,7 +128,7 @@ const Prepare = () => {
isClickRef.current = true
isClickRef.current = true
palyAudio(audio['蹦蹦top出现首页.wav'].u)
palyAudio(audio['蹦蹦top出现首页.wav'].u)
getQuestionList(
+router.params.id || 1
).then(() => {
getQuestionList(
{ stageId: +router.params.id || 1 }
).then(() => {
isClickRef.current = false
isClickRef.current = false
navigateTo({
navigateTo({
url: `
/
pages
/
game
/
play
/
index
?
id
=
$
{
router
.
params
.
id
}
`
url: `
/
pages
/
game
/
play
/
index
?
id
=
$
{
router
.
params
.
id
}
`
...
...
src/utils/index.ts
View file @
91b790cb
...
@@ -16,4 +16,16 @@ function omit<T extends object, K extends (keyof T)[] = []>(value: T, keys: K):
...
@@ -16,4 +16,16 @@ function omit<T extends object, K extends (keyof T)[] = []>(value: T, keys: K):
return
ret
return
ret
}
}
export
function
singular
<
T
extends
(...
arg
:
any
[])
=>
any
>
(
fn
:
T
)
{
let
isRunning
=
false
return
async
function
(...
arg
:
Parameters
<
T
>
)
{
if
(
isRunning
)
return
try
{
return
await
fn
(...
arg
)
}
finally
{
isRunning
=
false
}
}
}
export
{
omit
}
export
{
omit
}
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