course.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="center">
  3. <view class="english">various courses for children</view>
  4. <scroll-view scroll-y="true" class="list">
  5. <view v-for="(item,index) in courseList" :key="index" class="listBox">
  6. <view class="bg"></view>
  7. <view class="title">{{ item.title}}</view>
  8. <view class="teacher">{{ item.teacher }}</view>
  9. <view class="bzr">{{ item.bzr }}</view>
  10. <view class="button">上传作业</view>
  11. </view>
  12. </scroll-view>
  13. </view>
  14. </template>
  15. <script>
  16. import getCourse from '@/api/course.js'
  17. export default {
  18. data() {
  19. return {
  20. page: 1,
  21. limit: 10,
  22. loadingType: 'more',
  23. courseList: [
  24. ],
  25. }
  26. },
  27. onShow() {
  28. this.loadData();
  29. },
  30. //下拉刷新
  31. onPullDownRefresh() {
  32. this.loadData('refresh');
  33. },
  34. //监听页面是否滚动到底部加载更多
  35. onReachBottom() {
  36. this.loadData();
  37. },
  38. methods: {
  39. async loadData(type = 'add', loading) {
  40. let obj = this;
  41. if (type === 'add') {
  42. if (obj.loadingType === 'nomore') {
  43. return;
  44. }
  45. obj.loadingType = 'loading';
  46. } else {
  47. obj.loadingType = 'more';
  48. }
  49. if (type === 'refresh') {
  50. // 清空数组
  51. obj.courseList = [];
  52. obj.page = 1
  53. }
  54. //获取课程
  55. getCourse({
  56. page: obj.page,
  57. limit: obj.limit
  58. }).then(e => {
  59. obj.courseList = obj.courseList.concat(e.data);
  60. //判断是否还有下一页,有是more 没有是nomore
  61. if (obj.limit==e.data.length) {
  62. obj.page++
  63. obj.loadingType='more'
  64. } else{
  65. obj.loadingType='nomore'
  66. }
  67. if (type === 'refresh') {
  68. if (loading == 1) {
  69. uni.hideLoading();
  70. } else {
  71. uni.stopPullDownRefresh();
  72. }
  73. }
  74. })
  75. }
  76. }
  77. }
  78. </script>
  79. <style lang="scss">
  80. page,
  81. .center {
  82. width: 100%;
  83. height: 100%;
  84. background-color: #f8f8f8;
  85. }
  86. .english {
  87. padding-left: 41rpx;
  88. font-size: 25rpx;
  89. font-family: Source Han Sans CN;
  90. font-weight: 400;
  91. color: #C2C2C2;
  92. }
  93. .list {
  94. height: calc(100%-400px);
  95. }
  96. .listBox {
  97. position: relative;
  98. width: 90%;
  99. height: 250rpx;
  100. margin: 0 auto;
  101. margin-top: 34rpx;
  102. box-shadow: 0rpx 5rpx 16rpx 0rpx rgba(253, 90, 84, 0.48);
  103. border-radius: 28rpx;
  104. .bg {
  105. width: 100%;
  106. height: 100%;
  107. position: absolute;
  108. left: 0;
  109. top: 0;
  110. background-color: #4EADFA;;
  111. border-radius: 28rpx;
  112. }
  113. .title {
  114. position: relative;
  115. padding-top: 36rpx;
  116. padding-left: 36rpx;
  117. font-size: 36rpx;
  118. font-weight: bold;
  119. color: #FFFFFF;
  120. z-index: 1;
  121. }
  122. .teacher {
  123. position: relative;
  124. margin-top: 56rpx;
  125. margin-left: 36rpx;
  126. font-size: 24rpx;
  127. font-weight: 500;
  128. color: #FFFFFF;
  129. z-index: 1;
  130. }
  131. .bzr {
  132. position: relative;
  133. margin-left: 36rpx;
  134. font-size: 24rpx;
  135. font-weight: 500;
  136. color: #FFFFFF;
  137. z-index: 1;
  138. }
  139. .button {
  140. position: absolute;
  141. right: 26rpx;
  142. bottom: 35rpx;
  143. width: 160rpx;
  144. height: 57rpx;
  145. background: #FFFFFF;
  146. border-radius: 28rpx;
  147. text-align: center;
  148. line-height: 57rpx;
  149. font-size: 27rpx;
  150. font-weight: bold;
  151. color: #FD5954;
  152. }
  153. }
  154. </style>