优化排行榜切换样式

1. 添加现代化的滑动切换效果
2. 使用渐变背景和阴影提升视觉效果
3. 添加平滑的动画过渡效果

🤖 Generated with [Claude Code](https://claude.com/claude-code)&#10;&#10;Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
燕陇琪 2025-11-17 21:22:48 +08:00
parent 6efc437198
commit 6eb6c5243d
2 changed files with 67 additions and 10 deletions

View File

@ -472,6 +472,50 @@
} }
} }
.rankingSwitch {
display: flex;
background: #f5f5f5;
border-radius: 20px;
padding: 4px;
margin-bottom: 16px;
width: fit-content;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}
.rankingSwitchButton {
padding: 6px 16px;
border: none;
background: transparent;
border-radius: 16px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
color: #666;
transition: all 0.3s ease;
position: relative;
z-index: 1;
&:hover {
color: #333;
}
&.active {
color: #fff;
font-weight: 600;
}
}
.rankingSwitchSlider {
position: absolute;
top: 4px;
left: 4px;
height: calc(100% - 8px);
background: linear-gradient(135deg, #1890ff 0%, #40a9ff 100%);
border-radius: 16px;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: 0 2px 8px rgba(24, 144, 255, 0.3);
}
.rankingCard { .rankingCard {
border-radius: 16px; border-radius: 16px;
background: rgba(255, 255, 255, 0.9); background: rgba(255, 255, 255, 0.9);

View File

@ -108,6 +108,7 @@ const Home: React.FC = () => {
const [totalRanking, setTotalRanking] = useState<questionApi.UserStats[]>([]) const [totalRanking, setTotalRanking] = useState<questionApi.UserStats[]>([])
const [rankingLoading, setRankingLoading] = useState(false) const [rankingLoading, setRankingLoading] = useState(false)
const [rankingType, setRankingType] = useState<'daily' | 'total'>('daily') // 排行榜类型:每日或总榜 const [rankingType, setRankingType] = useState<'daily' | 'total'>('daily') // 排行榜类型:每日或总榜
const [sliderPosition, setSliderPosition] = useState<'left' | 'right'>('left') // 滑块位置
// 答题设置状态 // 答题设置状态
const [autoNext, setAutoNext] = useState(() => { const [autoNext, setAutoNext] = useState(() => {
@ -176,6 +177,12 @@ const Home: React.FC = () => {
} }
} }
// 切换排行榜类型
const switchRankingType = (type: 'daily' | 'total') => {
setRankingType(type)
setSliderPosition(type === 'daily' ? 'left' : 'right')
}
// 加载用户信息 // 加载用户信息
useEffect(() => { useEffect(() => {
const token = localStorage.getItem('token') const token = localStorage.getItem('token')
@ -686,20 +693,26 @@ const Home: React.FC = () => {
<Title level={4} className={styles.sectionTitle}> <Title level={4} className={styles.sectionTitle}>
<TrophyOutlined /> <TrophyOutlined />
</Title> </Title>
<div style={{ marginBottom: 16 }}> <div className={styles.rankingSwitch}>
<Button <div
type={rankingType === 'daily' ? 'primary' : 'default'} className={styles.rankingSwitchButton}
onClick={() => setRankingType('daily')} onClick={() => switchRankingType('daily')}
style={{ marginRight: 8 }}
> >
</Button> </div>
<Button <div
type={rankingType === 'total' ? 'primary' : 'default'} className={styles.rankingSwitchButton}
onClick={() => setRankingType('total')} onClick={() => switchRankingType('total')}
> >
</Button> </div>
<div
className={styles.rankingSwitchSlider}
style={{
width: 'calc(50% - 4px)',
left: sliderPosition === 'left' ? '4px' : 'calc(50% + 0px)',
}}
/>
</div> </div>
{rankingLoading ? ( {rankingLoading ? (
<Card className={styles.rankingCard} loading={true} /> <Card className={styles.rankingCard} loading={true} />