Commit 974597e5 authored by hewenhao's avatar hewenhao

feat: 一战到底

parent acc860b3
...@@ -13,7 +13,12 @@ declare module '*.styl'; ...@@ -13,7 +13,12 @@ declare module '*.styl';
type CountUptime = React.FC<{ maxNum }> type CountUptime = React.FC<{ maxNum }>
type CountUpTime = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & { 'max-value'?: number, onTimeup?: () => void }, HTMLElement> type CountUpTime = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
'maxValue'?: number;
'isDown'?: boolean;
'startValue': number;
onTimeup?: () => void;
}, HTMLElement>
declare namespace JSX{ declare namespace JSX{
interface IntrinsicElements { interface IntrinsicElements {
......
...@@ -19,7 +19,7 @@ export const enum StageStatus { ...@@ -19,7 +19,7 @@ export const enum StageStatus {
export const enum StageType { export const enum StageType {
Strong = '强化', Strong = '强化',
Enhance = '应用', Enhance = '应用',
OneStop = '一站到底', OneStop = '一战到底',
} }
export const enum StageLevel { export const enum StageLevel {
......
...@@ -27,6 +27,14 @@ Component({ ...@@ -27,6 +27,14 @@ Component({
type: Number, type: Number,
value: 100 * 60 * 60 value: 100 * 60 * 60
}, },
isDown: {
type: Boolean,
value: false,
},
startValue: {
type: Number,
value: 0
}
}, },
data: { data: {
...@@ -35,7 +43,6 @@ Component({ ...@@ -35,7 +43,6 @@ Component({
}, },
attached () { attached () {
this._tick = 0
this.startCount() this.startCount()
console.log(this) console.log(this)
}, },
...@@ -48,12 +55,23 @@ Component({ ...@@ -48,12 +55,23 @@ Component({
}, },
startCount () { startCount () {
this.stop() this.stop()
this._tick = this.data.startValue
this._timer = setInterval(() => { this._timer = setInterval(() => {
console.log(this.data)
const isDown = this.data.isDown
if (isDown) {
this._tick -= 1
if (this._tick <= 0) {
this.stop()
this.triggerEvent('timeup')
}
} else {
this._tick += 1 this._tick += 1
if (this._tick >= this.data.maxValue) { if (this._tick >= this.data.maxValue) {
this.stop() this.stop()
this.triggerEvent('timeup') this.triggerEvent('timeup')
} }
}
const { minutes, seconds } = this.data const { minutes, seconds } = this.data
const val = this._tick * 1000 const val = this._tick * 1000
...@@ -70,11 +88,6 @@ Component({ ...@@ -70,11 +88,6 @@ Component({
this.setData(opts) this.setData(opts)
}, 1000) }, 1000)
}, },
onMyButtonTap: function () {
this.setData({
// 更新属性和数据的方法与更新页面数据的方法类似
})
},
} }
}) })
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
padding: 40px 32px 100px 32px; padding: 40px 32px 100px 32px;
display: flex; display: flex;
align-items: center; align-items: center;
&.is_stop {
padding-bottom: 50px;
}
} }
.process { .process {
......
import { View, Image } from '@tarojs/components' import { View, Image } from '@tarojs/components'
import { useState, useEffect, useCallback, useMemo, useRef } from 'react' import { useState, useEffect, useCallback, useMemo, useRef } from 'react'
import { createSelectorQuery, getCurrentInstance } from '@tarojs/taro' import { createSelectorQuery, getCurrentInstance } from '@tarojs/taro'
import classNames from 'classnames'
import { useStoreState } from '@/store/hooks' import { useStoreState } from '@/store/hooks'
import { type StageDetail } from '@/api' import { type StageDetail, StageType } from '@/api'
import styles from './count-up.module.scss' import styles from './count-up.module.scss'
...@@ -35,6 +36,17 @@ const CountUp = (props: CountUpProps) => { ...@@ -35,6 +36,17 @@ const CountUp = (props: CountUpProps) => {
}) })
}, []) }, [])
const isOneStop = useMemo(() => {
return stageDetail.type === StageType.OneStop
}, [stageDetail])
const startTick = useMemo(() => {
if (stageDetail.type === StageType.OneStop) {
return stageDetail.bTime
}
return 0
}, [stageDetail])
const roleStyle = useMemo(() => { const roleStyle = useMemo(() => {
return { return {
transform: `translateX(${width}px)`, transform: `translateX(${width}px)`,
...@@ -66,18 +78,20 @@ const CountUp = (props: CountUpProps) => { ...@@ -66,18 +78,20 @@ const CountUp = (props: CountUpProps) => {
}, []) }, [])
return ( return (
<View className={styles.count}> <View className={classNames(styles.count, isOneStop && styles.is_stop)}>
<View className={styles.process} id={id}> <View className={styles.process} id={id}>
<View className={styles.process_inner} style={processInnerStyle}></View> <View className={styles.process_inner} style={processInnerStyle}></View>
{!isOneStop && (
<View className={styles.role} style={roleStyle}> <View className={styles.role} style={roleStyle}>
<View className={styles.tick}></View> <View className={styles.tick}></View>
<Image src={require('../assets/count-cat.png')} className={styles.cat}></Image> <Image src={require('../assets/count-cat.png')} className={styles.cat}></Image>
<View className={styles.tips}>通关要求</View> <View className={styles.tips}>通关要求</View>
</View> </View>
)}
</View> </View>
<View className={styles.time}> <View className={styles.time}>
<Image src={require('../assets/count-time.png')} className={styles.icon}></Image> <Image src={require('../assets/count-time.png')} className={styles.icon}></Image>
<count-up-time max-value={60 * 60} onTimeup={handleTimeUp} ref={countUp} /> <count-up-time maxValue={60 * 60} startValue={startTick} isDown={isOneStop} onTimeup={handleTimeUp} ref={countUp} />
</View> </View>
</View> </View>
) )
......
...@@ -77,10 +77,10 @@ export function groupRoundToSmallPart (list: Stage[]): SmallPart[] { ...@@ -77,10 +77,10 @@ export function groupRoundToSmallPart (list: Stage[]): SmallPart[] {
while (start < len) { while (start < len) {
if (flag === 'even') { if (flag === 'even') {
const rounds = list.slice(start, start + 2) const stages = list.slice(start, start + 2)
let partType: SmallPart['type'] = 'even' let partType: SmallPart['type'] = 'even'
let bg: ImageSource let bg: ImageSource
if (rounds.length < 2) { if (stages.length < 2) {
specialIndex += 1 specialIndex += 1
partType = 'special' partType = 'special'
bg = getSmallPartBg(specialIndex, partType) bg = getSmallPartBg(specialIndex, partType)
...@@ -89,7 +89,7 @@ export function groupRoundToSmallPart (list: Stage[]): SmallPart[] { ...@@ -89,7 +89,7 @@ export function groupRoundToSmallPart (list: Stage[]): SmallPart[] {
bg = getSmallPartBg(evenIndex, partType) bg = getSmallPartBg(evenIndex, partType)
} }
ret.push({ ret.push({
rounds, stages,
bg, bg,
offset: start, offset: start,
type: partType type: partType
...@@ -99,7 +99,7 @@ export function groupRoundToSmallPart (list: Stage[]): SmallPart[] { ...@@ -99,7 +99,7 @@ export function groupRoundToSmallPart (list: Stage[]): SmallPart[] {
} else if (flag === 'odd') { } else if (flag === 'odd') {
oddIndex += 1 oddIndex += 1
ret.push({ ret.push({
rounds: list.slice(start, start + 1), stages: list.slice(start, start + 1),
bg: getSmallPartBg(oddIndex, 'odd'), bg: getSmallPartBg(oddIndex, 'odd'),
offset: start, offset: start,
type: 'odd' type: 'odd'
...@@ -112,17 +112,8 @@ export function groupRoundToSmallPart (list: Stage[]): SmallPart[] { ...@@ -112,17 +112,8 @@ export function groupRoundToSmallPart (list: Stage[]): SmallPart[] {
return ret return ret
} }
export const enum RoundState {
/** 未解锁 */
Locked = 1,
/** 已完成 */
Clear = 2,
/** 已解锁 */
UnLocked = 3
}
export type SmallPart = { export type SmallPart = {
rounds: Stage[]; stages: Stage[];
bg: ImageSource; bg: ImageSource;
offset: number; offset: number;
type: 'odd' | 'even' | 'special'; type: 'odd' | 'even' | 'special';
......
...@@ -24,7 +24,7 @@ const SceneSmallPart = (props: SceneSmallPartProps) => { ...@@ -24,7 +24,7 @@ const SceneSmallPart = (props: SceneSmallPartProps) => {
const { part } = props const { part } = props
return ( return (
<LazeImage source={part.bg}> <LazeImage source={part.bg}>
{part.rounds.map((item, index) => { {part.stages.map((item, index) => {
return ( return (
<RoundComp stage={item} key={item.id} className={getClassName(index, part.type)} /> <RoundComp stage={item} key={item.id} className={getClassName(index, part.type)} />
) )
......
...@@ -4,7 +4,7 @@ import { useState, useMemo, useEffect, useCallback } from 'react' ...@@ -4,7 +4,7 @@ import { useState, useMemo, useEffect, useCallback } from 'react'
import { useStoreActions, useStoreState } from '@/store/hooks' import { useStoreActions, useStoreState } from '@/store/hooks'
import type { TabbarRef } from '../../custom-tab-bar/index' import type { TabbarRef } from '../../custom-tab-bar/index'
import { CurrentRoundId, SceneContext } from './components/scene/constants' import { CurrentRoundId, SceneContext, StageStatus } from './components/scene/constants'
import MainHeader from './components/header' import MainHeader from './components/header'
import MainChapter from './components/chapter' import MainChapter from './components/chapter'
import MainScene from './components/scene' import MainScene from './components/scene'
...@@ -33,11 +33,15 @@ const MainPage = () => { ...@@ -33,11 +33,15 @@ const MainPage = () => {
fetchAccount() fetchAccount()
const tabbar = getTabBar<TabbarRef>(page) const tabbar = getTabBar<TabbarRef>(page)
tabbar?.setSelected(0) tabbar?.setSelected(0)
fetchStage().then(() => { fetchStage().then((list) => {
setTimeout(() => { setTimeout(() => {
if (!list.find(c => c.status === StageStatus.CURRENT)) {
setIsReady(true)
} else {
scrollToCurrent(() => { scrollToCurrent(() => {
setIsReady(true) setIsReady(true)
}) })
}
}, 1000) }, 1000)
}) })
}) })
......
...@@ -7,7 +7,7 @@ import { type Stage, getStageList } from '@/api' ...@@ -7,7 +7,7 @@ import { type Stage, getStageList } from '@/api'
export interface MainModel { export interface MainModel {
stageList: Stage[]; stageList: Stage[];
updateStageList: Action<MainModel, Stage[]>; updateStageList: Action<MainModel, Stage[]>;
fetchStage: Thunk<MainModel, void, void, AppStoreModel>; fetchStage: Thunk<MainModel, void, void, AppStoreModel, Promise<Stage[]>>;
} }
const mainModel: MainModel = { const mainModel: MainModel = {
...@@ -16,12 +16,15 @@ const mainModel: MainModel = { ...@@ -16,12 +16,15 @@ const mainModel: MainModel = {
state.stageList = stageList state.stageList = stageList
}), }),
fetchStage: thunk(async (actions, _) => { fetchStage: thunk(async (actions, _) => {
let ret: Stage[] = []
try { try {
const { data: stageList } = await getStageList() const { data: stageList } = await getStageList()
actions.updateStageList(stageList) ret = stageList
} catch (err) { } catch (err) {
actions.updateStageList([]) ret = []
} }
actions.updateStageList(ret)
return ret
}), }),
} }
......
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