Commit acc860b3 authored by hewenhao's avatar hewenhao

feat: update

parent a90fc4d7
import { View, Image, Text } from '@tarojs/components' import { View, Image, Text } from '@tarojs/components'
import assets from '@/assets/oss/assets-complete' import assets from '@/assets/oss/assets-complete'
import { useMemo } from 'react' import { useMemo, useCallback } from 'react'
import { navigateBack } from '@tarojs/taro'
import classNames from 'classnames' import classNames from 'classnames'
import { useStoreState } from '@/store/hooks' import { useStoreState } from '@/store/hooks'
import { StageLevel } from '@/api' import { StageLevel } from '@/api'
...@@ -68,11 +69,16 @@ const GameCompleteAchieve = () => { ...@@ -68,11 +69,16 @@ const GameCompleteAchieve = () => {
return Math.ceil(rankNo / 500) * 500 return Math.ceil(rankNo / 500) * 500
}, [rankNo]) }, [rankNo])
const handleContinue = useCallback(() => {
navigateBack()
}, [])
const renderBtn = () => ( const renderBtn = () => (
<View className={styles.footer}> <View className={styles.footer}>
<View <View
className={styles.btn_continue} className={styles.btn_continue}
hoverClass={styles.is_active} hoverClass={styles.is_active}
onClick={handleContinue}
> >
继续 继续
</View> </View>
...@@ -83,7 +89,7 @@ const GameCompleteAchieve = () => { ...@@ -83,7 +89,7 @@ const GameCompleteAchieve = () => {
return null return null
} }
if (gameResult.errNum > 0) { if (gameResult.errNum > 0 || !gameResult.level) {
return ( return (
<> <>
<View>没关系,差一点就成功了! 加油!加油!</View> <View>没关系,差一点就成功了! 加油!加油!</View>
......
...@@ -47,6 +47,27 @@ let evenIndex = 0 ...@@ -47,6 +47,27 @@ let evenIndex = 0
let oddIndex = 0 let oddIndex = 0
let specialIndex = 0 let specialIndex = 0
export function stageToParts (stageList: Stage[]): Part[] {
evenIndex = 0
oddIndex = 0
specialIndex = 0
const ret: Part[] = []
stageList.forEach(item => {
const last = ret.find(c => c.number === (item.part || 0))
if (last) {
last.stages.push(item)
} else {
ret.push({
number: item.part ?? 0,
stages: [item]
})
}
})
return ret
}
export function groupRoundToSmallPart (list: Stage[]): SmallPart[] { export function groupRoundToSmallPart (list: Stage[]): SmallPart[] {
const ret: SmallPart[] = [] const ret: SmallPart[] = []
let flag: 'even' | 'odd' = 'even' let flag: 'even' | 'odd' = 'even'
......
...@@ -2,34 +2,16 @@ import { View } from '@tarojs/components' ...@@ -2,34 +2,16 @@ import { View } from '@tarojs/components'
import assets from '@/assets/oss/assets-main' import assets from '@/assets/oss/assets-main'
import { useMemo } from 'react' import { useMemo } from 'react'
import LazeImage from '../lazy-image' import LazeImage from '../lazy-image'
import { Part, Stage } from './constants' import { stageToParts, type Stage } from './constants'
import ScenePart from './part' import ScenePart from './part'
type SceneProps = { type SceneProps = {
stageList: Stage[]; stageList: Stage[];
} }
function toPart (stageList: Stage[]): Part[] {
const ret: Part[] = []
stageList.forEach(item => {
const last = ret.find(c => c.number === (item.part || 0))
if (last) {
last.stages.push(item)
} else {
ret.push({
number: item.part ?? 0,
stages: [item]
})
}
})
return ret
}
const Scene = (props: SceneProps) => { const Scene = (props: SceneProps) => {
const partList = useMemo(() => { const partList = useMemo(() => {
return toPart(props.stageList) return stageToParts(props.stageList)
}, [props.stageList]) }, [props.stageList])
return ( return (
......
...@@ -18,14 +18,8 @@ const MainPage = () => { ...@@ -18,14 +18,8 @@ const MainPage = () => {
const fetchStage = useStoreActions(actions => actions.mainModel.fetchStage) const fetchStage = useStoreActions(actions => actions.mainModel.fetchStage)
const stageList = useStoreState(state => state.mainModel.stageList) const stageList = useStoreState(state => state.mainModel.stageList)
const fetchAccount = useStoreActions(actions => actions.userModel.fetchAccount) const fetchAccount = useStoreActions(actions => actions.userModel.fetchAccount)
useDidShow(() => {
fetchAccount()
const tabbar = getTabBar<TabbarRef>(page)
tabbar?.setSelected(0)
})
const [nav] = useState(getMenuButtonBoundingClientRect()) const [nav] = useState(getMenuButtonBoundingClientRect())
const scrollToCurrent = useCallback((callback?: () => void) => { const scrollToCurrent = useCallback((callback?: () => void) => {
const height = getSystemInfoSync().windowHeight const height = getSystemInfoSync().windowHeight
pageScrollTo({ pageScrollTo({
...@@ -35,7 +29,10 @@ const MainPage = () => { ...@@ -35,7 +29,10 @@ const MainPage = () => {
}) })
}, []) }, [])
useEffect(() => { useDidShow(() => {
fetchAccount()
const tabbar = getTabBar<TabbarRef>(page)
tabbar?.setSelected(0)
fetchStage().then(() => { fetchStage().then(() => {
setTimeout(() => { setTimeout(() => {
scrollToCurrent(() => { scrollToCurrent(() => {
...@@ -43,7 +40,7 @@ const MainPage = () => { ...@@ -43,7 +40,7 @@ const MainPage = () => {
}) })
}, 1000) }, 1000)
}) })
}, [scrollToCurrent, fetchStage]) })
return ( return (
<> <>
......
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