Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.

Commit e4be3d9

Browse files
committed
更新 - 完成 recommend
1 parent a16c00f commit e4be3d9

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/api/the-recommend.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function getRecommendItem (recommendId) {
4646
}
4747
}
4848

49+
// 在没有 header 验证的情况下直接使用 jsonp 请求 url,否则使用后端 ajax 代理
4950
// return jsonp(RECOMMEND_ITEM_URL, data, {
5051
// ...options,
5152
// // https://github.com/webmodules/jsonp/blob/master/index.js#L50

src/components/parts-recom-item/parts-recom-item.vue

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PartsMusicList
44
:bgImage="itemBgImage"
55
:title="itemTitle"
6+
:songs="itemSongs"
67
/>
78
</transition>
89
</template>
@@ -11,16 +12,41 @@
1112
import PartsMusicList from 'components/parts-music-list/parts-music-list'
1213
import { mapGetters } from 'vuex'
1314
import { getRecommendItem } from 'api/the-recommend'
14-
// import { ERR_OK } from 'api/config'
15+
import { ERR_OK } from 'api/config'
16+
import { createSong } from 'common/js/normalize-song'
1517
1618
export default {
1719
methods: {
1820
_getRecommendItem (id) {
19-
getRecommendItem(id).then(res => console.log(res))
21+
if (!this.recommendItem.dissid) { // 在 recommend 详情页刷新时,跳转至首页
22+
this.$router.push({ path: '/recommend' })
23+
return
24+
}
25+
26+
getRecommendItem(id).then(res => {
27+
if (res.code === ERR_OK) {
28+
this.itemSongs = this._normalizeSongs(res.cdlist[0].songlist)
29+
console.info('%c Loading recommend songs', 'color: dodgerblue')
30+
}
31+
})
32+
},
33+
34+
_normalizeSongs (list) {
35+
let ret = []
36+
list.forEach(musicData => {
37+
if (musicData.songmid && musicData.albummid) {
38+
ret.push(createSong(musicData))
39+
}
40+
})
41+
return ret
2042
}
2143
},
44+
2245
computed: {
2346
itemTitle () {
47+
if (!this.recommendItem.dissid) { // 在 recommend 详情页刷新时
48+
return
49+
}
2450
return this.recommendItem.creator.name
2551
},
2652
@@ -37,6 +63,12 @@ export default {
3763
this._getRecommendItem(this.recommendItem.dissid)
3864
},
3965
66+
data () {
67+
return {
68+
itemSongs: []
69+
}
70+
},
71+
4072
components: {
4173
PartsMusicList
4274
}

0 commit comments

Comments
 (0)