index.vue 4.1 KB

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