Skip to content

Commit

Permalink
feat: 最新歌曲页面
Browse files Browse the repository at this point in the history
  • Loading branch information
sl1673495 committed Jul 26, 2019
1 parent fa197b6 commit e0e2aaf
Show file tree
Hide file tree
Showing 18 changed files with 269 additions and 68 deletions.
3 changes: 2 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_777085_pk0u28fv7cl.css">
<title>vue-netease-muisc</title>
Expand Down
3 changes: 3 additions & 0 deletions src/api/song.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ export const getSongUrl = id => request.get(`/song/url?id=${id}`)

// 获取音乐详情
export const getSongDetail = ids => request.get(`/song/detail?ids=${ids}`)

// 新歌速递
export const getTopSongs = (type) => request.get(`/top/song?type=${type}`)
74 changes: 59 additions & 15 deletions src/base/tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
:class="{[align]: true}"
>
<div
v-for="(tab, index) in tabs"
v-for="(tab, index) in normalizedTabs"
:key="index"
class="tab-item"
:class="getActiveCls(tab, index)"
@click="onChangeTab(tab, index)"
:style="getTabItemStyle(tab, index)"
>
<span class="title">
{{tab.title}}
Expand All @@ -21,6 +22,13 @@
const ACTIVE_PROP = 'active'
const ACTIVE_CHANGE = 'tabChange'
const typeStyleMap = {
small: {
itemStyle: { fontSize: '12px' },
activeItemStyle: { color: '#d33a31' }
}
}
export default {
created() {
this.ACTIVE_PROP = ACTIVE_PROP
Expand All @@ -37,6 +45,17 @@ export default {
align: {
type: String,
default: 'left'
},
itemStyle: {
type: Object,
default: () => ({})
},
activeItemStyle: {
type: Object,
default: () => ({})
},
type: {
type: String,
}
},
model: {
Expand All @@ -51,38 +70,67 @@ export default {
this.$emit(ACTIVE_CHANGE, index)
}
},
isActive(tab, index) {
if (
// 路由模式
(this.isRouteMode && this.$route.path === tab.to) ||
// 非路由模式
(!this.isRouteMode && index === this[ACTIVE_PROP])
) {
return true
}
return false
},
getActiveCls(tab, index) {
const ACTIVE_CLS = 'active'
// 路由模式
if (this.isRouteMode) {
if (this.$route.path === tab.to) {
return ACTIVE_CLS
}
} else if (index === this[ACTIVE_PROP]) {
return ACTIVE_CLS
}
return this.isActive(tab, index) ? ACTIVE_CLS : ''
},
getTabItemStyle(tab, index) {
return Object.assign(
{},
(typeStyleMap[this.type] || {}).itemStyle,
this.itemStyle,
this.isActive(tab, index)
? Object.assign(
{},
(typeStyleMap[this.type] || {}).activeItemStyle,
this.activeItemStyle
)
: null
)
}
},
computed: {
isRouteMode() {
return this.tabs.length && !!this.tabs[0].to
}
}
},
normalizedTabs() {
return typeof this.tabs[0] === 'string'
? this.tabs.map(tab => ({ title: tab }))
: this.tabs
},
},
}
</script>

<style lang="scss" scoped>
.tab-wrap {
// padding: 12px;
display: flex;
flex-wrap: wrap;
&.center {
justify-content: center;
}
&.right {
justify-content: flex-end;
}
.tab-item {
padding: 12px;
color: var(--tab-item-color);
font-size: $font-size-medium;
cursor: pointer;
&.active {
Expand All @@ -96,10 +144,6 @@ export default {
&:hover {
color: var(--tab-item-hover-color);
}
.title {
font-size: $font-size-medium;
}
}
}
</style>
2 changes: 1 addition & 1 deletion src/components/mini-player.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="song">
<template v-if="hasCurrentSong">
<div class="img-wrap">
<img :src="currentSong.img" />
<img :src="$utils.genImgUrl(currentSong.img, 80)" />
</div>
<div class="content">
<div class="top">
Expand Down
4 changes: 1 addition & 3 deletions src/components/playlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
>
<SongTable
:songs="dataSource"
:hideColumns="['index', 'albumName']"
:hideColumns="['index', 'img', 'albumName']"
:showPromptOnPlay="false"
/>
</div>
Expand All @@ -50,7 +50,6 @@

<script type="text/ecmascript-6">
import { mapState, mapMutations, mapActions } from 'vuex'
import Tabs from '@/base/tabs'
import LeaveHide from '@/base/leave-hide'
import SongTable from './song-table'
export default {
Expand Down Expand Up @@ -101,7 +100,6 @@ export default {
components: {
SongTable,
LeaveHide,
Tabs
}
}
</script>
Expand Down
5 changes: 1 addition & 4 deletions src/components/song-card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ export default {
}
.play-icon {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
@include abs-center;
}
}
Expand Down
43 changes: 40 additions & 3 deletions src/components/song-table.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<el-table
v-bind="$attrs"
v-if="songs.length"
:data="songs"
@row-click="onRowClick"
Expand All @@ -9,13 +10,14 @@
<template v-for="(column, index) in showColumns">
<!-- 需要自定义渲染的列 -->
<el-table-column
v-if="['index', 'durationSecond'].includes(column.prop)"
v-if="['index', 'img', 'durationSecond'].includes(column.prop)"
:key="index"
:label="column.label"
:prop="column.prop"
v-bind="column"
>
<template slot-scope="scope">
<!-- 序号 -->
<template v-if="column.prop === 'index'">
<Icon
class="horn"
Expand All @@ -25,9 +27,19 @@
/>
<span v-else>{{scope.$index + 1}}</span>
</template>

<!-- 时长 -->
<template v-else-if="column.prop === 'durationSecond'">
<span>{{ $utils.formatTime(scope.row.durationSecond) }}</span>
</template>

<!-- 图片 -->
<template v-else-if="column.prop === 'img'">
<div class="song-table-img-wrap">
<img :src="$utils.genImgUrl(scope.row.img, 120)" />
<PlayIcon class="song-table-play-icon" />
</div>
</template>
</template>

</el-table-column>
Expand All @@ -45,6 +57,8 @@

<script>
import { mapMutations, mapActions, mapState } from "vuex"
import PlayIcon from '@/base/play-icon'
export default {
props: {
hideColumns: {
Expand All @@ -67,6 +81,10 @@ export default {
prop: 'index',
label: '',
width: '50'
}, {
prop: 'img',
label: ' ',
width: '100',
}, {
prop: 'name',
label: '音乐标题',
Expand All @@ -81,7 +99,7 @@ export default {
}, {
prop: 'durationSecond',
label: '时长',
width: '100'
width: '100',
}]
}
},
Expand All @@ -106,12 +124,19 @@ export default {
},
computed: {
showColumns() {
const hideColumns = this.hideColumns.slice()
const reference = this.songs[0]
const { img } = reference
if (!img) {
hideColumns.push('img')
}
return this.columns.filter(column => {
return !this.hideColumns.find((prop) => prop === column.prop)
})
},
...mapState(['currentSong'])
}
},
components: { PlayIcon }
}
</script>

Expand All @@ -123,4 +148,16 @@ export default {
.song-active {
color: $theme-color;
}
.song-table-img-wrap {
position: relative;
@include img-wrap(60px);
img {
border-radius: 4px;
}
.song-table-play-icon {
@include abs-center;
}
}
</style>
3 changes: 1 addition & 2 deletions src/components/top-playlist-card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ export default {
.desc {
@include text-ellipsis-multi(5);
font-size: $font-size-sm;
color: #708b90;
color: $font-color-transparent;
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/layout/header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<script type="text/ecmascript-6">
import logo from "@/assets/logo.png"
import Theme from '@/components/theme'
import Tabs from '@/base/tabs'
import Search from '@/components/search'
export default {
created() {
Expand All @@ -41,10 +40,10 @@ export default {
title: '歌单',
to: '/playlists',
},
// {
// title: '音乐',
// to: '/songs'
// }
{
title: '最新音乐',
to: '/songs'
}
]
},
data() {
Expand All @@ -57,7 +56,7 @@ export default {
this.$router.push("/discovery")
}
},
components: { Theme, Search, Tabs }
components: { Theme, Search }
}
</script>

Expand Down
8 changes: 5 additions & 3 deletions src/layout/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<script type="text/ecmascript-6">
import LayoutHeader from "./header"
import LayoutMenu from "./menu"
import { topRoutes } from '@/router'
export default {
data() {
Expand All @@ -27,7 +28,9 @@ export default {
},
computed: {
routerViewCls() {
return ['/discovery', '/playlists'].includes(this.$route.path) ? 'router-view-center' : ''
return topRoutes.find(({ path }) => path === this.$route.path)
? 'router-view-center'
: ''
}
}
}
Expand All @@ -46,11 +49,10 @@ export default {
overflow-y: auto;
margin-bottom: $mini-player-height;
padding-bottom: 32px;
display: flex;
justify-content: center;
.router-view-center {
max-width: $center-content-width;
margin: auto;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/page/discovery/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default {

<style lang="scss" scoped>
.discovery {
padding: 0 36px;
padding: 0 32px;
.discovery-content {
padding-bottom: 36px;
}
}
</style>
Loading

0 comments on commit e0e2aaf

Please sign in to comment.