musicRecommend.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="bg">
  3. <!-- 播放全部 -->
  4. <view class="header">
  5. <view class="header-left">
  6. <!-- 播放按钮 -->
  7. <view class="play-circle" @click="palyHeaderBtn">
  8. <image
  9. style="width: 48rpx; height: 48rpx"
  10. src="/src/static//icon/fi-rr-play-alt.svg"
  11. ></image>
  12. </view>
  13. <text class="text-gray">播放全部 (22首)</text>
  14. </view>
  15. <!-- 循环播放 -->
  16. <view class="header-right" @click="cycleBtn">
  17. <image v-if="isRefresh" class="imgIcon" src="/src/static/icon/fi-rr-refresh.svg"></image>
  18. <image v-else class="imgIcon" src="/src/static/icon/fi-rr-shuffle.svg"></image>
  19. </view>
  20. </view>
  21. <!-- 当前播放 循环播放-->
  22. <view class="currently-playing" v-show="playDom">
  23. <view class="currently-playing-left">
  24. <view class="play-circle" @click="palyBtn">
  25. <image v-if="isRePaly" class="palyIcon" src="/src/static/icon/fi-rr-play.svg"></image>
  26. <image v-else class="imgIcon" src="/src/static/icon/fi-rr-pause.svg"></image>
  27. </view>
  28. <text class="text-paly">继续播放: {{ songTitle }}</text>
  29. </view>
  30. <view style="display: flex; gap: 80rpx">
  31. <image
  32. @click="cleanBtn"
  33. class="imgIcon"
  34. src="/src/static/icon/fi-rr-cross-small.svg"
  35. ></image>
  36. </view>
  37. </view>
  38. <!-- 播放列表 -->
  39. <view class="playlist">
  40. <view v-for="(song, index) in songs" :key="index" class="playlist-item">
  41. <view class="album-cover">
  42. <image
  43. style="width: 100rpx; height: 100rpx"
  44. src="/src/static/icon/fi-rr-big-play.svg"
  45. ></image>
  46. </view>
  47. <view class="song-details" @click="playFavoriteBtn(song, index)">
  48. <text class="song-name">{{ song.name }}</text>
  49. </view>
  50. <view class="song-controls">
  51. <text>{{ song.duration }}</text>
  52. <image
  53. style="width: 40rpx; height: 40rpx"
  54. v-if="type === 0"
  55. :src="
  56. song.favorite
  57. ? '/src/static/icon/fi-rr-heart-grey.svg'
  58. : '/src/static/icon/fi-rr-heart.svg'
  59. "
  60. @click="toggleFavorite(song)"
  61. ></image>
  62. <image
  63. v-else
  64. style="width: 40rpx; height: 40rpx"
  65. src="/src/static/icon/fi-rr-heart.svg"
  66. @click="toggHeartCancel(song)"
  67. ></image>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script setup>
  74. import { ref } from 'vue'
  75. // 综合还是收藏
  76. const props = defineProps({
  77. type: {
  78. type: Number,
  79. default: true,
  80. },
  81. })
  82. const songs = ref([
  83. { name: '玛卡巴卡', duration: '3:35', favorite: false },
  84. { name: '海绵宝宝主题曲', duration: '3:35', favorite: true },
  85. { name: '开心超人', duration: '3:35', favorite: false },
  86. { name: '小燕子', duration: '3:35', favorite: true },
  87. { name: '小燕子 (哄睡版)', duration: '3:35', favorite: true },
  88. { name: '小兔子乖乖', duration: '3:35', favorite: false },
  89. { name: '两只老虎', duration: '3:35', favorite: false },
  90. { name: '小毛驴', duration: '3:35', favorite: true },
  91. { name: '我是一只小小鸟', duration: '3:35', favorite: false },
  92. { name: '小星星', duration: '3:35', favorite: true },
  93. { name: '世上只有妈妈好', duration: '3:35', favorite: false },
  94. { name: '蜗牛与黄鹂鸟', duration: '3:35', favorite: true },
  95. ])
  96. const isRefresh = ref(true) // 循环
  97. const isRePaly = ref(true) // 播放暂停切换
  98. const playDom = ref(true)
  99. const songTitle = ref('')
  100. // 播放 暂停
  101. const palyHeaderBtn = () => {
  102. console.log(111, '播放', '暂停')
  103. }
  104. // 播放 暂停
  105. const palyBtn = () => {
  106. isRePaly.value = !isRePaly.value
  107. console.log(111, '播放', '暂停')
  108. }
  109. // 循环播放
  110. const cycleBtn = () => {
  111. isRefresh.value = !isRefresh.value
  112. console.log(111, '循环播放')
  113. }
  114. // 清除当前播放DOM
  115. const cleanBtn = () => {
  116. playDom.value = false
  117. }
  118. // 当前列表
  119. const playFavoriteBtn = (song, index) => {
  120. console.log(222)
  121. playDom.value = true
  122. songTitle.value = song.name
  123. console.log(song, 'songsong')
  124. const songData = encodeURIComponent(JSON.stringify(song))
  125. uni.navigateTo({
  126. url: `/pages/music/component/musicPlayback?songDate=${songData}`,
  127. })
  128. }
  129. // 切换歌曲的收藏状态
  130. const toggleFavorite = (song) => {
  131. console.log(song, 'indexindex')
  132. song.isFavorite = !song.isFavorite
  133. }
  134. // 点击取消收藏
  135. const toggHeartCancel = (song) => {
  136. console.log(song, 'songsong')
  137. }
  138. onLoad(() => {
  139. console.log(props, '111111')
  140. })
  141. </script>
  142. <style scoped lang="scss">
  143. .header {
  144. display: flex;
  145. align-items: center;
  146. justify-content: space-between;
  147. border-bottom: 2rpx solid #f0f0f0;
  148. padding: 16rpx 32rpx;
  149. background: #fff;
  150. .header-left {
  151. display: flex;
  152. align-items: center;
  153. }
  154. }
  155. .play-circle {
  156. display: flex;
  157. align-items: center;
  158. height: 100rpx;
  159. }
  160. .text-gray {
  161. padding-left: 25rpx;
  162. font-size: 32rpx;
  163. color: #333;
  164. overflow: hidden;
  165. text-overflow: ellipsis;
  166. white-space: nowrap;
  167. }
  168. .text-paly {
  169. padding-left: 25rpx;
  170. font-size: 24rpx;
  171. color: #333;
  172. overflow: hidden;
  173. text-overflow: ellipsis;
  174. white-space: nowrap;
  175. }
  176. /* 播放 */
  177. .currently-playing {
  178. display: flex;
  179. align-items: center;
  180. justify-content: space-between;
  181. padding: 0rpx 32rpx;
  182. background: #fff;
  183. border-bottom: 2rpx solid #f0f0f0;
  184. .currently-playing-left {
  185. display: flex;
  186. align-items: center;
  187. }
  188. }
  189. /* 列表 */
  190. .playlist {
  191. height: calc(100vh - 620rpx);
  192. overflow: auto;
  193. }
  194. .playlist::-webkit-scrollbar {
  195. display: none;
  196. }
  197. .playlist-item {
  198. display: flex;
  199. align-items: center;
  200. border-bottom: 2rpx solid #f0f0f0;
  201. padding: 16rpx 32rpx;
  202. background: #fff;
  203. }
  204. .album-cover {
  205. width: 100rpx;
  206. height: 100rpx;
  207. margin-right: 24rpx;
  208. overflow: hidden;
  209. }
  210. .song-details {
  211. flex: 1;
  212. }
  213. .song-name {
  214. font-size: 32rpx;
  215. color: #333;
  216. }
  217. .song-controls {
  218. display: flex;
  219. gap: 32rpx;
  220. align-items: center;
  221. font-size: 24rpx;
  222. color: #999;
  223. }
  224. .imgIcon {
  225. width: 32rpx;
  226. height: 32rpx;
  227. }
  228. .palyIcon {
  229. width: 28rpx;
  230. height: 28rpx;
  231. }
  232. </style>