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
14f990d9
Commit
14f990d9
authored
Apr 05, 2023
by
m
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://118.24.71.244/hewenhao/GeekLearnMathWeapp
parents
fa581ec1
d3061f51
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
108 additions
and
98 deletions
+108
-98
auth.ts
src/api/auth.ts
+11
-0
game.ts
src/api/game.ts
+1
-0
group.ts
src/api/group.ts
+2
-2
index.js
src/native-components/count-up/index.js
+2
-3
complete-head.tsx
src/pages/game/complete/components/complete-head.tsx
+1
-1
count-up.module.scss
src/pages/game/play/components/count-up.module.scss
+9
-2
count-up.tsx
src/pages/game/play/components/count-up.tsx
+22
-21
modal-continue.tsx
src/pages/game/play/components/modal-continue.tsx
+2
-15
index.tsx
src/pages/game/play/index.tsx
+1
-2
index.ts
src/pages/game/play/model/index.ts
+2
-0
utils.ts
src/pages/game/play/model/utils.ts
+4
-1
header.module.scss
src/pages/main/components/header.module.scss
+8
-6
header.tsx
src/pages/main/components/header.tsx
+2
-1
stage.tsx
src/pages/main/components/scene/stage.tsx
+4
-0
main.tsx
src/pages/main/main.tsx
+2
-0
answer-sheet.tsx
src/pages/market/components/answer-sheet.tsx
+0
-29
exchange-item.tsx
src/pages/market/components/exchange-item.tsx
+3
-1
index.tsx
src/pages/prepare/index.tsx
+14
-6
user.ts
src/store/modules/user.ts
+16
-6
types.ts
src/types.ts
+1
-1
silent-login.ts
src/utils/silent-login.ts
+1
-1
No files found.
src/api/auth.ts
View file @
14f990d9
...
...
@@ -37,6 +37,17 @@ export function getAccountInfo () {
}))
}
export
function
updateUserInfo
(
nickName
:
string
)
{
return
requestAfterSilentLogin
<
void
,
{
nickName
:
string
;
userId
?:
number
;
}
>
(
userInfo
=>
({
method
:
'POST'
,
url
:
'/service-idea/stage/user/updateUserInfo'
,
data
:
{
nickName
,
userId
:
userInfo
?.
userId
}
}))
}
export
function
getSetting
()
{
return
requestAfterSilentLogin
<
{
pointToCard
:
number
},
{}
>
(()
=>
({
method
:
'GET'
,
...
...
src/api/game.ts
View file @
14f990d9
...
...
@@ -104,6 +104,7 @@ export interface CompleteStageParam {
correctNum
:
number
;
level
:
StageLevel
|
null
;
levelTime
:
number
;
isTimeout
:
boolean
;
num
:
number
;
questions
:
CompleteQuestion
[];
resultTime
:
number
;
...
...
src/api/group.ts
View file @
14f990d9
...
...
@@ -16,7 +16,7 @@ export const createTribe = ({ groupNo }: Pick<CreateTribeParams, 'groupNo'>) =>
data
:
{
groupNo
,
bizType
:
'RKLL'
,
memberName
:
userInfo
?.
nick
n
ame
||
'CTO'
,
memberName
:
userInfo
?.
nick
N
ame
||
'CTO'
,
memberId
:
userInfo
?.
userId
,
}
}))
...
...
@@ -42,7 +42,7 @@ export const joinTribe = ({ groupId }: { groupId: number }) => {
data
:
{
groupId
,
memberId
:
userInfo
?.
userId
,
memberName
:
userInfo
?.
nick
n
ame
||
'爹🐂'
memberName
:
userInfo
?.
nick
N
ame
||
'爹🐂'
}
}))
}
...
...
src/native-components/count-up/index.js
View file @
14f990d9
...
...
@@ -81,9 +81,8 @@ Component({
}
}
else
{
this
.
_tick
+=
1
if
(
this
.
_tick
>=
this
.
data
.
maxValue
)
{
this
.
stop
()
this
.
triggerEvent
(
'timeup'
)
if
(
this
.
_tick
===
this
.
data
.
maxValue
)
{
this
.
triggerEvent
(
'exceed'
)
}
}
const
{
minutes
,
seconds
}
=
this
.
data
...
...
src/pages/game/complete/components/complete-head.tsx
View file @
14f990d9
...
...
@@ -122,7 +122,7 @@ const GameCompleteHead = () => {
</
View
>
<
View
className=
{
styles
.
item
}
>
<
Image
src=
{
require
(
'../assets/time.png'
)
}
className=
{
styles
.
icon
}
></
Image
>
<
View
className=
{
classNames
(
styles
.
item_text
,
gameResult
.
errNum
<=
0
&&
!
gameResult
.
level
&&
styles
.
err
)
}
>
{
time
.
minutes
}
:
{
time
.
seconds
}
</
View
>
<
View
className=
{
classNames
(
styles
.
item_text
,
gameResult
.
isTimeout
&&
styles
.
err
)
}
>
{
time
.
minutes
}
:
{
time
.
seconds
}
</
View
>
</
View
>
</
View
>
</
View
>
...
...
src/pages/game/play/components/count-up.module.scss
View file @
14f990d9
...
...
@@ -42,14 +42,21 @@
}
}
.roleWrap
{
position
:
absolute
;
left
:
0
;
top
:
0
;
right
:
0
;
width
:
100%
;
transform
:
translateX
(
0px
);
}
.role
{
position
:
absolute
;
left
:
0
;
top
:
-8px
;
margin-left
:
-40px
;
transform
:
translateX
(
0px
);
.tick
{
width
:
6px
;
border-radius
:
3px
;
...
...
src/pages/game/play/components/count-up.tsx
View file @
14f990d9
import
{
View
,
Image
}
from
'@tarojs/components'
import
{
use
State
,
useEffect
,
use
Callback
,
useMemo
}
from
'react'
import
{
createSelectorQuery
}
from
'@tarojs/taro'
import
{
useCallback
,
useMemo
}
from
'react'
import
{
useDidShow
,
nextTick
}
from
'@tarojs/taro'
import
classNames
from
'classnames'
import
{
useBoolean
}
from
'@/hooks'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
...
...
@@ -8,8 +8,6 @@ import { type StageDetail, StageType } from '@/api'
import
styles
from
'./count-up.module.scss'
const
id
=
'_process__'
type
CountUpProps
=
{
stageDetail
:
StageDetail
}
...
...
@@ -21,24 +19,13 @@ const CountUp = (props: CountUpProps) => {
const
questionList
=
useStoreState
(
state
=>
state
.
gameModel
.
questionList
)
const
isSubmit
=
useStoreState
(
state
=>
state
.
gameModel
.
isSubmit
)
const
submit
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
submit
)
const
[
width
,
setWidth
]
=
useState
(
0
)
const
[
isExceed
,
exceedActions
]
=
useBoolean
(
false
)
const
[
isStarted
,
startActions
]
=
useBoolean
(
false
)
const
questionLength
=
useMemo
(()
=>
{
return
questionList
.
length
},
[
questionList
])
useEffect
(()
=>
{
createSelectorQuery
().
select
(
`#
${
id
}
`
)
.
boundingClientRect
()
.
exec
((
res
)
=>
{
console
.
log
(
res
)
if
(
res
[
0
])
{
setWidth
(
res
[
0
].
width
)
}
})
},
[])
const
isOneStop
=
useMemo
(()
=>
{
return
stageDetail
.
type
===
StageType
.
OneStop
},
[
stageDetail
])
...
...
@@ -50,12 +37,24 @@ const CountUp = (props: CountUpProps) => {
return
0
},
[
stageDetail
])
useDidShow
(()
=>
{
nextTick
(()
=>
{
startActions
.
setTrue
()
})
})
const
roleStyle
=
useMemo
(()
=>
{
if
(
isStarted
)
{
return
{
transform
:
'translateX(100%)'
,
transition
:
`transform
${
stageDetail
.
bTime
}
s linear`
,
}
}
return
{
transform
:
`translateX(
${
width
}
px)`
,
transform
:
'translateX(0)'
,
transition
:
`transform
${
stageDetail
.
bTime
}
s linear`
,
}
},
[
width
,
stageDetail
.
bTime
])
},
[
stageDetail
,
isStarted
])
const
processInnerStyle
=
useMemo
(()
=>
{
if
(
isSubmit
)
{
...
...
@@ -77,14 +76,16 @@ const CountUp = (props: CountUpProps) => {
return
(
<
View
className=
{
classNames
(
styles
.
count
,
isOneStop
&&
styles
.
is_stop
)
}
>
<
View
className=
{
styles
.
process
}
id=
{
id
}
>
<
View
className=
{
styles
.
process
}
>
<
View
className=
{
styles
.
process_inner
}
style=
{
processInnerStyle
}
></
View
>
{
!
isOneStop
&&
(
<
View
className=
{
styles
.
role
}
style=
{
roleStyle
}
>
<
View
className=
{
styles
.
roleWrap
}
style=
{
roleStyle
}
>
<
View
className=
{
styles
.
role
}
>
<
View
className=
{
styles
.
tick
}
></
View
>
<
Image
src=
{
require
(
'../assets/count-cat.png'
)
}
className=
{
styles
.
cat
}
></
Image
>
<
View
className=
{
styles
.
tips
}
>
通关要求
</
View
>
</
View
>
</
View
>
)
}
</
View
>
<
View
className=
{
classNames
(
styles
.
time
,
isExceed
&&
styles
.
red
)
}
>
...
...
@@ -95,7 +96,7 @@ const CountUp = (props: CountUpProps) => {
<
count
-
up
-
time
exceedTime=
{
20
}
onExceed=
{
exceedActions
.
setTrue
}
maxValue=
{
60
*
60
}
maxValue=
{
stageDetail
.
bTime
}
startValue=
{
startTick
}
isDown=
{
isOneStop
}
onTimeup=
{
handleTimeUp
}
...
...
src/pages/game/play/components/modal-continue.tsx
View file @
14f990d9
...
...
@@ -5,16 +5,9 @@ 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
ModalContinue
=
()
=>
{
const
modalContinueVisible
=
useStoreState
(
state
=>
state
.
gameModel
.
modalContinueVisible
)
const
cardNum
=
useStoreState
(
state
=>
state
.
userModel
.
cardNum
)
...
...
@@ -22,12 +15,6 @@ const ModalContinue = (props: ModalContinueProps) => {
const
submit
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
submit
)
const
reborn
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
reborn
)
const
handleClick
=
useCallback
(()
=>
{
if
(
closeOnClickModal
)
{
onClose
?.()
}
},
[
closeOnClickModal
,
onClose
])
useEffect
(()
=>
{
if
(
modalContinueVisible
)
{
fetchAccount
()
...
...
@@ -40,7 +27,7 @@ const ModalContinue = (props: ModalContinueProps) => {
return
(
<
RootPortal
>
<
View
className=
{
classNames
(
styles
.
mask
,
modalContinueVisible
&&
styles
.
is_show
)
}
onClick=
{
handleClick
}
>
<
View
className=
{
classNames
(
styles
.
mask
,
modalContinueVisible
&&
styles
.
is_show
)
}
>
</
View
>
<
View
className=
{
classNames
(
styles
.
modal
,
modalContinueVisible
&&
styles
.
is_show
)
}
>
<
View
className=
{
styles
.
title
}
>
是否继续闯关?
</
View
>
...
...
src/pages/game/play/index.tsx
View file @
14f990d9
...
...
@@ -16,7 +16,6 @@ import styles from './index.module.scss'
const
GamePlay
=
()
=>
{
const
currentQuestion
=
useStoreState
(
states
=>
states
.
gameModel
.
currentQuestion
)
const
stageDetail
=
useStoreState
(
state
=>
state
.
gameModel
.
stageDetail
)
const
[
val
,
actions
]
=
useBoolean
(
false
)
return
(
<>
...
...
@@ -41,7 +40,7 @@ const GamePlay = () => {
</>
)
}
</
View
>
<
ModalContinue
closeOnClickModal
onClose=
{
actions
.
setFalse
}
/>
<
ModalContinue
/>
</>
)
}
...
...
src/pages/game/play/model/index.ts
View file @
14f990d9
...
...
@@ -13,6 +13,7 @@ import { buildCompleteStageParam, convertQuestion, determinQuestion } from './ut
interface
CompleteStageDetail
extends
CompleteStageOut
{
errNum
:
number
;
levelTime
:
number
;
isTimeout
:
boolean
;
}
const
COUNTER_ID
=
'z__countdown__'
...
...
@@ -277,6 +278,7 @@ const gameModel: GameModel = {
actions
.
updateState
({
gameResult
:
{
...
gameResult
,
isTimeout
:
params
.
isTimeout
,
errNum
:
params
.
num
-
params
.
correctNum
,
levelTime
:
params
.
levelTime
}
...
...
src/pages/game/play/model/utils.ts
View file @
14f990d9
...
...
@@ -40,7 +40,7 @@ export function convertQuestion (question: QuestionType): QuestionType {
}
export
function
buildCompleteStageParam
(
questionList
:
QuestionType
[],
stageDetail
:
StageDetail
,
resultTime
:
number
):
CompleteStageParam
{
const
wrongList
=
questionList
.
map
(
c
=>
!
determinQuestion
(
c
)).
filter
(
Boolean
)
const
wrongList
=
questionList
.
filter
(
c
=>
!
determinQuestion
(
c
)
)
const
wrongLength
=
wrongList
.
length
if
(
wrongLength
>
0
)
{
...
...
@@ -55,6 +55,8 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta
const
num
=
questionList
.
length
let
levelTime
:
number
=
0
const
isTimeout
=
resultTime
>
bTime
const
correctNum
=
num
-
wrongLength
if
(
correctNum
===
num
)
{
...
...
@@ -73,6 +75,7 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta
return
{
correctNum
,
level
,
isTimeout
,
levelTime
,
stageId
:
stageDetail
.
id
,
questions
:
questionList
.
map
(
convert
),
...
...
src/pages/main/components/header.module.scss
View file @
14f990d9
...
...
@@ -32,13 +32,15 @@
.avatar
{
flex
:
1
;
.icon
{
min-width
:
0
;
.name
{
overflow
:
hidden
;
text-overflow
:
ellipsis
;
white-space
:
nowrap
;
font-size
:
14
PX
;
font-weight
:
500
;
margin-left
:
16
PX
;
width
:
32
PX
;
height
:
32
PX
;
margin-right
:
4
PX
;
border-radius
:
16
PX
;
background-color
:
#999
;
color
:
#FFFFFF
;
}
}
...
...
src/pages/main/components/header.tsx
View file @
14f990d9
...
...
@@ -25,6 +25,7 @@ const MainHeader = () => {
const
cardNum
=
useStoreState
(
state
=>
state
.
userModel
.
cardNum
)
const
point
=
useStoreState
(
state
=>
state
.
userModel
.
point
)
const
userInfo
=
useStoreState
(
state
=>
state
.
userModel
.
userInfo
)
return
(
<
View
className=
{
styles
.
header
}
>
...
...
@@ -38,7 +39,7 @@ const MainHeader = () => {
>
<
View
className=
{
styles
.
inner
}
style=
{
innerStyle
}
>
<
View
className=
{
styles
.
avatar
}
>
<
Image
src=
"https://cdn.jkwljy.com/pbb/6gkGHSsPmxc_coeGYahBkelo_2w_/96x96"
className=
{
styles
.
icon
}
></
Image
>
<
Text
className=
{
styles
.
name
}
>
{
userInfo
?.
nickName
??
''
}
</
Text
>
</
View
>
<
View
className=
{
classNames
(
styles
.
score
,
cs
.
bounce_btn
)
}
onClick=
{
goStore
}
hoverClass=
{
cs
.
bounce_btn_hover
}
>
<
Image
src=
{
require
(
'../assets/score.png'
)
}
className=
{
styles
.
icon
}
/>
...
...
src/pages/main/components/scene/stage.tsx
View file @
14f990d9
...
...
@@ -4,6 +4,7 @@ import classNames from 'classnames'
import
{
cs
}
from
'@/styles'
import
{
navigateTo
}
from
'@tarojs/taro'
import
type
{
ImageSource
}
from
'@/types'
import
{
useStoreActions
}
from
'@/store/hooks'
import
{
type
Stage
,
StageType
,
StageStatus
,
StageLevel
,
CurrentRoundId
,
SceneContext
}
from
'./constants'
import
StageTag
from
'./stage-tag'
...
...
@@ -103,6 +104,7 @@ const getIconClassNames = (type?: StageType, extra: string[] = []) => {
const
StageComp
=
(
props
:
StageProps
)
=>
{
const
{
stage
}
=
props
const
updateState
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
updateState
)
const
renderRound
=
(
ready
:
boolean
)
=>
{
switch
(
stage
.
status
)
{
...
...
@@ -143,6 +145,8 @@ const StageComp = (props: StageProps) => {
const
handleClick
=
()
=>
{
if
(
stage
.
status
!==
StageStatus
.
DISABLED
)
{
/** 从首页进入更新状态 */
updateState
({
isSubmit
:
false
})
navigateTo
({
url
:
`/pages/prepare/index?id=
${
stage
.
id
}
`
})
}
}
...
...
src/pages/main/main.tsx
View file @
14f990d9
...
...
@@ -24,6 +24,7 @@ const MainPage = () => {
const
fetchStage
=
useStoreActions
(
actions
=>
actions
.
mainModel
.
fetchStage
)
const
stageList
=
useStoreState
(
state
=>
state
.
mainModel
.
stageList
)
const
fetchAccount
=
useStoreActions
(
actions
=>
actions
.
userModel
.
fetchAccount
)
const
updateUserInfo
=
useStoreActions
(
actions
=>
actions
.
userModel
.
updateUserInfo
)
const
fetchTribeInfo
=
useStoreActions
(
actions
=>
actions
.
groupModel
.
fetchTribeInfo
)
const
[
nav
]
=
useState
(
getMenuButtonBoundingClientRect
())
const
router
=
useRouter
<
{
groupId
:
string
,
inviteId
:
string
}
>
()
...
...
@@ -40,6 +41,7 @@ const MainPage = () => {
useDidShow
(()
=>
{
fetchAccount
()
updateUserInfo
(
'曾牛逼'
)
const
tabbar
=
getTabBar
<
TabbarRef
>
(
page
)
tabbar
?.
setSelected
(
0
)
...
...
src/pages/market/components/answer-sheet.tsx
deleted
100644 → 0
View file @
fa581ec1
import
{
View
,
Text
,
Button
}
from
'@tarojs/components'
import
Modal
from
'@/components/Modal'
import
{
useBoolean
}
from
'@/hooks/use-boolean'
// import { MarketModalProps } from '../types'
import
CardMain
from
'./card-main'
const
AnswerSheet
=
({
onConfirm
,
loading
})
=>
{
const
[
isVisible
,
{
setTrue
,
setFalse
}]
=
useBoolean
(
false
)
return
(
<
View
className=
"card-body"
>
<
CardMain
title=
"答题卡"
subtitle=
"答题卡是不断追求更高档位与排名的必备道具答题卡是不断追求更高档位与排名的必备道具"
extra=
{
<
Text
className=
"card-stock"
>
本月库存10
</
Text
>
}
onClick=
{
setTrue
}
/>
<
Modal
isVisible=
{
isVisible
}
onClose=
{
setFalse
}
>
<
View
>
<
Text
>
兑换几张
</
Text
>
<
Button
size=
"mini"
loading=
{
loading
}
onClick=
{
()
=>
onConfirm
(
'CARD'
,
setFalse
)
}
>
兑换
</
Button
>
</
View
>
</
Modal
>
</
View
>
)
}
export
default
AnswerSheet
src/pages/market/components/exchange-item.tsx
View file @
14f990d9
...
...
@@ -28,8 +28,10 @@ const ExchangeItem = (props: ExchangeItemProps) => {
},
[
val
])
useEffect
(()
=>
{
if
(
visible
)
{
if
(
!
visible
)
{
setTimeout
(()
=>
{
setVal
(
0
)
},
1000
)
}
},
[
visible
])
...
...
src/pages/prepare/index.tsx
View file @
14f990d9
import
{
View
,
Text
,
Image
}
from
'@tarojs/components'
import
{
useMemo
,
useState
}
from
'react'
import
{
useMemo
,
useState
,
useEffect
}
from
'react'
import
{
useRouter
,
redirectTo
,
useDidShow
,
getMenuButtonBoundingClientRect
,
useShareAppMessage
,
navigateTo
}
from
'@tarojs/taro'
import
classNames
from
'classnames'
...
...
@@ -38,6 +38,8 @@ const Prepare = () => {
const
getStageDetail
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
getStageDetail
)
const
getQuestionList
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
getQuestionList
)
const
updateState
=
useStoreActions
(
actions
=>
actions
.
gameModel
.
updateState
)
const
getSetting
=
useStoreActions
(
actions
=>
actions
.
userModel
.
getSetting
)
const
setting
=
useStoreState
(
state
=>
state
.
userModel
.
setting
)
const
tabs
:
TabItem
[]
=
[
{
...
...
@@ -73,6 +75,12 @@ const Prepare = () => {
}
},
[
nav
.
height
,
nav
.
top
])
useEffect
(()
=>
{
if
(
cardNum
<
1
)
{
getSetting
()
}
},
[
cardNum
,
getSetting
])
useDidShow
(()
=>
{
getStageDetail
(
+
router
.
params
.
id
||
1
)
})
...
...
@@ -151,21 +159,21 @@ const Prepare = () => {
</View>
</ShareView>}
{isSubmit ? renderFisrtActions() : renderAgainActions()}
{
!
isSubmit ? renderFisrtActions() : renderAgainActions()}
</View>
<AnswerCardModal isVisible={isVisible} onClose={setFalse}>
<View
className={classNames(styles.buy_card, {
[styles.buy_card_disabled]: point <
30
,
[styles.buy_card_disabled]: point <
setting.pointToCard
,
[styles.buy_card_loading]: loading,
})}
onClick={() => !loading && point >=
30
&& exchange({ num: 1 })}
onClick={() => !loading && point >=
setting.pointToCard
&& exchange({ num: 1 })}
>
<Loading size="small" className={styles.buy_card_spin} spinning={loading} />
<View className={styles.inner}>
<Image className={styles.logo} src={point >=
30
? assets['diamond.png'].u : assets['diamond-un.png'].u} mode="widthFix" />
<Text>-
30
</Text>
<Image className={styles.logo} src={point >=
setting.pointToCard
? assets['diamond.png'].u : assets['diamond-un.png'].u} mode="widthFix" />
<Text>-
{setting.pointToCard}
</Text>
<Text className={styles.buy}>购买</Text>
<Text className={styles.balance}>(当前剩余 {point})</Text>
</View>
...
...
src/store/modules/user.ts
View file @
14f990d9
import
{
action
,
Action
,
Thunk
,
thunk
,
State
}
from
'easy-peasy'
import
{
getAccountInfo
,
getSetting
}
from
'@/api'
import
{
getAccountInfo
,
getSetting
,
updateUserInfo
}
from
'@/api'
import
type
{
UserInfo
}
from
'@/types'
import
{
pointToCard
}
from
'@/api/account'
import
{
showModal
,
showToast
,
showLoading
,
hideLoading
}
from
'@tarojs/taro'
import
{
getStorage
,
StorageKeys
}
from
'@/utils/storage'
import
{
getStorage
,
StorageKeys
,
updateStorage
}
from
'@/utils/storage'
import
{
AppStoreModel
}
from
'../store-model'
export
interface
UserModel
{
...
...
@@ -14,9 +14,9 @@ export interface UserModel {
point
:
number
;
updateState
:
Action
<
UserModel
,
Partial
<
State
<
UserModel
>>>
;
fetchAccount
:
Thunk
<
UserModel
,
void
,
void
,
AppStoreModel
>
;
updateUserInfo
:
Action
<
UserModel
,
UserInfo
>
;
setting
:
{
pointToCard
:
number
};
getSetting
:
Thunk
<
UserModel
,
void
,
void
,
AppStoreModel
>
;
updateUserInfo
:
Thunk
<
UserModel
,
string
,
void
,
AppStoreModel
>
;
exchangeItem
:
Thunk
<
UserModel
,
{
name
:
string
;
num
:
number
;
},
void
,
AppStoreModel
>
;
}
...
...
@@ -34,6 +34,19 @@ const userModel: UserModel = {
actions
.
updateState
({
setting
:
{
pointToCard
:
Infinity
}
})
}
}),
updateUserInfo
:
thunk
(
async
(
actions
,
nickName
,
helpers
)
=>
{
try
{
await
updateUserInfo
(
nickName
)
const
{
userInfo
}
=
helpers
.
getState
()
const
current
=
{
...
userInfo
,
nickName
}
updateStorage
(
StorageKeys
.
userInfo
,
current
)
actions
.
updateState
({
userInfo
:
current
})
}
catch
(
err
)
{
console
.
log
(
err
)
}
}),
exchangeItem
:
thunk
(
async
(
actions
,
payload
)
=>
{
try
{
showLoading
({
mask
:
true
,
title
:
'兑换中...'
})
...
...
@@ -52,9 +65,6 @@ const userModel: UserModel = {
})
}
}),
updateUserInfo
:
action
((
state
,
user
)
=>
{
state
.
userInfo
=
user
}),
updateState
:
action
((
state
,
payload
)
=>
{
for
(
const
key
in
payload
)
{
state
[
key
]
=
payload
[
key
]
...
...
src/types.ts
View file @
14f990d9
...
...
@@ -4,7 +4,7 @@ export type UserInfo = {
openId
:
string
;
userId
?:
number
;
city
?:
string
;
nick
n
ame
?:
string
|
null
;
nick
N
ame
?:
string
|
null
;
phone
?:
string
|
null
;
}
...
...
src/utils/silent-login.ts
View file @
14f990d9
...
...
@@ -28,7 +28,7 @@ async function silentLogin () {
updateStorage(StorageKeys.openid, data.openId)
updateStorage(StorageKeys.userInfo, data)
store.getActions().userModel.update
UserInfo(data
)
store.getActions().userModel.update
State({ userInfo: data }
)
setProfile(data.openId, `
$
{
data
.
userId
}
`)
} catch (silentLoginError) {
...
...
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