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
ebde4b1f
Commit
ebde4b1f
authored
Apr 05, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 兑换答题卡
parent
f70c4484
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
504 additions
and
174 deletions
+504
-174
stage-tag.tsx
src/pages/main/components/scene/stage-tag.tsx
+0
-1
add.png
src/pages/market/assets/add.png
+0
-0
btn-off.png
src/pages/market/assets/btn-off.png
+0
-0
btn-on.png
src/pages/market/assets/btn-on.png
+0
-0
gift.png
src/pages/market/assets/gift.png
+0
-0
minus.png
src/pages/market/assets/minus.png
+0
-0
ph.png
src/pages/market/assets/ph.png
+0
-0
score.png
src/pages/market/assets/score.png
+0
-0
card-main.module.scss
src/pages/market/components/card-main.module.scss
+102
-0
card-main.tsx
src/pages/market/components/card-main.tsx
+37
-13
card.module.scss
src/pages/market/components/card.module.scss
+8
-4
card.tsx
src/pages/market/components/card.tsx
+1
-3
exchange-item.module.scss
src/pages/market/components/exchange-item.module.scss
+100
-0
exchange-item.tsx
src/pages/market/components/exchange-item.tsx
+88
-0
index.config.ts
src/pages/market/index.config.ts
+4
-2
index.module.scss
src/pages/market/index.module.scss
+60
-0
index.scss
src/pages/market/index.scss
+0
-77
index.tsx
src/pages/market/index.tsx
+76
-69
user.ts
src/store/modules/user.ts
+28
-5
No files found.
src/pages/main/components/scene/stage-tag.tsx
View file @
ebde4b1f
...
@@ -33,7 +33,6 @@ const StageTag = (props: StageTagProps) => {
...
@@ -33,7 +33,6 @@ const StageTag = (props: StageTagProps) => {
useEffect
(()
=>
{
useEffect
(()
=>
{
let
observer
:
IntersectionObserver
|
null
=
null
let
observer
:
IntersectionObserver
|
null
=
null
const
fn
=
()
=>
{
const
fn
=
()
=>
{
console
.
log
(
ready
,
isFocus
,
111
)
if
(
ready
&&
isFocus
)
{
if
(
ready
&&
isFocus
)
{
const
navVal
=
nav
.
current
const
navVal
=
nav
.
current
// @ts-ignore
// @ts-ignore
...
...
src/pages/market/assets/add.png
0 → 100644
View file @
ebde4b1f
470 Bytes
src/pages/market/assets/btn-off.png
0 → 100644
View file @
ebde4b1f
2.86 KB
src/pages/market/assets/btn-on.png
0 → 100644
View file @
ebde4b1f
2.2 KB
src/pages/market/assets/gift.png
0 → 100644
View file @
ebde4b1f
5.2 KB
src/pages/market/assets/minus.png
0 → 100644
View file @
ebde4b1f
374 Bytes
src/pages/market/assets/ph.png
0 → 100644
View file @
ebde4b1f
5.43 KB
src/pages/market/assets/score.png
0 → 100644
View file @
ebde4b1f
4.72 KB
src/pages/market/components/card-main.module.scss
0 → 100644
View file @
ebde4b1f
@import
'@/styles/mixins.scss'
;
.card-action
{
@include
flexLayout
(
column
,
_
,
space-between
);
flex-grow
:
1
;
.card-description
{
flex-grow
:
1
;
@include
flexLayout
(
column
,
_
,
space-between
);
.card-title
{
font-size
:
36px
;
font-weight
:
500
;
color
:
#465164
;
line-height
:
50px
;
margin-bottom
:
8px
;
display
:
flex
;
justify-content
:
space-between
;
align-items
:
center
;
}
.card-subtitle
{
font-size
:
32px
;
font-weight
:
400
;
color
:
rgba
(
70
,
81
,
100
,
0
.8
);
line-height
:
44px
;
@include
multi-ellipsis
(
2
);
}
}
.stoke-left
{
font-size
:
24px
;
font-weight
:
400
;
color
:
rgba
(
70
,
81
,
100
,
0
.5
);
line-height
:
34px
;
}
.left_value
{
color
:
#1786F7
;
}
.card-footer
{
margin-top
:
32px
;
@include
flexLayout
(
_
,
_
,
space-between
);
.card-score
{
@include
flexLayout
(
_
,
center
);
&
-icon
{
width
:
32
PX
;
height
:
32
PX
;
margin-right
:
4px
;
}
&
-text
{
font-size
:
32px
;
font-weight
:
500
;
color
:
#1786F7
;
line-height
:
38px
;
}
}
.card-exchange
{
@include
btn
();
}
}
}
.btn
{
width
:
248px
;
height
:
72px
;
background-image
:
url(../assets/btn-off.png)
;
background-size
:
100%
100%
;
display
:
flex
;
align-items
:
center
;
justify-content
:
center
;
font-size
:
28px
;
font-weight
:
500
;
color
:
#FFFFFF
;
line-height
:
40px
;
&
.btn_on
{
background-image
:
url(../assets/btn-on.png)
;
}
&
.disabled
{
background-image
:
none
;
background-color
:
#E2E6ED
;
color
:
#C2C8D1
;
border-radius
:
36px
;
}
}
.card-main
{
@include
flexLayout
(
column
,
_
,
space-between
);
margin-right
:
16px
;
.card-image
{
width
:
140px
;
height
:
140px
;
}
}
src/pages/market/components/card-main.tsx
View file @
ebde4b1f
import
{
View
,
Image
,
Text
,
Button
}
from
'@tarojs/components'
import
{
View
,
Image
,
Text
}
from
'@tarojs/components'
import
classNames
from
'classnames'
import
styles
from
'./card-main.module.scss'
interface
CardMainProps
{
interface
CardMainProps
{
onClick
:
()
=>
void
;
onClick
:
()
=>
void
;
cover
?:
string
;
cover
?:
string
;
title
:
string
;
title
:
string
;
subtitle
:
string
;
subtitle
:
string
;
extra
?:
React
.
ReactNode
disabled
?:
boolean
;
extra
?:
React
.
ReactNode
;
price
:
number
;
stoke
:
number
|
null
;
}
}
export
default
({
export
default
({
...
@@ -14,24 +19,43 @@ export default ({
...
@@ -14,24 +19,43 @@ export default ({
extra
,
extra
,
subtitle
,
subtitle
,
onClick
,
onClick
,
disabled
,
price
,
stoke
}:
CardMainProps
)
=>
{
}:
CardMainProps
)
=>
{
const
_onClick
=
()
=>
{
if
(
!
disabled
)
{
onClick
()
}
}
return
(
return
(
<>
<>
<
View
className=
"card-main"
>
<
View
className=
{
styles
[
'card-main'
]
}
>
<
Image
className=
"card-image"
src=
{
cover
}
defaultSource=
"https://cdn.jkwljy.com/pbb/6gkGHSsPmxc_coeGYahBkelo_2w_/96x96"
/>
<
Image
className=
{
styles
[
'card-image'
]
}
src=
{
cover
}
defaultSource=
"https://cdn.jkwljy.com/pbb/6gkGHSsPmxc_coeGYahBkelo_2w_/96x96"
/>
{
extra
}
{
extra
}
</
View
>
</
View
>
<
View
className=
"card-action"
>
<
View
className=
{
styles
[
'card-action'
]
}
>
<
View
className=
"card-description"
>
<
View
className=
{
styles
[
'card-description'
]
}
>
<
Text
className=
"card-title"
>
{
title
}
</
Text
>
<
View
className=
{
styles
[
'card-title'
]
}
>
<
Text
className=
"card-subtitle"
>
{
subtitle
}
</
Text
>
{
title
}
{
stoke
!==
null
&&
(
<
View
className=
{
styles
[
'stoke-left'
]
}
>
本月库存
<
Text
className=
{
styles
.
left_value
}
>
{
stoke
}
</
Text
></
View
>
)
}
</
View
>
<
Text
className=
{
styles
[
'card-subtitle'
]
}
>
{
subtitle
}
</
Text
>
</
View
>
</
View
>
<
View
className=
"card-footer"
>
<
View
className=
{
styles
[
'card-footer'
]
}
>
<
View
className=
"card-score"
>
<
View
className=
{
styles
[
'card-score'
]
}
>
<
Image
src=
{
require
(
'../../main/assets/score.png'
)
}
className=
"card-score-icon"
/>
<
Image
src=
{
require
(
'../../main/assets/score.png'
)
}
className=
{
styles
[
'card-score-icon'
]
}
/>
<
Text
className=
"card-score-text"
>
积分271
</
Text
>
<
Text
className=
{
styles
[
'card-score-text'
]
}
>
{
price
}
</
Text
>
</
View
>
<
View
className=
{
classNames
(
styles
.
btn
,
disabled
&&
styles
.
disabled
)
}
onClick=
{
_onClick
}
hoverClass=
{
!
disabled
?
styles
.
btn_on
:
''
}
>
兑换
</
View
>
</
View
>
<
Button
className=
"card-exchange"
onClick=
{
onClick
}
>
兑换
</
Button
>
</
View
>
</
View
>
</
View
>
</
View
>
</>
</>
...
...
src/pages/market/components/card.module.scss
View file @
ebde4b1f
.card
{
.card
{
position
:
relative
;
position
:
relative
;
background-color
:
#fff
;
background-color
:
#fff
;
margin-bottom
:
12
PX
;
margin-bottom
:
64px
;
padding
:
12
PX
;
}
}
.bordered
{
.bordered
{
border
:
1px
solid
#f0f0f0
;
border
:
1px
solid
#f0f0f0
;
}
}
...
@@ -19,9 +18,14 @@
...
@@ -19,9 +18,14 @@
display
:
flex
;
display
:
flex
;
align-items
:
center
;
align-items
:
center
;
justify-content
:
space-between
;
justify-content
:
space-between
;
margin-bottom
:
8
PX
;
margin-bottom
:
24px
;
}
}
.title
{
.title
{
font-weight
:
500
;
font-weight
:
500
;
font-size
:
40px
;
color
:
#465164
;
line-height
:
56px
;
}
}
src/pages/market/components/card.tsx
View file @
ebde4b1f
...
@@ -10,7 +10,6 @@ interface CardProps {
...
@@ -10,7 +10,6 @@ interface CardProps {
headStyle
?:
React
.
CSSProperties
;
headStyle
?:
React
.
CSSProperties
;
loading
?:
boolean
;
loading
?:
boolean
;
title
?:
React
.
ReactNode
;
title
?:
React
.
ReactNode
;
hoverable
?:
boolean
;
extra
?:
React
.
ReactNode
;
extra
?:
React
.
ReactNode
;
bodyStyle
?:
React
.
CSSProperties
;
bodyStyle
?:
React
.
CSSProperties
;
}
}
...
@@ -20,7 +19,6 @@ const Card = ({
...
@@ -20,7 +19,6 @@ const Card = ({
extra
,
extra
,
loading
,
loading
,
bordered
,
bordered
,
hoverable
,
headStyle
,
headStyle
,
bodyStyle
,
bodyStyle
,
children
children
...
@@ -30,7 +28,7 @@ const Card = ({
...
@@ -30,7 +28,7 @@ const Card = ({
})
})
return
(
return
(
<
View
className=
{
cardClass
}
hoverClass=
{
hoverable
&&
styles
.
hoverable
}
>
<
View
className=
{
cardClass
}
>
{
(
title
||
extra
)
&&
(
{
(
title
||
extra
)
&&
(
<
View
className=
{
styles
.
head
}
style=
{
headStyle
}
>
<
View
className=
{
styles
.
head
}
style=
{
headStyle
}
>
{
title
&&
<
View
className=
{
styles
.
title
}
>
{
title
}
</
View
>
}
{
title
&&
<
View
className=
{
styles
.
title
}
>
{
title
}
</
View
>
}
...
...
src/pages/market/components/exchange-item.module.scss
0 → 100644
View file @
ebde4b1f
.cancel
,
.confirm
{
width
:
246px
;
height
:
72px
;
border-radius
:
36px
;
border
:
4px
solid
rgba
(
70
,
81
,
100
,
0
.3
);
font-size
:
28px
;
font-weight
:
500
;
color
:
rgba
(
70
,
81
,
100
,
0
.5
);
line-height
:
40px
;
display
:
flex
;
align-items
:
center
;
justify-content
:
center
;
}
.confirm
{
background
:
#1786F7
;
border-color
:
transparent
;
color
:
#fff
;
&
.disbaled
{
background
:
#C7C9D0
;
}
}
.footer
{
display
:
flex
;
align-items
:
center
;
justify-content
:
space-between
;
padding
:
0
32px
;
}
.input
{
display
:
flex
;
align-items
:
center
;
font-size
:
32px
;
font-weight
:
600
;
color
:
#465164
;
line-height
:
44px
;
padding
:
32px
32px
104px
32px
;
}
.input_main
{
flex
:
1
;
display
:
flex
;
align-items
:
center
;
padding
:
16px
;
background
:
#F0F2F9
;
border-radius
:
48px
;
margin-right
:
16px
;
}
.num
{
flex
:
1
;
text-align
:
center
;
font-size
:
48px
;
font-weight
:
bold
;
color
:
#FFC056
;
line-height
:
58px
;
}
.input_main_wrap
{
flex
:
1
;
position
:
relative
;
}
.tips
{
position
:
absolute
;
left
:
0
;
right
:
0
;
bottom
:
-56px
;
text-align
:
center
;
font-size
:
28px
;
font-weight
:
400
;
color
:
rgba
(
88
,
97
,
112
,
0
.5
);
line-height
:
40px
;
}
.tips_val
{
color
:
#1786F7
;
}
.btn
{
background
:
#9BA1AF
;
border-radius
:
32px
;
&
.is_add
{
background-color
:
#FFC056
;
}
&
.disabled
{
background
:
#C7C9D0
;
}
.icon
{
width
:
64px
;
height
:
64px
;
display
:
block
;
}
}
src/pages/market/components/exchange-item.tsx
0 → 100644
View file @
ebde4b1f
import
{
View
,
Image
,
Text
}
from
'@tarojs/components'
import
{
showToast
}
from
'@tarojs/taro'
import
{
useStoreActions
}
from
'@/store/hooks'
import
{
useState
,
useCallback
,
useMemo
,
useEffect
}
from
'react'
import
classNames
from
'classnames'
import
styles
from
'./exchange-item.module.scss'
type
ExchangeItemProps
=
{
stepValue
:
number
;
maxValue
:
number
;
title
:
string
;
// onConfirm: (arg: number) => void;
onCancel
:
()
=>
void
;
visible
:
boolean
;
}
const
ExchangeItem
=
(
props
:
ExchangeItemProps
)
=>
{
const
{
stepValue
,
maxValue
,
onCancel
,
visible
,
title
}
=
props
const
exchangeItem
=
useStoreActions
(
actions
=>
actions
.
userModel
.
exchangeItem
)
const
[
val
,
setVal
]
=
useState
(
0
)
const
handleMinus
=
useCallback
(()
=>
{
if
(
val
<
1
)
{
return
}
setVal
(
value
=>
value
-
1
)
},
[
val
])
useEffect
(()
=>
{
if
(
visible
)
{
setVal
(
0
)
}
},
[
visible
])
const
handleAdd
=
useCallback
(()
=>
{
const
next
=
val
+
1
if
(
next
*
stepValue
>
maxValue
)
{
return
showToast
({
title
:
'学分不足~'
,
icon
:
'none'
})
}
setVal
(
next
)
},
[
val
,
stepValue
,
maxValue
])
const
disableAdd
=
useMemo
(()
=>
{
return
(
val
+
1
)
*
stepValue
>
maxValue
},
[
val
,
stepValue
,
maxValue
])
const
disableMinus
=
useMemo
(()
=>
{
return
val
<
1
},
[
val
])
const
handleConfirm
=
()
=>
{
if
(
val
<
1
)
{
return
showToast
({
title
:
'兑换数量必须大于0'
,
icon
:
'none'
})
}
exchangeItem
({
name
:
title
,
num
:
val
}).
then
(
onCancel
)
}
return
(
<>
<
View
className=
{
styles
.
input
}
>
<
View
>
兑换:
</
View
>
<
View
className=
{
styles
.
input_main_wrap
}
>
<
View
className=
{
styles
.
input_main
}
>
<
View
className=
{
classNames
(
styles
.
btn
,
disableMinus
&&
styles
.
disabled
)
}
onClick=
{
handleMinus
}
>
<
Image
src=
{
require
(
'../assets/minus.png'
)
}
className=
{
styles
.
icon
}
></
Image
>
</
View
>
<
View
className=
{
styles
.
num
}
>
{
val
}
</
View
>
<
View
className=
{
classNames
(
styles
.
btn
,
styles
.
is_add
,
disableAdd
&&
styles
.
disabled
)
}
onClick=
{
handleAdd
}
>
<
Image
src=
{
require
(
'../assets/add.png'
)
}
className=
{
styles
.
icon
}
></
Image
>
</
View
>
</
View
>
<
View
className=
{
styles
.
tips
}
>
将消耗
<
Text
className=
{
styles
.
tips_val
}
>
{
val
*
stepValue
}
</
Text
>
水晶
</
View
>
</
View
>
<
View
>
张
</
View
>
</
View
>
<
View
className=
{
styles
.
footer
}
>
<
View
className=
{
styles
.
cancel
}
onClick=
{
()
=>
onCancel
()
}
>
取消
</
View
>
<
View
className=
{
classNames
(
styles
.
confirm
,
val
<
1
&&
styles
.
disbaled
)
}
onClick=
{
handleConfirm
}
>
确定
</
View
>
</
View
>
</>
)
}
export
default
ExchangeItem
src/pages/market/index.config.ts
View file @
ebde4b1f
export
default
definePageConfig
({
export
default
definePageConfig
({
navigationBarTitleText
:
'pk-math'
,
navigationBarTitleText
:
'学分小店'
,
navigationStyle
:
'custom'
navigationStyle
:
'default'
,
navigationBarBackgroundColor
:
'#2B3347'
,
navigationBarTextStyle
:
'white'
})
})
src/pages/market/index.module.scss
0 → 100644
View file @
ebde4b1f
@import
'../../styles/mixins.scss'
;
.card-body
{
display
:
flex
;
padding
:
32px
28px
;
position
:
relative
;
border-radius
:
32px
;
border
:
6px
solid
#F0F2F9
;
}
.card-stock
{
color
:
#666
;
font-size
:
14
PX
;
text-align
:
center
;
}
.card_list
{
position
:
relative
;
z-index
:
1
;
background
:
#FFFFFF
;
border-radius
:
40px
40px
0px
0px
;
margin-top
:
-40px
;
overflow
:
hidden
;
padding
:
60px
32px
40px
32px
;
}
.head
{
background-color
:
#2B3347
;
padding
:
34px
64px
94px
40px
;
display
:
flex
;
justify-content
:
space-between
;
}
.moal_body
{
width
:
654px
;
box-sizing
:
border-box
;
}
.score_icon
{
width
:
112px
;
height
:
112px
;
}
.score_text
{
padding-top
:
18px
;
font-size
:
64px
;
font-weight
:
500
;
color
:
#FFFFFF
;
line-height
:
78px
;
display
:
flex
;
align-items
:
flex-end
;
.unit
{
font-size
:
24px
;
font-weight
:
500
;
color
:
rgba
(
255
,
255
,
255
,
0
.5
);
line-height
:
34px
;
margin-left
:
8px
;
}
}
src/pages/market/index.scss
deleted
100644 → 0
View file @
f70c4484
@import
'../../styles/mixins.scss'
;
.wrapper
{
padding
:
16px
;
}
.card-body
{
display
:
flex
;
padding
:
12
PX
;
position
:
relative
;
border
:
1px
solid
red
;
.card-main
{
@include
flexLayout
(
column
,
_
,
space-between
);
min-width
:
160px
;
margin-right
:
12
PX
;
.card-image
{
width
:
100%
;
height
:
180px
;
background-color
:
#000
;
}
.card-stock
{
color
:
#666
;
font-size
:
14
PX
;
text-align
:
center
;
}
}
.card-action
{
@include
flexLayout
(
column
,
center
,
space-between
);
flex-grow
:
1
;
.card-description
{
flex-grow
:
1
;
@include
flexLayout
(
column
,
_
,
space-between
);
.card-title
{
color
:
#333
;
font-weight
:
500
;
margin-bottom
:
8px
;
}
.card-subtitle
{
color
:
#666
;
@include
multi-ellipsis
(
2
);
}
}
.card-footer
{
width
:
100%
;
margin-top
:
48px
;
@include
flexLayout
(
_
,
_
,
space-between
);
.card-score
{
@include
flexLayout
(
_
,
center
);
&
-icon
{
width
:
32
PX
;
height
:
32
PX
;
margin-right
:
4px
;
}
&
-text
{
color
:
#666
;
margin-right
:
8px
;
}
}
.card-exchange
{
@include
btn
();
}
}
}
}
\ No newline at end of file
src/pages/market/index.tsx
View file @
ebde4b1f
import
{
useState
}
from
'react'
/* eslint-disable import/no-commonjs */
import
{
View
,
Text
,
Button
}
from
'@tarojs/components'
import
{
useState
,
useCallback
}
from
'react'
import
{
getMenuButtonBoundingClientRect
,
showToast
,
showModal
}
from
'@tarojs/taro'
import
{
View
,
Text
,
Image
}
from
'@tarojs/components'
import
{
useDidShow
}
from
'@tarojs/taro'
import
{
useBoolean
,
useToggle
,
useRequest
}
from
'@/hooks'
import
{
useBoolean
}
from
'@/hooks'
import
{
pointToCard
}
from
'@/api/account'
import
Modal
from
'@/components/Modal'
import
Modal
from
'@/components/Modal'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
import
MainHeader
from
'../main/components/header
'
import
ExchangeItem
from
'./components/exchange-item
'
import
Card
from
'./components/card'
import
Card
from
'./components/card'
import
CardMain
from
'./components/card-main'
import
CardMain
from
'./components/card-main'
import
{
Demo
}
from
'./types'
import
styles
from
'./index.module.scss'
import
'./index.scss'
const
AnswerSheet
=
()
=>
{
type
ExchangeGoods
=
{
return
(
title
:
string
;
<
Text
>
答题卡
</
Text
>
subTitle
:
string
;
)
description
:
string
;
price
:
number
;
stoke
:
number
|
null
;
img
:
string
;
}
}
const
MysteryBox
=
()
=>
{
const
ExchangeItems
:
ExchangeGoods
[]
=
[
return
(
{
<
Text
>
MysteryBox
</
Text
>
title
:
'答题卡'
,
)
subTitle
:
'答题卡'
,
}
description
:
'答题卡是不断追求更高档位与排名的必备道具答题卡是不断追求更高档位与排名的必备道具'
,
price
:
30
,
stoke
:
null
,
img
:
require
(
'./assets/ph.png'
),
},
const
StudyMarket
=
()
=>
{
{
const
[
nav
]
=
useState
(
getMenuButtonBoundingClientRect
())
title
:
'月度神秘大礼'
,
const
paddingTop
=
`
${
nav
.
height
+
nav
.
top
+
5
}
px`
subTitle
:
'神秘大礼'
,
description
:
'兑换神秘大礼,线下领取超级大礼'
,
price
:
30
,
stoke
:
10
,
img
:
require
(
'./assets/gift.png'
),
}
]
const
StudyMarket
=
()
=>
{
const
[
isVisible
,
{
setTrue
,
setFalse
}]
=
useBoolean
(
false
)
const
[
isVisible
,
{
setTrue
,
setFalse
}]
=
useBoolean
(
false
)
const
[
state
,
{
setDefault
,
setReverse
}]
=
useToggle
({
defaultValue
:
Demo
.
AnswerSheet
,
reverseValue
:
Demo
.
Mystery
})
const
[
currentGoods
,
setCurrentGoods
]
=
useState
<
ExchangeGoods
|
null
>
(
null
)
const
point
=
useStoreState
(
state
=>
state
.
userModel
.
point
)
const
fetchAccount
=
useStoreActions
(
actions
=>
actions
.
userModel
.
fetchAccount
)
const
{
loading
}
=
useRequest
(
pointToCard
,
{
useDidShow
(()
=>
{
immediate
:
false
,
fetchAccount
()
onSuccess
()
{
showToast
({
title
:
'成功'
})
setFalse
()
},
onError
(
error
)
{
showModal
({
title
:
error
.
msg
||
error
.
message
})
}
})
})
return
(
const
open
=
useCallback
((
goods
:
ExchangeGoods
)
=>
{
<
View
className=
"wrapper"
>
setCurrentGoods
(
goods
)
<
MainHeader
/>
setTrue
()
<
View
style=
{
{
paddingTop
}
}
>
},
[
setTrue
])
<
Card
hoverable
title=
"答题卡"
>
<
View
className=
"card-body"
>
<
CardMain
title=
"答题卡"
subtitle=
"答题卡是不断追求更高档位与排名的必备道具答题卡是不断追求更高档位与排名的必备道具"
onClick=
{
()
=>
{
setDefault
()
setTrue
()
}
}
/>
</
View
>
</
Card
>
<
Card
hoverable
title=
"月度神秘大礼"
>
return
(
<
View
className=
"card-body"
>
<>
<
CardMain
<
View
className=
{
styles
.
head
}
>
title=
"神秘大礼"
<
View
className=
{
styles
.
score_text
}
>
{
point
}
<
Text
className=
{
styles
.
unit
}
>
水晶
</
Text
></
View
>
subtitle=
"兑换神秘大礼,线下领取超级大礼"
<
Image
src=
{
require
(
'./assets/score.png'
)
}
className=
{
styles
.
score_icon
}
></
Image
>
extra=
{
<
Text
className=
"card-stock"
>
本月库存10
</
Text
>
}
</
View
>
onClick=
{
()
=>
{
<
View
className=
{
styles
.
card_list
}
>
setReverse
()
{
ExchangeItems
.
map
(
item
=>
(
setTrue
()
<
Card
title=
{
item
.
title
}
key=
{
item
.
title
}
>
}
}
<
View
className=
{
styles
[
'card-body'
]
}
>
/>
<
CardMain
</
View
>
title=
{
item
.
subTitle
}
</
Card
>
cover=
{
item
.
img
}
stoke=
{
item
.
stoke
}
price=
{
item
.
price
}
disabled=
{
item
.
stoke
!==
null
&&
item
.
stoke
<
1
}
subtitle=
{
item
.
description
}
onClick=
{
()
=>
{
open
(
item
)
}
}
/>
</
View
>
</
Card
>
))
}
</
View
>
</
View
>
<
Modal
isVisible=
{
isVisible
}
onClose=
{
setFalse
}
>
<
Modal
isVisible=
{
isVisible
}
bodyClassName=
{
styles
.
moal_body
}
onClose=
{
setFalse
}
maskClosable=
{
false
}
tilte=
{
`兑换${currentGoods?.title ?? ''}`
}
>
{
state
}
<
ExchangeItem
<
View
>
title=
{
currentGoods
?.
title
??
''
}
{
state
===
Demo
.
AnswerSheet
&&
<
AnswerSheet
/>
}
stepValue=
{
currentGoods
?.
price
??
Infinity
}
{
state
===
Demo
.
Mystery
&&
<
MysteryBox
/>
}
maxValue=
{
point
}
<
Button
size=
"mini"
loading=
{
loading
}
onClick=
{
setTrue
}
>
兑换
</
Button
>
visible=
{
isVisible
}
</
View
>
onCancel=
{
setFalse
}
/>
</
Modal
>
</
Modal
>
</
View
>
</>
)
)
}
}
...
...
src/store/modules/user.ts
View file @
ebde4b1f
import
{
import
{
action
,
Action
,
Thunk
,
thunk
action
,
Action
,
Thunk
,
thunk
,
State
}
from
'easy-peasy'
}
from
'easy-peasy'
import
{
getAccountInfo
}
from
'@/api'
import
{
getAccountInfo
}
from
'@/api'
import
type
{
UserInfo
}
from
'@/types'
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
}
from
'@/utils/storage'
import
{
AppStoreModel
}
from
'../store-model'
import
{
AppStoreModel
}
from
'../store-model'
...
@@ -10,21 +12,42 @@ export interface UserModel {
...
@@ -10,21 +12,42 @@ export interface UserModel {
userInfo
:
UserInfo
;
userInfo
:
UserInfo
;
cardNum
:
number
;
cardNum
:
number
;
point
:
number
;
point
:
number
;
updateState
:
Action
<
UserModel
,
{
cardNum
:
number
;
point
:
number
}
>
;
updateState
:
Action
<
UserModel
,
Partial
<
State
<
UserModel
>>
>
;
fetchAccount
:
Thunk
<
UserModel
,
void
,
void
,
AppStoreModel
>
;
fetchAccount
:
Thunk
<
UserModel
,
void
,
void
,
AppStoreModel
>
;
updateUserInfo
:
Action
<
UserModel
,
UserInfo
>
;
updateUserInfo
:
Action
<
UserModel
,
UserInfo
>
;
exchangeItem
:
Thunk
<
UserModel
,
{
name
:
string
;
num
:
number
;
},
void
,
AppStoreModel
>
;
}
}
const
userModel
:
UserModel
=
{
const
userModel
:
UserModel
=
{
userInfo
:
getStorage
(
StorageKeys
.
userInfo
)
!
,
userInfo
:
getStorage
(
StorageKeys
.
userInfo
)
!
,
cardNum
:
0
,
cardNum
:
0
,
point
:
0
,
point
:
0
,
exchangeItem
:
thunk
(
async
(
actions
,
payload
)
=>
{
try
{
showLoading
({
mask
:
true
,
title
:
'兑换中...'
})
const
{
data
:
list
}
=
await
pointToCard
({
num
:
payload
.
num
})
const
cardNum
=
list
?.
find
(
c
=>
c
.
accountType
===
'CARD'
)?.
amount
??
0
const
point
=
list
?.
find
(
c
=>
c
.
accountType
===
'POINT'
)?.
amount
??
0
actions
.
updateState
({
cardNum
,
point
})
hideLoading
()
showToast
({
title
:
'兑换成功'
,
icon
:
'success'
})
}
catch
(
err
)
{
hideLoading
()
showModal
({
title
:
'提示'
,
content
:
err
.
message
,
showCancel
:
false
})
}
}),
updateUserInfo
:
action
((
state
,
user
)
=>
{
updateUserInfo
:
action
((
state
,
user
)
=>
{
state
.
userInfo
=
user
state
.
userInfo
=
user
}),
}),
updateState
:
action
((
state
,
{
cardNum
,
point
})
=>
{
updateState
:
action
((
state
,
payload
)
=>
{
state
.
cardNum
=
cardNum
for
(
const
key
in
payload
)
{
state
.
point
=
point
state
[
key
]
=
payload
[
key
]
}
}),
}),
fetchAccount
:
thunk
(
async
(
actions
)
=>
{
fetchAccount
:
thunk
(
async
(
actions
)
=>
{
...
...
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