EpisodeBox.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="episode-box">
  3. <view class="header-box main-between cross-center">
  4. <text class="title">{{ title }}</text>
  5. <view
  6. v-if="refreshType.indexOf(type) !== -1"
  7. class="refresh main-left cross-center"
  8. @click="handleRefresh"
  9. >
  10. <text>换一批</text>
  11. <view class="icon">
  12. <u-icon name="reload" size="32rpx" bold />
  13. </view>
  14. </view>
  15. </view>
  16. <view
  17. class="container dir-left-wrap"
  18. :class="{
  19. loading: loading,
  20. 'main-center':loading,
  21. 'cross-center': loading
  22. }"
  23. >
  24. <u-loading-icon :show="loading" vertical />
  25. <template v-if="episodes.length && !loading">
  26. <episode
  27. v-for="(episode,index) in episodes"
  28. :key="index"
  29. :episode="episode"
  30. :guess="episode.guess"
  31. :recent="episode.recent"
  32. :rank="episode.rank"
  33. :custom-style="{
  34. marginRight: ((index+1) % 3 !== 0 ? '20rpx' :''),
  35. }"
  36. />
  37. </template>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import Episode from '../../../components/Episode/index'
  43. export default {
  44. name: 'EpisodeBox',
  45. components: { Episode },
  46. props: {
  47. title: {
  48. type: String,
  49. required: true
  50. },
  51. type: {
  52. type: String,
  53. required: true
  54. }
  55. },
  56. data() {
  57. return {
  58. loading: false,
  59. refreshType: ['recommend'],
  60. episodes: []
  61. }
  62. },
  63. computed: {},
  64. created() {
  65. this.handleRefresh()
  66. },
  67. methods: {
  68. getRecommend() {
  69. this.loading = true
  70. this.$api.episode.recommend().then(res => {
  71. this.loading = false
  72. this.episodes = res.data
  73. })
  74. },
  75. getTodayRecommend() {
  76. this.loading = true
  77. this.$api.episode.todayRecommend().then(res => {
  78. this.loading = false
  79. this.episodes = res.data
  80. })
  81. },
  82. getNews() {
  83. this.loading = true
  84. this.$api.episode.news().then(res => {
  85. this.loading = false
  86. this.episodes = res.data
  87. })
  88. },
  89. getRank() {
  90. this.loading = true
  91. this.$api.episode.rank().then(res => {
  92. this.loading = false
  93. this.episodes = res.data
  94. })
  95. },
  96. handleRefresh() {
  97. this.type === 'recommend' && this.getRecommend()
  98. this.type === 'todayRecommend' && this.getTodayRecommend()
  99. this.type === 'news' && this.getNews()
  100. this.type === 'rank' && this.getRank()
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. .episode-box {
  107. margin-top: 30rpx;
  108. .header-box{
  109. .title{
  110. font-size: 32rpx;
  111. color: #ffffff;
  112. }
  113. .refresh{
  114. text{
  115. color: $info-color;
  116. font-size: 24rpx;
  117. line-height: 22rpx;
  118. margin-right: 4rpx;
  119. }
  120. }
  121. }
  122. .container{
  123. margin-top: 30rpx;
  124. min-height: 458rpx;
  125. &.loading{
  126. }
  127. }
  128. }
  129. </style>