Skip to content

Commit ae03b23

Browse files
committed
重构:将Community组件模块化,拆分样式和功能代码
1 parent d0323e7 commit ae03b23

File tree

5 files changed

+178
-118
lines changed

5 files changed

+178
-118
lines changed

office-website/src/components/Community.tsx

Lines changed: 0 additions & 118 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import {
3+
QrCodeItem,
4+
QrCodeImage,
5+
QrCodeText,
6+
StyledLink
7+
} from '../../styles/components/Community.styles';
8+
9+
interface QrCodeCardProps {
10+
imageUrl: string;
11+
imageAlt: string;
12+
text: string;
13+
linkUrl?: string;
14+
linkText?: string;
15+
}
16+
17+
const QrCodeCard: React.FC<QrCodeCardProps> = ({
18+
imageUrl,
19+
imageAlt,
20+
text,
21+
linkUrl,
22+
linkText
23+
}) => {
24+
return (
25+
<QrCodeItem>
26+
<QrCodeImage src={imageUrl} alt={imageAlt} />
27+
<QrCodeText>
28+
{linkUrl && linkText ? (
29+
<>
30+
<StyledLink href={linkUrl} target="_blank">{linkText}</StyledLink>
31+
{" "}{text}
32+
</>
33+
) : (
34+
text
35+
)}
36+
</QrCodeText>
37+
</QrCodeItem>
38+
);
39+
};
40+
41+
export default QrCodeCard;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export interface QrCodeCardData {
2+
imageUrl: string;
3+
imageAlt: string;
4+
text: string;
5+
linkUrl?: string;
6+
linkText?: string;
7+
}
8+
9+
export const qrCodes: QrCodeCardData[] = [
10+
{
11+
imageUrl: "https://cdn.jsdelivr.net/gh/JSREI/.github/profile/README.assets/image-20241016230653669.png",
12+
imageAlt: "微信交流群二维码",
13+
text: "扫码加入逆向技术微信交流群"
14+
},
15+
{
16+
imageUrl: "https://cdn.jsdelivr.net/gh/JSREI/.github/profile/README.assets/image-20231030132026541-7614065.png",
17+
imageAlt: "个人微信二维码",
18+
text: "如群二维码过期,可以加我个人微信,发送【逆向群】拉你进群"
19+
},
20+
{
21+
imageUrl: "https://cdn.jsdelivr.net/gh/JSREI/.github/profile/README.assets/image-20241016231143315.png",
22+
imageAlt: "TG交流群二维码",
23+
text: "扫码加入TG交流群",
24+
linkUrl: "https://t.me/jsreijsrei",
25+
linkText: "点此"
26+
}
27+
];
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import {
3+
CommunityContainer,
4+
CommunityContent,
5+
CommunityTitle,
6+
QrCodesContainer
7+
} from '../../styles/components/Community.styles';
8+
import QrCodeCard from './QrCodeCard';
9+
import { qrCodes } from './QrCodeData';
10+
11+
const Community: React.FC = () => {
12+
return (
13+
<CommunityContainer id="community">
14+
<CommunityContent>
15+
<CommunityTitle>逆向技术交流群</CommunityTitle>
16+
17+
<QrCodesContainer>
18+
{qrCodes.map((qrCode, index) => (
19+
<QrCodeCard
20+
key={`qr-code-${index}`}
21+
imageUrl={qrCode.imageUrl}
22+
imageAlt={qrCode.imageAlt}
23+
text={qrCode.text}
24+
linkUrl={qrCode.linkUrl}
25+
linkText={qrCode.linkText}
26+
/>
27+
))}
28+
</QrCodesContainer>
29+
</CommunityContent>
30+
</CommunityContainer>
31+
);
32+
};
33+
34+
export default Community;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import styled from 'styled-components';
2+
3+
export const CommunityContainer = styled.section`
4+
padding: 5rem 0;
5+
background-color: ${({ theme }) => theme.colors.backgroundAlt};
6+
`;
7+
8+
export const CommunityContent = styled.div`
9+
max-width: 1200px;
10+
margin: 0 auto;
11+
padding: 0 1.5rem;
12+
`;
13+
14+
export const CommunityTitle = styled.h2`
15+
color: ${({ theme }) => theme.colors.heading};
16+
font-size: 2.25rem;
17+
font-weight: 700;
18+
text-align: center;
19+
margin-bottom: 2.5rem;
20+
`;
21+
22+
export const QrCodesContainer = styled.div`
23+
display: flex;
24+
justify-content: center;
25+
flex-wrap: wrap;
26+
gap: 3rem;
27+
margin: 3rem 0;
28+
29+
@media (max-width: ${({ theme }) => theme.breakpoints.md}) {
30+
flex-direction: column;
31+
align-items: center;
32+
}
33+
`;
34+
35+
export const QrCodeItem = styled.div`
36+
display: flex;
37+
flex-direction: column;
38+
align-items: center;
39+
max-width: 240px;
40+
background-color: white;
41+
border-radius: 12px;
42+
padding: 1.5rem;
43+
box-shadow: ${({ theme }) => theme.boxShadow.medium};
44+
transition: transform 0.3s ease, box-shadow 0.3s ease;
45+
46+
&:hover {
47+
transform: translateY(-5px);
48+
box-shadow: ${({ theme }) => theme.boxShadow.large};
49+
}
50+
`;
51+
52+
export const QrCodeImage = styled.img`
53+
width: 200px;
54+
height: auto;
55+
border-radius: 8px;
56+
margin-bottom: 1.5rem;
57+
`;
58+
59+
export const QrCodeText = styled.p`
60+
color: ${({ theme }) => theme.colors.text};
61+
text-align: center;
62+
font-size: 1rem;
63+
line-height: 1.6;
64+
`;
65+
66+
export const StyledLink = styled.a`
67+
color: ${({ theme }) => theme.colors.primary};
68+
font-weight: 500;
69+
text-decoration: none;
70+
transition: color 0.2s ease;
71+
72+
&:hover {
73+
color: ${({ theme }) => theme.colors.primaryDark};
74+
text-decoration: underline;
75+
}
76+
`;

0 commit comments

Comments
 (0)