EpisodeBox.vue 2.8 KB

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