综述: 重构电商首页,引入卡片式布局和轮播功能
- **样式重构**:
    - 引入 `cards-container` 网格布局,替代原有的 `market-section`。
    - 新增通用的 `card` 卡片样式,并分别为菜市场卡片 (`market-card`) 和商品卡片 (`product-card`) 设计了详细的样式,包括图片、标题、评分、价格、操作按钮等。
    - 为菜市场卡片增加了轮播图的样式,包括轮播指示器。
- **HTML结构更新**:
    - 使用新的卡片式布局完全重构了首页内容区域。
    - 增加了一个包含两个菜市场信息的轮播卡片。
    - 新增了四个商品展示卡片,包含商品图片、名称、价格、店铺等信息。
- **新增JavaScript功能**:
    - 增加了轮播图的自动播放和手动切换功能。
    - 添加了对移动端触摸滑动的支持,用户可以通过左右滑动来切换轮播图。
			
			
This commit is contained in:
		
							parent
							
								
									0686c09e9d
								
							
						
					
					
						commit
						bf88518b9c
					
				
							
								
								
									
										527
									
								
								用户端APP/电商首页.html
								
								
								
								
							
							
						
						
									
										527
									
								
								用户端APP/电商首页.html
								
								
								
								
							|  | @ -133,6 +133,7 @@ | |||
|             border-radius: 20px 20px 0 0; | ||||
|             margin-top: -15px; | ||||
|             padding: 20px; | ||||
|             padding-bottom: 120px; | ||||
|             min-height: calc(100vh - 200px); | ||||
|         } | ||||
| 
 | ||||
|  | @ -261,40 +262,283 @@ | |||
|             color: rgba(255,255,255,0.7); | ||||
|         } | ||||
| 
 | ||||
|         /* 菜市场区域 */ | ||||
|         .market-section { | ||||
|         /* 卡片容器 */ | ||||
|         .cards-container { | ||||
|             display: grid; | ||||
|             grid-template-columns: 1fr 1fr; | ||||
|             gap: 15px; | ||||
|             margin-bottom: 20px; | ||||
|         } | ||||
| 
 | ||||
|         /* 通用卡片样式 */ | ||||
|         .card { | ||||
|             background: white; | ||||
|             border-radius: 15px; | ||||
|             padding: 15px; | ||||
|             margin-bottom: 20px; | ||||
|             padding: 0; | ||||
|             position: relative; | ||||
|             overflow: hidden; | ||||
|             box-shadow: 0 2px 10px rgba(0,0,0,0.1); | ||||
|             height: 320px; | ||||
|         } | ||||
| 
 | ||||
|         /* 菜市场轮播卡片 */ | ||||
|         .market-card { | ||||
|             position: relative; | ||||
|         } | ||||
| 
 | ||||
|         .market-title { | ||||
|             background: linear-gradient(135deg, #2d5a3d, #4a7c59); | ||||
|             color: white; | ||||
|             padding: 10px 15px; | ||||
|             border-radius: 10px; | ||||
|             font-size: 16px; | ||||
|             font-weight: bold; | ||||
|             margin-bottom: 10px; | ||||
|         .market-carousel { | ||||
|             position: relative; | ||||
|             overflow: hidden; | ||||
|             height: 100%; | ||||
|         } | ||||
| 
 | ||||
|         .market-slide { | ||||
|             position: absolute; | ||||
|             top: 0; | ||||
|             left: 0; | ||||
|             width: 100%; | ||||
|             height: 100%; | ||||
|             opacity: 0; | ||||
|             transition: opacity 0.5s ease-in-out; | ||||
|             display: flex; | ||||
|             flex-direction: column; | ||||
|         } | ||||
| 
 | ||||
|         .market-slide.active { | ||||
|             opacity: 1; | ||||
|         } | ||||
| 
 | ||||
|         .market-image { | ||||
|             width: 100%; | ||||
|             height: 120px; | ||||
|             background: linear-gradient(135deg, #4a7c59, #70b77e); | ||||
|             border-radius: 10px; | ||||
|             height: 150px; | ||||
|             background-size: cover; | ||||
|             background-position: center; | ||||
|             position: relative; | ||||
|             overflow: hidden; | ||||
|             flex-shrink: 0; | ||||
|         } | ||||
| 
 | ||||
|         .market-image::after { | ||||
|             content: '🥗'; | ||||
|         .market-title { | ||||
|             position: absolute; | ||||
|             top: 15px; | ||||
|             left: 15px; | ||||
|             background: rgba(0,0,0,0.7); | ||||
|             color: white; | ||||
|             padding: 6px 12px; | ||||
|             border-radius: 15px; | ||||
|             font-size: 14px; | ||||
|             font-weight: bold; | ||||
|         } | ||||
| 
 | ||||
|         .brand-badge { | ||||
|             position: absolute; | ||||
|             right: 15px; | ||||
|             bottom: 15px; | ||||
|             font-size: 30px; | ||||
|             left: 15px; | ||||
|             background: #ffa500; | ||||
|             color: white; | ||||
|             padding: 4px 10px; | ||||
|             border-radius: 12px; | ||||
|             font-size: 11px; | ||||
|             font-weight: bold; | ||||
|         } | ||||
| 
 | ||||
|         .market-info { | ||||
|             padding: 12px 15px; | ||||
|             flex: 1; | ||||
|             display: flex; | ||||
|             flex-direction: column; | ||||
|         } | ||||
| 
 | ||||
|         .market-name { | ||||
|             font-size: 13px; | ||||
|             color: #333; | ||||
|             margin-bottom: 5px; | ||||
|             font-weight: 500; | ||||
|         } | ||||
| 
 | ||||
|         .market-rating { | ||||
|             display: flex; | ||||
|             align-items: center; | ||||
|             gap: 5px; | ||||
|             font-size: 11px; | ||||
|             color: #666; | ||||
|             margin-bottom: 5px; | ||||
|         } | ||||
| 
 | ||||
|         .rating-star { | ||||
|             color: #ffa500; | ||||
|         } | ||||
| 
 | ||||
|         .market-stats { | ||||
|             display: flex; | ||||
|             justify-content: space-between; | ||||
|             align-items: center; | ||||
|             font-size: 11px; | ||||
|             color: #666; | ||||
|             margin-bottom: 10px; | ||||
|         } | ||||
| 
 | ||||
|         .market-delivery { | ||||
|             background: #f0f8f0; | ||||
|             color: #4a7c59; | ||||
|             padding: 2px 6px; | ||||
|             border-radius: 8px; | ||||
|             font-size: 10px; | ||||
|         } | ||||
| 
 | ||||
|         .market-actions { | ||||
|             display: flex; | ||||
|             justify-content: center; | ||||
|             align-items: center; | ||||
|             padding: 0 15px 10px; | ||||
|         } | ||||
| 
 | ||||
|         .action-group { | ||||
|             display: flex; | ||||
|             align-items: center; | ||||
|             gap: 12px; | ||||
|         } | ||||
| 
 | ||||
|         .action-btn { | ||||
|             display: flex; | ||||
|             align-items: center; | ||||
|             gap: 3px; | ||||
|             font-size: 11px; | ||||
|             color: #666; | ||||
|             background: none; | ||||
|             border: none; | ||||
|             cursor: pointer; | ||||
|         } | ||||
| 
 | ||||
|         .action-btn.liked { | ||||
|             color: #ff6b6b; | ||||
|         } | ||||
| 
 | ||||
|         /* 轮播指示器 */ | ||||
|         .carousel-indicators { | ||||
|             position: absolute; | ||||
|             bottom: 50px; | ||||
|             right: 15px; | ||||
|             display: flex; | ||||
|             gap: 5px; | ||||
|         } | ||||
| 
 | ||||
|         .indicator { | ||||
|             width: 6px; | ||||
|             height: 6px; | ||||
|             border-radius: 50%; | ||||
|             background: rgba(255,255,255,0.5); | ||||
|             cursor: pointer; | ||||
|             transition: background 0.3s; | ||||
|         } | ||||
| 
 | ||||
|         .indicator.active { | ||||
|             background: white; | ||||
|         } | ||||
| 
 | ||||
|         /* 商品卡片 */ | ||||
|         .product-card { | ||||
|             position: relative; | ||||
|             display: flex; | ||||
|             flex-direction: column; | ||||
|             height: 320px; | ||||
|         } | ||||
| 
 | ||||
|         .product-image { | ||||
|             width: 80px; | ||||
|             height: 80px; | ||||
|             background-size: cover; | ||||
|             background-position: center; | ||||
|             border-radius: 50%; | ||||
|             margin: 15px auto 10px; | ||||
|             position: relative; | ||||
|             flex-shrink: 0; | ||||
|         } | ||||
| 
 | ||||
|         .product-badge { | ||||
|             position: absolute; | ||||
|             top: 10px; | ||||
|             right: 10px; | ||||
|             background: rgba(0,0,0,0.7); | ||||
|             color: white; | ||||
|             padding: 4px 8px; | ||||
|             border-radius: 10px; | ||||
|             font-size: 10px; | ||||
|         } | ||||
| 
 | ||||
|         .product-info { | ||||
|             padding: 0 15px 15px; | ||||
|             text-align: center; | ||||
|             flex: 1; | ||||
|             display: flex; | ||||
|             flex-direction: column; | ||||
|         } | ||||
| 
 | ||||
|         .product-name { | ||||
|             font-size: 13px; | ||||
|             color: #333; | ||||
|             margin-bottom: 8px; | ||||
|             font-weight: 500; | ||||
|             line-height: 1.3; | ||||
|         } | ||||
| 
 | ||||
|         .product-price { | ||||
|             color: #ff6b6b; | ||||
|             font-size: 16px; | ||||
|             font-weight: bold; | ||||
|             margin-bottom: 8px; | ||||
|         } | ||||
| 
 | ||||
|         .product-price .unit { | ||||
|             font-size: 12px; | ||||
|             color: #999; | ||||
|             font-weight: normal; | ||||
|         } | ||||
| 
 | ||||
|         .product-store { | ||||
|             font-size: 11px; | ||||
|             color: #666; | ||||
|             margin-bottom: 8px; | ||||
|             line-height: 1.2; | ||||
|         } | ||||
| 
 | ||||
|         .product-meta { | ||||
|             display: flex; | ||||
|             justify-content: center; | ||||
|             gap: 8px; | ||||
|             font-size: 10px; | ||||
|             color: #999; | ||||
|             margin-bottom: 8px; | ||||
|         } | ||||
| 
 | ||||
|         .product-delivery { | ||||
|             font-size: 10px; | ||||
|             color: #999; | ||||
|             margin-bottom: 10px; | ||||
|         } | ||||
| 
 | ||||
|         .product-actions { | ||||
|             display: flex; | ||||
|             justify-content: center; | ||||
|             gap: 10px; | ||||
|             margin-top: auto; | ||||
|             padding-bottom: 5px; | ||||
|         } | ||||
| 
 | ||||
|         .add-to-cart { | ||||
|             position: absolute; | ||||
|             bottom: 15px; | ||||
|             right: 15px; | ||||
|             width: 28px; | ||||
|             height: 28px; | ||||
|             background: #4a7c59; | ||||
|             color: white; | ||||
|             border: none; | ||||
|             border-radius: 50%; | ||||
|             display: flex; | ||||
|             align-items: center; | ||||
|             justify-content: center; | ||||
|             font-size: 16px; | ||||
|             cursor: pointer; | ||||
|         } | ||||
| 
 | ||||
|         /* 底部导航 */ | ||||
|  | @ -385,12 +629,12 @@ | |||
| <body> | ||||
|     <!-- 状态栏 --> | ||||
|     <div class="status-bar"> | ||||
|         <div>08:24</div> | ||||
|         <div>09:15</div> | ||||
|         <div class="status-icons"> | ||||
|             <span>🔵</span> | ||||
|             <span>📶</span> | ||||
|             <span>📶</span> | ||||
|             <span>🔋 58%</span> | ||||
|             <span>🔋 52%</span> | ||||
|         </div> | ||||
|     </div> | ||||
| 
 | ||||
|  | @ -494,10 +738,192 @@ | |||
|             </div> | ||||
|         </div> | ||||
| 
 | ||||
|         <!-- 菜市场区域 --> | ||||
|         <div class="market-section"> | ||||
|             <div class="market-title">全季菜市场</div> | ||||
|             <div class="market-image"></div> | ||||
|         <!-- 卡片容器 --> | ||||
|         <div class="cards-container"> | ||||
|             <!-- 菜市场轮播卡片 --> | ||||
|             <div class="card market-card"> | ||||
|                 <div class="market-carousel"> | ||||
|                     <div class="market-slide active"> | ||||
|                         <div class="market-image" style="background: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.1)), linear-gradient(135deg, #4a7c59 0%, #70b77e 50%, #a8e6cf 100%);"> | ||||
|                             <div class="market-title">华径菜场</div> | ||||
|                             <div class="brand-badge">👑 品牌</div> | ||||
|                         </div> | ||||
|                         <div class="market-info"> | ||||
|                             <div class="market-name">春申路1501号</div> | ||||
|                             <div class="market-rating"> | ||||
|                                 <span class="rating-star">⭐</span> | ||||
|                                 <span>5.0分</span> | ||||
|                                 <span>📍 0.1km</span> | ||||
|                             </div> | ||||
|                             <div class="market-stats"> | ||||
|                                 <span>销量:0份</span> | ||||
|                                 <span class="market-delivery">满¥99免运费</span> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                         <div class="market-actions"> | ||||
|                             <div class="action-group"> | ||||
|                                 <button class="action-btn"> | ||||
|                                     <span>🔗</span> | ||||
|                                     <span>分享</span> | ||||
|                                 </button> | ||||
|                                 <button class="action-btn liked"> | ||||
|                                     <span>👍</span> | ||||
|                                     <span>1</span> | ||||
|                                 </button> | ||||
|                                 <button class="action-btn liked"> | ||||
|                                     <span>❤️</span> | ||||
|                                     <span>2</span> | ||||
|                                 </button> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                     </div> | ||||
|                     <div class="market-slide"> | ||||
|                         <div class="market-image" style="background: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.1)), linear-gradient(135deg, #2d5a3d 0%, #4a7c59 50%, #70b77e 100%);"> | ||||
|                             <div class="market-title">全季菜市场</div> | ||||
|                             <div class="brand-badge">🏪 市场</div> | ||||
|                         </div> | ||||
|                         <div class="market-info"> | ||||
|                             <div class="market-name">徐汇区田林路</div> | ||||
|                             <div class="market-rating"> | ||||
|                                 <span class="rating-star">⭐</span> | ||||
|                                 <span>4.8分</span> | ||||
|                                 <span>📍 0.3km</span> | ||||
|                             </div> | ||||
|                             <div class="market-stats"> | ||||
|                                 <span>销量:15份</span> | ||||
|                                 <span class="market-delivery">满¥66免运费</span> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                         <div class="market-actions"> | ||||
|                             <div class="action-group"> | ||||
|                                 <button class="action-btn"> | ||||
|                                     <span>🔗</span> | ||||
|                                     <span>分享</span> | ||||
|                                 </button> | ||||
|                                 <button class="action-btn"> | ||||
|                                     <span>👍</span> | ||||
|                                     <span>5</span> | ||||
|                                 </button> | ||||
|                                 <button class="action-btn"> | ||||
|                                     <span>❤️</span> | ||||
|                                     <span>3</span> | ||||
|                                 </button> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                     </div> | ||||
|                 </div> | ||||
|                 <div class="carousel-indicators"> | ||||
|                     <div class="indicator active" onclick="showSlide(0)"></div> | ||||
|                     <div class="indicator" onclick="showSlide(1)"></div> | ||||
|                 </div> | ||||
|             </div> | ||||
| 
 | ||||
|             <!-- 商品卡片1 --> | ||||
|             <div class="card product-card"> | ||||
|                 <div class="product-image" style="background: radial-gradient(circle, #8b4513 30%, #654321 70%);"></div> | ||||
|                 <div class="product-info"> | ||||
|                     <div class="product-name">盐池滩羊腿肉约800g</div> | ||||
|                     <div class="product-price">¥99.8<span class="unit">/份</span></div> | ||||
|                     <div class="product-store">华清羊肉店(全季菜市场)</div> | ||||
|                     <div class="product-meta"> | ||||
|                         <span>⭐ 4.8分</span> | ||||
|                         <span>📍 0.3km</span> | ||||
|                     </div> | ||||
|                     <div class="product-delivery">起送¥20 满¥50免运费</div> | ||||
|                     <div class="product-actions"> | ||||
|                         <button class="action-btn"> | ||||
|                             <span>👍</span> | ||||
|                             <span>12</span> | ||||
|                         </button> | ||||
|                         <button class="action-btn"> | ||||
|                             <span>❤️</span> | ||||
|                             <span>8</span> | ||||
|                         </button> | ||||
|                     </div> | ||||
|                 </div> | ||||
|                 <button class="add-to-cart">+</button> | ||||
|             </div> | ||||
| 
 | ||||
|             <!-- 商品卡片2 --> | ||||
|             <div class="card product-card"> | ||||
|                 <div class="product-image" style="background: linear-gradient(45deg, #ff69b4, #ffc0cb);"> | ||||
|                     <div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;">🥩</div> | ||||
|                 </div> | ||||
|                 <div class="product-badge">订单备货中</div> | ||||
|                 <div class="product-info"> | ||||
|                     <div class="product-name">盐池滩羊排骨丝</div> | ||||
|                     <div class="product-price">¥105.8<span class="unit">/份</span></div> | ||||
|                     <div class="product-store">清羊肉店(全季菜市场)</div> | ||||
|                     <div class="product-meta"> | ||||
|                         <span>⭐ 4.9分</span> | ||||
|                         <span>📍 0.3km</span> | ||||
|                     </div> | ||||
|                     <div class="product-delivery">起送¥30 满¥80免运费</div> | ||||
|                     <div class="product-actions"> | ||||
|                         <button class="action-btn"> | ||||
|                             <span>👍</span> | ||||
|                             <span>6</span> | ||||
|                         </button> | ||||
|                         <button class="action-btn"> | ||||
|                             <span>❤️</span> | ||||
|                             <span>4</span> | ||||
|                         </button> | ||||
|                     </div> | ||||
|                 </div> | ||||
|                 <button class="add-to-cart">+</button> | ||||
|             </div> | ||||
| 
 | ||||
|             <!-- 商品卡片3 --> | ||||
|             <div class="card product-card"> | ||||
|                 <div class="product-image" style="background: radial-gradient(circle, #dda0dd 40%, #9370db 70%);"></div> | ||||
|                 <div class="product-info"> | ||||
|                     <div class="product-name">巨峰葡萄约100g</div> | ||||
|                     <div class="product-price">¥12<span class="unit">/份</span></div> | ||||
|                     <div class="product-store">四季水果店(春申菜市场)</div> | ||||
|                     <div class="product-meta"> | ||||
|                         <span>⭐ 4.7分</span> | ||||
|                         <span>📍 0.1km</span> | ||||
|                     </div> | ||||
|                     <div class="product-delivery">起送¥10 满¥30免运费</div> | ||||
|                     <div class="product-actions"> | ||||
|                         <button class="action-btn"> | ||||
|                             <span>👍</span> | ||||
|                             <span>23</span> | ||||
|                         </button> | ||||
|                         <button class="action-btn"> | ||||
|                             <span>❤️</span> | ||||
|                             <span>18</span> | ||||
|                         </button> | ||||
|                     </div> | ||||
|                 </div> | ||||
|                 <button class="add-to-cart">+</button> | ||||
|             </div> | ||||
| 
 | ||||
|             <!-- 商品卡片4 --> | ||||
|             <div class="card product-card"> | ||||
|                 <div class="product-image" style="background: radial-gradient(circle, #ffa500 30%, #ff8c00 70%);"></div> | ||||
|                 <div class="product-info"> | ||||
|                     <div class="product-name">新疆哈密瓜约500g</div> | ||||
|                     <div class="product-price">¥28<span class="unit">/份</span></div> | ||||
|                     <div class="product-store">新鲜果园(华径菜场)</div> | ||||
|                     <div class="product-meta"> | ||||
|                         <span>⭐ 4.9分</span> | ||||
|                         <span>📍 0.1km</span> | ||||
|                     </div> | ||||
|                     <div class="product-delivery">起送¥15 满¥40免运费</div> | ||||
|                     <div class="product-actions"> | ||||
|                         <button class="action-btn"> | ||||
|                             <span>👍</span> | ||||
|                             <span>31</span> | ||||
|                         </button> | ||||
|                         <button class="action-btn liked"> | ||||
|                             <span>❤️</span> | ||||
|                             <span>25</span> | ||||
|                         </button> | ||||
|                     </div> | ||||
|                 </div> | ||||
|                 <button class="add-to-cart">+</button> | ||||
|             </div> | ||||
|         </div> | ||||
|     </div> | ||||
| 
 | ||||
|  | @ -526,5 +952,54 @@ | |||
|             <span>我的</span> | ||||
|         </div> | ||||
|     </div> | ||||
| 
 | ||||
|     <script> | ||||
|         let currentSlide = 0; | ||||
|         const slides = document.querySelectorAll('.market-slide'); | ||||
|         const indicators = document.querySelectorAll('.indicator'); | ||||
|          | ||||
|         function showSlide(index) { | ||||
|             // 移除所有活跃状态 | ||||
|             slides[currentSlide].classList.remove('active'); | ||||
|             indicators[currentSlide].classList.remove('active'); | ||||
|              | ||||
|             // 设置新的活跃状态 | ||||
|             currentSlide = index; | ||||
|             slides[currentSlide].classList.add('active'); | ||||
|             indicators[currentSlide].classList.add('active'); | ||||
|         } | ||||
|          | ||||
|         // 自动轮播 | ||||
|         function autoSlide() { | ||||
|             const nextSlide = (currentSlide + 1) % slides.length; | ||||
|             showSlide(nextSlide); | ||||
|         } | ||||
|          | ||||
|         // 每3秒自动切换 | ||||
|         setInterval(autoSlide, 3000); | ||||
|          | ||||
|         // 触摸滑动支持 | ||||
|         let startX = 0; | ||||
|         const carousel = document.querySelector('.market-carousel'); | ||||
|          | ||||
|         carousel.addEventListener('touchstart', function(e) { | ||||
|             startX = e.touches[0].clientX; | ||||
|         }); | ||||
|          | ||||
|         carousel.addEventListener('touchend', function(e) { | ||||
|             const endX = e.changedTouches[0].clientX; | ||||
|             const diff = startX - endX; | ||||
|              | ||||
|             if (Math.abs(diff) > 50) { // 滑动距离超过50px | ||||
|                 if (diff > 0) { | ||||
|                     // 向左滑动,显示下一张 | ||||
|                     showSlide((currentSlide + 1) % slides.length); | ||||
|                 } else { | ||||
|                     // 向右滑动,显示上一张 | ||||
|                     showSlide((currentSlide - 1 + slides.length) % slides.length); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|     </script> | ||||
| </body> | ||||
| </html> | ||||
		Loading…
	
		Reference in New Issue