Skip to content

Commit f3c0849

Browse files
committed
[feat] perfect recommend
1 parent c29834d commit f3c0849

File tree

7 files changed

+153
-7
lines changed

7 files changed

+153
-7
lines changed

src/api/recommend.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,24 @@ export function getDiscList() {
3636
return Promise.resolve(res.data)
3737
})
3838
}
39+
40+
export function getSongList(disstid) {
41+
const url = '/api/getSongList'
42+
43+
const data = Object.assign({}, commonParams, {
44+
disstid,
45+
type: 1,
46+
json: 1,
47+
utf8: 1,
48+
onlysong: 0,
49+
platform: 'yqq',
50+
hostUin: 0,
51+
needNewCode: 0,
52+
g_tk: 67232076
53+
})
54+
return axios.get(url, {
55+
params: data
56+
}).then(res => {
57+
return Promise.resolve(res.data)
58+
})
59+
}

src/components/disc/disc.vue

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<template>
2+
<transition name="slide">
3+
<music-list :title="title" :bg-image="bgImage" :songs="songs"/>
4+
</transition>
5+
</template>
6+
7+
<script>
8+
import MusicList from "../music-list/music-list";
9+
import {mapGetters} from 'vuex'
10+
import {getSongList} from 'api/recommend'
11+
import {createSong} from 'common/js/song'
12+
import {ERR_OK} from "api/config";
13+
14+
export default {
15+
name: "disc",
16+
components: {MusicList},
17+
data() {
18+
return {
19+
songs: []
20+
}
21+
},
22+
computed: {
23+
title(){
24+
return this.disc.dissname
25+
},
26+
bgImage() {
27+
return this.disc.imgurl
28+
},
29+
...mapGetters([
30+
'disc'
31+
])
32+
},
33+
created() {
34+
this._getSongList()
35+
},
36+
methods: {
37+
_getSongList() {
38+
if (!this.disc.dissid) {
39+
this.$router.push('/recommend')
40+
return
41+
}
42+
getSongList(this.disc.dissid).then((res) => {
43+
if (res.code === ERR_OK) {
44+
this.songs = this._normalizeSongs(res.cdlist[0].songlist)
45+
}
46+
})
47+
},
48+
_normalizeSongs(list) {
49+
let ret = []
50+
list.forEach((musicData) => {
51+
if (musicData.songid && musicData.albummid) {
52+
ret.push(createSong(musicData))
53+
}
54+
})
55+
return ret
56+
}
57+
},
58+
}
59+
</script>
60+
61+
<style scoped lang="stylus" rel="stylesheet/stylus">
62+
.slide-enter-active, .slide-leave-active
63+
transition: all 0.3s
64+
65+
.slide-enter, .slide-leave-to
66+
transform: translate3d(100%, 0, 0)
67+
</style>

src/components/recommend/recommend.vue

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class="recommend-list">
1515
<h1 class="list-title">热门歌单推荐</h1>
1616
<ul>
17-
<li v-for="(item,index) in discList" :key="index" class="item">
17+
<li @click="selectItem(item)" v-for="(item,index) in discList" :key="index" class="item">
1818
<div class="icon">
1919
<img width="60" height="60" v-lazy="item.imgurl"/>
2020
</div>
@@ -30,6 +30,7 @@
3030
<loading></loading>
3131
</div>
3232
</scroll>
33+
<router-view/>
3334
</div>
3435
</template>
3536

@@ -40,10 +41,11 @@
4041
import Scroll from "base/scroll/scroll";
4142
import Loading from "base/loading/loading";
4243
import {playlistMixin} from "common/js/mixin";
44+
import {mapMutations} from 'vuex'
4345
4446
export default {
4547
name: "recommend",
46-
mixins:[playlistMixin],
48+
mixins: [playlistMixin],
4749
data() {
4850
return {
4951
recommends: [],
@@ -63,6 +65,12 @@
6365
this.$refs.recommend.style.bottom = bottom
6466
this.$refs.scroll.refresh()
6567
},
68+
selectItem(item) {
69+
this.$router.push({
70+
path: `/recommend/${item.dissid}`
71+
})
72+
this.setDisc(item)
73+
},
6674
_getRecommend() {
6775
getRecommend().then((res) => {
6876
if (res.code === ERR_OK) {
@@ -82,7 +90,10 @@
8290
this.$refs.scroll.refresh()
8391
this.checkLoaded = true
8492
}
85-
}
93+
},
94+
...mapMutations({
95+
setDisc: 'SET_DISC'
96+
})
8697
}
8798
}
8899
</script>

src/router/router.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ export default new Router({
1212
{
1313
path: '/recommend',
1414
name: 'recommend',
15-
component: () => import( 'components/recommend/recommend.vue')
15+
component: () => import( 'components/recommend/recommend.vue'),
16+
children: [
17+
{
18+
path:':id',
19+
name:'disc',
20+
component: () => import( 'components/disc/disc.vue')
21+
}
22+
]
1623
},
1724
{
1825
path: '/rank',

src/store/mutations.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const mutations = {
44
[types.SET_SINGER](state, singer) {
55
state.singer = singer
66
},
7-
[types.SET_PLAYING_STATE](state,flag){
7+
[types.SET_PLAYING_STATE](state, flag) {
88
state.playing = flag
99
},
1010
[types.SET_FULL_SCREEN](state, flag) {
@@ -21,6 +21,21 @@ const mutations = {
2121
},
2222
[types.SET_CURRENT_INDEX](state, index) {
2323
state.currentIndex = index
24+
},
25+
[types.SET_DISC](state, disc) {
26+
state.disc = disc
27+
},
28+
[types.SET_TOP_LIST](state, topList) {
29+
state.topList = topList
30+
},
31+
[types.SET_SEARCH_HISTORY](state, history) {
32+
state.searchHistory = history
33+
},
34+
[types.SET_PLAY_HISTORY](state, history) {
35+
state.playHistory = history
36+
},
37+
[types.SET_FAVORITE_LIST](state, list) {
38+
state.favoriteList = list
2439
}
2540
}
2641

src/store/state.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const state = {
77
playlist: [],
88
sequenceList: [],
99
mode: playMode.sequence,
10-
currentIndex: -1
10+
currentIndex: -1,
11+
disc:{}
1112
}
1213
export default state

vue.config.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ module.exports = {
1616
},
1717
devServer: {
1818
before(app) {
19-
var url = "https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg";
2019
app.get('/api/getDiscList', function (req, res) {
20+
var url = "https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg";
2121
axios.get(url, {
2222
headers: {
2323
referer: 'https://c.y.qq.com/',
@@ -53,6 +53,30 @@ module.exports = {
5353
console.log(e)
5454
})
5555
})
56+
app.get('/api/getSongList', function (req, res) {
57+
var url = 'https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg'
58+
59+
axios.get(url, {
60+
headers: {
61+
referer: 'https://c.y.qq.com/',
62+
host: 'c.y.qq.com'
63+
},
64+
params: req.query
65+
}).then((response) => {
66+
var ret = response.data
67+
if (typeof ret === 'string') {
68+
// var reg = /^\w+\(({[^()]+})\)$/
69+
var reg = /{.*}/
70+
var matches = ret.match(reg)
71+
if (matches) {
72+
ret = JSON.parse(matches[0])
73+
}
74+
}
75+
res.json(ret)
76+
}).catch((e) => {
77+
console.log(e)
78+
})
79+
})
5680
}
5781
}
5882
}

0 commit comments

Comments
 (0)