Index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <main>
  3. <div class="bg">
  4. <img src="@/assets/index/bg.gif" />
  5. <img src="@/assets/index/bg.png" />
  6. </div>
  7. <section>
  8. <header>
  9. <p>
  10. 欢迎使用<b>{{ title }}</b>
  11. </p>
  12. <div>{{ desc }}</div>
  13. </header>
  14. <div class="swiper-main">
  15. <div :class="{ prev: true, disabled: page === 0 }" @click="goPrev">
  16. <icon-left />
  17. </div>
  18. <swiper
  19. class="the-swiper-wrap"
  20. :slides-per-group="number"
  21. :slides-per-view="number"
  22. :space-between="10"
  23. @swiper="onSwiper"
  24. >
  25. <swiper-slide v-for="(item, key) in slider" :key="key" width="230">
  26. <div
  27. class="swiper-item"
  28. @mouseover="onMouseover(key)"
  29. @mouseleave="onMouseleave"
  30. @click="handleClick(key)"
  31. >
  32. <div>
  33. <img :src="getAssetURL(item.img)" width="48" />
  34. <p>{{ item.title }}</p>
  35. </div>
  36. </div>
  37. </swiper-slide>
  38. </swiper>
  39. <div :class="{ next: true, disabled: page === pages - 1 }" @click="goNext">
  40. <icon-right />
  41. </div>
  42. </div>
  43. </section>
  44. </main>
  45. </template>
  46. <script>
  47. import { defineComponent, inject, onMounted, ref } from "vue";
  48. import { Swiper, SwiperSlide } from "swiper/vue";
  49. import "swiper/css";
  50. export default defineComponent({
  51. props: ["number"],
  52. components: {
  53. Swiper,
  54. SwiperSlide
  55. },
  56. setup(props, { emit }) {
  57. const { helper, config } = inject("$global");
  58. let useSwiper = null;
  59. let page = ref(0);
  60. const title = ref(config.defaultTitle);
  61. const desc = ref(config.defaultDesc);
  62. const pages = ref(Math.ceil(config.slider.length / props.number));
  63. const onSwiper = (swiper) => {
  64. useSwiper = swiper;
  65. };
  66. const goNext = () => {
  67. if (page.value === pages.value - 1) return;
  68. page.value += 1;
  69. useSwiper.slideTo(props.number * page.value);
  70. };
  71. const goPrev = () => {
  72. if (page.value === 0) return;
  73. page.value -= 1;
  74. useSwiper.slideTo(props.number * page.value);
  75. };
  76. const onMouseover = (key) => {
  77. title.value = config.slider[key].title;
  78. desc.value = config.slider[key].desc;
  79. };
  80. const onMouseleave = () => {
  81. title.value = config.defaultTitle;
  82. desc.value = config.defaultDesc;
  83. };
  84. const handleClick = (index) => {
  85. emit("select-nav", index);
  86. };
  87. return {
  88. onSwiper,
  89. getAssetURL: helper.getAssetURL,
  90. slider: config.slider,
  91. goNext,
  92. goPrev,
  93. page,
  94. pages,
  95. onMouseover,
  96. onMouseleave,
  97. title,
  98. desc,
  99. handleClick
  100. };
  101. }
  102. });
  103. </script>
  104. <style lang="scss" scoped>
  105. main {
  106. width: 100%;
  107. height: 100%;
  108. position: relative;
  109. overflow: hidden;
  110. > section {
  111. padding-top: 67px;
  112. position: relative;
  113. z-index: 2;
  114. margin: 0 auto;
  115. width: 85%;
  116. > header {
  117. text-align: center;
  118. color: #fff;
  119. > p {
  120. font-size: 40px;
  121. }
  122. > div {
  123. margin-top: 10px;
  124. font-size: 20px;
  125. }
  126. }
  127. .swiper-main {
  128. position: relative;
  129. height: 90px;
  130. margin-top: 40px;
  131. .prev,
  132. .next {
  133. position: absolute;
  134. width: 40px;
  135. height: 40px;
  136. border-radius: 20px;
  137. display: flex;
  138. justify-content: center;
  139. align-items: center;
  140. background: #fff;
  141. top: 25px;
  142. cursor: pointer;
  143. &:hover {
  144. opacity: 0.8;
  145. }
  146. &.disabled {
  147. cursor: not-allowed;
  148. &:hover {
  149. opacity: 1;
  150. }
  151. }
  152. }
  153. .prev {
  154. left: -20px;
  155. }
  156. .next {
  157. right: -20px;
  158. }
  159. .the-swiper-wrap {
  160. position: absolute;
  161. top: 0;
  162. left: 30px;
  163. right: 30px;
  164. overflow: hidden;
  165. .swiper-item {
  166. width: 230px;
  167. height: 90px;
  168. background: #fff;
  169. border-radius: 12px;
  170. display: flex;
  171. justify-content: center;
  172. align-items: center;
  173. cursor: pointer;
  174. &:hover {
  175. background: #00aea3;
  176. > div > p {
  177. color: #fff;
  178. }
  179. }
  180. > div {
  181. display: flex;
  182. align-items: center;
  183. > p {
  184. font-weight: 600;
  185. color: #000;
  186. margin-left: 12px;
  187. font-size: 18px;
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }
  194. }
  195. .bg {
  196. position: absolute;
  197. top: 0;
  198. left: 0;
  199. right: 0;
  200. bottom: 0;
  201. background-color: #f8f9fc;
  202. display: flex;
  203. flex-direction: column;
  204. overflow: hidden;
  205. z-index: 1;
  206. }
  207. </style>