AudioPage.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <el-row class="movie-list">
  3. <el-col :md="12">
  4. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  5. <el-card class="box-card">
  6. <div slot="header" class="clearfix">
  7. <el-row>
  8. <span v-html="audio.title" />
  9. </el-row>
  10. </div>
  11. <div class="text item">
  12. <el-row>
  13. <audio-player
  14. ref="audioPlayer"
  15. :show-prev-button="false"
  16. :show-next-button="false"
  17. :show-playback-rate="false"
  18. :audio-list="audioList.map(elm => elm.url)"
  19. :before-play="handleBeforePlay"
  20. theme-color="#87CEFA"
  21. />
  22. </el-row>
  23. <el-divider v-if="audio.description !== undefined && audio.description !== null"/>
  24. <el-row>
  25. <span v-html="audio.description" />
  26. </el-row>
  27. <el-divider/>
  28. <el-row>
  29. 发布于 <span v-html="audio.pubDate" />
  30. </el-row>
  31. <el-divider/>
  32. <el-row>
  33. <span>
  34. <span>
  35. <i :class=collectedIcon @click="collectItem"/>
  36. </span>
  37. </span>
  38. </el-row>
  39. </div>
  40. </el-card>
  41. </el-row>
  42. </el-col>
  43. <el-col :md="6">
  44. <user-avatar-card :userAvatar="user" />
  45. </el-col>
  46. </el-row>
  47. </template>
  48. <script>
  49. import UserAvatarCard from '@/components/card/UserAvatarCard'
  50. import { getAudio } from "@/api/audio";
  51. import {getUserInfo} from "@/api/user";
  52. export default {
  53. name: 'AudioPage',
  54. components: { UserAvatarCard },
  55. filters: {
  56. ellipsis(value) {
  57. if (!value) return ''
  58. const max = 20
  59. if (value.length > max) {
  60. return value.slice(0, max) + '...'
  61. }
  62. return value
  63. }
  64. },
  65. data() {
  66. return {
  67. currentAudioName: '',
  68. audio: null,
  69. audioList: [],
  70. user: null,
  71. collected: false,
  72. collectedIcon: 'el-icon-star-off'
  73. }
  74. },
  75. created() {
  76. const audioId = this.$route.params.audioId
  77. getAudio(audioId).then(res => {
  78. if (res.code === 0) {
  79. this.audio = res.data
  80. this.audioList = [
  81. { name: this.audio.title, url: this.audio.audioUrl }
  82. ]
  83. document.title = '音频 - ' + this.audio.title
  84. } else {
  85. }
  86. getUserInfo(10001).then(res => {
  87. if (res.code === 0) {
  88. this.user = res.data
  89. }
  90. })
  91. })
  92. },
  93. methods: {
  94. // 播放前做的事
  95. handleBeforePlay(next) {
  96. // 这里可以做一些事情...
  97. this.currentAudioName = this.audioList[this.$refs.audioPlayer.currentPlayIndex].name
  98. // 开始播放
  99. next()
  100. },
  101. handlePlaySpecify() {
  102. this.$refs.audioPlayer.currentPlayIndex = 1
  103. this.$nextTick(() => {
  104. this.$refs.audioPlayer.play()
  105. this.title = this.audioList[
  106. this.$refs.audioPlayer.currentPlayIndex
  107. ].name
  108. })
  109. },
  110. collectItem() {
  111. if (this.collected) {
  112. console.log('取消收藏音频')
  113. this.collected = false
  114. this.collectedIcon = 'el-icon-star-off'
  115. } else {
  116. console.log('收藏音频')
  117. this.collected = true
  118. this.collectedIcon = 'el-icon-star-on'
  119. }
  120. }
  121. }
  122. }
  123. </script>
  124. <style scoped>
  125. .movie-list {
  126. padding-top: 15px;
  127. padding-left: 6%;
  128. padding-right: 6%;
  129. }
  130. /*处于手机屏幕时*/
  131. @media screen and (max-width: 768px) {
  132. .movie-list {
  133. padding-top: 8px;
  134. padding-left: 0.5%;
  135. padding-right: 0.5%;
  136. }
  137. }
  138. .clearfix:before,
  139. .clearfix:after {
  140. display: table;
  141. content: "";
  142. }
  143. .clearfix:after {
  144. clear: both;
  145. }
  146. </style>