index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div class="com-main">
  3. <carousel
  4. v-if="indexBanner.length"
  5. :banner="indexBanner"
  6. :height="'538px'"></carousel>
  7. <sub-nav :secondaryBanner="secondaryBanner"></sub-nav>
  8. <section class="com-width-1200 com-margin-auto">
  9. <pc-title :title="'Trending Products'"></pc-title>
  10. <div class="card-wrap com-margin-auto">
  11. <card
  12. v-for="(item, k) in indexGoodsRankLists"
  13. :key="k"
  14. :cardData="item"
  15. ref="card"
  16. @addCompare="addCompareList"></card>
  17. <transition
  18. @before-enter="beforeEnter"
  19. @enter="enter"
  20. @after-enter="afterEnter">
  21. <div
  22. class="ball"
  23. v-show="shopCarBall"
  24. ref="ball">
  25. <div class="linner_ball"></div>
  26. </div>
  27. </transition>
  28. </div>
  29. </section>
  30. <a
  31. :href="midBanner[0]?.link"
  32. target="_target"
  33. v-if="midBanner.length">
  34. <el-image
  35. lazy
  36. :src="midBanner[0]?.image"
  37. alt="why choose us"
  38. class="middle_banner"
  39. fit="cover"></el-image>
  40. </a>
  41. <section class="com-width-1400 com-margin-auto row-card">
  42. <row-card
  43. v-for="(item, k) in articleList"
  44. :key="k"
  45. :data="item"></row-card>
  46. <!-- <subscription></subscription> -->
  47. </section>
  48. </div>
  49. </template>
  50. <script>
  51. export default {
  52. name: 'IndexPage',
  53. layout: 'default',
  54. async asyncData({ $axios, req }) {
  55. // type:1、首页顶部banner,2、首页小图推荐,3、中部banner,4、,5、推荐文章栏目,6、底部banner,7、社交链接
  56. const indexBanner = await $axios.post('home/indexBanner', {
  57. site: 1,
  58. type: 1,
  59. })
  60. const secondaryBanner = await $axios.post('home/indexBanner', {
  61. site: 1,
  62. type: 2,
  63. })
  64. const indexGoodsRankLists = await $axios.post('home/indexGoodsRankLists', {
  65. site: 1,
  66. })
  67. const midBanner = await $axios.post('home/indexBanner', {
  68. site: 1,
  69. type: 3,
  70. })
  71. const articleList = await $axios.post('home/indexBanner', {
  72. site: 1,
  73. type: 5,
  74. })
  75. return {
  76. indexBanner: indexBanner.result.data,
  77. secondaryBanner: secondaryBanner.result.data,
  78. indexGoodsRankLists: indexGoodsRankLists.result,
  79. midBanner: midBanner.result.data,
  80. articleList: articleList.result.data,
  81. }
  82. },
  83. data() {
  84. return {
  85. indexBanner: [],
  86. secondaryBanner: [],
  87. indexGoodsRankLists: [],
  88. midBanner: [],
  89. articleList: [],
  90. shopCarBall: false,
  91. shopCarBallEl: null,
  92. ss: null,
  93. }
  94. },
  95. created() {},
  96. methods: {
  97. addCompareList(target) {
  98. this.shopCarBallEl = target
  99. this.shopCarBall = true
  100. },
  101. // 动画开始
  102. beforeEnter(el) {
  103. // 获取元素的大小及其相对于视口的位置
  104. if (process.client) {
  105. const dom = this.shopCarBallEl.getBoundingClientRect()
  106. const comparePosition = document
  107. .querySelector('.compare-list')
  108. .getBoundingClientRect()
  109. const offsetX = comparePosition.left - dom.left
  110. const offsetY = dom.top - comparePosition.top - 20
  111. el.style.display = ''
  112. // y轴是曲直向上的,x轴是蜿蜒的向右的
  113. el.style.transform = `translate3D( -${offsetX}px,${offsetY}px,0)`
  114. }
  115. },
  116. enter(el, done) {
  117. // 触发重绘,来实现动画的移动过程
  118. if (process.client) {
  119. this.ss = document.body.offsetHeight
  120. el.style.transform = `translate3D( 0,0,0)`
  121. el.addEventListener('transitionend', done)
  122. }
  123. },
  124. afterEnter(el) {
  125. this.shopCarBall = false
  126. el.style.display = 'none'
  127. },
  128. },
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .card-wrap {
  133. display: grid;
  134. justify-items: center;
  135. justify-content: space-evenly;
  136. // grid-template-columns: repeat(5,1fr);
  137. }
  138. .middle_banner {
  139. width: 100%;
  140. height: 580px;
  141. margin: 0 0 30px;
  142. }
  143. .ball {
  144. position: fixed;
  145. top: 86px;
  146. right: 19%;
  147. width: 20px;
  148. height: 20px;
  149. border-radius: 50%;
  150. background: #e90000;
  151. transition: all 0.5s linear;
  152. z-index: 9999;
  153. .linner_ball {
  154. transition: all 0.5s linear;
  155. }
  156. }
  157. </style>