tab4-3.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="tab4-3" v-if="musicList.length !== 0">
  3. <div class="right">
  4. <div class="right_img"></div>
  5. <div class="right_top">
  6. <!-- 歌词 -->
  7. <div class="title">{{ myObj.name }}</div>
  8. <div class="txt" v-html="myObj.description"></div>
  9. </div>
  10. <div class="right_bottom">
  11. <Audio
  12. :audioSrc="baseURL + myObj.filePath"
  13. :title="myObj.name"
  14. @sonCutMu="sonCutMu"
  15. />
  16. </div>
  17. </div>
  18. <div class="left">
  19. <div class="title">歌单列表</div>
  20. <div class="listCon">
  21. <p
  22. :title="item.name"
  23. v-for="(item, index) in musicList"
  24. :key="item.id"
  25. :class="{ active: audioInd === index }"
  26. @click="cutMusic(item.id, index)"
  27. >
  28. <span
  29. class="triangle"
  30. :class="{ triangleShow: audioInd === index }"
  31. ></span>
  32. <span>{{ index + 1 }}</span>
  33. &emsp;{{ item.name }}
  34. </p>
  35. </div>
  36. </div>
  37. <!-- <div class="right_top" :style="{'background':`url(${baseURL+myObj.thumb}) #f3ebdd no-repeat center center`}"> -->
  38. </div>
  39. <div class="tab4-3 conNull" v-else>暂 无 数 据</div>
  40. </template>
  41. <script>
  42. import Audio from "./audio.vue";
  43. import axios from "@/utils/request";
  44. import { musicList, webVisit } from "@/utils/api";
  45. export default {
  46. name: "tab4-3",
  47. components: { Audio },
  48. data() {
  49. // 这里存放数据
  50. return {
  51. audioInd: 0,
  52. baseURL: "",
  53. musicList: [],
  54. myObj: {},
  55. };
  56. },
  57. // 监听属性 类似于data概念
  58. computed: {},
  59. // 监控data中的数据变化
  60. watch: {
  61. audioInd(index) {
  62. this.myObj = this.musicList[index];
  63. //控制被选中的音乐滚动在中间
  64. const gundong = document.querySelector(".listCon");
  65. gundong.scrollTo({ top: index * 40, behavior: "smooth" });
  66. },
  67. },
  68. // 方法集合
  69. methods: {
  70. // 点击左侧音乐
  71. async cutMusic(id, index) {
  72. this.audioInd = index;
  73. // 记录访问量
  74. await webVisit("music", id);
  75. },
  76. //子组件传过来的上一首下一首方法
  77. sonCutMu(val) {
  78. if (val === "left") {
  79. if (this.audioInd === 0) this.audioInd = this.musicList.length - 1;
  80. else this.audioInd--;
  81. } else {
  82. if (this.audioInd === this.musicList.length - 1) this.audioInd = 0;
  83. else this.audioInd++;
  84. }
  85. },
  86. },
  87. // 生命周期 - 创建完成(可以访问当前this实例)
  88. created() {
  89. // 获取服务器前缀地址
  90. this.baseURL = axios.defaults.baseURL;
  91. },
  92. // 生命周期 - 挂载完成(可以访问DOM元素)
  93. async mounted() {
  94. let res = await musicList({ pageNum: 1, pageSize: 999 });
  95. this.musicList = res.data.records;
  96. this.myObj = this.musicList[0];
  97. // 进页面为第一个视频添加访问量
  98. if (res.data.records[0]) await webVisit("music", res.data.records[0].id);
  99. // this.videoSrc=this.musicList[0].filePath
  100. // console.log(998, res);
  101. },
  102. beforeCreate() {}, // 生命周期 - 创建之前
  103. beforeMount() {}, // 生命周期 - 挂载之前
  104. beforeUpdate() {}, // 生命周期 - 更新之前
  105. updated() {}, // 生命周期 - 更新之后
  106. beforeDestroy() {}, // 生命周期 - 销毁之前
  107. destroyed() {}, // 生命周期 - 销毁完成
  108. activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
  109. };
  110. </script>
  111. <style lang='less' scoped>
  112. .conNull {
  113. font-size: 30px;
  114. align-items: center;
  115. justify-content: center;
  116. color: #b9412e;
  117. }
  118. /deep/::-webkit-scrollbar-thumb {
  119. background-color: #d8b581 !important;
  120. outline: 1px solid #d8b581 !important;
  121. outline-offset: 0;
  122. }
  123. .tab4-3 {
  124. padding: 30px 200px;
  125. display: flex;
  126. width: 100%;
  127. height: 595px;
  128. .left {
  129. margin-left: 30px;
  130. border-radius: 8px;
  131. padding: 10px 0;
  132. text-align: center;
  133. color: #333333;
  134. width: 300px;
  135. height: 100%;
  136. .title {
  137. font-weight: 700;
  138. text-align: left;
  139. padding-left: 72px;
  140. font-size: 22px;
  141. margin-bottom: 10px;
  142. }
  143. .listCon {
  144. padding-right: 30px;
  145. height: 485px;
  146. overflow-y: auto;
  147. }
  148. p {
  149. .triangle {
  150. margin-right: 10px;
  151. display: inline-block;
  152. width: 0;
  153. height: 0;
  154. border-top: 8px solid transparent;
  155. border-left: 15px solid transparent;
  156. border-bottom: 8px solid transparent;
  157. }
  158. .triangleShow {
  159. border-top: 8px solid transparent;
  160. border-left: 15px solid #b9412e;
  161. border-bottom: 8px solid transparent;
  162. }
  163. text-align: left;
  164. padding: 0 20px 0 50px;
  165. overflow: hidden;
  166. text-overflow: ellipsis;
  167. white-space: nowrap;
  168. cursor: pointer;
  169. font-size: 20px;
  170. height: 40px;
  171. line-height: 40px;
  172. margin: 10px 0;
  173. & > img {
  174. margin-top: -5px;
  175. }
  176. &:hover {
  177. color: #b9412e;
  178. }
  179. &:first-child {
  180. margin-top: 0px;
  181. }
  182. }
  183. .active {
  184. color: #b9412e;
  185. }
  186. }
  187. .right {
  188. flex: 1;
  189. display: flex;
  190. .right_img {
  191. width: 270px;
  192. background: url('../../assets/img/musicC.png') no-repeat center center;
  193. }
  194. .right_top {
  195. overflow-y: auto;
  196. padding: 15px 50px;
  197. padding-top: 0;
  198. flex: 1;
  199. & > div {
  200. margin: 10px 0;
  201. text-align: center;
  202. color: #333333;
  203. }
  204. .txt {
  205. font-size: 22px;
  206. /deep/p {
  207. margin: 10px 0;
  208. font-size: 18px;
  209. }
  210. }
  211. .title {
  212. margin-top: 0;
  213. font-size: 24px;
  214. font-weight: 700;
  215. }
  216. }
  217. .right_bottom {
  218. position: fixed;
  219. bottom: 0;
  220. left: 0;
  221. width: 100%;
  222. height: 70px;
  223. background-color: rgba(0,0,0,.6);
  224. }
  225. }
  226. }
  227. </style>