普兆健康管家前端代码仓库
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.

201 lines
4.6 KiB

  1. <template>
  2. <view>
  3. <swiper
  4. class="swiper"
  5. :current="current"
  6. :autoplay="autoplay"
  7. :display-multiple-items="1.5"
  8. @change="onChange"
  9. >
  10. <swiper-item v-for="item in list" :key="item.id" style="display: inline-block;">
  11. <view class="swiper-item">
  12. <view class="swiper-item-content">
  13. <image class="img" :src="item.image" mode="widthFix"></image>
  14. <view class="content">
  15. <view>
  16. <view
  17. v-for="(line, lIdx) in item.arr"
  18. :key="lIdx"
  19. :class="line.class"
  20. >
  21. {{ line.text }}
  22. </view>
  23. </view>
  24. <button class="btn flex" @click="jumpToTest(item.paperId)">
  25. <image class="btn-icon" src="@/pages_order/static/index/btn-icon.png" mode="widthFix"></image>
  26. <text>{{ item.btnTxt }}</text>
  27. </button>
  28. </view>
  29. </view>
  30. </view>
  31. </swiper-item>
  32. <swiper-item style="display: inline-block;">
  33. <view class="swiper-item"></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. let result = await this.$fetch('getPersonalized')
  60. this.list = result.map(item => {
  61. const { id, title, subTitle, info, image, btnTxt, paperId } = item
  62. return {
  63. id,
  64. image,
  65. arr: [
  66. { text: title, class: 'font1' },
  67. { text: subTitle, class: 'font2' },
  68. { text: info, class: 'font3' },
  69. ],
  70. btnTxt,
  71. paperId,
  72. }
  73. })
  74. } catch (err) {
  75. }
  76. },
  77. jumpToTest(paperId) {
  78. this.$utils.navigateTo(`/pages_order/report/test/intro?id=${paperId}`)
  79. },
  80. onChange(e) {
  81. this.current = e.detail.current
  82. const currentTime = this.$dayjs()
  83. if (this.last) {
  84. const diff = currentTime.diff(this.last, 'millisecond')
  85. console.log('diff', diff, e.detail.source)
  86. if (diff < 2500 && e.detail.source === 'autoplay') {
  87. console.log('autoplay abnormal')
  88. this.autoplay = false
  89. setTimeout(() => {
  90. console.log('autoplay restart')
  91. this.autoplay = true
  92. }, 3000 - diff)
  93. }
  94. }
  95. this.last = currentTime
  96. }
  97. },
  98. }
  99. </script>
  100. <style scoped lang="scss">
  101. .swiper {
  102. width: 100vw;
  103. height: 320rpx;
  104. padding-left: 22rpx;
  105. &-item {
  106. width: 512rpx;
  107. height: 320rpx;
  108. padding: 24rpx 30rpx 40rpx 10rpx;
  109. box-sizing: border-box;
  110. &-content {
  111. position: relative;
  112. width: 100%;
  113. height: 100%;
  114. padding: 12rpx;
  115. box-sizing: border-box;
  116. border-radius: 32rpx;
  117. background-image: linear-gradient(#FAFAFF, #F3F3F3);
  118. box-shadow: -5rpx -5rpx 10rpx 0 #FFFFFF,
  119. 10rpx 10rpx 20rpx 0 #AAAACC80,
  120. 4rpx 4rpx 10rpx 0 #AAAACC40,
  121. -2rpx -2rpx 5rpx 0 #FFFFFF;
  122. .img {
  123. position: absolute;
  124. right: 24rpx;
  125. bottom: 24rpx;
  126. width: 200rpx;
  127. height: auto;
  128. }
  129. .content {
  130. position: absolute;
  131. left: 0;
  132. top: 0;
  133. width: 100%;
  134. height: 100%;
  135. padding: 24rpx;
  136. box-sizing: border-box;
  137. .font1 {
  138. font-size: 30rpx;
  139. font-weight: 600;
  140. line-height: 1.4;
  141. font-family: PingFang SC;
  142. color: #252545;
  143. }
  144. .font2 {
  145. font-size: 26rpx;
  146. font-weight: 400;
  147. line-height: 1.4;
  148. font-family: PingFang SC;
  149. color: #989898;
  150. }
  151. .font3 {
  152. font-size: 24rpx;
  153. font-weight: 400;
  154. line-height: 1.4;
  155. font-family: PingFang SC;
  156. color: #252545;
  157. }
  158. .btn {
  159. margin-top: 32rpx;
  160. display: inline-flex;
  161. padding: 14rpx 24rpx;
  162. font-size: 24rpx;
  163. font-family: PingFang SC;
  164. font-weight: 400;
  165. line-height: 1.4;
  166. color: #252545;
  167. border: 1rpx solid #252545;
  168. border-radius: 28rpx;
  169. &-icon {
  170. width: 28rpx;
  171. height: 28rpx;
  172. margin-right: 8rpx;
  173. }
  174. }
  175. }
  176. }
  177. }
  178. }
  179. </style>