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
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
130 additions
and
21 deletions
+130
-21
game.ts
src/api/game.ts
+8
-0
pk.ts
src/api/pk.ts
+39
-0
index.tsx
src/pages/accept-pk/index.tsx
+16
-1
model.ts
src/pages/battles/model.ts
+0
-6
battle-complete.tsx
src/pages/game/play/components/battle-complete.tsx
+4
-3
index.ts
src/pages/game/play/model/index.ts
+32
-7
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) => {
}))
}
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
)
=>
{
return
requestAfterSilentLogin
<
null
,
{
stageId
:
number
,
userId
?:
number
}
>
(
userInfo
=>
({
method
:
'GET'
,
...
...
src/api/pk.ts
View file @
91b790cb
...
...
@@ -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'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
import
assetsPk
from
'@/assets/oss/assets-pk'
import
assetsMainNext
from
'@/assets/oss/assets-main-next'
import
{
useRef
}
from
'react'
import
{
badgeImages
}
from
'../battles/const'
import
styles
from
'./index.module.scss'
import
TopHeader
from
'./components/top-header'
...
...
@@ -15,6 +16,8 @@ const AcceptPk = () => {
const
details
=
useStoreState
((
state
)
=>
state
.
battlesModel
.
details
)
const
userInfo
=
useStoreState
((
state
)
=>
state
.
userModel
.
userInfo
)
const
getQuestionList
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
getQuestionList
)
const
getStageDetail
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
getStageDetail
)
const
fetchUserDetails
=
useStoreActions
(
(
actions
)
=>
actions
.
battlesModel
.
fetchUserDetails
...
...
@@ -29,9 +32,21 @@ const AcceptPk = () => {
}
})
const
isClickRef
=
useRef
(
false
)
const
toGame
=
()
=>
{
if
(
isClickRef
.
current
)
return
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=
${
router
.
params
.
stageId
}
`
url
:
`/pages/game/play/index?id=
${
stageId
}
&isBattle=true`
})
})
}
...
...
src/pages/battles/model.ts
View file @
91b790cb
...
...
@@ -32,10 +32,7 @@ const battlesModel: BattlesModel = {
fetchUserDetails
:
thunk
(
async
(
actions
,
payload
)
=>
{
try
{
const
res
=
await
fetchUserDetails
(
payload
)
if
(
res
.
code
===
200
)
{
console
.
log
(
'res'
,
res
)
actions
.
setUserDetails
(
res
.
data
)
}
}
catch
(
err
)
{
}
}),
...
...
@@ -43,10 +40,7 @@ const battlesModel: BattlesModel = {
fetchUserRecords
:
thunk
(
async
(
actions
,
payload
)
=>
{
try
{
const
res
=
await
fetchUserRecords
(
payload
)
if
(
res
.
code
===
200
)
{
console
.
log
(
'res'
,
res
)
actions
.
setUserRecords
(
res
.
data
.
records
)
}
}
catch
(
err
)
{
}
}),
...
...
src/pages/game/play/components/battle-complete.tsx
View file @
91b790cb
...
...
@@ -3,16 +3,17 @@ import assetsGame from '@/assets/oss/assets-game'
import
assetsPrepare
from
'@/assets/oss/assets-prepare'
import
assetsPk
from
'@/assets/oss/assets-pk'
import
classNames
from
'classnames'
import
{
useStoreState
}
from
'@/store/hooks'
import
styles
from
'./battle-complete.module.scss'
type
BattleCompleteProps
=
{
data
?:
{}
}
const
BattleComplete
=
(
props
:
BattleCompleteProps
)
=>
{
const
{
data
}
=
props
if
(
!
data
)
{
const
pkResult
=
useStoreState
(
states
=>
states
.
gameModel
.
pkResult
)
if
(
!
pkResult
)
{
return
null
}
...
...
src/pages/game/play/model/index.ts
View file @
91b790cb
...
...
@@ -2,7 +2,7 @@ import { action, computed, thunk } from 'easy-peasy'
import
{
getQuestionList
,
StageLevel
,
getStageDetail
,
completeStage
,
StageType
,
resumeGame
,
fetchUserDetails
resumeGame
,
getPkQuestionList
,
submitPkResult
}
from
'@/api'
import
{
showLoading
,
hideLoading
,
showModal
,
redirectTo
,
...
...
@@ -15,7 +15,7 @@ import {
isSelectionQuestion
,
// QuestionOption,
}
from
'../types'
import
{
buildCompleteStageParam
,
convertQuestion
,
determinQuestion
}
from
'./utils'
import
{
buildCompleteStageParam
,
convertQuestion
,
determinQuestion
,
buildSubmitPkParams
}
from
'./utils'
import
{
GameModel
}
from
'./types'
...
...
@@ -38,6 +38,7 @@ const gameModel: GameModel = {
counterId
:
COUNTER_ID
,
questionList
:
[],
errList
:
[],
isBattle
:
false
,
gameResult
:
{
/** 排名档位 */
gear
:
10
,
...
...
@@ -66,6 +67,7 @@ const gameModel: GameModel = {
stageDetail
:
null
,
stageDetailPre
:
null
,
pkResult
:
null
,
updateState
:
action
((
state
,
obj
)
=>
{
for
(
const
key
in
obj
)
{
...
...
@@ -229,19 +231,28 @@ const gameModel: GameModel = {
}
}),
getQuestionList
:
thunk
(
async
(
actions
,
round
,
helpers
)
=>
{
getQuestionList
:
thunk
(
async
(
actions
,
{
isBattle
=
false
,
stageId
}
,
helpers
)
=>
{
try
{
// showLoading()
let
questionList
if
(
!
isBattle
)
{
const
stageList
=
helpers
.
getStoreState
().
mainModel
.
stageList
const
isFirstStage
=
stageList
.
findIndex
(
c
=>
String
(
c
.
id
)
===
String
(
roun
d
))
===
0
const
isFirstStage
=
stageList
.
findIndex
(
c
=>
String
(
c
.
id
)
===
String
(
stageI
d
))
===
0
const
stageDetail
=
helpers
.
getState
().
stageDetail
const
isNormal
=
!
isFirstStage
||
!!
stageDetail
?.
level
const
{
data
:
questionList
}
=
await
getQuestionList
(
round
,
isNormal
)
const
{
data
:
list
}
=
await
getQuestionList
(
stageId
,
isNormal
)
questionList
=
list
}
else
{
const
{
data
:
list
}
=
await
getPkQuestionList
(
stageId
)
questionList
=
list
}
actions
.
updateState
({
questionList
:
questionList
.
map
(
convertQuestion
),
currentInputIndex
:
0
,
currentQuestionIndex
:
0
,
errList
:
[],
isBattle
,
pkResult
:
null
,
modalContinueVisible
:
false
,
bornTimes
:
3
,
gameStartTime
:
Date
.
now
(),
...
...
@@ -273,8 +284,10 @@ const gameModel: GameModel = {
disableAlertBeforeUnload
()
actions
.
updateState
({
isSubmit
:
true
})
stopCounter
()
const
{
questionList
,
stageDetail
}
=
helpers
.
getState
()
const
{
errList
,
errNum
,
...
rest
}
=
buildCompleteStageParam
(
questionList
,
stageDetail
!
,
getCounter
()?.
getCount
()
??
0
)
const
{
questionList
,
stageDetail
,
isBattle
}
=
helpers
.
getState
()
const
out
=
buildCompleteStageParam
(
questionList
,
stageDetail
!
,
getCounter
()?.
getCount
()
??
0
)
const
{
errList
,
errNum
,
...
rest
}
=
out
if
(
!
isBattle
)
{
const
{
data
:
gameResult
}
=
await
completeStage
(
rest
)
actions
.
updateState
({
errList
,
...
...
@@ -289,6 +302,18 @@ const gameModel: GameModel = {
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
))
actions
.
updateState
({
pkResult
:
result
.
data
,
})
}
}
catch
(
err
)
{
hideLoading
()
showModal
({
...
...
src/pages/game/play/model/types.ts
View file @
91b790cb
...
...
@@ -39,6 +39,8 @@ export interface GameModelState {
counterId
:
string
;
rightIcon
:
string
|
null
;
isBattle
:
boolean
;
}
export
interface
GameModel
extends
GameModelState
{
...
...
@@ -61,7 +63,7 @@ export interface GameModel extends GameModelState {
canGoNext
:
Computed
<
GameModel
,
boolean
>
;
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
>
;
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
{
getStorage
,
StorageKeys
}
from
'@/utils/storage'
import
{
UserInfo
}
from
'@/types'
import
{
type
QuestionType
,
isBlankQuestion
,
isVerticalDivisionQuestion
,
isSelectionQuestion
}
from
'../types'
const
logger
=
getLogManager
({
level
:
1
})
...
...
@@ -155,3 +156,15 @@ export function determinQuestion (question: QuestionType) {
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 = () => {
throttleDelay: 1000,
onSuccess: () => {
palyAudio(audio['蹦蹦top出现首页.wav'].u)
getQuestionList(
+router.params.id || 1
).then(() => {
getQuestionList(
{ stageId: +router.params.id || 1 }
).then(() => {
setFalse()
navigateTo({
url: `
/
pages
/
game
/
play
/
index
?
id
=
$
{
router
.
params
.
id
}
`
...
...
@@ -128,7 +128,7 @@ const Prepare = () => {
isClickRef.current = true
palyAudio(audio['蹦蹦top出现首页.wav'].u)
getQuestionList(
+router.params.id || 1
).then(() => {
getQuestionList(
{ stageId: +router.params.id || 1 }
).then(() => {
isClickRef.current = false
navigateTo({
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):
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
}
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