Home.jsx
4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import React, { useState } from 'react';
import { Link, useNavigate } from 'react-router-dom';
const Home = () => {
const [searchTerm, setSearchTerm] = useState('');
const navigate = useNavigate();
const handleSearch = (e) => {
e.preventDefault();
if (searchTerm.trim()) {
navigate(`/products?search=${encodeURIComponent(searchTerm)}`);
}
};
return (
<div style={containerStyle}>
<section style={heroStyle}>
<h1 style={heroTitleStyle}>欢迎来到普罗米修甄选水果平台</h1>
{/* 搜索框 */}
<div style={searchContainerStyle}>
<form onSubmit={handleSearch} style={searchFormStyle}>
<input
type="text"
placeholder="搜索水果..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
style={searchInputStyle}
/>
<button type="submit" style={searchButtonStyle}>
搜索
</button>
</form>
</div>
</section>
<section style={categoriesStyle}>
<h2 style={sectionTitleStyle}>热门果蔬</h2>
<div style={categoriesGridStyle}>
<Link to="/products?category=electronics" style={categoryCardStyle}>
<h3>秦岭猕猴桃</h3>
<p>秀色可餐,果香浓郁</p>
</Link>
<Link to="/products?category=clothing" style={categoryCardStyle}>
<h3>栖霞红富士苹果</h3>
<p>红艳诱人,脆爽多汁</p>
</Link>
<Link to="/products?category=home" style={categoryCardStyle}>
<h3>长安石榴</h3>
<p>晶莹剔透,粉黛抹腮</p>
</Link>
<Link to="/products?category=sports" style={categoryCardStyle}>
<h3>鄠邑葡萄</h3>
<p>甜而不腻,皮薄肉厚</p>
</Link>
</div>
</section>
</div>
);
};
const containerStyle = {
minHeight: 'calc(100vh - 200px)',
};
const heroStyle = {
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
color: 'white',
padding: '1.5rem 1rem', // 降低内边距
textAlign: 'center',
minHeight: '35vh', // 降低高度
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
};
const heroTitleStyle = {
fontSize: '2rem', // 减小字体
marginBottom: '0.8rem', // 减小边距
fontWeight: 'bold',
};
const heroSubtitleStyle = {
fontSize: '1rem', // 减小字体
marginBottom: '1.5rem', // 减小边距
opacity: 0.9,
maxWidth: '500px', // 减小宽度
margin: '0 auto 1.5rem', // 减小边距
lineHeight: '1.5',
};
// 搜索框样式
const searchContainerStyle = {
width: '100%',
maxWidth: '500px', // 减小宽度
margin: '0 auto',
};
const searchFormStyle = {
display: 'flex',
background: 'white',
borderRadius: '50px',
overflow: 'hidden',
boxShadow: '0 8px 25px rgba(0, 0, 0, 0.15)',
transition: 'transform 0.3s ease, box-shadow 0.3s ease',
};
const searchInputStyle = {
flex: 1,
border: 'none',
outline: 'none',
padding: '0.8rem 1.2rem', // 减小内边距
fontSize: '0.9rem', // 减小字体
color: '#333',
background: 'transparent',
};
const searchButtonStyle = {
background: 'linear-gradient(135deg, #ff6b6b, #ee5a52)',
color: 'white',
border: 'none',
padding: '0.8rem 1.5rem', // 减小内边距
fontSize: '0.9rem', // 减小字体
fontWeight: 'bold',
cursor: 'pointer',
transition: 'all 0.3s ease',
};
const categoriesStyle = {
padding: '3rem 1rem', // 保持适当内边距
backgroundColor: '#f8f9fa',
minHeight: '50vh', // 增加高度
};
const sectionTitleStyle = {
textAlign: 'center',
fontSize: '2.2rem', // 稍微调整字体
marginBottom: '2.5rem', // 调整边距
color: '#333',
};
const categoriesGridStyle = {
display: 'grid',
gridTemplateColumns: 'repeat(auto-fit, minmax(250px, 1fr))',
gap: '2rem',
maxWidth: '1200px',
margin: '0 auto',
};
const categoryCardStyle = {
backgroundColor: 'white',
padding: '2rem',
borderRadius: '10px',
textAlign: 'center',
textDecoration: 'none',
color: '#333',
boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)',
transition: 'transform 0.3s, box-shadow 0.3s',
border: '1px solid #e0e0e0',
};
// 添加悬停效果
Object.assign(categoryCardStyle, {
':hover': {
transform: 'translateY(-5px)',
boxShadow: '0 8px 25px rgba(0, 0, 0, 0.15)',
}
});
Object.assign(searchFormStyle, {
':hover': {
transform: 'translateY(-2px)',
boxShadow: '0 12px 35px rgba(0, 0, 0, 0.2)',
}
});
Object.assign(searchButtonStyle, {
':hover': {
background: 'linear-gradient(135deg, #ff5252, #e53935)',
}
});
export default Home;