Commit a7aa3e4e authored by hewenhao's avatar hewenhao

feat: 年级、区域选择

parent afb43270
{
"areas": ["成都", "重庆", "宜宾", "自贡", "乐山", "南充", "遂宁", "德阳", "其他"],
"grades": ["一年级", "二年级", "三年级", "四年级", "五年级", "六年级"]
}
{
"arrow.png": {
"u": "https://cdn.jkwljy.com/pk-math/41KjFnEyinPQpz9nsFHpnZm8cBCx/128x128",
"w": 128,
"h": 128,
"ossName": "/pk-math/41KjFnEyinPQpz9nsFHpnZm8cBCx/128x128"
},
"continue-arrow.png": {
"u": "https://cdn.jkwljy.com/pk-math/dLYoV177Xybh5Urd2apGTYQDpbv/28x28",
"w": 28,
"h": 28,
"ossName": "/pk-math/dLYoV177Xybh5Urd2apGTYQDpbv/28x28"
},
"modal-bg-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/mFR86xsmGbKnCC9yu5ak2yadejB/510x272",
"w": 510,
"h": 272,
"ossName": "/pk-math/mFR86xsmGbKnCC9yu5ak2yadejB/510x272"
},
"modal-bg-2.png": {
"u": "https://cdn.jkwljy.com/pk-math/2LZyrqzLwgYFGvJEb1vteEo4KL2r/510x184",
"w": 510,
"h": 184,
"ossName": "/pk-math/2LZyrqzLwgYFGvJEb1vteEo4KL2r/510x184"
},
"modal-head.png": {
"u": "https://cdn.jkwljy.com/pk-math/3RPqhiVDv7gqUtb31RjRobZHb9J1/654x230",
"w": 654,
"h": 230,
"ossName": "/pk-math/3RPqhiVDv7gqUtb31RjRobZHb9J1/654x230"
},
"star.png": {
"u": "https://cdn.jkwljy.com/pk-math/41BF6vWpR1xmEfcufsRg4fuhV9zC/40x40",
"w": 40,
"h": 40,
"ossName": "/pk-math/41BF6vWpR1xmEfcufsRg4fuhV9zC/40x40"
},
"btn-off.png": {
"u": "https://cdn.jkwljy.com/pk-math/2M1n6JwnVNg4BWShQ2nPtK2T4GiX/248x72",
"w": 248,
"h": 72,
"ossName": "/pk-math/2M1n6JwnVNg4BWShQ2nPtK2T4GiX/248x72"
},
"cat.png": {
"u": "https://cdn.jkwljy.com/pk-math/4BHQoERKbxYHztUDdPWnKxqVEsLn/200x300",
"w": 200,
"h": 300,
"ossName": "/pk-math/4BHQoERKbxYHztUDdPWnKxqVEsLn/200x300"
}
}
......@@ -95,3 +95,14 @@ export function getNickNameWords (url = 'nickname-words') {
timeout: 30000
}).then(({ data }) => data)
}
export type AreaAndGrades = { areas: string[]; grades: string[] }
export function getAreaAndGrades () {
return requesNative<AreaAndGrades>({
method: 'GET',
url: `https://cdn.jkwljy.com/pk-math/setting/area-grade.json?d=${Date.now()}`,
header: { 'Cache-Control': 'no-cache' },
timeout: 30000
}).then(({ data }) => data)
}
/* eslint-disable quotes */
/* eslint-disable quote-props */
export default {
"arrow.png": {
"u": "https://cdn.jkwljy.com/pk-math/41KjFnEyinPQpz9nsFHpnZm8cBCx/128x128",
"w": 128,
"h": 128
},
"continue-arrow.png": {
"u": "https://cdn.jkwljy.com/pk-math/dLYoV177Xybh5Urd2apGTYQDpbv/28x28",
"w": 28,
"h": 28
},
"modal-bg-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/mFR86xsmGbKnCC9yu5ak2yadejB/510x272",
"w": 510,
"h": 272
},
"modal-bg-2.png": {
"u": "https://cdn.jkwljy.com/pk-math/2LZyrqzLwgYFGvJEb1vteEo4KL2r/510x184",
"w": 510,
"h": 184
},
"modal-head.png": {
"u": "https://cdn.jkwljy.com/pk-math/3RPqhiVDv7gqUtb31RjRobZHb9J1/654x230",
"w": 654,
"h": 230
},
"star.png": {
"u": "https://cdn.jkwljy.com/pk-math/41BF6vWpR1xmEfcufsRg4fuhV9zC/40x40",
"w": 40,
"h": 40
},
"btn-off.png": {
"u": "https://cdn.jkwljy.com/pk-math/2M1n6JwnVNg4BWShQ2nPtK2T4GiX/248x72",
"w": 248,
"h": 72
},
"cat.png": {
"u": "https://cdn.jkwljy.com/pk-math/4BHQoERKbxYHztUDdPWnKxqVEsLn/200x300",
"w": 200,
"h": 300
}
} as const
......@@ -5,10 +5,11 @@ import {
nextTick,
onAppHide,
} from '@tarojs/taro'
import { useMemo, useCallback, useEffect } from 'react'
import { useMemo, useCallback, useEffect, useRef } from 'react'
import { useStoreActions, useStoreState } from '@/store/hooks'
import { useFocus } from '@/hooks/use-focus'
import { EyeProtectionView } from '@/components'
import Tutorial, { type TutorialRef } from './tutorial'
import type { TabbarRef } from '../../../custom-tab-bar/index'
import { CurrentRoundId, StageStatus } from './scene/constants'
......@@ -31,6 +32,8 @@ const MainPage = () => {
const fetchAccount = useStoreActions(actions => actions.userModel.fetchAccount)
const nav = useMemo(getMenuButtonBoundingClientRect, [])
const tutorialRef = useRef<TutorialRef | null>(null)
const scrollToCurrent = useCallback((callback?: () => void) => {
const height = getSystemInfoSync().windowHeight
pageScrollTo({
......@@ -49,6 +52,8 @@ const MainPage = () => {
useEffect(() => {
if (isFocus) {
player.play()
// TODO
// tutorialRef.current?.start()
}
}, [player, isFocus])
......@@ -94,6 +99,7 @@ const MainPage = () => {
<MainShortCut onClick={() => scrollToCurrent()} />
)}
<ShareModal />
<Tutorial ref={tutorialRef} />
</>
)
}
......
......@@ -9,7 +9,62 @@
.guide_wrap {
border-radius: 50%;
border: 2px dashed #fff;
&::after {
content: " ";
position: absolute;
left: -16px;
right: -16px;
top: -16px;
bottom: -16px;
pointer-events: none;
border: 4px dashed #fff;
border-radius: 50%;
}
}
.tutorial {
position: absolute;
left: 84px;
bottom: 48px;
transform: translate3d(-100%, 100%, 0);
white-space: nowrap;
display: flex;
flex-direction: column;
align-items: flex-end;
}
.tutorial_arrow {
width: 128px;
height: 128px;
margin-right: 54px;
display: block;
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);
}
}
.tutorial_text {
font-size: 36px;
font-weight: 600;
color: #FFFFFF;
line-height: 50px;
margin-top: 24px;
}
......
import { View, Image, ViewProps } from '@tarojs/components'
import { View, Image } from '@tarojs/components'
import assets from '@/assets/oss/assets-round'
import classNames from 'classnames'
import { cs } from '@/styles'
......@@ -6,6 +6,7 @@ import { navigateTo } from '@tarojs/taro'
import type { ImageSource } from '@/types'
import { useStoreActions, useStoreState } from '@/store/hooks'
import { UserGuideView } from '@/components'
import tutorial from '@/assets/oss/assets-tutorial'
import { type Stage, StageType, StageStatus, StageLevel, CurrentRoundId } from './constants'
import StageTag from './stage-tag'
......@@ -131,13 +132,16 @@ const StageComp = (props: StageProps) => {
src={getUnlockedIcon(stage.type).u}
compnent={Image}
className={getIconClassNames(stage.type)}
isActive={stage.status === StageStatus.CURRENT}
verticalPadding={4}
horizonPadding={4}
isActive={false}
verticalPadding={0}
horizonPadding={0}
wrapClass={styles.guide_wrap}
onClickConent={handleClick}
guideContent={(
<View style={{ color: '#ffffff' }}>123123123234234234sdfsdf sdfsdfsdf sdf sdf sdf sdf sdfsd fsd </View>
<View className={styles.tutorial}>
<Image src={tutorial['arrow.png'].u} className={styles.tutorial_arrow}></Image>
<View className={styles.tutorial_text}>让我们从第一关开始吧~</View>
</View>
)}
></UserGuideView>
)
......
import { View, Text, RootPortal, Image } from '@tarojs/components'
import { useCallback, useEffect, useState } from 'react'
import { useCallback, useEffect, useState, useRef } from 'react'
import { useRouter, showToast, showModal, switchTab, useDidShow } from '@tarojs/taro'
import classNames from 'classnames'
import { useStoreActions, useStoreState } from '@/store/hooks'
import { Deferred } from '@/utils/deferred'
import { getTribeInfo, joinTribe, type MemberItem } from '@/api/group'
import { useRequest, useBoolean } from '@/hooks'
......@@ -23,7 +24,11 @@ export default function ShareModal () {
const [isVisible, { setTrue, setFalse }] = useBoolean(false)
const [detail, setDetail] = useState<DetailType>({})
const deferRef = useRef<Deferred<void> | null>(null)
const userInfo = useStoreState(state => state.userModel.userInfo)
const joinDefered = useStoreState(state => state.userModel.joinDefered)
const updateState = useStoreActions(actions => actions.userModel.updateState)
const fetchTribeInfo = useStoreActions(actions => actions.groupModel.fetchTribeInfo)
const router = useRouter<{ groupId: string, shareUserId: string }>()
......@@ -37,6 +42,8 @@ export default function ShareModal () {
} catch (error) {
showModal({ title: error })
}
} else {
deferRef.current?.resolve()
}
}, [groupId, shareUserId, userInfo.userId, fetchTribeInfo])
......@@ -47,15 +54,27 @@ export default function ShareModal () {
}
}, [joinTribeWithCode, fetchTribeInfo])
const handleCancel = useCallback(() => {
setFalse()
deferRef.current?.resolve()
}, [setFalse])
useEffect(() => {
deferRef.current = new Deferred<void>()
updateState({ joinDefered: deferRef.current })
showShareModal()
}, [showShareModal])
return () => {
updateState({ joinDefered: null })
}
}, [showShareModal, updateState])
// 加入部落
const { run } = useRequest(joinTribe, {
immediate: false,
onSuccess: async () => {
setFalse()
deferRef.current?.resolve()
await showToast({ title: '加入成功', mask: true })
switchTab({ url: '/pages/group/index' })
}
......@@ -149,7 +168,7 @@ export default function ShareModal () {
</View>
<View className={styles.footer}>
<Text className={styles.cancel} onClick={setFalse}>暂不加入</Text>
<Text className={styles.cancel} onClick={handleCancel}>暂不加入</Text>
<Text className={styles.confirm} onClick={() => run({ groupId: detail.groupId!, shareUserId: detail.shareUserId! })}>
确定加入
</Text>
......
import { useState, useImperativeHandle, forwardRef, useCallback, useEffect, useRef } from 'react'
import { showToast } from '@tarojs/taro'
import { getAreaAndGrades, type AreaAndGrades } from '@/api'
import { useStoreState } from '@/store/hooks'
import ModalArea from './modal-area'
import ModalGrade from './modal-grade'
import ModalResult from './modal-result'
export type TutorialRef = {
start: () => void;
}
const Tutorial = forwardRef<TutorialRef, {}>((_, ref) => {
const joinDefered = useStoreState(state => state.userModel.joinDefered)
const [step, setStep] = useState(0)
const [selected, setSelected] = useState({ area: '', grade: '' })
const [enable, setEnable] = useState(false)
useEffect(() => {
if (!joinDefered) {
setEnable(false)
} else {
joinDefered.getPromise().then(() => {
setEnable(true)
})
}
return () => {
setEnable(false)
}
}, [joinDefered])
const [data, setData] = useState<AreaAndGrades>({ areas: [], grades: [] })
const handleConfirm = useCallback(() => {
setStep(0)
}, [])
const loadData = useCallback(() => {
return getAreaAndGrades().then(setData)
}, [])
const handleConfirmArea = useCallback((val: string) => {
setSelected(v => ({ ...v, area: val }))
setStep(2)
}, [])
const handleConfirmGrade = useCallback((val: string) => {
setSelected(v => ({ ...v, grade: val }))
setStep(3)
}, [])
useEffect(() => {
loadData()
}, [loadData])
useImperativeHandle(ref, () => {
return {
start: () => {
if (!data.areas.length) {
loadData().catch(() => {
showToast({
title: '加载数据失败',
icon: 'none'
})
})
}
setStep(1)
}
}
})
if (!enable) {
return null
}
return (
<>
{step === 1 && <ModalArea options={data.areas} onConfirm={handleConfirmArea} />}
{step === 2 && <ModalGrade options={data.grades} onConfirm={handleConfirmGrade} />}
{step === 3 && <ModalResult grade={selected.grade} onConfirm={handleConfirm} />}
</>
)
})
export default Tutorial
import { View, RootPortal, Image, ScrollView } from '@tarojs/components'
import tutorialAssets from '@/assets/oss/assets-tutorial'
import { useState } from 'react'
import classNames from 'classnames'
import styles from './shared.module.scss'
type ModalAreaProps = {
options: string[];
onConfirm: (arg: string) => void;
}
const ModalArea = (props: ModalAreaProps) => {
const { options, onConfirm } = props
const [current, setCurrent] = useState('')
const handleConfirm = () => {
if (current) {
onConfirm(current)
}
}
return (
<RootPortal>
<View className={styles.mask} catchMove></View>
<View className={styles.modal} catchMove>
<Image src={tutorialAssets['modal-head.png'].u} className={styles.head}></Image>
<View className={styles.modal_body}>
<View className={styles.title}>请问同学就读于哪个地区呢?</View>
<View className={styles.title_tips}>让我为你匹配对应的教材版本</View>
<ScrollView scrollY className={styles.content}>
<View className={styles.option_wrap}>
{options.map(item => (
<View className={styles.option_item} key={item}>
<View className={classNames(styles.option_item_inner, item === current && styles.is_active)}
onClick={() => setCurrent(item)}
>{item}</View>
</View>
))}
</View>
</ScrollView>
<View className={styles.modal_footer}>
<View className={classNames(styles.btn, !current && styles.disabled)} onClick={handleConfirm} hoverClass={styles.btn_on}>继续</View>
</View>
</View>
</View>
</RootPortal>
)
}
export default ModalArea
import { View, RootPortal, Image, ScrollView } from '@tarojs/components'
import tutorialAssets from '@/assets/oss/assets-tutorial'
import { useState } from 'react'
import classNames from 'classnames'
import styles from './shared.module.scss'
type ModalGradeProps = {
options: string[];
onConfirm: (arg: string) => void;
}
const ModalGrade = (props: ModalGradeProps) => {
const { options, onConfirm } = props
const [current, setCurrent] = useState('')
const handleConfirm = () => {
if (current) {
onConfirm(current)
}
}
return (
<RootPortal>
<View className={styles.mask} catchMove></View>
<View className={styles.modal} catchMove>
<Image src={tutorialAssets['modal-head.png'].u} className={styles.head}></Image>
<View className={styles.modal_body}>
<View className={styles.title}>现在就读几年级呢?</View>
<View className={styles.title_tips}>让我为你挑选合适的内容</View>
<ScrollView scrollY className={styles.content}>
<View className={styles.option_wrap}>
{options.map(item => (
<View className={styles.option_item} key={item}>
<View className={classNames(styles.option_item_inner, item === current && styles.is_active)}
onClick={() => setCurrent(item)}
>{item}</View>
</View>
))}
</View>
</ScrollView>
<View className={styles.modal_footer}>
<View
className={classNames(styles.btn, !current && styles.disabled)}
onClick={handleConfirm}
hoverClass={styles.btn_on}
>继续</View>
</View>
</View>
</View>
</RootPortal>
)
}
export default ModalGrade
import { View, RootPortal, Image, Text } from '@tarojs/components'
import tutorialAssets from '@/assets/oss/assets-tutorial'
import { useMemo } from 'react'
import classNames from 'classnames'
import styles from './shared.module.scss'
type ModalResultProps = {
grade: string;
onConfirm: () => void;
}
const ModalResult = (props: ModalResultProps) => {
const { grade, onConfirm } = props
const isLevel1 = useMemo(() => {
return grade === '一年级'
}, [grade])
return (
<RootPortal>
<View className={styles.mask} catchMove></View>
<View className={styles.result_wrap} catchMove>
<Image src={tutorialAssets['cat.png'].u} className={styles.result_cat} />
<View className={styles.result_main}>
<View className={classNames(styles.dialog, isLevel1 && styles.is_lower)}>
{isLevel1
? (
<View>
一年级匹配的内容还在准备中,如果孩子比较
<Text className={styles.em}>可以来试试</Text>哦。
</View>
)
: (
<View>
让我们先从基本功开始。已经为你准备好了打好基本功所必须掌握的
<Text className={styles.em}>计算达标</Text>、
<Text className={styles.em}>常考的应用题</Text>、
以及<Text className={styles.em}>附加思维题</Text>哦。
</View>
)}
<View className={styles.continue}>
<View className={styles.continue_btn} onClick={() => onConfirm()}>
继续<Image src={tutorialAssets['continue-arrow.png'].u} className={styles.continue_icon} />
</View>
</View>
</View>
<View className={styles.tips}>
<Image src={tutorialAssets['star.png'].u} className={styles.star}></Image>
<View>每天花10分钟,让所有关卡都达标,考试高分就会很轻松哦!</View>
</View>
</View>
</View>
</RootPortal>
)
}
export default ModalResult
.mask {
position: fixed;
left: 0;
top: 0;
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
z-index: 99999;
opacity: 1;
}
.head {
width: 654px;
height: 230px;
display: block;
}
.modal_body {
width: 654px;
background: #FFFEFF;
border-radius: 0px 0px 32px 32px;
text-align: center;
}
.modal_footer {
padding: 24px 0 32px 0;
display: flex;
align-items: center;
justify-content: center;
}
.content {
max-height: 40vh;
}
.option_wrap {
padding: 24px 24px 24px 56px;
display: flex;
flex-wrap: wrap;
}
.btn {
width: 248px;
height: 72px;
background-image: url(../../../market/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(../../../market/assets/btn-on.png);
}
&.disabled {
background-image: none;
background-color: #E2E6ED;
color: #C2C8D1;
border-radius: 36px;
}
}
.option_item {
width: 33.33333%;
padding-right: 32px;
padding-bottom: 28px;
box-sizing: border-box;
.option_item_inner {
height: 80px;
background: #F4F6F8;
border-radius: 16px;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
border: 6px solid transparent;
font-size: 32px;
font-weight: 500;
color: rgba(70,81,100,0.8);
line-height: 44px;
&.is_active {
border-color: #FFC056;
}
}
}
.title {
font-size: 40px;
font-weight: 600;
color: #465164;
line-height: 56px;
padding-top: 32px;
}
.title_tips {
font-size: 28px;
font-weight: 500;
color: rgba(70,81,100,0.5);
line-height: 40px;
margin-top: 16px;
padding-bottom: 24px;
}
.modal {
display: flex;
height: 100vh;
z-index: 100000;
position: fixed;
width: 100vw;
left: 0;
top: 0;
flex-direction: column;
align-items: center;
justify-content: center;
}
.result_wrap {
position: fixed;
z-index: 100000;
bottom: 15vh;
left: 0;
right: 0;
display: flex;
padding: 0 16px;
}
.result_main {
flex: 1;
padding-top: 60px;
margin-left: -8px;
}
.result_cat {
width: 200px;
height: 300px;
}
.dialog {
width: 510px;
height: 272px;
padding: 24px 20px 0 42px;
box-sizing: border-box;
background-size: 100% 100%;
background-image: url(https://cdn.jkwljy.com/pk-math/mFR86xsmGbKnCC9yu5ak2yadejB/510x272);
font-size: 28px;
font-weight: 500;
color: rgba(70,81,100,0.8);
line-height: 44px;
.em {
color: #FFC056;
}
&.is_lower {
height: 184px;
background-image: url(https://cdn.jkwljy.com/pk-math/2LZyrqzLwgYFGvJEb1vteEo4KL2r/510x184);
}
}
.tips {
margin-top: 26px;
display: flex;
font-size: 24px;
font-weight: 500;
color: #FFFFFF;
line-height: 40px;
width: 510px;
padding-right: 24px;
box-sizing: border-box;
}
.star {
width: 40px;
height: 40px;
flex-shrink: 0;
display: block;
}
.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;
}
......@@ -97,7 +97,7 @@ const Scene6 = (props: Scene6Props) => {
<Image src={assets['touzi.png'].u} className={classNames(styles.input_icon, isGenerating && styles.is_gen)} onClick={handleGen}></Image>
</View>
<View className={styles.input_tip}>
确定后奖励<Image src={assets['score.png'].u} className={styles.score}></Image><Text className={styles.em}>+100</Text>
{/* 确定后奖励<Image src={assets['score.png'].u} className={styles.score}></Image><Text className={styles.em}>+100</Text> */}
</View>
</View>
<View className={styles.bottom}></View>
......
......@@ -6,9 +6,12 @@ import type { UserInfo } from '@/types'
import { pointToCard } from '@/api/account'
import { showModal, showToast, showLoading, hideLoading } from '@tarojs/taro'
import { getStorage, StorageKeys, updateStorage } from '@/utils/storage'
import { Deferred } from '@/utils/deferred'
import { AppStoreModel } from '../store-model'
export interface UserModel {
/** 加入部落 */
joinDefered: Deferred | null;
userInfo: UserInfo;
cardNum: number;
point: number;
......@@ -25,6 +28,7 @@ export interface UserModel {
}
const userModel: UserModel = {
joinDefered: null,
userInfo: getStorage(StorageKeys.userInfo)!,
isEyeProtectionMode: false,
cardNum: 0,
......
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