Commit eaf4e397 authored by hewenhao's avatar hewenhao

feat: 学分小店引导

parent e4b3fed5
{
"item-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/2pzQ94eQbeDxLzt3863g8CBuowbz/140x140",
"w": 140,
"h": 140,
"ossName": "/pk-math/2pzQ94eQbeDxLzt3863g8CBuowbz/140x140"
},
"item-2.png": {
"u": "https://cdn.jkwljy.com/pk-math/2abYbhhvmBN6VFeSyTK8QuF3wvDA/140x140",
"w": 140,
"h": 140,
"ossName": "/pk-math/2abYbhhvmBN6VFeSyTK8QuF3wvDA/140x140"
},
"item-3.png": {
"u": "https://cdn.jkwljy.com/pk-math/eXdpuQAq5Vou3Yb3EVCGQz4xgx3/140x140",
"w": 140,
"h": 140,
"ossName": "/pk-math/eXdpuQAq5Vou3Yb3EVCGQz4xgx3/140x140"
},
"item-4.png": {
"u": "https://cdn.jkwljy.com/pk-math/23NSBHEwQ5ojdYvh9FyUQXLf5ApJ/140x140",
"w": 140,
"h": 140,
"ossName": "/pk-math/23NSBHEwQ5ojdYvh9FyUQXLf5ApJ/140x140"
},
"item-5.png": {
"u": "https://cdn.jkwljy.com/pk-math/YXXdWEf2Qp8sUvismRaUTdPP5vx/140x140",
"w": 140,
"h": 140,
"ossName": "/pk-math/YXXdWEf2Qp8sUvismRaUTdPP5vx/140x140"
},
"tool-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/hEdnianZUWWpf1q9kmzDJ6T2djv/140x140",
"w": 140,
"h": 140,
"ossName": "/pk-math/hEdnianZUWWpf1q9kmzDJ6T2djv/140x140"
},
"point-receive.png": {
"u": "https://cdn.jkwljy.com/pk-math/Dy8SZfhurhoHyS9RZ6x33vhi6jY/750x960",
"w": 750,
"h": 960,
"ossName": "/pk-math/Dy8SZfhurhoHyS9RZ6x33vhi6jY/750x960"
},
"receive-btn.png": {
"u": "https://cdn.jkwljy.com/pk-math/29QTjXfLwPrvQMiHpxDGME1yW2P7/328x104",
"w": 328,
"h": 104,
"ossName": "/pk-math/29QTjXfLwPrvQMiHpxDGME1yW2P7/328x104"
}
}
...@@ -76,5 +76,23 @@ ...@@ -76,5 +76,23 @@
"w": 160, "w": 160,
"h": 160, "h": 160,
"ossName": "/pk-math/N1W4H6L8pSdt4psXdBFAX4YEnAH/160x160" "ossName": "/pk-math/N1W4H6L8pSdt4psXdBFAX4YEnAH/160x160"
},
"cat-3.png": {
"u": "https://cdn.jkwljy.com/pk-math/2SHjUzxyXYQaDkVVZcDqdFErdu4C/180x300",
"w": 180,
"h": 300,
"ossName": "/pk-math/2SHjUzxyXYQaDkVVZcDqdFErdu4C/180x300"
},
"guide-arrow-3.png": {
"u": "https://cdn.jkwljy.com/pk-math/2yt1dAZKvjpHzx8Cg5aRbPGGWdL3/128x128",
"w": 128,
"h": 128,
"ossName": "/pk-math/2yt1dAZKvjpHzx8Cg5aRbPGGWdL3/128x128"
},
"guide-point.png": {
"u": "https://cdn.jkwljy.com/pk-math/39zMBKhthpUN8JGaLtJ5e1qmnewc/750x960",
"w": 750,
"h": 960,
"ossName": "/pk-math/39zMBKhthpUN8JGaLtJ5e1qmnewc/750x960"
} }
} }
...@@ -112,3 +112,9 @@ export function getAreaAndGrades () { ...@@ -112,3 +112,9 @@ export function getAreaAndGrades () {
timeout: 30000 timeout: 30000
}).then(({ data }) => data) }).then(({ data }) => data)
} }
export const completeGuide = () => requestAfterSilentLogin<void, { userId?: number }>(user => ({
method: 'GET',
url: '/service-idea/stage/user/receivePoint',
data: { userId: user?.userId }
}))
/* eslint-disable quotes */
/* eslint-disable quote-props */
export default {
"item-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/2pzQ94eQbeDxLzt3863g8CBuowbz/140x140",
"w": 140,
"h": 140
},
"item-2.png": {
"u": "https://cdn.jkwljy.com/pk-math/2abYbhhvmBN6VFeSyTK8QuF3wvDA/140x140",
"w": 140,
"h": 140
},
"item-3.png": {
"u": "https://cdn.jkwljy.com/pk-math/eXdpuQAq5Vou3Yb3EVCGQz4xgx3/140x140",
"w": 140,
"h": 140
},
"item-4.png": {
"u": "https://cdn.jkwljy.com/pk-math/23NSBHEwQ5ojdYvh9FyUQXLf5ApJ/140x140",
"w": 140,
"h": 140
},
"item-5.png": {
"u": "https://cdn.jkwljy.com/pk-math/YXXdWEf2Qp8sUvismRaUTdPP5vx/140x140",
"w": 140,
"h": 140
},
"tool-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/hEdnianZUWWpf1q9kmzDJ6T2djv/140x140",
"w": 140,
"h": 140
},
"point-receive.png": {
"u": "https://cdn.jkwljy.com/pk-math/Dy8SZfhurhoHyS9RZ6x33vhi6jY/750x960",
"w": 750,
"h": 960
},
"receive-btn.png": {
"u": "https://cdn.jkwljy.com/pk-math/29QTjXfLwPrvQMiHpxDGME1yW2P7/328x104",
"w": 328,
"h": 104
}
} as const
...@@ -65,5 +65,20 @@ export default { ...@@ -65,5 +65,20 @@ export default {
"u": "https://cdn.jkwljy.com/pk-math/N1W4H6L8pSdt4psXdBFAX4YEnAH/160x160", "u": "https://cdn.jkwljy.com/pk-math/N1W4H6L8pSdt4psXdBFAX4YEnAH/160x160",
"w": 160, "w": 160,
"h": 160 "h": 160
},
"cat-3.png": {
"u": "https://cdn.jkwljy.com/pk-math/2SHjUzxyXYQaDkVVZcDqdFErdu4C/180x300",
"w": 180,
"h": 300
},
"guide-arrow-3.png": {
"u": "https://cdn.jkwljy.com/pk-math/2yt1dAZKvjpHzx8Cg5aRbPGGWdL3/128x128",
"w": 128,
"h": 128
},
"guide-point.png": {
"u": "https://cdn.jkwljy.com/pk-math/39zMBKhthpUN8JGaLtJ5e1qmnewc/750x960",
"w": 750,
"h": 960
} }
} as const } as const
...@@ -89,6 +89,62 @@ ...@@ -89,6 +89,62 @@
color: #C2C8D1; color: #C2C8D1;
border-radius: 36px; border-radius: 36px;
} }
&.is_guide_active {
position: relative;
z-index: 1;
}
}
.guide {
position: absolute;
top: -16px;
right: -60px;
left: -442px;
transform: translateY(-100%);
display: flex;
pointer-events: none;
}
.guide_cat {
width: 180px;
height: 300px;
}
.guide_tips {
padding-top: 100px;
padding-left: 60px;
font-size: 36px;
font-family: PingFangSC-Semibold, PingFang SC;
font-weight: 600;
color: #FFFFFF;
line-height: 56px;
}
.guide_arrow {
width: 128px;
height: 128px;
display: block;
margin-top: 24px;
margin-left: 162px;
animation-name: bounce;
animation-duration: 1s;
animation-timing-function: ease-in;
animation-iteration-count: infinite;
}
@keyframes bounce {
0% {
transform: translate3d(-20px, -20px, 0);
}
50% {
transform: translate3d(0, 0, 0);
}
100% {
transform: translate3d(-20px, -20px, 0);
}
} }
.card-main { .card-main {
......
import { View, Image, Text } from '@tarojs/components' import { View, Image, Text } from '@tarojs/components'
import classNames from 'classnames' import classNames from 'classnames'
import tutorialAssets from '@/assets/oss/assets-tutorial'
import { useStoreActions } from '@/store/hooks'
import styles from './card-main.module.scss' import styles from './card-main.module.scss'
interface CardMainProps { interface CardMainProps {
...@@ -10,6 +12,7 @@ interface CardMainProps { ...@@ -10,6 +12,7 @@ interface CardMainProps {
disabled?: boolean; disabled?: boolean;
extra?: React.ReactNode; extra?: React.ReactNode;
disabledText?: string; disabledText?: string;
isGuideActive?: boolean;
price: number; price: number;
stock: number | null; stock: number | null;
} }
...@@ -23,10 +26,15 @@ export default ({ ...@@ -23,10 +26,15 @@ export default ({
disabled, disabled,
price, price,
stock, stock,
isGuideActive,
disabledText = '积分不足' disabledText = '积分不足'
}: CardMainProps) => { }: CardMainProps) => {
const nextStoreGuide = useStoreActions(state => state.guideModel.nextStoreGuide)
const _onClick = () => { const _onClick = () => {
if (!disabled) { if (!disabled) {
if (isGuideActive) {
nextStoreGuide()
}
onClick() onClick()
} }
} }
...@@ -52,11 +60,21 @@ export default ({ ...@@ -52,11 +60,21 @@ export default ({
<Text className={styles['card-score-text']}>{ price }</Text> <Text className={styles['card-score-text']}>{ price }</Text>
</View> </View>
<View <View
className={classNames(styles.btn, disabled && styles.disabled)} className={classNames(styles.btn, disabled && styles.disabled, isGuideActive && styles.is_guide_active)}
onClick={_onClick} onClick={_onClick}
hoverClass={!disabled ? styles.btn_on : ''} hoverClass={!disabled ? styles.btn_on : ''}
> >
{disabled ? disabledText : '兑换'} {disabled ? disabledText : '兑换'}
{isGuideActive && (
<View className={styles.guide}>
<Image src={tutorialAssets['cat-3.png'].u} className={styles.guide_cat}></Image>
<View className={styles.guide_tips}>
尝试兑换一次答题卡吧~
<Image src={tutorialAssets['guide-arrow-2.png'].u} className={styles.guide_arrow}></Image>
</View>
</View>
)}
</View> </View>
</View> </View>
</View> </View>
......
.card { .card {
position: relative;
background-color: #fff; background-color: #fff;
margin-bottom: 64px; margin-bottom: 24px;
} }
.bordered { .bordered {
...@@ -26,6 +25,7 @@ ...@@ -26,6 +25,7 @@
font-size: 40px; font-size: 40px;
color: #465164; color: #465164;
line-height: 56px; line-height: 56px;
margin-top: 40px;
} }
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
background: #1786F7; background: #1786F7;
border-color: transparent; border-color: transparent;
color: #fff; color: #fff;
position: relative;
&.disbaled { &.disbaled {
background: #C7C9D0; background: #C7C9D0;
...@@ -30,6 +31,45 @@ ...@@ -30,6 +31,45 @@
padding: 0 32px; padding: 0 32px;
} }
.guide {
position: absolute;
bottom: 0;
right: -8px;
left: -122px;
transform: translateY(100%);
font-size: 36px;
font-weight: 600;
color: #FFFFFF;
line-height: 56px;
pointer-events: none;
}
.guide_arrow {
width: 128px;
height: 128px;
display: block;
margin-bottom: 24px;
margin-left: 132px;
animation-name: bounce;
animation-duration: 1s;
animation-timing-function: ease-in;
animation-iteration-count: infinite;
}
@keyframes bounce {
0% {
transform: translate3d(-20px, 20px, 0);
}
50% {
transform: translate3d(0, 0, 0);
}
100% {
transform: translate3d(-20px, 20px, 0);
}
}
.input { .input {
display: flex; display: flex;
align-items: center; align-items: center;
......
import { View, Image, Text } from '@tarojs/components' import { View, Image, Text } from '@tarojs/components'
import { showToast } from '@tarojs/taro' import { showToast } from '@tarojs/taro'
import { useStoreActions } from '@/store/hooks' import { useStoreActions, useStoreState } from '@/store/hooks'
import { useState, useCallback, useMemo, useEffect } from 'react' import { useState, useCallback, useMemo, useEffect } from 'react'
import tutorialAssets from '@/assets/oss/assets-tutorial'
import classNames from 'classnames' import classNames from 'classnames'
import styles from './exchange-item.module.scss' import styles from './exchange-item.module.scss'
...@@ -18,7 +19,14 @@ type ExchangeItemProps = { ...@@ -18,7 +19,14 @@ type ExchangeItemProps = {
const ExchangeItem = (props: ExchangeItemProps) => { const ExchangeItem = (props: ExchangeItemProps) => {
const { stepValue, maxValue, onCancel, visible, title } = props const { stepValue, maxValue, onCancel, visible, title } = props
const exchangeItem = useStoreActions(actions => actions.userModel.exchangeItem) const exchangeItem = useStoreActions(actions => actions.userModel.exchangeItem)
const [val, setVal] = useState(0) const nextStoreGuide = useStoreActions(actions => actions.guideModel.nextStoreGuide)
const storeGuideStep = useStoreState(state => state.guideModel.storeGuideStep)
const storeGuideActive = useStoreState(state => state.guideModel.storeGuideActive)
const [val, setVal] = useState(1)
const isGuideActive = useMemo(() => {
return storeGuideStep === 3 && storeGuideActive
}, [storeGuideStep, storeGuideActive])
const handleMinus = useCallback(() => { const handleMinus = useCallback(() => {
if (val < 1) { if (val < 1) {
...@@ -30,7 +38,7 @@ const ExchangeItem = (props: ExchangeItemProps) => { ...@@ -30,7 +38,7 @@ const ExchangeItem = (props: ExchangeItemProps) => {
useEffect(() => { useEffect(() => {
if (!visible) { if (!visible) {
setTimeout(() => { setTimeout(() => {
setVal(0) setVal(1)
}, 1000) }, 1000)
} }
}, [visible]) }, [visible])
...@@ -58,7 +66,16 @@ const ExchangeItem = (props: ExchangeItemProps) => { ...@@ -58,7 +66,16 @@ const ExchangeItem = (props: ExchangeItemProps) => {
exchangeItem({ exchangeItem({
name: title, name: title,
num: val num: val
}).then(onCancel) }).then(() => {
if (isGuideActive) {
nextStoreGuide(val)
}
onCancel && onCancel()
}).catch(() => {
if (isGuideActive) {
nextStoreGuide(0)
}
})
} }
return ( return (
...@@ -81,7 +98,15 @@ const ExchangeItem = (props: ExchangeItemProps) => { ...@@ -81,7 +98,15 @@ const ExchangeItem = (props: ExchangeItemProps) => {
</View> </View>
<View className={styles.footer}> <View className={styles.footer}>
<View className={styles.cancel} onClick={() => onCancel()}>取消</View> <View className={styles.cancel} onClick={() => onCancel()}>取消</View>
<View className={classNames(styles.confirm, val < 1 && styles.disbaled)} onClick={handleConfirm}>确定</View> <View className={classNames(styles.confirm, val < 1 && styles.disbaled)} onClick={handleConfirm}>
确定
{isGuideActive && (
<View className={styles.guide}>
<Image src={tutorialAssets['guide-arrow-3.png'].u} className={styles.guide_arrow}></Image>
<View>点击确定,兑换答题卡</View>
</View>
)}
</View>
</View> </View>
</> </>
) )
......
.header {
background-color: #2B3347;
position: fixed;
z-index: 2;
left: 0;
top: 0;
width: 100vw;
color: #fff;
&.mask {
&::after {
content: " ";
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
background-color: rgba(0,0,0,.7);
}
}
}
.inner {
position: relative;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
.arrow {
position: absolute;
left: 10PX;
width: 30PX;
height: 30PX;
}
import { View, Image, Text } from '@tarojs/components'
import { getMenuButtonBoundingClientRect, navigateBack } from '@tarojs/taro'
import { useState, memo } from 'react'
import classNames from 'classnames'
import styles from './top-header.module.scss'
type PageHeadProps = {
hasMask: boolean;
}
const PageHead = ({ hasMask }: PageHeadProps) => {
const [nav] = useState(getMenuButtonBoundingClientRect())
return (
<View className={classNames(styles.header, hasMask && styles.mask)}>
<View
style={{
height: `${nav.height + 10}px`,
paddingTop: `${nav.top - 5}px`
}}
>
<View className={styles.inner} style={{ height: `${nav.height + 10}px` }}>
<Image src={require('../assets/arrow.png')} className={styles.arrow} onClick={() => navigateBack()}></Image>
<Text>学分小店</Text>
</View>
</View>
</View>
)
}
export default memo(PageHead)
import { View, RootPortal, Image, Button } from '@tarojs/components'
import { useStoreState } from '@/store/hooks'
import tutorialAssets from '@/assets/oss/assets-tutorial'
import styles from './shared.module.scss'
type ModalAreaProps = {
onConfirm: () => void;
}
const GuideFinish = (props: ModalAreaProps) => {
const { onConfirm } = props
const pointToCardNum = useStoreState(state => state.guideModel.pointToCardNum)
const handleConfirm = async () => {
onConfirm && onConfirm()
}
return (
<RootPortal>
<View className={styles.mask} catchMove></View>
<View className={styles.modal} catchMove>
<Image src={tutorialAssets['guide-point.png'].u} className={styles.icon}></Image>
<View className={styles.count}>答题卡 +{pointToCardNum}</View>
<View className={styles.tips}>接下来开启你的闯关之旅吧!</View>
<Button className={styles.btn} onClick={handleConfirm}>好的</Button>
</View>
</RootPortal>
)
}
export default GuideFinish
import { useStoreState, useStoreActions } from '@/store/hooks'
import ReceivePointModal from './receive-point'
import GuideFinish from './guide-finish'
export type TutorialRef = {
start: () => void;
}
const Tutorial = () => {
const storeGuideStep = useStoreState(state => state.guideModel.storeGuideStep)
const storeGuideActive = useStoreState(state => state.guideModel.storeGuideActive)
const revceiPoint = useStoreActions(state => state.guideModel.revceiPoint)
const completeStoreGuide = useStoreActions(state => state.guideModel.completeStoreGuide)
return (
<>
{storeGuideActive && storeGuideStep === 1 && <ReceivePointModal onConfirm={revceiPoint} />}
{storeGuideActive && storeGuideStep === 4 && <GuideFinish onConfirm={completeStoreGuide} />}
</>
)
}
export default Tutorial
import { View, RootPortal, Image, Button } from '@tarojs/components'
import { showToast } from '@tarojs/taro'
import { useBoolean } from '@/hooks'
import { completeGuide } from '@/api'
import giftAssets from '@/assets/oss/assets-gift'
import styles from './shared.module.scss'
type ReceivePointProps = {
onConfirm: () => void;
}
const ModalReceivePoint = (props: ReceivePointProps) => {
const { onConfirm } = props
const [loading, loadingActions] = useBoolean(false)
const handleConfirm = async () => {
if (loading) return
loadingActions.setTrue()
try {
await completeGuide()
loadingActions.setFalse()
onConfirm && onConfirm()
} catch (err) {
showToast({ title: err.message, icon: 'none' })
loadingActions.setFalse()
}
}
return (
<RootPortal>
<View className={styles.mask} catchMove></View>
<View className={styles.modal} catchMove>
<Image src={giftAssets['point-receive.png'].u} className={styles.icon}></Image>
<View className={styles.count}>水晶 +100</View>
<View className={styles.tips}>阿喵老师的奖励,继续加油哦~</View>
<Button className={styles.btn} onClick={handleConfirm} loading={loading}>领取</Button>
</View>
</RootPortal>
)
}
export default ModalReceivePoint
.mask {
position: fixed;
left: 0;
top: 0;
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
z-index: 99999;
opacity: 1;
}
.modal {
position: fixed;
left: 0;
top: 0;
bottom: 0;
right: 0;
z-index: 100000;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.count {
font-size: 40px;
font-weight: 600;
color: #FFFFFF;
margin-top: -284px;
line-height: 56px;
}
.btn {
width: 328px;
height: 104px;
background-image: url(https://cdn.jkwljy.com/pk-math/29QTjXfLwPrvQMiHpxDGME1yW2P7/328x104);
background-size: 100% 100%;
margin-top: 20px;
font-size: 36px;
font-weight: 600;
color: #FFFFFF;
line-height: 50px;
display: flex;
align-items: center;
justify-content: center;
background-color: transparent;
}
.tips {
font-size: 28px;
font-weight: 400;
color: #FFFFFF;
line-height: 40px;
margin-top: 112px;
}
.icon {
width: 750px;
height: 960px;
margin-top: -80px;
}
export default definePageConfig({ export default definePageConfig({
navigationBarTitleText: '学分小店', navigationBarTitleText: '学分小店',
navigationStyle: 'default', navigationStyle: 'custom',
navigationBarBackgroundColor: '#2B3347', navigationBarBackgroundColor: '#2B3347',
navigationBarTextStyle: 'white' navigationBarTextStyle: 'white'
}) })
...@@ -5,12 +5,98 @@ ...@@ -5,12 +5,98 @@
background-color: #FFFFFF; background-color: #FFFFFF;
} }
.guide_mask {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(0,0,0,.7);
}
.continue {
display: flex;
justify-content: flex-end;
}
.continue_btn {
display: flex;
justify-content: flex-end;
align-items: center;
font-size: 28px;
font-weight: 500;
color: #1786F7;
padding: 2px 8px 2px 20px;
margin-right: -8px;
line-height: 40px;
}
.continue_icon {
width: 28px;
height: 28px;
display: block;
margin-left: 4px;
}
.guide_main {
}
.dialog {
width: 510px;
padding: 24px 20px 0 42px;
box-sizing: border-box;
background-size: 100% 100%;
height: 184px;
background-image: url(https://cdn.jkwljy.com/pk-math/2LZyrqzLwgYFGvJEb1vteEo4KL2r/510x184);
font-size: 28px;
font-weight: 500;
color: rgba(70,81,100,0.8);
line-height: 44px;
.em {
color: #FFC056;
}
}
.guide_cat {
width: 200px;
height: 220px;
}
.guide_content {
position: absolute;
top: 0;
left: 0;
right: 0;
transform: translateY(-100%);
display: flex;
}
.card-body { .card-body {
display: flex; display: flex;
padding: 32px 28px; padding: 32px 28px;
position: relative;
border-radius: 32px; border-radius: 32px;
border: 6px solid #F0F2F9; border: 6px solid #F0F2F9;
background-color: #FFFFFF;
&.is_guide_card {
z-index: 1;
position: relative;
border-radius: 32px;
&::after {
content: " ";
position: absolute;
left: -8px;
top: -8px;
right: -8px;
bottom: -8px;
border-radius: 32px;
border: 4px dashed #FFFFFF;
}
}
} }
.card-stock { .card-stock {
...@@ -20,13 +106,10 @@ ...@@ -20,13 +106,10 @@
} }
.card_list { .card_list {
position: relative;
z-index: 1;
background: #FFFFFF; background: #FFFFFF;
border-radius: 40px 40px 0px 0px; border-radius: 40px 40px 0px 0px;
margin-top: -40px; margin-top: -40px;
overflow: hidden; padding: 20px 32px 40px 32px;
padding: 60px 32px 40px 32px;
} }
.head { .head {
......
/* eslint-disable import/no-commonjs */ /* eslint-disable import/no-commonjs */
import { useState, useCallback, useMemo } from 'react' import { useState, useCallback, useMemo, useEffect } from 'react'
import { View, Text, Image } from '@tarojs/components' import { View, Text, Image } from '@tarojs/components'
import { useDidShow } from '@tarojs/taro' import { useDidShow, getMenuButtonBoundingClientRect } from '@tarojs/taro'
import { useBoolean } from '@/hooks' import { useBoolean } from '@/hooks'
import Modal from '@/components/Modal' import Modal from '@/components/Modal'
import { useStoreState, useStoreActions } from '@/store/hooks' import { useStoreState, useStoreActions } from '@/store/hooks'
import { EyeProtectionView } from '@/components' import { EyeProtectionView } from '@/components'
import assets from '@/assets/oss/assets-gift'
import classNames from 'classnames'
import tutorialAssets from '@/assets/oss/assets-tutorial'
import Tutorial from './components/tutorial'
import TopHeader from './components/top-header'
import ExchangeItem from './components/exchange-item' 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'
...@@ -14,26 +19,80 @@ import CardMain from './components/card-main' ...@@ -14,26 +19,80 @@ import CardMain from './components/card-main'
import styles from './index.module.scss' import styles from './index.module.scss'
type ExchangeGoods = { type ExchangeGoods = {
title: string; title?: string;
subTitle: string; subTitle: string;
description: string; description: string;
price: number; price: number;
isGuideCard?: boolean;
stock: number | null; stock: number | null;
img: string; img: string;
} }
const itemList: ExchangeGoods[] = [
{
title: '成长奖励',
subTitle: '网红盆栽·莓你不行',
description: '体验亲手种出甜甜草莓的感觉,在种植中体验不一样的快乐。',
price: 600,
isGuideCard: true,
stock: null,
img: assets['item-1.png'].u,
},
{
subTitle: '网红盆栽·天天向上',
description: '让元气满满的向日葵,陪伴你一起向阳而生吧。',
price: 600,
stock: null,
img: assets['item-2.png'].u,
},
{
subTitle: '网红盆栽·好柿发生',
description: '播下种子,浇水施肥,收获属于你的酸甜小小西红柿。',
price: 600,
stock: null,
img: assets['item-3.png'].u,
},
{
subTitle: '乐高·积木玫瑰',
description: '用心拼一朵玫瑰,送给为你辛苦的妈妈。',
price: 700,
stock: null,
img: assets['item-4.png'].u,
},
{
subTitle: '奇妙绘·涂鸦本',
description: '自带颜料的创意绘画本,让你随地作画,随时随地开启小画家模式。',
price: 700,
stock: null,
img: assets['item-5.png'].u,
},
]
const StudyMarket = () => { const StudyMarket = () => {
const nav = useMemo(getMenuButtonBoundingClientRect, [])
const [isVisible, { setTrue, setFalse }] = useBoolean(false) const [isVisible, { setTrue, setFalse }] = useBoolean(false)
const [currentGoods, setCurrentGoods] = useState<ExchangeGoods | null>(null) const [currentGoods, setCurrentGoods] = useState<ExchangeGoods | null>(null)
const point = useStoreState(state => state.userModel.point) const point = useStoreState(state => state.userModel.point)
const setting = useStoreState(state => state.userModel.setting) const setting = useStoreState(state => state.userModel.setting)
const storeGuideStep = useStoreState(state => state.guideModel.storeGuideStep)
const storeGuideActive = useStoreState(state => state.guideModel.storeGuideActive)
const userInfo = useStoreState(state => state.userModel.userInfo)
const fetchAccount = useStoreActions(actions => actions.userModel.fetchAccount) const fetchAccount = useStoreActions(actions => actions.userModel.fetchAccount)
const getSetting = useStoreActions(actions => actions.userModel.getSetting) const getSetting = useStoreActions(actions => actions.userModel.getSetting)
const nextStoreGuide = useStoreActions(actions => actions.guideModel.nextStoreGuide)
const updateStoreGuideActive = useStoreActions(actions => actions.guideModel.updateStoreGuideActive)
useDidShow(() => { useDidShow(() => {
getSetting() getSetting()
fetchAccount() fetchAccount()
}) })
useEffect(() => {
if (userInfo.pointReceive === 'N') {
updateStoreGuideActive(true)
}
}, [userInfo, updateStoreGuideActive])
const list: ExchangeGoods[] = useMemo(() => { const list: ExchangeGoods[] = useMemo(() => {
return [ return [
{ {
...@@ -42,17 +101,10 @@ const StudyMarket = () => { ...@@ -42,17 +101,10 @@ const StudyMarket = () => {
description: '答题卡是不断追求更高档位与排名的必备道具', description: '答题卡是不断追求更高档位与排名的必备道具',
price: setting.pointToCard, price: setting.pointToCard,
stock: null, stock: null,
img: require('./assets/ph.png'), isGuideCard: true,
img: assets['tool-1.png'].u,
}, },
...itemList
{
title: '礼品屋',
subTitle: '神秘大礼',
description: '兑换神秘大礼,线下领取超级大礼',
price: 1000,
stock: null,
img: require('./assets/gift.png'),
}
] ]
}, [setting]) }, [setting])
...@@ -61,55 +113,90 @@ const StudyMarket = () => { ...@@ -61,55 +113,90 @@ const StudyMarket = () => {
setTrue() setTrue()
}, [setTrue]) }, [setTrue])
const isMaskActive = useMemo(() => {
return (storeGuideStep === 0 || storeGuideStep === 2) && storeGuideActive
}, [storeGuideStep, storeGuideActive])
const isStep1Active = useMemo(() => {
return storeGuideStep === 0 && storeGuideActive
}, [storeGuideStep, storeGuideActive])
return ( return (
<EyeProtectionView className={styles.container}> <>
<View className={styles.head}> <TopHeader hasMask={isMaskActive} />
<View className={styles.score_text}>{point} <Text className={styles.unit}>水晶</Text></View> {isMaskActive && (
<Image src={require('./assets/score.png')} className={styles.score_icon}></Image> <View className={styles.guide_mask}></View>
</View> )}
<View className={styles.card_list}> <EyeProtectionView className={styles.container} style={{ paddingTop: `${nav.height + nav.top + 5}px` }}>
{list.map(item => { <View className={styles.head}>
const pric = item.price <View className={styles.score_text}>{point} <Text className={styles.unit}>水晶</Text></View>
let disabledText = '积分不足' <Image src={require('./assets/score.png')} className={styles.score_icon}></Image>
let disabled = point < pric || (item.stock !== null && item.stock < 1) </View>
if (item.subTitle === '神秘大礼') { <View className={styles.card_list}>
disabled = true {list.map((item, index) => {
if (point >= pric) { const pric = item.price
disabledText = '敬请期待' let disabledText = '积分不足'
let disabled = point < pric || (item.stock !== null && item.stock < 1)
if (item.subTitle === '神秘大礼') {
disabled = true
if (point >= pric) {
disabledText = '敬请期待'
}
} }
}
return (
return ( <Card title={item.title} key={item.title}>
<Card title={item.title} key={item.title}> <View className={classNames(styles['card-body'], item.isGuideCard && isStep1Active && styles.is_guide_card)}>
<View className={styles['card-body']}> {index === 0 && isStep1Active && (
<CardMain <View className={styles.guide_content}>
title={item.subTitle} <Image src={tutorialAssets['cat-2.png'].u} className={styles.guide_cat} />
cover={item.img} <View className={styles.guide_main}>
stock={item.stock} <View className={classNames(styles.dialog)}>
price={pric} <View>
disabled={disabled} 在这里,可以兑换闯关消耗的<Text className={styles.em}>答题卡</Text>,以及
subtitle={item.description} <Text className={styles.em}>成长奖励</Text>哦~
disabledText={disabledText} </View>
onClick={() => { <View className={styles.continue}>
open(item) <View className={styles.continue_btn} onClick={() => nextStoreGuide()}>
}} 继续<Image src={tutorialAssets['continue-arrow.png'].u} className={styles.continue_icon} />
/> </View>
</View> </View>
</Card> </View>
) </View>
})}
</View> </View>
)}
<Modal isVisible={isVisible} bodyClassName={styles.moal_body} onClose={setFalse} maskClosable={false} tilte={`兑换${currentGoods?.title ?? ''}`}> <CardMain
<ExchangeItem title={item.subTitle}
title={currentGoods?.title ?? ''} cover={item.img}
stepValue={currentGoods?.price ?? Infinity} stock={item.stock}
maxValue={point} price={pric}
visible={isVisible} disabled={disabled}
onCancel={setFalse} subtitle={item.description}
/> disabledText={disabledText}
</Modal> isGuideActive={isMaskActive && storeGuideStep === 2 && index === 0}
</EyeProtectionView> onClick={() => {
open(item)
}}
/>
</View>
</Card>
)
})}
</View>
<Modal isVisible={isVisible} bodyClassName={styles.moal_body} onClose={setFalse} maskClosable={false} tilte={`兑换${currentGoods?.title ?? ''}`}>
<ExchangeItem
title={currentGoods?.title ?? ''}
stepValue={currentGoods?.price ?? Infinity}
maxValue={point}
visible={isVisible}
onCancel={setFalse}
/>
</Modal>
</EyeProtectionView>
<Tutorial />
</>
) )
} }
......
...@@ -3,6 +3,7 @@ import { ...@@ -3,6 +3,7 @@ import {
} from 'easy-peasy' } from 'easy-peasy'
import { AppStoreModel } from '@/store/store-model' import { AppStoreModel } from '@/store/store-model'
import { getStorage, StorageKeys, updateStorage } from '@/utils/storage' import { getStorage, StorageKeys, updateStorage } from '@/utils/storage'
import { UserInfo } from '@/types'
export interface GuideModel { export interface GuideModel {
updateState: Action<GuideModel, Partial<State<GuideModel>>>; updateState: Action<GuideModel, Partial<State<GuideModel>>>;
...@@ -10,6 +11,9 @@ export interface GuideModel { ...@@ -10,6 +11,9 @@ export interface GuideModel {
mainGuideActive: boolean; mainGuideActive: boolean;
/** 部落引导激活 */ /** 部落引导激活 */
groupGuideActive: boolean; groupGuideActive: boolean;
/** 学分小店引导激活 */
storeGuideActive: boolean;
updateStoreGuideActive: Action<GuideModel, boolean>;
updateGuideActive: Action<GuideModel, boolean>; updateGuideActive: Action<GuideModel, boolean>;
updateGroupGuideActive: Action<GuideModel, boolean>; updateGroupGuideActive: Action<GuideModel, boolean>;
/** 完成首页引导 */ /** 完成首页引导 */
...@@ -23,8 +27,10 @@ export interface GuideModel { ...@@ -23,8 +27,10 @@ export interface GuideModel {
storeGuideStep: number; storeGuideStep: number;
groupGuideStep: number; groupGuideStep: number;
nextStoreGuide: Action<GuideModel>; nextStoreGuide: Action<GuideModel, number | void>;
revceiPoint: Thunk<GuideModel, void, void, AppStoreModel>;
nextGroupGuide: Action<GuideModel>; nextGroupGuide: Action<GuideModel>;
pointToCardNum: number;
completeStoreGuide: Thunk<GuideModel, void, void, AppStoreModel>; completeStoreGuide: Thunk<GuideModel, void, void, AppStoreModel>;
completeGroupGuide: Thunk<GuideModel, void, void, AppStoreModel>; completeGroupGuide: Thunk<GuideModel, void, void, AppStoreModel>;
...@@ -35,8 +41,10 @@ export interface GuideModel { ...@@ -35,8 +41,10 @@ export interface GuideModel {
const guideModel: GuideModel = { const guideModel: GuideModel = {
groupGuideActive: false, groupGuideActive: false,
mainGuideActive: false, mainGuideActive: false,
storeGuideActive: false,
groupGuideStep: 0, groupGuideStep: 0,
storeGuideStep: 0, storeGuideStep: 0,
pointToCardNum: 0,
isStoreGuideComplete: getStorage(StorageKeys.isStoreGuideComplete), isStoreGuideComplete: getStorage(StorageKeys.isStoreGuideComplete),
isMainGuideComplete: getStorage(StorageKeys.isMainGuideComplete), isMainGuideComplete: getStorage(StorageKeys.isMainGuideComplete),
isErrQuestionGuideComplete: getStorage(StorageKeys.isErrQuestionGuideComplete), isErrQuestionGuideComplete: getStorage(StorageKeys.isErrQuestionGuideComplete),
...@@ -45,9 +53,23 @@ const guideModel: GuideModel = { ...@@ -45,9 +53,23 @@ const guideModel: GuideModel = {
updateGuideActive: action((state, payload) => { updateGuideActive: action((state, payload) => {
state.mainGuideActive = payload state.mainGuideActive = payload
}), }),
updateStoreGuideActive: action((state, payload) => {
state.storeGuideActive = payload
}),
nextStoreGuide: action(state => { nextStoreGuide: action((state, num) => {
state.storeGuideStep += 1 state.storeGuideStep += 1
if (num !== undefined) {
state.pointToCardNum = num
}
}),
revceiPoint: thunk(async (actions, _, helpers) => {
actions.nextStoreGuide()
const userInfo = getStorage(StorageKeys.userInfo)
const newUserInfo = { ...userInfo, pointReceive: 'Y' } as UserInfo
updateStorage(StorageKeys.userInfo, newUserInfo)
helpers.getStoreActions().userModel.updateState({ userInfo: newUserInfo })
}), }),
nextGroupGuide: action(state => { nextGroupGuide: action(state => {
state.groupGuideStep += 1 state.groupGuideStep += 1
......
...@@ -7,6 +7,8 @@ export type UserInfo = { ...@@ -7,6 +7,8 @@ export type UserInfo = {
grade?: string; grade?: string;
nickName?: string | null; nickName?: string | null;
phone?: string | null; phone?: string | null;
/** 是否以获取了积分 */
pointReceive?: 'Y' | 'N';
} }
export type RequestResultPagingLike<T> = RequestResult<PagingLike<T>> export type RequestResultPagingLike<T> = RequestResult<PagingLike<T>>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment