功能:查询歌曲,播放歌曲,播放MV,显示海报,显示评论,显示评论图片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios@0.21.1/dist/axios.min.js"></script>
<style>
*{
margin: 0;
padding:0;
list-style: none;
border:none;
/*去除得到焦点外边框*/
outline: none;
/*怪异盒子模型*/
box-sizing: border-box;
}
html,body{
width: 100%;
}
i{
/*去除斜体*/
font-style:normal;
/*图标名字*/
font-family: 'icomoon';
}
/*图标样式*/
@font-face {
/*图标名字*/
font-family: 'icomoon';
/*图标地址*/
src: url('fonts/icomoon.eot?oetgau');
src: url('fonts/icomoon.eot?oetgau#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?oetgau') format('truetype'),
url('fonts/icomoon.woff?oetgau') format('woff'),
url('fonts/icomoon.svg?oetgau#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
}
#box{
width: 100%;
height: 100vh;
/*背景渐变*/
background: linear-gradient(-45deg,rgba(198,92,104,.6),rgba(246,126,63,0.8));
/*使MP3播放面与MV图层重叠*/
position: relative;
}
#content{
width: 800px;
height: 500px;
/*使MP3播放固定页面,不影响MV布局*/
position: fixed;
left: 50%;
top: 50%;
transform:translate(-50%,-50%);
}
/*头部搜索栏*/
.play-head{
width: 100%;
height: 50px;
background-color: skyblue;
border-radius: 5px 5px 0 0;
}
.play-head .logo{
color: #fff;
float: left;
font-weight: bold;
font-size: 18px;
line-height: 50px;
margin-left:20px;
}
.play-head .nav{
float: right;
line-height: 50px;
margin-right: 20px;
/*定位搜索图标*/
position: relative;
}
.play-head .nav input{
height: 30px;
width: 200px;
border-radius: 15px;
padding-left: 20px;
padding-right: 30px;
overflow: hidden;
}
.play-head .nav span{
/*图标名*/
font-family: 'icomoon';
color:#959595;
/*定位搜索图标*/
position: absolute;
right: 10px;
top: 2px;
}
/*身体部位*/
.play-body{
width: 100%;
height: 400px;
background-color: rgba(255,255,255,.2);
}
.play-body .play-body-left{
height: 100%;
width: 25%;
/*background-color: red;*/
float: left;
/*溢出滚动条部位隐藏*/
overflow: hidden;
}
.play-body-left ul{
padding-top:10px;
width: 120%;
height: 100%;
margin: 0 auto;
/*滚动页面*/
overflow: auto;
}
.play-body-left ul li{
height: 45px;
line-height: 45px;
padding-left: 10px;
/*横向布局*/
display: flex;
margin:0 10px;
margin-right: 30px;
}
.play-body-left ul li span{
padding-left:5PX;
width: 125PX;
/*字体溢出隐藏*/
overflow: hidden;
}
.play-body-left ul li i:nth-child(1){
cursor: pointer;
color: red;
}
.play-body-left ul li i:nth-child(2){
display: none;
}
.play-body-left ul li i:last-child{
height: 45px;
line-height: 45px;
padding-left: 5px;
cursor: pointer;
}
.play-body-left ul li:nth-child(odd){
background-color: rgba(236,236,236,0.4);
border-radius: 5px;
}
/*content-content*/
.play-body .play-body-midder{
height: 100%;
width: 50%;
float: left;
position: relative;
box-shadow: -1px 0px 2px rgba(236,236,236,0.4),1px 0px 2px rgba(236,236,236,0.4);
}
.anim{
animation:rota 4s infinite linear;
}
@keyframes rota{
0%{transform: rotate(0deg)}
100%{transform: rotate(360deg)}
}
.play-body-midder span{
display: block;
width: 250px;
height: 250px;
border:50px solid black;
/*opacity: 0.2;*/
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
z-index: 1;
}
.play-body-midder img{
width: 180px;
border-radius: 50%;
position: absolute;
top: 28%;
left: 28%;
}
/*content-right*/
.play-body .play-body-right{
height: 100%;
width: 25%;
float: right;
overflow: hidden;
}
.play-body-right .w{
margin:10px 5px 0 10px;
height: 100%;
width: 106%;
}
.play-body-right .w ul{
margin-top: 10px;
width: 100%;
height: 100%;
overflow: auto;
}
.play-body-right ul li{
margin-top: 5px;
}
.play-body-right img {
width: 23%;
border-radius: 50%;
vertical-align: top;
}
.play-body-right span {
overflow: hidden;
display: inline-block;
padding-left: 5px;
width: 72%;
min-height: 40px;
font-size: 14px;
}
/*MP3播放*/
.play-fooder{
width: 100%;
height: 50px;
background-color: #ececec;
}
.play-fooder audio{
width: 100%;
height: 50px;
}
#video{
position: relative;
z-index: 1;
width:100%;
height: 100vh;
display: none;
}
.display{
display: block !important;
}
#video video{
width: 800px;
height: 500px;
background-color: black;
transform: translate(70%,38%);
position: absolute;
z-index: 2
}
#video span{
display: inline-block;
width:100%;
height: 100vh;
background-color: #ccc;
position: absolute;
z-index: 1
}
</style>
<body>
<div id="box">
<div id="content">
<div id="play">
<!-- Mp3头部页面 -->
<div class="play-head">
<div class="logo">畅听音乐</div>
<div class="nav">
<input type="text"/ v-model="name" @keyup.enter="getkeyword">
<span></span>
</div>
</div>
<!-- Mp3内容页面 -->
<div class="play-body">
<!-- Mp3内容页面-左边 -->
<div class="play-body-left">
<ul>
<li v-for="item in muisclist">
<i @click="getMusic(item.id)"></i>
<i></i>
<span>{{item.name}}</span>
<i @click="getmv(item.mvid)" v-if="item.mvid!=0"></i>
</li>
</ul>
</div>
<!-- Mp3内容页面-中间 -->
<div class="play-body-midder" >
<span></span>
<img :src="musicimage" :class="{anim:isunplay}">
</div>
<!-- Mp3内容页面-右边 -->
<div class="play-body-right">
<div class="w">
<h3>热门留言</h3>
<ul>
<li class="nav" v-for="item in usertell">
<img :src="item.user.avatarUrl" alt="">
<span>{{item.content}}</span>
<li>
</ul>
</div>
</div>
</div>
<!-- Mp3尾部页面 -->
<div class="play-fooder">
<audio :src="musicUrl" controls="controls" autoplay @play="play" @pause="pause"></audio>
</div>
</div>
</div>
<!-- mv播放页面 -->
<div id="video" :class="{display:isplay}" >
<video :src="mvUrl" controls="controls" ></video>
<span @click="hid" ></span>
</div>
</div>
<script>
var vm = new Vue({
el:'#box',
data:{
name:'',
muisclist:[],
musicUrl:'',
mvUrl:'',
isplay:false,
isunplay:false,
musicimage:'',
usertell:[],
},
methods:{
// 控制封面图旋转
play(){
this.isunplay = true;
},
pause(){
this.isunplay = false;
},
// 控制MV的css隐藏
hid(){
this.isplay = false;
},
getkeyword(){
var that =this;
// 搜索歌曲
// 请求地址:https://autumnfish.cn/search
// 请求方式:get
// 请求参数:keywords(查询关键词)
// 响应内容:歌曲搜索结果
axios.get("https://autumnfish.cn/search?keywords="+this.name).then(function(respontse){
that.muisclist = respontse.data.result.songs
console.log(respontse)
console.log(respontse.data.result.songs)
},function(err){console.log(err)})
},
getMusic(musicId){
console.log(musicId)
var that = this;
// 歌曲播放接口
// 请求地址:https://autumnfish.cn/song/url
// 请求方式:get
// 请求参数:id(歌曲id)
// 响应内容:歌曲的url地址
axios.get("https://autumnfish.cn/song/url?id="+musicId)
.then(function(respontse){
that.musicUrl=respontse.data.data[0].url;
//console.log(respontse.data.data[0].url)
},function(err){console.log(err)});
// 歌曲封面接口
// 请求地址:https://autumnfish.cn/song/detail
// 请求方式:get
// 请求参数:ids(歌曲id)
// 响应内容:歌曲详情,包含页面信息
axios.get("https://autumnfish.cn/song/detail?ids="+musicId)
.then(function(respontse){
that.musicimage=respontse.data.songs[0].al.picUrl;
console.log(respontse)
},function(err){console.log(err)});
// 留言接口
// 请求地址:https://autumnfish.cn/comment/hot?type=0
// 请求方式:get
// 请求参数:id(id歌曲,type=0固定)
// 响应内容:歌曲的热门评论
axios.get("https://autumnfish.cn/comment/hot?type=0&id="+musicId)
.then(function(respontse){
// 响应内容:歌曲的热门评论
that.usertell=respontse.data.hotComments;
console.log(respontse)
},function(err){console.log(err)});
},
getmv(mvid){
console.log(mvid)
var that = this;
// Mv接口
// 请求地址:https://autumnfish.cn/mv/url
// 请求方式:get
// 请求参数:id(mvid为0,则没有mv)
// 响应内容:mv地址
axios.get("https://autumnfish.cn/mv/url?id="+mvid)
.then(function(respontse){
// 响应内容:mv地址
that.mvUrl=respontse.data.data.url
console.log(respontse)
}
,function(err){console.log(err)});
// 控制MV的css显示
that.isplay=true;
}
},
})
</script>
</body>
</html>