Commit 1ba4a327 authored by m's avatar m

feat: update 进入关卡ye2

parent 37d4ffa2
......@@ -7,7 +7,8 @@
export default {
pages: [
'pages/main/main',
'pages/group/index'
'pages/group/index',
'pages/level-prepare/index',
],
subPackages: {{packages}},
resizable: true,
......
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 60px;
}
.title {
font-weight: bold;
}
.totalQuestions {
margin-top: 24px;
}
.requirement {
display: flex;
justify-content: space-between;
width: 60%;
margin-top: 24px;
}
.duration {
}
.startChallenge {
position: relative;
margin-top: 48px;
z-index: 1;
width: 70%;
}
.tip {
position: absolute;
z-index: 10;
top: -32px;
right: -12%;
font-size: 24px;
color: #ff0000;
background-color: #fff;
border: 1px solid #ff0000;
border-radius: 8px;
padding: 8px 12px;
}
.modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 20px;
border-radius: 10px;
z-index: 101;
display: flex;
flex-direction: column;
align-items: center;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
width: 80%;
max-width: 400px;
}
.modalOverlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 100;
}
.modal button {
margin-top: 10px;
}
.topLeftInfo {
position: absolute;
top: 0;
left: 24px;
display: flex;
flex-direction: column;
gap: 16px;
font-size: 20px;
}
.calculation,
.enhancement {
background-color: #f5f5f5;
padding: 4px 8px;
border: 1px solid #ccc;
}
import React from 'react';
import { View, Text } from '@tarojs/components';
import { useStoreState } from '@/store/hooks';
import TopLeftInfo from './top-left-info';
// import StartChallengeButton from './start-challenge-button';
import { formatTime } from '../../utils'
import styles from './index.module.scss';
const LevelInfo: React.FC = () => {
const levelInfo = useStoreState((state) => state.levelPrepareModel.levelInfo)
const onStartChallenge = () => {
console.log('onStartChallenge')
}
return (
<View className={styles.wrapper}>
<Text className={styles.title}>
{levelInfo.title}
</Text>
<Text className={styles.totalQuestions}>
共{levelInfo.totalQuestions}题
</Text>
<View className={styles.requirement}>
<Text className={styles.passingRequirement}>
通过要求:{levelInfo.passingRequirement}
</Text>
<Text className={styles.duration}>
时间:{formatTime(levelInfo.duration)}
</Text>
</View>
{/* <StartChallengeButton /> */}
<TopLeftInfo />
</View>
)
}
export default LevelInfo;
// import React, { useState, useEffect, useRef } from 'react'
// import { View, Text, Button } from '@tarojs/components'
// import Taro from '@tarojs/taro';
// import styles from './index.module.scss';
// const StartChallengeButton: React.FC = () => {
// const [showModal, setShowModal] = useState(false)
// const hasFreePass = false
// const modalRef = useRef(null)
// const [opacity, setOpacity] = useState(0)
// const [scale, setScale] = useState(0.8)
// const handleChallengeClick = () => {
// if (!hasFreePass) {
// setShowModal(true);
// } else {
// // Start the challenge
// }
// }
// useEffect(() => {
// if (showModal) {
// const animation = Taro.createAnimation({
// duration: 200,
// timingFunction: 'ease-out',
// });
// animation.opacity(1).scale(1).step();
// if (modalRef.current) {
// modalRef.current.animate(animation.export());
// }
// }
// }, [showModal]);
// return (
// <View className={styles.startChallenge}>
// <Button onClick={handleChallengeClick}>开始闯关</Button>
// <Text className={styles.tip}>
// {hasFreePass ? '首次免答题卡' : '-1答题卡'}
// </Text>
// {showModal && (
// <>
// <View className={styles.modalOverlay}>
// </View>
// <View ref={modalRef} className={styles.modal}>
// <Text>你的答题卡已经用完了</Text>
// <Button onClick={handleChallengeClick}>建设学习部落得更多答题卡</Button>
// <Button onClick={handleChallengeClick}>购买</Button>
// <Button onClick={() => setShowModal(false)}>关闭</Button>
// </View>
// </>
// )}
// </View>
// )
// }
// export default StartChallengeButton
\ No newline at end of file
import { View, Text } from '@tarojs/components'
import styles from './index.module.scss';
const TopLeftInfo = () => {
return (
<View className={styles.topLeftInfo}>
<Text className={styles.calculation}>计算达标</Text>
<Text className={styles.enhancement}>强化</Text>
</View>
)
}
export default TopLeftInfo
\ No newline at end of file
.wrap {
display: flex;
flex-direction: column;
}
.title {
text-align: center;
margin-bottom: 24px;
}
.list {
min-height: 300px;
max-height: 400px;
overflow: hidden;
overflow-y: auto;
display: flex;
flex-direction: column;
row-gap: 24px;
}
.item {
padding: 0 24px;
display: flex;
justify-content: space-between;
}
.highlight {
background-color: yellow;
}
.noTopThree {
border: 1px solid red;
margin: 24px 0;
}
\ No newline at end of file
import { View, Button, Text } from '@tarojs/components'
import React, { useState } from 'react'
import classNames from 'classnames'
import { useStoreState } from '@/store/hooks';
import { User } from '../../types'
import UserInfo from './user-info'
import TimeDisplay from './time-display'
import styles from './index.module.scss'
interface RankingListProps {
users: User[];
currentUser?: User;
}
const RankingList: React.FC<RankingListProps> = ({ users, currentUser }) => {
const [showAll, setShowAll] = useState(false)
const { currentUserInTopThree, topThreeUsers } = useStoreState((state) => state.levelPrepareModel)
const renderItem = (user: User) => {
const isCurrentUser = currentUser && currentUser.nickname === user.nickname
return (
<View key={user.nickname} className={classNames(styles.item, isCurrentUser && styles.highlight)}>
<UserInfo {...user} />
<TimeDisplay time={user.time} />
</View >
)
}
const displayUsers = showAll ? users : topThreeUsers
return (
<View className={styles.wrap}>
<Text className={styles.title}>本关英雄榜</Text>
<View className={styles.list}>
{displayUsers.map(renderItem)}
</View>
{!showAll && (
<Button className={styles.loadMore} onClick={() => setShowAll(!showAll)}>
展示更多
</Button>
)}
{!currentUserInTopThree && currentUser && (
<View key={currentUser.nickname} className={classNames(styles.item, styles.noTopThree)}>
<UserInfo {...currentUser} />
<TimeDisplay time={currentUser.time} />
</View >
)}
</View>
)
}
export default RankingList
import React from 'react'
import { Text } from '@tarojs/components';
import { TimeDisplayProps } from '../../types'
const formatTime = (time: number): string => {
const minutes = Math.floor(time / 60);
const seconds = time % 60;
return `${minutes}分${seconds}秒`;
}
const TimeDisplay: React.FC<TimeDisplayProps> = ({ time = 0 }) => {
return (
<Text className='time-display'>
{formatTime(time)}
</Text>
)
}
export default TimeDisplay
\ No newline at end of file
.userInfo {
display: flex;
column-gap: 16px;
}
.avatar {
width: 60px;
height: 60px;
border-radius: 50%;
background-color: pink;
}
.userDetails {
display: flex;
flex-direction: column;
row-gap: 16px;
line-height: 1;
}
\ No newline at end of file
import React from 'react'
import { View, Image, Text } from '@tarojs/components';
import { UserInfoProps } from '../../types'
import styles from './user-info.module.scss'
const UserInfo: React.FC<UserInfoProps> = ({ avatar, nickname, schoolName }) => {
return (
<View className={styles.userInfo}>
<View className={styles.avatar} />
{/* <Image className='avatar' src={avatar} /> */}
<View className={styles.userDetails}>
<Text className='nickname'>{nickname}</Text>
<Text className='school'>{schoolName}</Text>
</View>
</View>
)
}
export default UserInfo
\ No newline at end of file
import { View } from '@tarojs/components';
import { useEffect } from 'react';
import { useStoreState, useStoreActions } from '@/store/hooks';
import LevelInfo from './components/level-info/index';
import Ranking from './components/ranking-list/index'
const StagePrepare: React.FC = () => {
const { currentUser, list } = useStoreState((state) => state.levelPrepareModel)
const refresh = useStoreActions((actions) => actions.levelPrepareModel.refresh)
useEffect(() => {
refresh()
}, [currentUser])
return (
<View>
<LevelInfo />
<Ranking users={list} currentUser={currentUser} />
</View>
);
};
export default StagePrepare;
\ No newline at end of file
export type UserInfoProps = {
avatar?: string;
nickname?: string;
schoolName?: string;
}
export type TimeDisplayProps = {
time?: number;
}
export type User = UserInfoProps & TimeDisplayProps
export interface LevelInfo {
title: string;
totalQuestions: number;
passingRequirement: string;
duration: number;
}
\ No newline at end of file
export const formatTime = (time: number) => {
const minutes = Math.floor(time / 60)
const seconds = time % 60
return `${minutes}分${seconds}秒`
}
\ No newline at end of file
import { computed, Action, Computed, action } from 'easy-peasy'
import WithPaging from '@/utils/with-paging'
import { PagingFn } from '@/types'
import { User, LevelInfo } from '@/pages/level-prepare/types'
interface Model {
levelInfo: LevelInfo;
setTitle: Action<LevelPrepareModel, string>;
setTotalQuestions: Action<LevelPrepareModel, number>;
setPassingRequirement: Action<LevelPrepareModel, string>;
setDuration: Action<LevelPrepareModel, number>;
currentUser: User;
setCurrentUser: Action<LevelPrepareModel, User>;
topThreeUsers: Computed<LevelPrepareModel, User[]>;
currentUserInTopThree: Computed<LevelPrepareModel, boolean>;
}
const api: PagingFn<any, {}> = async () => {
return {
code: 0,
sysTime: Date.now(),
data: {
list: [
{
nickname: 'index1',
schoolName: 'index1',
avatar: 'index1',
time: 10,
},
{
nickname: 'index2',
schoolName: 'index2',
avatar: 'index1',
time: 20,
},
{
nickname: 'index3',
schoolName: 'index3',
avatar: 'index1',
time: 30,
},
{
nickname: 'index4',
schoolName: 'index4',
avatar: 'index4',
time: 110,
},,
{
nickname: 'index5',
schoolName: 'index5',
avatar: 'index1',
time: 30,
},
{
nickname: 'index6',
schoolName: 'inex6',
avatar: 'index6',
time: 110,
},
],
total: 400,
hasNextPage: true
}
}
}
const levelPrepareModel = WithPaging<User, Model, {}>(api)({
currentUser: {
nickname: 'index4',
schoolName: 'index4',
avatar: 'index4',
time: 30,
},
levelInfo: {
title: '表内除法',
totalQuestions: 10,
passingRequirement: '全√',
duration: 80,
},
topThreeUsers: computed((state) => state.list.slice(0, 3)),
currentUserInTopThree: computed(
(state) => state.topThreeUsers.some(
(user) => user.nickname === state.currentUser.nickname
),
),
setCurrentUser: action((state, user) => {
state.currentUser = user
}),
setTitle: action((state, payload) => {
state.levelInfo.title = payload;
}),
setTotalQuestions: action((state, payload) => {
state.levelInfo.totalQuestions = payload;
}),
setPassingRequirement: action((state, payload) => {
state.levelInfo.passingRequirement = payload;
}),
setDuration: action((state, payload) => {
state.levelInfo.duration = payload;
}),
})
export default levelPrepareModel
export type LevelPrepareModel = typeof levelPrepareModel;
import cartModel from './modules/cart'
import counterModel from './modules/counter'
import levelPrepareModel from './modules/level-prepare'
const appStoreModel = {
cartModel,
counterModel
counterModel,
levelPrepareModel,
}
export default appStoreModel
......
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