Commit 974597e5 authored by hewenhao's avatar hewenhao

feat: 一战到底

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