Skip to content

Commit 716bebf

Browse files
committed
改进移动端响应式布局,优化导航栏和组件显示
1 parent aca8552 commit 716bebf

File tree

10 files changed

+428
-98
lines changed

10 files changed

+428
-98
lines changed

package-lock.json

Lines changed: 56 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"@ant-design/icons": "^5.6.1",
1717
"@types/markdown-it": "^14.1.2",
18+
"@types/react-responsive": "^8.0.8",
1819
"antd": "^5.16.4",
1920
"fuse.js": "^7.1.0",
2021
"i18next": "^24.2.2",
@@ -26,6 +27,7 @@
2627
"react-i18next": "^15.4.1",
2728
"react-markdown": "^10.1.0",
2829
"react-markdown-editor-lite": "^1.3.4",
30+
"react-responsive": "^10.0.1",
2931
"react-router-dom": "^6.23.1",
3032
"react-syntax-highlighter": "^15.6.1",
3133
"rehype-raw": "^7.0.0",

src/App.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,44 @@
9292
.read-the-docs {
9393
color: #888;
9494
}
95+
96+
/* 移动端响应式样式 */
97+
@media (max-width: 768px) {
98+
/* 导航栏调整 */
99+
.navbar-container {
100+
width: 100%;
101+
padding: 0 16px;
102+
}
103+
104+
/* 移动端内容区域调整 */
105+
.content-wrapper {
106+
padding: 10px 0 !important;
107+
}
108+
109+
/* 移动端卡片样式调整 */
110+
.ant-card {
111+
border-radius: 8px;
112+
}
113+
114+
/* 移动端表格调整 */
115+
.ant-table {
116+
font-size: 12px;
117+
}
118+
119+
/* 移动端表单样式 */
120+
.ant-form-item-label {
121+
padding-bottom: 4px;
122+
}
123+
124+
/* 移动端按钮样式 */
125+
.ant-btn {
126+
font-size: 14px;
127+
height: 32px;
128+
padding: 0 15px;
129+
}
130+
131+
/* 防止溢出 */
132+
.mobile-container {
133+
overflow-x: hidden;
134+
}
135+
}

src/components/GitHubRibbon.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import { useMediaQuery } from 'react-responsive';
23

34
interface GitHubRibbonProps {
45
/**
@@ -20,12 +21,20 @@ interface GitHubRibbonProps {
2021
/**
2122
* GitHub Ribbon组件
2223
* 显示"Fork me on GitHub"的角标
24+
* 在移动端下完全隐藏
2325
*/
2426
const GitHubRibbon: React.FC<GitHubRibbonProps> = ({
2527
repositoryUrl,
2628
text = 'Fork me on GitHub',
2729
position = 'right'
2830
}) => {
31+
const isMobile = useMediaQuery({ maxWidth: 768 });
32+
33+
// 如果是移动设备,不显示GitHub角标
34+
if (isMobile) {
35+
return null;
36+
}
37+
2938
// 根据position确定位置样式
3039
const getPositionStyle = () => {
3140
switch(position) {

src/components/HomePage/ChallengeSection.tsx

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ import {
1010
challengeContainerStyle,
1111
challengeTitleContainerStyle,
1212
viewMoreButtonContainerStyle,
13-
viewMoreButtonStyle
13+
viewMoreButtonStyle,
14+
challengeSectionMobileStyle,
15+
challengeTitleMobileStyle,
16+
viewMoreButtonMobileStyle
1417
} from './styles';
18+
import { useMediaQuery } from 'react-responsive';
1519

1620
const { Title } = Typography;
1721

@@ -39,17 +43,23 @@ const ChallengeSection: React.FC<ChallengeSectionProps> = ({
3943
}) => {
4044
const navigate = useNavigate();
4145
const { t } = useTranslation();
46+
const isMobile = useMediaQuery({ maxWidth: 768 });
4247

4348
return (
44-
<div style={challengeSectionStyle}>
49+
<div style={{ ...challengeSectionStyle, ...(isMobile ? challengeSectionMobileStyle : {}) }}>
4550
<div style={challengeContainerStyle}>
4651
<Row gutter={[48, 48]}>
4752
{/* 最新挑战 */}
4853
<Col xs={24} lg={12}>
49-
<div style={challengeTitleContainerStyle}>
54+
<div
55+
style={{ ...challengeTitleContainerStyle, ...(isMobile ? challengeTitleMobileStyle : {}) }}
56+
className="challenge-section-title"
57+
>
5058
<Space align="center">
51-
<RocketOutlined style={{ fontSize: '24px', color: '#1890ff' }} />
52-
<Title level={3} style={{ margin: 0 }}>{t('home.challenges.recent.title')}</Title>
59+
<RocketOutlined style={{ fontSize: isMobile ? '20px' : '24px', color: '#1890ff' }} />
60+
<Title level={3} style={{ margin: 0, fontSize: isMobile ? '1.3rem' : '1.5rem' }}>
61+
{t('home.challenges.recent.title')}
62+
</Title>
5363
</Space>
5464
</div>
5565
<SimpleChallengeList
@@ -69,7 +79,8 @@ const ChallengeSection: React.FC<ChallengeSectionProps> = ({
6979
type="primary"
7080
ghost
7181
onClick={() => navigate('/challenges')}
72-
style={viewMoreButtonStyle}
82+
style={{ ...viewMoreButtonStyle, ...(isMobile ? viewMoreButtonMobileStyle : {}) }}
83+
className="challenge-more-button"
7384
>
7485
{t('home.challenges.recent.viewMore')} <ArrowRightOutlined />
7586
</Button>
@@ -78,10 +89,15 @@ const ChallengeSection: React.FC<ChallengeSectionProps> = ({
7889

7990
{/* 热门挑战 */}
8091
<Col xs={24} lg={12}>
81-
<div style={challengeTitleContainerStyle}>
92+
<div
93+
style={{ ...challengeTitleContainerStyle, ...(isMobile ? challengeTitleMobileStyle : {}) }}
94+
className="challenge-section-title"
95+
>
8296
<Space align="center">
83-
<FireOutlined style={{ fontSize: '24px', color: '#f5222d' }} />
84-
<Title level={3} style={{ margin: 0 }}>{t('home.challenges.popular.title')}</Title>
97+
<FireOutlined style={{ fontSize: isMobile ? '20px' : '24px', color: '#f5222d' }} />
98+
<Title level={3} style={{ margin: 0, fontSize: isMobile ? '1.3rem' : '1.5rem' }}>
99+
{t('home.challenges.popular.title')}
100+
</Title>
85101
</Space>
86102
</div>
87103
<SimpleChallengeList
@@ -101,7 +117,8 @@ const ChallengeSection: React.FC<ChallengeSectionProps> = ({
101117
type="primary"
102118
ghost
103119
onClick={() => navigate('/challenges')}
104-
style={viewMoreButtonStyle}
120+
style={{ ...viewMoreButtonStyle, ...(isMobile ? viewMoreButtonMobileStyle : {}) }}
121+
className="challenge-more-button"
105122
>
106123
{t('home.challenges.popular.viewMore')} <ArrowRightOutlined />
107124
</Button>

src/components/HomePage/FeatureSection.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import {
1111
sectionTitleStyle,
1212
sectionTitleDividerStyle,
1313
featureCardStyle,
14-
featureCardContentStyle
14+
featureCardContentStyle,
15+
featureSectionMobileStyle,
16+
sectionTitleMobileStyle
1517
} from './styles';
18+
import { useMediaQuery } from 'react-responsive';
1619

1720
const { Title, Text } = Typography;
1821

@@ -21,6 +24,7 @@ const { Title, Text } = Typography;
2124
*/
2225
const FeatureSection: React.FC = () => {
2326
const { t } = useTranslation();
27+
const isMobile = useMediaQuery({ maxWidth: 768 });
2428

2529
// 从i18n获取功能特性数据
2630
const features = [
@@ -45,8 +49,12 @@ const FeatureSection: React.FC = () => {
4549
];
4650

4751
return (
48-
<div style={featureSectionStyle}>
49-
<Title level={2} style={sectionTitleStyle}>
52+
<div style={{ ...featureSectionStyle, ...(isMobile ? featureSectionMobileStyle : {}) }}>
53+
<Title
54+
level={2}
55+
style={{ ...sectionTitleStyle, ...(isMobile ? sectionTitleMobileStyle : {}) }}
56+
className="feature-title"
57+
>
5058
{t('home.features.title')}
5159
<div style={sectionTitleDividerStyle}></div>
5260
</Title>
@@ -60,23 +68,23 @@ const FeatureSection: React.FC = () => {
6068
>
6169
<div style={featureCardContentStyle}>
6270
<div style={{
63-
fontSize: '36px',
71+
fontSize: isMobile ? '32px' : '36px',
6472
color: feature.color,
6573
marginBottom: '16px',
6674
background: `rgba(${feature.color.replace('#', '').match(/.{2}/g)?.map(c => parseInt(c, 16)).join(',')}, 0.1)`,
67-
width: '80px',
68-
height: '80px',
75+
width: isMobile ? '70px' : '80px',
76+
height: isMobile ? '70px' : '80px',
6977
display: 'flex',
7078
alignItems: 'center',
7179
justifyContent: 'center',
72-
borderRadius: '40px'
80+
borderRadius: isMobile ? '35px' : '40px'
7381
}}>
7482
{feature.icon}
7583
</div>
76-
<Title level={4} style={{ color: feature.color, marginBottom: '8px' }}>
84+
<Title level={4} style={{ color: feature.color, marginBottom: '8px', fontSize: isMobile ? '18px' : '20px' }}>
7785
{feature.title}
7886
</Title>
79-
<Text type="secondary" style={{ fontSize: '16px' }}>
87+
<Text type="secondary" style={{ fontSize: isMobile ? '14px' : '16px' }}>
8088
{feature.content}
8189
</Text>
8290
</div>

0 commit comments

Comments
 (0)