Course.vue 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="Course-box">
  3. <div class="banner-box-top mglr-10" >
  4. <van-swipe class="banner-swipe" :autoplay="3000" @change="i => currentItem = i" :show-indicators="false">
  5. <van-swipe-item v-for="(image, index) in HomeBannerImages" :key="index">
  6. <ration-div :ratio="0.6">
  7. <van-image width="100%" height="100%" :src="image.thumb" />
  8. </ration-div>
  9. </van-swipe-item>
  10. </van-swipe>
  11. <div class="custom-indicator">
  12. <span v-for="(_, index) in HomeBannerImages" :key="index" :class="{'active': currentItem === index }"></span>
  13. </div>
  14. </div>
  15. <!-- list -->
  16. <van-list class="mglr-10 course-list" v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
  17. <course-card
  18. v-for="item in courseList"
  19. :key="item.courseId"
  20. v-bind="item"
  21. @click.native="$router.push({ name: 'ClassInfo', query: { courseId: item.courseId } })"
  22. ></course-card>
  23. </van-list>
  24. </div>
  25. </template>
  26. <script>
  27. import { parseTime } from '@/util/formattingData'
  28. import { getBanner, getCourse } from '@/util/api'
  29. export default {
  30. components: {
  31. RationDiv: () => import('@/components/RatioDiv/index.vue'),
  32. CourseCard: () => import('./components/CourseCard.vue')
  33. },
  34. data() {
  35. return {
  36. currentItem: -1,
  37. icon: require('@/assets/icon/courseIcon.svg'),
  38. loading: false,
  39. finished: true,
  40. currentPage: 1,
  41. pageSize: 10,
  42. courseList: [],
  43. HomeBannerImages: []
  44. }
  45. },
  46. mounted() {
  47. this.onBanner()
  48. this.kecheng()
  49. },
  50. methods: {
  51. goQuestion(courseId) {
  52. this.$router.push({ name: 'ClassInfo', params: { courseId: courseId } })
  53. // this.$router.push('/Questionnaire')
  54. },
  55. parseTime, //时间格式化
  56. kecheng() {
  57. getCourse().then((e) => {
  58. // console.log(parseTime(aTime, '{y}年{m}月{d}日 {h}:{i}'))
  59. this.courseList = e.records
  60. console.log('----------courseList--------------', this.courseList)
  61. })
  62. },
  63. onBanner() {
  64. getBanner('Training').then((e) => {
  65. this.HomeBannerImages = e.records
  66. console.log(e)
  67. })
  68. },
  69. onLoad() {
  70. // 异步更新数据
  71. let params = {
  72. // type: this.selectedType,
  73. index: this.currentPage, //页数
  74. size: this.pageSize //每页个数
  75. }
  76. // xxxxxxx(params).then((res) => {
  77. // console.log(res)
  78. // this.dataTotal = res.total
  79. // //进行判断
  80. // if (this.dataTotal <= this.pageSize) {
  81. // this.Array = res.data.list
  82. // console.log(this.Array)
  83. // } else {
  84. // this.currentPage++
  85. // let arr = res.data.data.list
  86. // this.Array = this.Array.concat(arr)
  87. // }
  88. // // 加载状态结束
  89. // this.loading = false
  90. // // 数据全部加载完成
  91. // if (this.Array.length >= this.dataTotal) {
  92. // this.finished = true //结束,显示我也是有底线的
  93. // }
  94. // })
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="less" scoped>
  100. .mglr-10 {
  101. margin-left: 10px;
  102. margin-right: 10px;
  103. }
  104. .Course-box {
  105. width: 100vw;
  106. padding-top: 10px;
  107. .banner-box-top {
  108. position: relative;
  109. width: calc(100% - 20px);
  110. .banner-swipe {
  111. border-radius: 6px;
  112. box-shadow: 0 0 6px 6px rgba(0, 0, 0, 0.12);
  113. }
  114. }
  115. .course-list {
  116. margin-top: 10vw;
  117. }
  118. .custom-indicator {
  119. position: absolute;
  120. width: 100%;
  121. text-align: center;
  122. left: 0;
  123. right: 0;
  124. z-index: 10;
  125. & > span {
  126. display: inline-block;
  127. width: 1em;
  128. height: 2px;
  129. background: rgba(0, 0, 0, 0.2);
  130. & + span {
  131. margin-left: .2em;
  132. }
  133. }
  134. .active {
  135. background: rgba(0, 0, 0, .65);
  136. }
  137. }
  138. }
  139. </style>