index.jsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import Taro from "@tarojs/taro"; // 导入 Taro
  2. import { Component } from "react";
  3. import { View, Image, Swiper, SwiperItem, Text } from "@tarojs/components";
  4. import { AtTabs } from "taro-ui";
  5. import "./index.less";
  6. import SearchBar from "../../components/index/SearchBar"; //搜索框
  7. import CategoryList from "../../components/index/CategoryList"; //分类列表
  8. import OperationArea from "../../components/index/OperationArea"; //运营区域
  9. import RecommendList from "../../components/index/RecommendList"; //邀请人推荐
  10. import ProductList from "../../components/index/ProductList"; //商品列表
  11. import myStoreIcon from "../../images/index/myStore.png";
  12. import backTopIcon from "../../images/index/back-top.png";
  13. export default class Index extends Component {
  14. state = {
  15. value: "",
  16. current: 0, // 添加当前选中的tab索引
  17. tabList: [
  18. // 添加模拟的tab数据
  19. { title: "推荐" },
  20. { title: "男装" },
  21. { title: "女装" },
  22. { title: "运动" },
  23. { title: "数码" },
  24. { title: "美妆" },
  25. { title: "箱包" },
  26. { title: "家居" },
  27. { title: "食品" },
  28. { title: "母婴" },
  29. ],
  30. bannerList: [
  31. {
  32. id: 1,
  33. img: "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1saL6x.img?w=768&h=411&m=6",
  34. },
  35. {
  36. id: 2,
  37. img: "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1saL6x.img?w=768&h=411&m=6",
  38. },
  39. {
  40. id: 3,
  41. img: "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1saL6x.img?w=768&h=411&m=6",
  42. },
  43. ],
  44. categoryList: [
  45. { id: 1, icon: "购物袋图标URL", name: "超市" },
  46. { id: 2, icon: "手机图标URL", name: "数码" },
  47. { id: 3, icon: "衣服图标URL", name: "服饰" },
  48. { id: 4, icon: "生鲜图标URL", name: "生鲜" },
  49. { id: 5, icon: "美妆图标URL", name: "美妆" },
  50. { id: 6, icon: "家电图标URL", name: "家电" },
  51. { id: 7, icon: "餐具图标URL", name: "餐厨" },
  52. { id: 8, icon: "书本图标URL", name: "图书" },
  53. { id: 9, icon: "药品图标URL", name: "医药" },
  54. { id: 10, icon: "更多图标URL", name: "更多" },
  55. ],
  56. };
  57. handleChange(value) {
  58. this.setState({ value });
  59. }
  60. // 添加tab切换处理函数
  61. handleClick(value) {
  62. this.setState({
  63. current: value,
  64. });
  65. }
  66. componentDidMount() {}
  67. componentWillUnmount() {}
  68. componentDidShow() {}
  69. componentDidHide() {}
  70. // 添加回到顶部方法
  71. handleBackTop = () => {
  72. Taro.pageScrollTo({
  73. scrollTop: 0,
  74. duration: 300,
  75. });
  76. };
  77. render() {
  78. return (
  79. <View className="index">
  80. <View
  81. className="header"
  82. style={{ paddingTop: Taro.navigationBarHeight + "px" }}
  83. >
  84. <View className="header-content">
  85. <Image
  86. className="header-img"
  87. src="https://video-img.fyshark.com/1731495433480WechatIMG674.jpg"
  88. />
  89. </View>
  90. {/* 搜索框 */}
  91. <SearchBar
  92. value={this.state.value}
  93. onChange={this.handleChange}
  94. onSearch={this.handleSearch}
  95. />
  96. {/* tab分类 */}
  97. <View className="tabs-list">
  98. <AtTabs
  99. current={this.state.current}
  100. scroll
  101. tabList={this.state.tabList}
  102. onClick={this.handleClick.bind(this)}
  103. />
  104. <View className="tab-more">
  105. <Image className="tab-more-img" />
  106. </View>
  107. </View>
  108. {/* 轮播图 */}
  109. <View className="banner-wrap">
  110. <Swiper
  111. className="banner-swiper"
  112. circular
  113. autoplay
  114. indicatorDots
  115. indicatorColor="#e8e8e8"
  116. indicatorActiveColor="#ffffff"
  117. >
  118. {this.state.bannerList.map((item) => (
  119. <SwiperItem className="banner-item" key={item.id}>
  120. <Image
  121. className="banner-img"
  122. src={item.img}
  123. mode="aspectFill"
  124. />
  125. </SwiperItem>
  126. ))}
  127. </Swiper>
  128. </View>
  129. </View>
  130. {/* 分类列表组件 */}
  131. <CategoryList categoryList={this.state.categoryList} />
  132. {/* 运营区域 */}
  133. <OperationArea />
  134. {/* 邀请人推荐 */}
  135. <RecommendList />
  136. {/* 商品列表 */}
  137. <ProductList />
  138. {/* 添加浮动按钮 */}
  139. <View className="float-buttons">
  140. <View
  141. className="float-btn"
  142. >
  143. <Image
  144. className="my-shop-bg"
  145. src={myStoreIcon}
  146. mode="aspectFit"
  147. />
  148. <Text>我的{"\n"}小店</Text>
  149. </View>
  150. <View
  151. className="float-btn"
  152. onClick={this.handleBackTop}
  153. >
  154. <Image
  155. className="back-top"
  156. src={backTopIcon}
  157. mode="aspectFit"
  158. />
  159. </View>
  160. </View>
  161. </View>
  162. );
  163. }
  164. }