index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <!-- 使用 type="home" 属性设置首页,其他页面不需要设置,默认为page;推荐使用json5,更强大,且允许注释 -->
  2. <route lang="json5" type="home">
  3. {
  4. layout: 'tabbar',
  5. style: {
  6. // 'custom' 表示开启自定义导航栏,默认 'default'
  7. navigationStyle: 'custom',
  8. },
  9. }
  10. </route>
  11. <script lang="ts" setup>
  12. // 必须导入需要用到的页面生命周期(即使在当前页面上没有直接使用到)(使用页面滚动)
  13. // eslint-disable-next-line unused-imports/no-unused-imports
  14. import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
  15. import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
  16. defineOptions({
  17. name: 'Index', // 首页
  18. })
  19. // 获取屏幕边界到安全区域距离
  20. const systemInfo = uni.getSystemInfoSync()
  21. const safeAreaInsets = systemInfo.safeAreaInsets
  22. // z-paging
  23. const paging = ref(null)
  24. // 类似mixins,如果是页面滚动务必要写这一行,并传入当前ref绑定的paging,注意此处是paging,而非paging.value
  25. useZPaging(paging)
  26. // 搜索
  27. function toSearch() {
  28. uni.navigateTo({
  29. url: '/pages/search/search',
  30. })
  31. }
  32. // 轮播图
  33. const current = ref<number>(0)
  34. const swiperList = ref([
  35. 'https://picsum.photos/750/420?random=1',
  36. 'https://picsum.photos/750/420?random=2',
  37. 'https://picsum.photos/750/420?random=3',
  38. 'https://picsum.photos/750/420?random=4',
  39. ])
  40. function handleClick(e) {
  41. // console.log(e)
  42. }
  43. function onChange(e) {
  44. // console.log(e)
  45. }
  46. // 导航图标
  47. const navIcons = ref([
  48. {
  49. image: '/static/icons/home-vip.png',
  50. title: 'home.missionCenter',
  51. size: '100rpx',
  52. url: '/pages/missionCenter/missionCenter',
  53. },
  54. {
  55. image: '/static/icons/home-vip.png',
  56. title: 'home.refer&earn',
  57. size: '100rpx',
  58. url: '/pages/referEarn/referEarn',
  59. },
  60. {
  61. image: '/static/icons/home-vip.png',
  62. title: 'home.vip',
  63. size: '112rpx',
  64. url: '/pages/vipMembership/vipMembership',
  65. },
  66. {
  67. image: '/static/icons/home-vip.png',
  68. title: 'home.bestSellers',
  69. size: '100rpx',
  70. url: '/pages/bestSellers/bestSellers',
  71. },
  72. {
  73. image: '/static/icons/home-vip.png',
  74. title: 'home.vip',
  75. size: '100rpx',
  76. },
  77. ])
  78. function toPage(url: string) {
  79. if (url) {
  80. uni.navigateTo({
  81. url,
  82. })
  83. }
  84. }
  85. // 新品列表
  86. const newProducts = ref([
  87. {
  88. image: 'https://picsum.photos/260?random=1',
  89. title: 'Chanel Rouge Coco Shine…',
  90. price: '123',
  91. sold: 100,
  92. },
  93. {
  94. image: 'https://picsum.photos/260?random=2',
  95. title: 'Chanel Rouge Coco Shine…',
  96. price: '123',
  97. sold: 100,
  98. },
  99. {
  100. image: 'https://picsum.photos/260?random=3',
  101. title: 'Chanel Rouge Coco Shine…',
  102. price: '123',
  103. sold: 100,
  104. },
  105. {
  106. image: 'https://picsum.photos/260?random=4',
  107. title: 'Chanel Rouge Coco Shine…',
  108. price: '123',
  109. sold: 100,
  110. },
  111. {
  112. image: 'https://picsum.photos/260?random=5',
  113. title: 'Chanel Rouge Coco Shine…',
  114. price: '123',
  115. sold: 100,
  116. },
  117. ])
  118. // 商品列表
  119. const priceTab = ref<number>(0)
  120. // 300Spot 500Spot 1000Spot 2000Spot
  121. const priceTabList = ref([
  122. {
  123. title: '300Spot',
  124. value: 300,
  125. },
  126. {
  127. title: '500Spot',
  128. value: 500,
  129. },
  130. {
  131. title: '1000Spot',
  132. value: 1000,
  133. },
  134. {
  135. title: '2000Spot',
  136. value: 2000,
  137. },
  138. ])
  139. const dataList = ref([])
  140. function queryList(pageNo, pageSize) {
  141. // 此处请求仅为演示,请替换为自己项目中的请求
  142. setTimeout(() => {
  143. dataList.value = [
  144. { title: '123' },
  145. { title: '123' },
  146. { title: '123' },
  147. { title: '12345' },
  148. ]
  149. paging.value.complete(dataList.value)
  150. }, 1000)
  151. }
  152. </script>
  153. <template>
  154. <z-paging ref="paging" refresher-only use-page-scroll @query="queryList">
  155. <template #top>
  156. <view
  157. class="flex items-center justify-between bg-white pb-40rpx pl-42rpx pr-34rpx pt-26rpx"
  158. :style="{ paddingTop: `${safeAreaInsets?.top + 13}px` }"
  159. >
  160. <image src="/static/header-logo.png" class="h-54rpx w-250rpx" />
  161. <view class="flex items-center">
  162. <wd-icon custom-class="mr-20rpx" name="search1" size="38rpx" @click="toSearch" />
  163. <wd-icon name="notification" size="38rpx" />
  164. </view>
  165. </view>
  166. </template>
  167. <wd-swiper
  168. v-model:current="current"
  169. :list="swiperList" autoplay
  170. :indicator="{ type: 'fraction' }"
  171. indicator-position="bottom-right"
  172. @click="handleClick"
  173. @change="onChange"
  174. />
  175. <view class="px-24rpx pb-24rpx">
  176. <view class="flex items-end justify-between pb-22rpx pt-24rpx">
  177. <view v-for="(item, index) in navIcons" :key="index" class="flex flex-col items-center" @click="toPage(item.url)">
  178. <image :src="item.image" :class="[`h-${item.size}`, `w-${item.size}`]" />
  179. <view class="mt-14rpx text-center text-22rpx text-#898989 font-bold">
  180. {{ $t(item.title) }}
  181. </view>
  182. </view>
  183. </view>
  184. <view>
  185. <view class="mb-16rpx text-32rpx">
  186. News
  187. </view>
  188. <scroll-view scroll-x>
  189. <view class="flex items-center gap-22rpx pb-24rpx">
  190. <product v-for="(item, index) in newProducts" :key="index" :item="item" />
  191. </view>
  192. </scroll-view>
  193. </view>
  194. <view>
  195. <wd-tabs v-model="priceTab" :line-width="0" :line-height="0">
  196. <block v-for="item in priceTabList" :key="item">
  197. <wd-tab :title="item.title" />
  198. </block>
  199. </wd-tabs>
  200. <view class="flex flex-wrap gap-22rpx">
  201. <product v-for="(item, index) in newProducts" :key="index" :height="340" :item="item" />
  202. <view />
  203. </view>
  204. </view>
  205. </view>
  206. </z-paging>
  207. </template>
  208. <style>
  209. page {
  210. background: #fff;
  211. }
  212. </style>