AudioPage.vue 3.9 KB

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