Commit 8cdd05d5 authored by hewenhao's avatar hewenhao

feat: update

parent dcc86a67
...@@ -86,7 +86,8 @@ export interface CompleteQuestion extends QuestionItem { ...@@ -86,7 +86,8 @@ export interface CompleteQuestion extends QuestionItem {
export interface CompleteStageParam { export interface CompleteStageParam {
correctNum: number; correctNum: number;
level: StageLevel; level: StageLevel | null;
levelTime: number;
num: number; num: number;
questions: CompleteQuestion[]; questions: CompleteQuestion[];
resultTime: number; resultTime: number;
...@@ -98,30 +99,25 @@ interface CompleteStageParamIn extends CompleteStageParam { ...@@ -98,30 +99,25 @@ interface CompleteStageParamIn extends CompleteStageParam {
} }
export interface CompleteStageOut { export interface CompleteStageOut {
/** 单题耗时 */
averageTime: number;
/** 排名档位 */ /** 排名档位 */
gear: number; gear: number;
/** 排名积分 */
gearReward: number;
/** 成就等级:SAB */ /** 成就等级:SAB */
level: StageLevel; level: StageLevel | null;
/** 下一档位 */ /** 之前成就 */
nextGear: number; levelBefore: StageLevel | null;
/** 下一档位时间 */ /** 成就奖励 */
nextGearTime: number; levelReward: number;
/** 积分后 */
pointAfter: number;
/** 积分前 */
pointBefore: number;
/** 排名 */ /** 排名 */
ranks: StageRank[]; ranks: StageRank[];
/** 正确率 */
rate: number;
/** 耗时 */ /** 耗时 */
resultTime: number; resultTime: number;
/** S时间 */
sLevelTime: number;
/** 是否升档奖励 */ /** 是否升档奖励 */
upGear: boolean; upGear: boolean;
/** 升档奖励 */
upGearReward: number;
} }
/** 完成 */ /** 完成 */
......
...@@ -24,6 +24,29 @@ ...@@ -24,6 +24,29 @@
font-weight: 600; font-weight: 600;
color: #465164; color: #465164;
line-height: 44px; line-height: 44px;
display: flex;
align-items: center;
}
.first_time {
height: 38px;
background: #FDB74B;
border-radius: 19px;
border: 2px solid #FF9E07;
margin-left: 16px;
display: flex;
align-items: center;
justify-content: center;
padding: 0 12px;
font-size: 24px;
font-weight: 500;
color: #FFFFFF;
line-height: 34px;
box-sizing: border-box;
&.is_second {
background: rgba($color: #465164, $alpha: 0.3);
border-color: transparent;
}
} }
.tips_text { .tips_text {
......
import { View, Image } 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 } from 'react'
import classNames from 'classnames'
import { useStoreState } from '@/store/hooks' import { useStoreState } from '@/store/hooks'
import { StageLevel } from '@/api' import { StageLevel } from '@/api'
import { useFormatTick } from '@/hooks/use-format-tick'
import { cs } from '@/styles' import { cs } from '@/styles'
import styles from './complete-achieve.module.scss' import styles from './complete-achieve.module.scss'
const getLevelBg = (s?: StageLevel): string => { const getLevelBg = (s?: StageLevel | null): string => {
switch (s) { switch (s) {
case StageLevel.S: { case StageLevel.S: {
return assets['level-small-s.png'].u return assets['level-small-s.png'].u
...@@ -49,6 +51,47 @@ const GameCompleteAchieve = () => { ...@@ -49,6 +51,47 @@ const GameCompleteAchieve = () => {
return getTopIcon(gameResult?.gear ?? 0) return getTopIcon(gameResult?.gear ?? 0)
}, [gameResult]) }, [gameResult])
const time = useFormatTick((gameResult?.levelTime ?? 0) * 1000)
const rankNo = useMemo(() => {
return gameResult?.ranks.find(c => c.me)?.no ?? 'NaN'
}, [gameResult])
const rankNoS = useMemo(() => {
if (rankNo === 'NaN') return 'NaN'
if (rankNo <= 10) {
return 10
}
if (rankNo <= 100) {
return 100
}
return Math.ceil(rankNo / 500) * 500
}, [rankNo])
const renderBtn = () => (
<View className={styles.footer}>
<View
className={styles.btn_continue}
hoverClass={styles.is_active}
>
继续
</View>
</View>
)
if (!gameResult) {
return null
}
if (gameResult.errNum > 0) {
return (
<>
<View>没关系,差一点就成功了! 加油!加油!</View>
{renderBtn()}
</>
)
}
return ( return (
<> <>
<View className={styles.wrap}> <View className={styles.wrap}>
...@@ -56,25 +99,39 @@ const GameCompleteAchieve = () => { ...@@ -56,25 +99,39 @@ const GameCompleteAchieve = () => {
<View className={styles.achieve_item}> <View className={styles.achieve_item}>
<Image src={level} className={styles.achieve_icon}></Image> <Image src={level} className={styles.achieve_icon}></Image>
<View className={cs.flex__item}> <View className={cs.flex__item}>
<View className={styles.main_text}>B等级</View> <View className={styles.main_text}>
<View className={styles.tips_text}>全对且用时≤1分30秒</View> {gameResult.level}等级
<Text className={classNames(styles.first_time, gameResult.levelReward <= 0 && styles.is_second)}>
{gameResult.levelReward > 0 ? '首次达成' : '二次达成'}
</Text>
</View>
<View className={styles.tips_text}>全对且用时≤{time.minutes}分{time.seconds}秒</View>
</View> </View>
{gameResult.levelReward > 0 && (
<View> <View>
<Image src={require('../assets/bonus.png')} className={styles.bonus_icon}></Image> <Image src={require('../assets/bonus.png')} className={styles.bonus_icon}></Image>
<View className={styles.bonus_text}>+30</View> <View className={styles.bonus_text}>+{gameResult.levelReward}</View>
</View> </View>
)}
</View> </View>
{topIcon && ( {topIcon && (
<View className={styles.achieve_item}> <View className={styles.achieve_item}>
<Image src={topIcon} className={styles.achieve_icon}></Image> <Image src={topIcon} className={styles.achieve_icon}></Image>
<View className={cs.flex__item}> <View className={cs.flex__item}>
<View className={styles.main_text}>TOP {gameResult?.gear ?? 0}%</View> <View className={styles.main_text}>
TOP {gameResult?.gear ?? 0}%
<Text className={classNames(styles.first_time, gameResult.gearReward <= 0 && styles.is_second)}>
{gameResult.gearReward > 0 ? '首次达成' : '二次达成'}
</Text>
</View>
<View className={styles.tips_text}>恭喜你成为了最优秀的{gameResult?.gear ?? 0}%</View> <View className={styles.tips_text}>恭喜你成为了最优秀的{gameResult?.gear ?? 0}%</View>
</View> </View>
{gameResult.gearReward > 0 && (
<View> <View>
<Image src={require('../assets/bonus.png')} className={styles.bonus_icon}></Image> <Image src={require('../assets/bonus.png')} className={styles.bonus_icon}></Image>
<View className={styles.bonus_text}>+20</View> <View className={styles.bonus_text}>+{gameResult.gearReward}</View>
</View> </View>
)}
</View> </View>
)} )}
...@@ -82,33 +139,28 @@ const GameCompleteAchieve = () => { ...@@ -82,33 +139,28 @@ const GameCompleteAchieve = () => {
<Image src={assets['rank.png'].u} className={styles.achieve_icon}></Image> <Image src={assets['rank.png'].u} className={styles.achieve_icon}></Image>
<View className={cs.flex__item}> <View className={cs.flex__item}>
<View className={styles.main_text}>全市排名</View> <View className={styles.main_text}>全市排名</View>
<View className={styles.tips_text}>恭喜你进入了全市前100名</View> <View className={styles.tips_text}>恭喜你进入了全市前{rankNoS}名</View>
</View> </View>
<View className={styles.rank_text}>89名</View> <View className={styles.rank_text}>{rankNo}名</View>
</View> </View>
{gameResult?.upGear && ( {gameResult?.upGear && (
<View className={styles.achieve_item}> <View className={styles.achieve_item}>
<Image src={assets['upgear.png'].u} className={styles.achieve_icon}></Image> <Image src={assets['upgear.png'].u} className={styles.achieve_icon}></Image>
<View className={cs.flex__item}> <View className={cs.flex__item}>
<View className={styles.main_text}>升档成功</View> <View className={styles.main_text}>升档成功</View>
<View className={styles.tips_text}>提升到50%-60%</View> <View className={styles.tips_text}>提升到{gameResult.gear - 10}%-{gameResult.gear}%</View>
</View> </View>
{gameResult.upGearReward > 0 && (
<View> <View>
<Image src={require('../assets/bonus.png')} className={styles.bonus_icon}></Image> <Image src={require('../assets/bonus.png')} className={styles.bonus_icon}></Image>
<View className={styles.bonus_text}>+10</View> <View className={styles.bonus_text}>+{gameResult.upGearReward}</View>
</View> </View>
)}
</View> </View>
)} )}
<View className={styles.gap}></View> <View className={styles.gap}></View>
</View> </View>
<View className={styles.footer}> {renderBtn()}
<View
className={styles.btn_continue}
hoverClass={styles.is_active}
>
继续
</View>
</View>
</> </>
) )
} }
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
width: 60px; width: 60px;
height: 60px; height: 60px;
margin-right: 6px; margin-right: 6px;
display: block;
} }
.item_text { .item_text {
...@@ -50,3 +51,7 @@ ...@@ -50,3 +51,7 @@
text-align: center; text-align: center;
line-height: 40px; line-height: 40px;
} }
.err {
color: #FF7770;
}
import { View, Image, Text } from '@tarojs/components' import { View, Image } from '@tarojs/components'
import { useMemo } from 'react' import { useMemo } from 'react'
import { getMenuButtonBoundingClientRect } from '@tarojs/taro' import { getMenuButtonBoundingClientRect } from '@tarojs/taro'
import classNames from 'classnames'
import assets from '@/assets/oss/assets-complete' import assets from '@/assets/oss/assets-complete'
import { useFormatTick } from '@/hooks/use-format-tick' import { useFormatTick } from '@/hooks/use-format-tick'
import { StageLevel } from '@/api' import { StageLevel } from '@/api'
...@@ -8,7 +9,7 @@ import { useStoreState } from '@/store/hooks' ...@@ -8,7 +9,7 @@ import { useStoreState } from '@/store/hooks'
import styles from './complete-head.module.scss' import styles from './complete-head.module.scss'
const getLevelBigBg = (s?: StageLevel): string => { const getLevelBigBg = (s?: StageLevel | null): string => {
switch (s) { switch (s) {
case StageLevel.S: { case StageLevel.S: {
return assets['level-big-s.png'].u return assets['level-big-s.png'].u
...@@ -24,7 +25,7 @@ const getLevelBigBg = (s?: StageLevel): string => { ...@@ -24,7 +25,7 @@ const getLevelBigBg = (s?: StageLevel): string => {
return assets['level-big-fail.png'].u return assets['level-big-fail.png'].u
} }
const getLevelText = (s?: StageLevel) => { const getLevelText = (s?: StageLevel | null) => {
switch (s) { switch (s) {
case StageLevel.S: { case StageLevel.S: {
return { return {
...@@ -76,6 +77,10 @@ const GameCompleteHead = () => { ...@@ -76,6 +77,10 @@ const GameCompleteHead = () => {
} }
}, [nav]) }, [nav])
if (!gameResult) {
return null
}
return ( return (
<View style={style} className={styles.head}> <View style={style} className={styles.head}>
<Image src={bg} className={styles.bg}></Image> <Image src={bg} className={styles.bg}></Image>
...@@ -87,7 +92,7 @@ const GameCompleteHead = () => { ...@@ -87,7 +92,7 @@ const GameCompleteHead = () => {
</View> </View>
<View className={styles.item}> <View className={styles.item}>
<Image src={require('../assets/right-count.png')} className={styles.icon}></Image> <Image src={require('../assets/right-count.png')} className={styles.icon}></Image>
<View className={styles.item_text}>全对</View> <View className={classNames(styles.item_text, gameResult.errNum > 0 && styles.err)}>{gameResult.errNum === 0 ? '全对' : `错${gameResult.errNum}题`}</View>
</View> </View>
<View className={styles.item}> <View className={styles.item}>
<Image src={require('../assets/time.png')} className={styles.icon}></Image> <Image src={require('../assets/time.png')} className={styles.icon}></Image>
......
import { View, ScrollView } from '@tarojs/components' import { View, ScrollView } from '@tarojs/components'
import { useStoreState, useStoreActions } from '@/store/hooks' import { useStoreState } from '@/store/hooks'
import { useEffect } from 'react' // import { useEffect } from 'react'
import { useRouter } from '@tarojs/taro' // import { useRouter } from '@tarojs/taro'
import { useBoolean } from '@/hooks/use-boolean' import { useBoolean } from '@/hooks/use-boolean'
import ModalContinue from './components/modal-continue' import ModalContinue from './components/modal-continue'
...@@ -15,17 +15,11 @@ import styles from './index.module.scss' ...@@ -15,17 +15,11 @@ import styles from './index.module.scss'
const GamePlay = () => { const GamePlay = () => {
const currentQuestion = useStoreState(states => states.gameModel.currentQuestion) const currentQuestion = useStoreState(states => states.gameModel.currentQuestion)
const getQuestionList = useStoreActions(actions => actions.gameModel.getQuestionList)
const stageDetail = useStoreState(state => state.gameModel.stageDetail) const stageDetail = useStoreState(state => state.gameModel.stageDetail)
const [val, actions] = useBoolean(false) const [val, actions] = useBoolean(false)
const router = useRouter<{ id: string }>()
useEffect(() => {
getQuestionList(+router.params.id)
}, [router, getQuestionList])
return ( return (
<>
<View className={styles.viewport}> <View className={styles.viewport}>
<PageHead /> <PageHead />
{currentQuestion && stageDetail && ( {currentQuestion && stageDetail && (
...@@ -46,8 +40,9 @@ const GamePlay = () => { ...@@ -46,8 +40,9 @@ const GamePlay = () => {
<PageFooter /> <PageFooter />
</> </>
)} )}
<ModalContinue closeOnClickModal onClose={actions.setFalse} />
</View> </View>
<ModalContinue closeOnClickModal onClose={actions.setFalse} />
</>
) )
} }
......
...@@ -10,13 +10,18 @@ import { ...@@ -10,13 +10,18 @@ import {
} from '../types' } from '../types'
import { buildCompleteStageParam, convertQuestion, determinQuestion } from './utils' import { buildCompleteStageParam, convertQuestion, determinQuestion } from './utils'
// import questionListJson from './test.json' import questionListJson from './test.json'
interface CompleteStageDetail extends CompleteStageOut {
errNum: number;
levelTime: number;
}
export interface GameModel { export interface GameModel {
/** 题目列表 */ /** 题目列表 */
questionList: QuestionType[]; questionList: QuestionType[];
stageDetail: StageDetail | null; stageDetail: StageDetail | null;
gameResult: CompleteStageOut | null; gameResult: CompleteStageDetail | null;
gameStartTime: number; gameStartTime: number;
updateState: Action<GameModel, Partial<State<GameModel>>>; updateState: Action<GameModel, Partial<State<GameModel>>>;
/** 当前题目 */ /** 当前题目 */
...@@ -54,34 +59,26 @@ export interface GameModel { ...@@ -54,34 +59,26 @@ export interface GameModel {
} }
const gameModel: GameModel = { const gameModel: GameModel = {
questionList: [], questionList: questionListJson as QuestionType[],
gameResult: { gameResult: {
/** 单题耗时 */
averageTime: 4,
/** 排名档位 */ /** 排名档位 */
gear: 10, gear: 10,
gearReward: 10,
levelBefore: StageLevel.B,
levelReward: 20,
upGearReward: 40,
errNum: 0,
/** 成就等级:SAB */ /** 成就等级:SAB */
level: StageLevel.S, level: StageLevel.S,
/** 下一档位 */ levelTime: 50,
nextGear: 10,
/** 下一档位时间 */
nextGearTime: 3,
/** 积分后 */
pointAfter: 80,
/** 积分前 */
pointBefore: 76,
/** 排名 */ /** 排名 */
ranks: [], ranks: [],
/** 正确率 */
rate: 80,
/** 耗时 */ /** 耗时 */
resultTime: 60, resultTime: 60,
/** S时间 */
sLevelTime: 70,
/** 是否升档奖励 */ /** 是否升档奖励 */
upGear: true upGear: true
}, },
modalContinueVisible: false, modalContinueVisible: true,
gameStartTime: 0, gameStartTime: 0,
isSubmit: false, isSubmit: false,
...@@ -130,7 +127,9 @@ const gameModel: GameModel = { ...@@ -130,7 +127,9 @@ const gameModel: GameModel = {
}), }),
updateUserAnswer: action((state, char) => { updateUserAnswer: action((state, char) => {
if (process.env.NODE_ENV === 'production') {
vibrateShort() vibrateShort()
}
const index = state.currentInputIndex const index = state.currentInputIndex
const answers = state.questionList[state.currentQuestionIndex]?.answers const answers = state.questionList[state.currentQuestionIndex]?.answers
const val = answers?.[index] const val = answers?.[index]
...@@ -211,15 +210,15 @@ const gameModel: GameModel = { ...@@ -211,15 +210,15 @@ const gameModel: GameModel = {
getQuestionList: thunk(async (actions, round) => { getQuestionList: thunk(async (actions, round) => {
try { try {
showLoading() // showLoading()
const { data: questionList } = await getQuestionList(round) const { data: questionList } = await getQuestionList(round)
actions.updateState({ actions.updateState({
questionList: questionList.map(convertQuestion), questionList: questionList.map(convertQuestion),
gameStartTime: Date.now(), gameStartTime: Date.now(),
}) })
hideLoading() // hideLoading()
} catch (err) { } catch (err) {
hideLoading() // hideLoading()
showModal({ showModal({
title: '提示', title: '提示',
content: err.message || '出错了', content: err.message || '出错了',
...@@ -239,8 +238,15 @@ const gameModel: GameModel = { ...@@ -239,8 +238,15 @@ const gameModel: GameModel = {
}) })
actions.updateState({ isSubmit: true }) actions.updateState({ isSubmit: true })
const { questionList, gameStartTime, stageDetail } = helpers.getState() const { questionList, gameStartTime, stageDetail } = helpers.getState()
const { data: gameResult } = await completeStage(buildCompleteStageParam(questionList, stageDetail!, gameStartTime)) const params = buildCompleteStageParam(questionList, stageDetail!, gameStartTime)
actions.updateState({ gameResult }) const { data: gameResult } = await completeStage(params)
actions.updateState({
gameResult: {
...gameResult,
errNum: params.num - params.correctNum,
levelTime: params.levelTime
}
})
redirectTo({ redirectTo({
url: '/pages/game/complete/index', url: '/pages/game/complete/index',
}) })
......
...@@ -42,23 +42,28 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta ...@@ -42,23 +42,28 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta
const { sTime, aTime, bTime } = stageDetail const { sTime, aTime, bTime } = stageDetail
let level = StageLevel.B let level: StageLevel | null = null
const num = questionList.length const num = questionList.length
let levelTime: number = 0
if (correctNum === num) { if (correctNum === num) {
if (resultTime <= sTime) { if (resultTime <= sTime) {
level = StageLevel.S level = StageLevel.S
levelTime = sTime
} else if (resultTime <= aTime) { } else if (resultTime <= aTime) {
level = StageLevel.A level = StageLevel.A
levelTime = aTime
} else if (resultTime <= bTime) { } else if (resultTime <= bTime) {
level = StageLevel.B level = StageLevel.B
levelTime = bTime
} }
} }
return { return {
correctNum, correctNum,
level, level,
levelTime,
stageId: stageDetail.id, stageId: stageDetail.id,
questions: questionList.map(convert), questions: questionList.map(convert),
num, num,
......
import React from 'react' import React from 'react'
import { View, Text, Button } from '@tarojs/components' import { View, Text, Button } from '@tarojs/components'
import { navigateTo, useRouter } from '@tarojs/taro'
// import Taro from '@tarojs/taro' // import Taro from '@tarojs/taro'
import Modal from '@/components/Modal' import Modal from '@/components/Modal'
import { useBoolean } from '@/hooks' import { useBoolean } from '@/hooks'
import { useStoreState, useStoreActions } from '@/store/hooks'
import styles from './index.module.scss' import styles from './index.module.scss'
const LaunchQuest: React.FC = () => { const LaunchQuest: React.FC = () => {
const [isVisible, { setTrue, setFalse }] = useBoolean(false) const [isVisible, { setTrue, setFalse }] = useBoolean(false)
const [loading, loadingAction] = useBoolean(false)
const cardNum = useStoreState(state => state.userModel.cardNum)
const getQuestionList = useStoreActions(actions => actions.gameModel.getQuestionList)
const router = useRouter<{ id: string }>()
const navigateTo = () => { const _navigateTo = () => {
if (cardNum < 1) {
setTrue() setTrue()
} else {
loadingAction.setTrue()
getQuestionList(+router.params.id || -1).then(() => {
loadingAction.setFalse()
navigateTo({
url: `/pages/game/play/index?id=${router.params.id}`
})
})
}
// Taro.navigateTo('/') // Taro.navigateTo('/')
} }
return ( return (
<> <>
<View className={styles.launchQuest}> <View className={styles.launchQuest}>
<Button onClick={navigateTo}>开始闯关</Button> <Button onClick={_navigateTo} loading={loading}>开始闯关</Button>
<Text className={styles.tip}> <Text className={styles.tip}>
首次免答题卡 首次免答题卡
{/* {hasFreePass ? '首次免答题卡' : '-1答题卡'} */} {/* {hasFreePass ? '首次免答题卡' : '-1答题卡'} */}
......
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