2
0
Эх сурвалжийг харах

✨ feat(homepage): 重构首页组件结构

- 重构首页组件 (mini/src/pages/index/index.tsx)
- 更新首页样式 (mini/src/pages/index/index.css)
- 集成TDesign Search组件(禁用状态,圆角32rpx)
- 集成TDesign Swiper组件(自动播放,导航指示器)
- 集成GoodsList商品列表组件
- 应用tcb-shop-demo页面结构和渐变背景色

🤖 Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 1 сар өмнө
parent
commit
85430aabda

+ 16 - 6
docs/stories/001.004.homepage-ui-refactor.md

@@ -33,12 +33,12 @@ Draft
   - [x] 参照 `tcb-shop-demo/components/goods-list/index.wxml` 实现列表结构
   - [x] 实现flex布局(按tcb-shop-demo实际布局)
   - [x] 集成商品卡片组件
-- [ ] 创建首页组件结构 (AC: 1)
-  - [ ] 创建 `mini/src/pages/index/index.tsx` 首页组件
-  - [ ] 参照 `tcb-shop-demo/pages/home/home.wxml` 实现页面结构
-  - [ ] 集成搜索栏组件(带搜索图标,禁用状态)
-  - [ ] 集成轮播图组件(自动播放,导航指示器)
-  - [ ] 集成商品列表组件
+- [x] 创建首页组件结构 (AC: 1)
+  - [x] 创建 `mini/src/pages/index/index.tsx` 首页组件
+  - [x] 参照 `tcb-shop-demo/pages/home/home.wxml` 实现页面结构
+  - [x] 集成搜索栏组件(带搜索图标,禁用状态)
+  - [x] 集成轮播图组件(自动播放,导航指示器)
+  - [x] 集成商品列表组件
   - [ ] 添加加载状态和下拉刷新功能
 - [ ] 应用tcb-shop-demo样式系统 (AC: 2, 4)
   - [ ] 应用渐变背景色(#fff 到 #f5f5f5)
@@ -326,6 +326,14 @@ export default function TDesignSwiper({
 - ✅ 已集成:商品卡片组件到商品列表组件
 - ✅ 已验证:商品列表组件TypeScript编译正常
 - ✅ 已验证:组件导入和依赖关系正确
+- ✅ 已完成:重构 `mini/src/pages/index/index.tsx` - 首页组件
+- ✅ 已完成:更新 `mini/src/pages/index/index.css` - 首页样式
+- ✅ 已集成:TDesign Search组件(禁用状态,圆角32rpx)
+- ✅ 已集成:TDesign Swiper组件(自动播放,导航指示器)
+- ✅ 已集成:GoodsList商品列表组件
+- ✅ 已应用:tcb-shop-demo页面结构(home-page-header + home-page-container)
+- ✅ 已应用:渐变背景色(#fff 到 #f5f5f5)
+- ✅ 已验证:首页组件TypeScript编译正常
 
 ### File List
 - **创建**: `mini/src/components/tdesign/search/index.tsx` - TDesign Search 组件
@@ -337,6 +345,8 @@ export default function TDesignSwiper({
 - **创建**: `mini/src/components/goods-card/index.css` - 商品卡片组件样式
 - **创建**: `mini/src/components/goods-list/index.tsx` - 商品列表组件
 - **创建**: `mini/src/components/goods-list/index.css` - 商品列表组件样式
+- **修改**: `mini/src/pages/index/index.tsx` - 首页组件(重构)
+- **修改**: `mini/src/pages/index/index.css` - 首页样式(重构)
 - **创建**: `mini/src/components/tdesign/search/index.css` - Search 组件样式
 - **创建**: `mini/src/components/tdesign/swiper/index.css` - Swiper 组件样式
 - **创建**: `mini/src/components/tdesign/toast/index.css` - Toast 组件样式

+ 31 - 109
mini/src/pages/index/index.css

@@ -1,131 +1,53 @@
-/* –u7 - ÆTCB Shop Demo¾¡Ä */
+/* 首页样� - �照 TCB Shop Demo */
 
-/* ubÌoØ */
-.homepage-container {
+/* 页�基础样� */
+.home-page-header {
   background: linear-gradient(#fff, #f5f5f5);
-  min-height: 100vh;
-}
-
-/* "7 */
-.search-container {
-  padding: 20rpx 32rpx;
-}
-
-.search-box {
-  height: 64rpx;
-  border-radius: 32rpx;
-  background-color: #f8f8f8;
-  border: 1rpx solid #e5e5e5;
-  display: flex;
-  align-items: center;
   padding: 0 24rpx;
 }
 
-.search-box.disabled {
-  background-color: #f5f5f5;
-  color: #999;
-}
-
-.search-icon {
-  color: #fa550f;
-  margin-right: 12rpx;
-}
-
-.search-placeholder {
-  color: #bbbbbb;
-  font-size: 28rpx;
-}
-
-/* n­þ:ß */
-.carousel-section {
-  padding: 0 32rpx 24rpx;
+.home-page-container {
+  background: #f5f5f5;
+  padding: 0 24rpx;
 }
 
-.carousel-container {
-  border-radius: 16rpx;
-  overflow: hidden;
+/* �索�样� */
+.home-page-header .search {
+  padding: 20rpx 0;
 }
 
-/* FÁh:ß */
-.goods-section {
-  padding: 0 32rpx;
+/* TDesign Search 组件样�适� */
+.home-page-header .tdesign-search__input-box {
+  border-radius: 32rpx !important;
+  height: 64rpx !important;
 }
 
-.goods-grid {
-  display: grid;
-  grid-template-columns: repeat(2, 1fr);
-  gap: 24rpx;
+.home-page-header .tdesign-search__input {
+  font-size: 28rpx !important;
+  color: rgb(116, 116, 116) !important;
 }
 
-/* FÁaG7 */
-.goods-card {
-  background: white;
-  border-radius: 16rpx;
-  overflow: hidden;
-  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
+/* 轮播图样� */
+.home-page-header .swiper-wrap {
+  margin-top: 20rpx;
+  display: flex;
+  justify-content: center;
+  align-items: center;
 }
 
-.goods-image {
+.home-page-header .tdesign-swiper {
   width: 100%;
-  height: 320rpx;
-  object-fit: cover;
-}
-
-.goods-info {
-  padding: 20rpx;
-}
-
-.goods-title {
-  font-size: 28rpx;
-  color: #333;
-  line-height: 1.4;
-  margin-bottom: 12rpx;
-  display: -webkit-box;
-  -webkit-line-clamp: 2;
-  -webkit-box-orient: vertical;
-  overflow: hidden;
-}
-
-.goods-price {
-  font-size: 32rpx;
-  color: #fa4126;
-  font-weight: 600;
-  margin-bottom: 16rpx;
 }
 
-.add-cart-btn {
-  background-color: #fa4126;
-  color: white;
-  border: none;
-  border-radius: 8rpx;
-  padding: 12rpx 0;
-  font-size: 24rpx;
-  text-align: center;
+.home-page-header .tdesign-swiper__image {
   width: 100%;
+  display: block;
+  margin: 0 auto;
+  border-radius: 10rpx;
 }
 
-.add-cart-btn:active {
-  background-color: #e03a22;
-}
-
-/*  }¶ */
-.loading-container {
-  display: flex;
-  justify-content: center;
-  align-items: center;
-  padding: 40rpx;
-}
-
-.loading-text {
-  color: #999;
-  font-size: 28rpx;
-}
-
-/* É7° */
-.refresh-indicator {
-  display: flex;
-  justify-content: center;
-  align-items: center;
-  padding: 20rpx;
-  color: #fa550f;
+/* 商�列表容器样� */
+.home-page-container .goods-list-wrap {
+  background: #f5f5f5 !important;
+  margin-top: 16rpx;
 }

+ 87 - 142
mini/src/pages/index/index.tsx

@@ -1,94 +1,66 @@
 import React, { useState, useEffect } from 'react'
-import { View, Text, ScrollView, Image } from '@tarojs/components'
+import { View, Text, ScrollView } from '@tarojs/components'
 import { TabBarLayout } from '@/layouts/tab-bar-layout'
-import { Carousel } from '@/components/ui/carousel'
-import { Navbar } from '@/components/ui/navbar'
+import TDesignSearch from '@/components/tdesign/search'
+import TDesignSwiper from '@/components/tdesign/swiper'
+import GoodsList, { GoodsData } from '@/components/goods-list'
 import './index.css'
 
-// 商品数据类型定义
-interface GoodsItem {
-  id: string
-  title: string
-  price: number
-  image: string
-  description?: string
-}
-
-// 轮播图数据类型定义
-interface CarouselItem {
-  src: string
-  title?: string
-  description?: string
-  link?: string
-}
-
 const HomePage: React.FC = () => {
-  const [loading, setLoading] = useState(true)
+  const [pageLoading, setPageLoading] = useState(true)
   const [refreshing, setRefreshing] = useState(false)
-  const [goodsList, setGoodsList] = useState<GoodsItem[]>([])
+  const [goodsList, setGoodsList] = useState<GoodsData[]>([])
 
   // 模拟轮播图数据
-  const carouselItems: CarouselItem[] = [
-    {
-      src: 'https://via.placeholder.com/750x400/fa4126/ffffff?text=Banner1',
-      title: '新品上市',
-      description: '精选好物限时优惠'
-    },
-    {
-      src: 'https://via.placeholder.com/750x400/fa550f/ffffff?text=Banner2',
-      title: '限时特惠',
-      description: '全场满减优惠多多'
-    },
-    {
-      src: 'https://via.placeholder.com/750x400/34c759/ffffff?text=Banner3',
-      title: '品质保证',
-      description: '正品保障售后无忧'
-    }
+  const imgSrcs = [
+    'https://via.placeholder.com/750x400/fa4126/ffffff?text=Banner1',
+    'https://via.placeholder.com/750x400/fa550f/ffffff?text=Banner2',
+    'https://via.placeholder.com/750x400/34c759/ffffff?text=Banner3'
   ]
 
   // 模拟商品数据
-  const mockGoodsList: GoodsItem[] = [
+  const mockGoodsList: GoodsData[] = [
     {
       id: '1',
-      title: '高品质T恤 纯棉舒适 多色可选',
-      price: 89.9,
-      image: 'https://via.placeholder.com/300x300/fa4126/ffffff?text=T恤',
-      description: '纯棉材质,舒适透气'
+      name: '高品质T恤 纯棉舒适 多色可选',
+      price: 8990, // 单位:分
+      cover_image: 'https://via.placeholder.com/300x300/fa4126/ffffff?text=T恤',
+      tags: ['热销', '新品']
     },
     {
       id: '2',
-      title: '时尚牛仔裤 修身版型 百搭款式',
-      price: 159.9,
-      image: 'https://via.placeholder.com/300x300/fa550f/ffffff?text=牛仔裤',
-      description: '修身版型,时尚百搭'
+      name: '时尚牛仔裤 修身版型 百搭款式',
+      price: 15990,
+      cover_image: 'https://via.placeholder.com/300x300/fa550f/ffffff?text=牛仔裤',
+      tags: ['热销']
     },
     {
       id: '3',
-      title: '运动鞋 轻便舒适 防滑耐磨',
-      price: 299.9,
-      image: 'https://via.placeholder.com/300x300/34c759/ffffff?text=运动鞋',
-      description: '轻便舒适,防滑耐磨'
+      name: '运动鞋 轻便舒适 防滑耐磨',
+      price: 29990,
+      cover_image: 'https://via.placeholder.com/300x300/34c759/ffffff?text=运动鞋',
+      tags: ['新品']
     },
     {
       id: '4',
-      title: '智能手表 多功能运动健康监测',
-      price: 599.9,
-      image: 'https://via.placeholder.com/300x300/007AFF/ffffff?text=智能手表',
-      description: '多功能运动健康监测'
+      name: '智能手表 多功能运动健康监测',
+      price: 59990,
+      cover_image: 'https://via.placeholder.com/300x300/007AFF/ffffff?text=智能手表',
+      tags: ['热销', '新品']
     },
     {
       id: '5',
-      title: '无线耳机 降噪蓝牙 长续航',
-      price: 399.9,
-      image: 'https://via.placeholder.com/300x300/8E44AD/ffffff?text=无线耳机',
-      description: '降噪蓝牙,长续航'
+      name: '无线耳机 降噪蓝牙 长续航',
+      price: 39990,
+      cover_image: 'https://via.placeholder.com/300x300/8E44AD/ffffff?text=无线耳机',
+      tags: ['热销']
     },
     {
       id: '6',
-      title: '保温杯 304不锈钢 长效保温',
-      price: 129.9,
-      image: 'https://via.placeholder.com/300x300/E74C3C/ffffff?text=保温杯',
-      description: '304不锈钢,长效保温'
+      name: '保温杯 304不锈钢 长效保温',
+      price: 12990,
+      cover_image: 'https://via.placeholder.com/300x300/E74C3C/ffffff?text=保温杯',
+      tags: ['新品']
     }
   ]
 
@@ -96,7 +68,7 @@ const HomePage: React.FC = () => {
   useEffect(() => {
     const timer = setTimeout(() => {
       setGoodsList(mockGoodsList)
-      setLoading(false)
+      setPageLoading(false)
     }, 1000)
 
     return () => clearTimeout(timer)
@@ -110,96 +82,69 @@ const HomePage: React.FC = () => {
     }, 1000)
   }
 
+  // 商品点击
+  const handleGoodsClick = (goods: GoodsData, index: number) => {
+    console.log('点击商品:', goods, index)
+  }
+
   // 添加购物车
-  const handleAddToCart = (goods: GoodsItem) => {
-    console.log('添加到购物车:', goods)
-    // 这里可以添加实际的购物车逻辑
+  const handleAddCart = (goods: GoodsData, index: number) => {
+    console.log('添加到购物车:', goods, index)
   }
 
-  // 轮播图点击
-  const handleCarouselClick = (item: CarouselItem, index: number) => {
-    console.log('点击轮播图:', item, index)
+  // 商品图片点击
+  const handleThumbClick = (goods: GoodsData, index: number) => {
+    console.log('点击商品图片:', goods, index)
+  }
+
+  // 搜索框点击
+  const handleSearchClick = () => {
+    console.log('点击搜索框')
   }
 
   return (
     <TabBarLayout activeKey="home">
-      <Navbar
-        title="首页"
-        rightIcon="i-heroicons-bell-20-solid"
-        onClickRight={() => console.log('点击通知')}
-        leftIcon=""
-      />
-
-      <ScrollView
-        className="homepage-container"
-        scrollY
-        refresherEnabled
-        refresherTriggered={refreshing}
-        onRefresherRefresh={handleRefresh}
-      >
-        {/* 搜索栏 */}
-        <View className="search-container">
-          <View className="search-box disabled">
-            <View className="search-icon i-heroicons-magnifying-glass-20-solid" />
-            <Text className="search-placeholder">搜索商品...</Text>
-          </View>
-        </View>
-
-        {/* 轮播图 */}
-        <View className="carousel-section">
-          <Carousel
-            items={carouselItems}
-            autoplay={true}
-            interval={3000}
-            showIndicators={true}
-            indicatorPosition="bottom"
-            circular={true}
-            imageMode="aspectFill"
-            height={320}
-            rounded="lg"
-            onItemClick={handleCarouselClick}
-            className="carousel-container"
-          />
+      {pageLoading ? (
+        <View style={{ textAlign: 'center', color: '#b9b9b9' }}>
+          <Text>加载中...</Text>
         </View>
-
-        {/* 商品列表 */}
-        <View className="goods-section">
-          {loading ? (
-            <View className="loading-container">
-              <Text className="loading-text">加载中...</Text>
+      ) : (
+        <View>
+          {/* 页面头部 - 搜索栏和轮播图 */}
+          <View className="home-page-header">
+            {/* 搜索栏 */}
+            <View className="search" onClick={handleSearchClick}>
+              <TDesignSearch
+                placeholder="搜索商品..."
+                disabled={true}
+                shape="round"
+              />
             </View>
-          ) : (
-            <View className="goods-grid">
-              {goodsList.map(goods => (
-                <View key={goods.id} className="goods-card">
-                  <Image
-                    src={goods.image}
-                    className="goods-image"
-                    mode="aspectFill"
-                  />
-                  <View className="goods-info">
-                    <Text className="goods-title">{goods.title}</Text>
-                    <Text className="goods-price">¥{goods.price.toFixed(2)}</Text>
-                    <View
-                      className="add-cart-btn"
-                      onClick={() => handleAddToCart(goods)}
-                    >
-                      <Text>加入购物车</Text>
-                    </View>
-                  </View>
-                </View>
-              ))}
+
+            {/* 轮播图 */}
+            <View className="swiper-wrap">
+              {imgSrcs.length > 0 && (
+                <TDesignSwiper
+                  images={imgSrcs}
+                  autoplay={true}
+                  interval={5000}
+                  indicatorDots={true}
+                />
+              )}
             </View>
-          )}
-        </View>
+          </View>
 
-        {/* 下拉刷新指示器 */}
-        {refreshing && (
-          <View className="refresh-indicator">
-            <Text>刷新中...</Text>
+          {/* 页面内容 - 商品列表 */}
+          <View className="home-page-container">
+            <GoodsList
+              goodsList={goodsList}
+              onClick={handleGoodsClick}
+              onAddCart={handleAddCart}
+              onThumbClick={handleThumbClick}
+            />
           </View>
-        )}
-      </ScrollView>
+        </View>
+      )}
     </TabBarLayout>
   )
 }