普兆健康管家前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
4.5 KiB

  1. <template>
  2. <view>
  3. <swiper
  4. class="swiper"
  5. :current="current"
  6. :autoplay="autoplay"
  7. @change="onChange"
  8. >
  9. <swiper-item v-for="item in list" :key="item.id">
  10. <view class="swiper-item">
  11. <view class="swiper-item-content">
  12. <image class="bg" :src="item.imageUrl" mode="aspectFill"></image>
  13. <view class="content">
  14. <!-- <view class="flex flex-column">
  15. <view
  16. v-for="(line, lIdx) in item.arr"
  17. :key="lIdx"
  18. :class="line.class"
  19. >
  20. {{ line.text }}
  21. </view>
  22. </view> -->
  23. <view class="btns">
  24. <button class="btn btn-left flex" @click="jumpToProduct">
  25. 全部产品
  26. </button>
  27. <button class="btn btn-right flex" :style="{ background: item.color }" @click="jumpToReport">
  28. 定制健康档案
  29. </button>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </swiper-item>
  35. </swiper>
  36. <indicator :current="current" :length="list.length" @click="current = $event"></indicator>
  37. </view>
  38. </template>
  39. <script>
  40. import indicator from '@/components/home/indicator.vue'
  41. export default {
  42. components: {
  43. indicator,
  44. },
  45. data() {
  46. return {
  47. current: 0,
  48. list: [],
  49. last: null,
  50. autoplay: true,
  51. }
  52. },
  53. created() {
  54. this.getData()
  55. },
  56. methods: {
  57. async getData() {
  58. try {
  59. this.list = await this.$fetch('getBanner')
  60. } catch (err) {
  61. }
  62. },
  63. jumpToProduct() {
  64. uni.navigateTo({
  65. url: '/pages/index/product'
  66. })
  67. },
  68. jumpToReport() {
  69. uni.navigateTo({
  70. url: '/pages/index/report'
  71. })
  72. },
  73. onChange(e) {
  74. this.current = e.detail.current
  75. const currentTime = this.$dayjs()
  76. if (this.last) {
  77. const diff = currentTime.diff(this.last, 'millisecond')
  78. console.log('diff', diff, e.detail.source)
  79. if (diff < 2500 && e.detail.source === 'autoplay') {
  80. console.log('autoplay abnormal')
  81. this.autoplay = false
  82. setTimeout(() => {
  83. console.log('autoplay restart')
  84. this.autoplay = true
  85. }, 3000 - diff)
  86. }
  87. }
  88. this.last = currentTime
  89. },
  90. },
  91. }
  92. </script>
  93. <style scoped lang="scss">
  94. .swiper {
  95. width: 100vw;
  96. height: calc(100vw * 578 / 375);
  97. &-item {
  98. width: 100%;
  99. height: 100%;
  100. padding: 10rpx 32rpx 40rpx 32rpx;
  101. box-sizing: border-box;
  102. &-content {
  103. position: relative;
  104. width: 100%;
  105. height: 100%;
  106. border-radius: 64rpx;
  107. box-shadow: -5rpx -5rpx 10rpx 0 #FFFFFF,
  108. 10rpx 10rpx 20rpx 0 #AAAACC80,
  109. 4rpx 4rpx 10rpx 0 #AAAACC40,
  110. -2rpx -2rpx 5rpx 0 #FFFFFF;
  111. }
  112. .bg {
  113. width: 100%;
  114. height: 100%;
  115. border-radius: 64rpx;
  116. }
  117. .content {
  118. position: absolute;
  119. bottom: 0;
  120. width: 100%;
  121. // height: 592rpx;
  122. padding: 170rpx 60rpx 80rpx 60rpx;
  123. box-sizing: border-box;
  124. background-image: linear-gradient(#FFFFFF00, #FFFFFF);
  125. border-radius: 64rpx;
  126. }
  127. .font1 {
  128. font-size: 48rpx;
  129. font-weight: 600;
  130. line-height: 1.4;
  131. font-family: PingFang SC;
  132. color: #252545;
  133. }
  134. .font2 {
  135. font-size: 48rpx;
  136. font-weight: 600;
  137. line-height: 1.4;
  138. font-family: PingFang SC;
  139. color: transparent;
  140. background-image: linear-gradient(to right, #4B348F, #845CFA);
  141. background-clip: text;
  142. display: inline-block;
  143. }
  144. .font3 {
  145. font-size: 32rpx;
  146. font-weight: 400;
  147. line-height: 1.4;
  148. font-family: PingFang SC;
  149. color: #252545;
  150. }
  151. .btns {
  152. margin-top: 72rpx;
  153. display: flex;
  154. justify-content: space-between;
  155. .btn {
  156. width: 264rpx;
  157. box-sizing: border-box;
  158. font-size: 30rpx;
  159. font-family: PingFang SC;
  160. line-height: 1.4;
  161. border-radius: 45rpx;
  162. &-left {
  163. padding: 23rpx 0;
  164. font-weight: 400;
  165. color: #252545;
  166. border: 1rpx solid #252545;
  167. }
  168. &-right {
  169. padding: 24rpx 0;
  170. font-weight: 600;
  171. color: #FFFFFF;
  172. // background-image: linear-gradient(to right, #4B348F, #845CFA);
  173. }
  174. }
  175. }
  176. }
  177. }
  178. </style>