Commit db3668b5 authored by 666's avatar 666

feat: update 1

parent 446f3c2e
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
export default { export default {
pages: [ pages: [
'pages/prepare/index',
'pages/main/main', 'pages/main/main',
'pages/group/index', 'pages/group/index',
'pages/game/play/index', 'pages/game/play/index',
'pages/level-prepare/index',
], ],
subPackages: {{packages}}, subPackages: {{packages}},
resizable: true, resizable: true,
......
.wrapper {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, 0.5);
opacity: 0;
transition: opacity 0.3s ease-in-out;
z-index: 100;
pointer-events: none;
}
.visible {
opacity: 1;
z-index: 999;
pointer-events: auto;
}
.inner {
background-color: #ffffff;
padding: 16px;
border-radius: 4px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
\ No newline at end of file
/** simple modal component */
import { View } from '@tarojs/components'
import classNames from 'classnames'
import styles from './index.module.scss'
interface ModalProps {
isVisible: boolean;
wrapClassName?: string;
children: React.ReactNode;
maskClosable?: boolean;
onClose: () => void;
}
const Modal: React.FC<ModalProps> = ({
isVisible,
onClose,
children,
wrapClassName,
maskClosable = true
}) => {
const wrapClass = classNames(
styles.wrapper,
wrapClassName,
isVisible ? styles.visible : ''
)
return (
<View className={wrapClass} onClick={() => maskClosable && onClose()}>
<View className={classNames(styles.inner)} onClick={(e) => e.stopPropagation()}>
{children}
</View>
</View>
)
}
export default Modal
.tabs {
display: flex;
width: 100%;
flex-direction: column;
}
.tabBar {
display: flex;
border-bottom: 1px solid #ccc;
}
.tab {
padding: 12px 16px;
color: #888;
border-bottom: 2px solid transparent;
transition: border-color 0.3s ease-in-out, color 0.3s ease-in-out;
&.active {
color: #333;
border-color: #333;
}
&.disabled {
opacity: 0.5;
}
}
.tabPanes {
display: flex;
flex-direction: column;
padding: 12px 16px;
margin-top: 16px;
}
.tabPane {
display: none;
&.active {
display: block;
}
}
import { useState, useEffect, useCallback, CSSProperties, ReactNode } from 'react'
import { View } from '@tarojs/components'
import classNames from 'classnames'
import styles from './index.module.scss'
export interface TabItem {
label: string | ReactNode;
children: ReactNode;
disabled?: boolean;
hidden?: boolean;
keepAlive?: boolean;
}
interface TabsProps {
items: TabItem[];
initialIndex?: number;
tabBarStyle?: CSSProperties;
tabBarGutter?: number;
onChange?: (index: number) => void;
}
const Tabs: React.FC<TabsProps> = ({
items,
initialIndex = 0,
tabBarStyle = {},
tabBarGutter = 16,
onChange,
}) => {
const [activeIndex, setActiveIndex] = useState(initialIndex)
useEffect(() => {
if (items[activeIndex].hidden) {
const newIndex = items.findIndex((tab, index) => !tab.hidden && index !== activeIndex)
setActiveIndex(newIndex)
}
}, [items, activeIndex])
const handleClick = useCallback((index: number) => {
if (!items[index].disabled && index !== activeIndex) {
setActiveIndex(index)
onChange?.(index)
}
}, [items, activeIndex, onChange])
const renderTabs = () => {
return items.map((tab, index) => {
if (tab.hidden) return null
const cls = classNames(styles.tab, {
[styles.active]: index === activeIndex,
[styles.disabled]: tab.disabled,
})
return (
<View
key={index}
className={cls}
style={{ marginRight: index < items.length - 1 ? tabBarGutter : undefined }}
onClick={() => handleClick(index)}
>
{tab.label}
</View>
)
})
}
const renderTabPanes = () => {
return items.map((tab, index) => {
if (tab.hidden && !tab.keepAlive) return null
const isActive = activeIndex === index
const isHidden = tab.hidden || !isActive
const cls = classNames(styles.tabPane, {
[styles.active]: isActive,
})
return (
<View key={index} className={cls} hidden={isHidden}>
{tab.children}
</View>
)
})
}
return (
<View className={styles.tabs}>
<View className={styles.tabBar} style={tabBarStyle}>
{renderTabs()}
</View>
<View className={styles.tabPanes}>
{renderTabPanes()}
</View>
</View>
)
}
export default Tabs
import { useState } from 'react'
interface UseModalResult {
isVisible: boolean;
showModal: () => void;
closeModal: () => void;
}
const useModal = (): UseModalResult => {
const [isVisible, setIsVisible] = useState(false)
const showModal = () => {
setIsVisible(true)
}
const closeModal = () => {
setIsVisible(false)
}
return {
isVisible,
showModal,
closeModal,
}
}
export default useModal
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 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 { 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
import { View, Text } from '@tarojs/components'
import styles from './index.module.scss'
const GloryBadge: React.FC = () => {
return (
<View className={styles.badge}>
<Text>TOP30%</Text>
<Text>升档成功</Text>
<Text>S级实力</Text>
</View>
)
}
export default GloryBadge
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
} }
.startChallenge { .launchQuest {
position: relative; position: relative;
margin-top: 48px; margin-top: 48px;
z-index: 1; z-index: 1;
...@@ -45,37 +45,6 @@ ...@@ -45,37 +45,6 @@
padding: 8px 12px; 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 { .topLeftInfo {
position: absolute; position: absolute;
top: 0; top: 0;
...@@ -92,3 +61,20 @@ ...@@ -92,3 +61,20 @@
padding: 4px 8px; padding: 4px 8px;
border: 1px solid #ccc; border: 1px solid #ccc;
} }
.badge {
display: flex;
align-items: center;
margin-top: 24px;
gap: 24px;
padding: 24px;
border: 1px solid #000;
Text {
border-radius: 8px;
padding: 12px;
display: flex;
align-items: center;
border: 1px dashed red;
}
}
\ No newline at end of file
import { View, Text } from '@tarojs/components'
// import { useStoreState } from '@/store/hooks';
import TopLeftInfo from './top-left-info'
import LaunchQuest from './launch-quest'
import GloryBadge from './glory-badge'
import { formatTime } from '../../utils'
import styles from './index.module.scss'
const Overview: React.FC = () => {
// const levelInfo = useStoreState((state) => state.prepareModel.levelInfo)
const levelInfo = {
title: '表内除法',
totalQuestions: 10,
duration: 80,
}
return (
<>
<TopLeftInfo />
<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}>
通过要求:全 √
</Text>
<Text className={styles.duration}>
时间:{formatTime(levelInfo.duration)}
</Text>
</View>
<LaunchQuest />
<GloryBadge />
</View>
</>
)
}
export default Overview
import React from 'react'
import { View, Text, Button } from '@tarojs/components'
import Modal from '@/components/Modal'
import useModal from '@/hooks/useModal'
import styles from './index.module.scss'
const LaunchQuest: React.FC = () => {
const { isVisible, showModal, closeModal } = useModal()
return (
<>
<View className={styles.launchQuest}>
<Button onClick={showModal}>开始闯关</Button>
<Text className={styles.tip}>
首次免答题卡
{/* {hasFreePass ? '首次免答题卡' : '-1答题卡'} */}
</Text>
</View>
<Modal isVisible={isVisible} onClose={closeModal}>
<View>
<Text>你的答题卡已经用完了</Text>
<Button onClick={closeModal}>建设学习部落得更多答题卡</Button>
<Button onClick={closeModal}>购买</Button>
</View>
</Modal>
</>
)
}
export default LaunchQuest
import { View, Text } from '@tarojs/components' import { View, Text } from '@tarojs/components'
import styles from './index.module.scss'; import styles from './index.module.scss'
const TopLeftInfo = () => { const TopLeftInfo = () => {
return ( return (
......
.wrap { .wrapper {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
.title { .head {
display: flex;
justify-content: flex-end;
Text {
width: 160px;
text-align: center;
}
}
.timing {
min-width: 320px;
display: flex;
align-items: center;
Text {
flex: 1;
text-align: center; text-align: center;
margin-bottom: 24px; }
} }
.list { .list {
...@@ -19,7 +35,7 @@ ...@@ -19,7 +35,7 @@
} }
.item { .item {
padding: 0 24px; padding: 16px 0;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
} }
...@@ -32,3 +48,22 @@ ...@@ -32,3 +48,22 @@
border: 1px solid red; border: 1px solid red;
margin: 24px 0; margin: 24px 0;
} }
.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 { View, Button, Text } from '@tarojs/components' import { View, Button, Text, } from '@tarojs/components'
import React, { useState } from 'react' import { useState } from 'react'
import classNames from 'classnames' import classNames from 'classnames'
import { useStoreState } from '@/store/hooks'; import { useStoreState } from '@/store/hooks'
import { User } from '../../types' import { User } from '../../types'
import UserInfo from './user-info' import UserInfo from './user-info'
import TimeDisplay from './time-display' import Timing from './timing'
import styles from './index.module.scss' import styles from './index.module.scss'
...@@ -13,16 +13,16 @@ interface RankingListProps { ...@@ -13,16 +13,16 @@ interface RankingListProps {
currentUser?: User; currentUser?: User;
} }
const RankingList: React.FC<RankingListProps> = ({ users, currentUser }) => { const RankList: React.FC<RankingListProps> = ({ users, currentUser }) => {
const [showAll, setShowAll] = useState(false) const [showAll, setShowAll] = useState(false)
const { currentUserInTopThree, topThreeUsers } = useStoreState((state) => state.levelPrepareModel) const { currentUserInTopThree, topThreeUsers } = useStoreState((state) => state.prepareModel)
const renderItem = (user: User) => { const renderItem = (user: User) => {
const isCurrentUser = currentUser && currentUser.nickname === user.nickname const isCurrentUser = currentUser && currentUser.nickname === user.nickname
return ( return (
<View key={user.nickname} className={classNames(styles.item, isCurrentUser && styles.highlight)}> <View key={user.nickname} className={classNames(styles.item, isCurrentUser && styles.highlight)}>
<UserInfo {...user} /> <UserInfo {...user} />
<TimeDisplay time={user.time} /> <Timing time={user.time} />
</View > </View >
) )
} }
...@@ -30,8 +30,17 @@ const RankingList: React.FC<RankingListProps> = ({ users, currentUser }) => { ...@@ -30,8 +30,17 @@ const RankingList: React.FC<RankingListProps> = ({ users, currentUser }) => {
const displayUsers = showAll ? users : topThreeUsers const displayUsers = showAll ? users : topThreeUsers
return ( return (
<View className={styles.wrap}> <View className={styles.wrapper}>
<Text className={styles.title}>本关英雄榜</Text> <View className={styles.header}>
<Text>首次</Text><Text>最佳</Text>
</View>
{!currentUserInTopThree && currentUser && (
<View key={currentUser.nickname} className={classNames(styles.item, styles.noTopThree)}>
<UserInfo {...currentUser} />
<Timing time={currentUser.time} />
</View >
)}
<View className={styles.list}> <View className={styles.list}>
{displayUsers.map(renderItem)} {displayUsers.map(renderItem)}
...@@ -39,20 +48,11 @@ const RankingList: React.FC<RankingListProps> = ({ users, currentUser }) => { ...@@ -39,20 +48,11 @@ const RankingList: React.FC<RankingListProps> = ({ users, currentUser }) => {
{!showAll && ( {!showAll && (
<Button className={styles.loadMore} onClick={() => setShowAll(!showAll)}> <Button className={styles.loadMore} onClick={() => setShowAll(!showAll)}>
展示更多 查看更多
</Button> </Button>
)} )}
{!currentUserInTopThree && currentUser && (
<View key={currentUser.nickname} className={classNames(styles.item, styles.noTopThree)}>
<UserInfo {...currentUser} />
<TimeDisplay time={currentUser.time} />
</View >
)}
</View> </View>
) )
} }
export default RankingList export default RankList
import React from 'react'
import { View, Text } from '@tarojs/components'
import { TimingProps } from '../../types'
// import { formatTime } from '../../utils'
import styles from './index.module.scss'
const Timing: React.FC<TimingProps> = ({ time = 0 }) => {
return (
<View className={styles.timing}>
<Text>34.23秒</Text>
<Text>21.23秒</Text>
</View>
)
}
export default Timing
import React from 'react' import React from 'react'
import { View, Image, Text } from '@tarojs/components' import { View, Text } from '@tarojs/components'
import { UserInfoProps } from '../../types' import { UserInfoProps } from '../../types'
import styles from './user-info.module.scss' import styles from './index.module.scss'
console.log('11')
const UserInfo: React.FC<UserInfoProps> = ({ avatar, nickname, schoolName }) => { const UserInfo: React.FC<UserInfoProps> = ({ avatar, nickname, schoolName }) => {
return ( return (
<View className={styles.userInfo}> <View className={styles.userInfo}>
......
import { View, Text } from '@tarojs/components'
import { useEffect } from 'react'
import Tabs, { type TabItem } from '@/components/Tabs'
import { useStoreState, useStoreActions } from '@/store/hooks'
import Overview from './components/overview/index'
import RankList from './components/rank-list/index'
const Prepare: React.FC = () => {
const { currentUser, list } = useStoreState((state) => state.prepareModel)
const refresh = useStoreActions((actions) => actions.prepareModel.refresh)
useEffect(() => {
refresh()
}, [currentUser])
const tabs: TabItem[] = [
{ label: '成都排行榜', children: <RankList users={list} currentUser={currentUser} /> },
{
label: '学习部落排行榜',
children: (
<View>
<RankList users={list} currentUser={currentUser} />
<Text>立即创建</Text>
</View>
)
},
]
return (
<View>
<Overview />
<Tabs items={tabs} />
</View>
)
}
export default Prepare
...@@ -4,15 +4,15 @@ export type UserInfoProps = { ...@@ -4,15 +4,15 @@ export type UserInfoProps = {
schoolName?: string; schoolName?: string;
} }
export type TimeDisplayProps = { export type TimingProps = {
time?: number; time?: number;
} }
export type User = UserInfoProps & TimeDisplayProps export type User = UserInfoProps & TimingProps
export interface LevelInfo { // export interface PanelView {
title: string; // title: string;
totalQuestions: number; // totalQuestions: number;
passingRequirement: string; // passingRequirement: string;
duration: number; // duration: number;
} // }
\ No newline at end of file
import { computed, Action, Computed, action } from 'easy-peasy' import { computed, Action, Computed, action } from 'easy-peasy'
import WithPaging from '@/utils/with-paging' import WithPaging from '@/utils/with-paging'
import { PagingFn } from '@/types' import { PagingFn } from '@/types'
import { User, LevelInfo } from '@/pages/level-prepare/types' import { User } from '@/pages/prepare/types'
interface Model { interface Model {
levelInfo: LevelInfo; // setTitle: Action<PrepareModel, string>;
setTitle: Action<LevelPrepareModel, string>; // setTotalQuestions: Action<PrepareModel, number>;
setTotalQuestions: Action<LevelPrepareModel, number>; // setPassingRequirement: Action<PrepareModel, string>;
setPassingRequirement: Action<LevelPrepareModel, string>; // setDuration: Action<PrepareModel, number>;
setDuration: Action<LevelPrepareModel, number>;
currentUser: User; currentUser: User;
setCurrentUser: Action<LevelPrepareModel, User>; setCurrentUser: Action<PrepareModel, User>;
topThreeUsers: Computed<LevelPrepareModel, User[]>; topThreeUsers: Computed<PrepareModel, User[]>;
currentUserInTopThree: Computed<LevelPrepareModel, boolean>; currentUserInTopThree: Computed<PrepareModel, boolean>;
} }
const api: PagingFn<any, {}> = async () => { const api: PagingFn<any, {}> = async () => {
...@@ -45,7 +43,7 @@ const api: PagingFn<any, {}> = async () => { ...@@ -45,7 +43,7 @@ const api: PagingFn<any, {}> = async () => {
schoolName: 'index4', schoolName: 'index4',
avatar: 'index4', avatar: 'index4',
time: 110, time: 110,
},, },
{ {
nickname: 'index5', nickname: 'index5',
schoolName: 'index5', schoolName: 'index5',
...@@ -65,7 +63,7 @@ const api: PagingFn<any, {}> = async () => { ...@@ -65,7 +63,7 @@ const api: PagingFn<any, {}> = async () => {
} }
} }
const levelPrepareModel = WithPaging<User, Model, {}>(api)({ const prepareModel = WithPaging<User, Model, {}>(api)({
currentUser: { currentUser: {
nickname: 'index4', nickname: 'index4',
schoolName: 'index4', schoolName: 'index4',
...@@ -73,12 +71,12 @@ const levelPrepareModel = WithPaging<User, Model, {}>(api)({ ...@@ -73,12 +71,12 @@ const levelPrepareModel = WithPaging<User, Model, {}>(api)({
time: 30, time: 30,
}, },
levelInfo: { // panelCard: {
title: '表内除法', // title: '表内除法',
totalQuestions: 10, // totalQuestions: 10,
passingRequirement: '全√', // passingRequirement: '全√',
duration: 80, // duration: 80,
}, // },
topThreeUsers: computed((state) => state.list.slice(0, 3)), topThreeUsers: computed((state) => state.list.slice(0, 3)),
...@@ -92,24 +90,23 @@ const levelPrepareModel = WithPaging<User, Model, {}>(api)({ ...@@ -92,24 +90,23 @@ const levelPrepareModel = WithPaging<User, Model, {}>(api)({
state.currentUser = user state.currentUser = user
}), }),
setTitle: action((state, payload) => { // setTitle: action((state, payload) => {
state.levelInfo.title = payload; // state.levelInfo.title = payload;
}), // }),
setTotalQuestions: action((state, payload) => { // setTotalQuestions: action((state, payload) => {
state.levelInfo.totalQuestions = payload; // state.levelInfo.totalQuestions = payload;
}), // }),
setPassingRequirement: action((state, payload) => { // setPassingRequirement: action((state, payload) => {
state.levelInfo.passingRequirement = payload; // state.levelInfo.passingRequirement = payload;
}), // }),
setDuration: action((state, payload) => { // setDuration: action((state, payload) => {
state.levelInfo.duration = payload; // state.levelInfo.duration = payload;
}), // }),
}) })
export default levelPrepareModel export default prepareModel
export type LevelPrepareModel = typeof levelPrepareModel;
export type PrepareModel = typeof prepareModel;
import cartModel from './modules/cart' import cartModel from './modules/cart'
import counterModel from './modules/counter' import counterModel from './modules/counter'
import levelPrepareModel from './modules/level-prepare' import prepareModel from './modules/prepare'
const appStoreModel = { const appStoreModel = {
cartModel, cartModel,
counterModel, counterModel,
levelPrepareModel, prepareModel,
} }
export default appStoreModel 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