Commit e55d14af authored by 666's avatar 666

feat: update

parent 95b665cd
...@@ -7,9 +7,10 @@ ...@@ -7,9 +7,10 @@
export default { export default {
pages: [ pages: [
'pages/main/main', 'pages/main/main',
'pages/prepare/index',
'pages/study-market/index',
'pages/group/index', 'pages/group/index',
'pages/game/play/index', 'pages/game/play/index',
'pages/prepare/index',
], ],
subPackages: {{packages}}, subPackages: {{packages}},
resizable: true, resizable: true,
......
import { Image } from '@tarojs/components'
import classNames from 'classnames'
export interface SkeletonAvatarProps {
animate?: boolean;
shape?: 'circle' | 'square';
size?: number;
}
const SkeletonAvatar: React.FC<SkeletonAvatarProps> = ({
animate = true,
shape = 'circle',
size = 48,
}) => {
const avatarClass = classNames(
'skeleton-avatar',
animate ? 'skeleton-loading' : null,
shape === 'circle' ? 'circle' : 'square'
)
return (
<Image
src=""
defaultSource="https://cdn.jkwljy.com/pbb/6gkGHSsPmxc_coeGYahBkelo_2w_/96x96"
className={avatarClass}
style={{ width: size, height: size }}
/>
)
}
export default SkeletonAvatar
import { View } from '@tarojs/components'
import classNames from 'classnames'
export interface SkeletonParagraphProps {
animate?: boolean;
rows?: number;
gap?: number;
height?: number;
width?: string | number | (string | number)[];
}
const SkeletonParagraph: React.FC<SkeletonParagraphProps> = ({
animate = true,
rows = 3,
gap = 8,
height = 16,
width = '100%',
}) => {
const paragraphRows = Array.from({ length: rows }, (_, i) => {
const rowWidth = Array.isArray(width)
? width[i] ?? width[width.length - 1]
: width
return (
<View
key={i}
className={classNames('skeleton-paragraph-row', animate ? 'skeleton-loading' : null,)}
style={{ width: rowWidth, height }}
/>
)
})
return (
<View className="skeleton-paragraph" style={{ gap: `${gap}px` }}>
{paragraphRows}
</View>
)
}
export default SkeletonParagraph
import { View } from '@tarojs/components'
import classNames from 'classnames'
export interface SkeletonTitleProps {
animate?: boolean;
height?: number;
width?: string | number;
}
const SkeletonTitle: React.FC<SkeletonTitleProps> = ({
animate = true,
height = 16,
width = '30%',
}) => {
return (
<View
className={classNames('skeleton-title', animate ? 'skeleton-loading' : null)}
style={{ width, height }}
/>
)
}
export default SkeletonTitle
.skeleton {
display: flex;
flex-direction: row;
margin: 8px 16px;
gap: 16px;
&-avatar {
width: 48px;
height: 48px;
border-radius: 50%;
background-color: #f0f0f0;
&.circle {
border-radius: 50%;
}
&.square {
border-radius: 4px;
}
}
&-content {
flex: 1;
}
&-title {
margin: 12px 0;
background-color: #f0f0f0;
}
&-paragraph {
display: flex;
flex-direction: column;
width: 100%;
margin: 12px 0;
&-row {
height: 32px;
background-color: #f0f0f0;
}
}
}
@keyframes loading {
0% {
background-position: 100% 50%;
}
100% {
background-position: 0 50%;
}
}
.skeleton-loading {
background-image: linear-gradient(
90deg,
rgba(255, 255, 255, 0) 25%,
rgba(255, 255, 255, 0.5) 50%,
rgba(255, 255, 255, 0) 75%
);
background-size: 200% 100%;
animation: loading 1.5s infinite;
}
.skeleton-avatar.skeleton-loading {
background-color: #f0f0f0;
}
.skeleton-title.skeleton-loading {
background-color: #f0f0f0;
}
.skeleton-paragraph.skeleton-loading {
background-color: #f0f0f0;
}
import React from 'react'
import { View } from '@tarojs/components'
import SkeletonAvatar, { type SkeletonAvatarProps } from './components/avatar'
import SkeletonTitle, { type SkeletonTitleProps } from './components/title'
import SkeletonParagraph, { type SkeletonParagraphProps } from './components/paragraph'
import './index.scss'
interface SkeletonProps {
loading: boolean;
animate?: boolean;
avatar?: SkeletonAvatarProps | boolean;
title?: SkeletonTitleProps | boolean;
paragraph?: SkeletonParagraphProps | boolean;
children?: React.ReactNode;
}
export default class Skeleton extends React.Component<SkeletonProps> {
static Avatar: typeof SkeletonAvatar
static Title: typeof SkeletonTitle
static Paragraph: typeof SkeletonParagraph
render () {
const {
loading,
avatar,
children,
animate = true,
title = true,
paragraph = true,
} = this.props
if (!loading) {
return children
}
return (
<View className="skeleton">
{avatar && <SkeletonAvatar animate={(avatar as SkeletonAvatarProps).animate || animate} {...avatar as SkeletonAvatarProps} />}
<View className="skeleton-content">
{title && <SkeletonTitle animate={(title as SkeletonTitleProps).animate || animate} {...title as SkeletonTitleProps} />}
{paragraph && <SkeletonParagraph animate={(paragraph as SkeletonTitleProps).animate || animate} {...paragraph as SkeletonParagraphProps} />}
</View>
</View>
)
}
}
Skeleton.Avatar = SkeletonAvatar
Skeleton.Title = SkeletonTitle
Skeleton.Paragraph = SkeletonParagraph
...@@ -44,7 +44,7 @@ const MainPage = () => { ...@@ -44,7 +44,7 @@ const MainPage = () => {
<SceneContext.Provider value={{ ready: isReady }}> <SceneContext.Provider value={{ ready: isReady }}>
<MainScene /> <MainScene />
</SceneContext.Provider> </SceneContext.Provider>
<View className={styles.gap}></View> {/* <View className={styles.gap}></View> */}
</View> </View>
{isReady && ( {isReady && (
<MainShortCut onClick={() => scrollToCurrent()} /> <MainShortCut onClick={() => scrollToCurrent()} />
......
import { View, Button, Text, } from '@tarojs/components' import { View, Button, Text, ScrollView } from '@tarojs/components'
import { memo } from 'react' import { memo, useMemo } from 'react'
import classNames from 'classnames' import classNames from 'classnames'
import { useStoreState } from '@/store/hooks' import { useStoreState } from '@/store/hooks'
import useToggle from '@/hooks/useToggle' import useToggle from '@/hooks/useToggle'
...@@ -11,7 +11,7 @@ import { User } from '../../types' ...@@ -11,7 +11,7 @@ import { User } from '../../types'
import styles from './index.module.scss' import styles from './index.module.scss'
const RankList: React.FC<{ users: User[] }> = ({ users }) => { const ScrollRankList: React.FC<{ users: User[] }> = ({ users }) => {
const [showAll, toggleShowAll] = useToggle() const [showAll, toggleShowAll] = useToggle()
const { currentUser, currentUserInTopThree, topThreeUsers } = useStoreState((state) => state.prepareModel) const { currentUser, currentUserInTopThree, topThreeUsers } = useStoreState((state) => state.prepareModel)
...@@ -25,7 +25,24 @@ const RankList: React.FC<{ users: User[] }> = ({ users }) => { ...@@ -25,7 +25,24 @@ const RankList: React.FC<{ users: User[] }> = ({ users }) => {
) )
} }
const computeUsers = showAll ? users : topThreeUsers const hasNextPage = true
const loading = false
const computedUsers = useMemo(() => {
if (showAll) {
return users
}
return topThreeUsers
}, [showAll, users, topThreeUsers])
const scrollStyle = {
height: '400px',
background: 'red'
}
const loadMore = () => {
console.log('loadMore')
}
return ( return (
<View className={styles.wrapper}> <View className={styles.wrapper}>
...@@ -40,8 +57,21 @@ const RankList: React.FC<{ users: User[] }> = ({ users }) => { ...@@ -40,8 +57,21 @@ const RankList: React.FC<{ users: User[] }> = ({ users }) => {
</View > </View >
)} )}
<ScrollView
scrollY
enableFlex
scrollWithAnimation
style={scrollStyle}
onScrollToLower={loadMore}
>
<View style={{ height: '300px' }}>A</View>
<View style={{ height: '300px' }}>B</View>
<View style={{ height: '300px' }}>C</View>
{hasNextPage && !loading && <Text>加载更多</Text>}
</ScrollView>
<View className={styles.list}> <View className={styles.list}>
{computeUsers.map(renderItem)} {computedUsers.map(renderItem)}
</View> </View>
{!showAll && ( {!showAll && (
...@@ -53,4 +83,4 @@ const RankList: React.FC<{ users: User[] }> = ({ users }) => { ...@@ -53,4 +83,4 @@ const RankList: React.FC<{ users: User[] }> = ({ users }) => {
) )
} }
export default memo(RankList) export default memo(ScrollRankList)
import { View, Text } from '@tarojs/components' import { View, Text } from '@tarojs/components'
import RankList from './rank-list/index' import ScrollRankList from './rank-list/index'
import { User } from '../types' import { User } from '../types'
const StudyLeagueRank: React.FC<{ users: User[] }> = ({ users }) => { const StudyLeagueRank: React.FC<{ users: User[] }> = ({ users }) => {
return ( return (
<View> <View>
<RankList users={users} /> <ScrollRankList users={users} />
<Text>立即创建</Text> <Text>立即创建</Text>
</View> </View>
) )
......
import { useEffect } from 'react' import { useEffect } from 'react'
import Tabs, { type TabItem } from '@/components/Tabs' import Tabs, { type TabItem } from '@/components/Tabs'
import Skeleton from '@/components/Skeleton'
import { useStoreState, useStoreActions } from '@/store/hooks' import { useStoreState, useStoreActions } from '@/store/hooks'
import Overview from './components/overview/index' import Overview from './components/overview/index'
import RankList from './components/rank-list/index' import ScrollRankList from './components/rank-list/index'
import StudyLeagueRank from './components/study-league-rank' import StudyLeagueRank from './components/study-league-rank'
const Prepare: React.FC = () => { const Prepare: React.FC = () => {
...@@ -16,7 +17,7 @@ const Prepare: React.FC = () => { ...@@ -16,7 +17,7 @@ const Prepare: React.FC = () => {
}, [refresh]) }, [refresh])
const tabs: TabItem[] = [ const tabs: TabItem[] = [
{ label: '成都排行榜', children: <RankList users={users} /> }, { label: '成都排行榜', children: <ScrollRankList users={users} /> },
{ label: '学习部落排行榜', children: <StudyLeagueRank users={users} /> } { label: '学习部落排行榜', children: <StudyLeagueRank users={users} /> }
] ]
......
export default definePageConfig({
navigationBarTitleText: 'pk-math',
navigationStyle: 'custom'
})
import { useState, useEffect } from 'react'
import Taro, { getMenuButtonBoundingClientRect } from '@tarojs/taro'
import { View } from '@tarojs/components'
import Skeleton from '@/components/Skeleton'
import MainHeader from '../main/components/header'
const StudyMarket: React.FC = () => {
const [nav] = useState(getMenuButtonBoundingClientRect())
Taro.showLoading({
title: '加载中',
mask: true
})
return (
<View>
<MainHeader />
<View style={{ paddingTop: `${nav.height + nav.top + 5}px` }}>
<Skeleton loading />
</View>
</View>
)
}
export default StudyMarket
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