Skip to content

Commit

Permalink
feat: 新增我的收藏页面
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Dec 8, 2023
1 parent a372570 commit b811b00
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 31 deletions.
34 changes: 34 additions & 0 deletions src/api/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,37 @@ export const getSimiVideo = (mvid) => {
},
});
};

/**
* 收藏/取消收藏视频
* @param {number} t - 操作类型,1为收藏,2为取消收藏
* @param {number} id - 视频id
*/
export const likeVideo = (t, id) => {
return axios({
method: "GET",
url: "/video/sub",
params: {
t,
id,
timestamp: new Date().getTime(),
},
});
};

/**
* 收藏/取消收藏 MV
* @param {number} t - 操作类型,1为收藏,2为取消收藏
* @param {number} mvid - MV id
*/
export const likeMv = (t, mvid) => {
return axios({
method: "GET",
url: "/mv/sub",
params: {
t,
mvid,
timestamp: new Date().getTime(),
},
});
};
3 changes: 2 additions & 1 deletion src/assets/icon.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@
"person-remove": "M14 8c0-2.21-1.79-4-4-4S6 5.79 6 8s1.79 4 4 4s4-1.79 4-4zM2 18v1c0 .55.45 1 1 1h14c.55 0 1-.45 1-1v-1c0-2.66-5.33-4-8-4s-8 1.34-8 4zm16-8h4c.55 0 1 .45 1 1s-.45 1-1 1h-4c-.55 0-1-.45-1-1s.45-1 1-1z",
"github": "M12 2A10 10 0 0 0 2 12c0 4.42 2.87 8.17 6.84 9.5c.5.08.66-.23.66-.5v-1.69c-2.77.6-3.36-1.34-3.36-1.34c-.46-1.16-1.11-1.47-1.11-1.47c-.91-.62.07-.6.07-.6c1 .07 1.53 1.03 1.53 1.03c.87 1.52 2.34 1.07 2.91.83c.09-.65.35-1.09.63-1.34c-2.22-.25-4.55-1.11-4.55-4.92c0-1.11.38-2 1.03-2.71c-.1-.25-.45-1.29.1-2.64c0 0 .84-.27 2.75 1.02c.79-.22 1.65-.33 2.5-.33c.85 0 1.71.11 2.5.33c1.91-1.29 2.75-1.02 2.75-1.02c.55 1.35.2 2.39.1 2.64c.65.71 1.03 1.6 1.03 2.71c0 3.82-2.34 4.66-4.57 4.91c.36.31.69.92.69 1.85V21c0 .27.16.59.67.5C19.14 20.16 22 16.42 22 12A10 10 0 0 0 12 2Z",
"phone": "M16 1H8C6.34 1 5 2.34 5 4v16c0 1.66 1.34 3 3 3h8c1.66 0 3-1.34 3-3V4c0-1.66-1.34-3-3-3zm1 17H7V4h10v14zm-3 3h-4v-1h4v1z",
"password": "M2 17h20v2H2v-2zm1.15-4.05L4 11.47l.85 1.48l1.3-.75l-.85-1.48H7v-1.5H5.3l.85-1.47L4.85 7L4 8.47L3.15 7l-1.3.75l.85 1.47H1v1.5h1.7l-.85 1.48l1.3.75zm6.7-.75l1.3.75l.85-1.48l.85 1.48l1.3-.75l-.85-1.48H15v-1.5h-1.7l.85-1.47l-1.3-.75L12 8.47L11.15 7l-1.3.75l.85 1.47H9v1.5h1.7l-.85 1.48zM23 9.22h-1.7l.85-1.47l-1.3-.75L20 8.47L19.15 7l-1.3.75l.85 1.47H17v1.5h1.7l-.85 1.48l1.3.75l.85-1.48l.85 1.48l1.3-.75l-.85-1.48H23v-1.5z"
"password": "M2 17h20v2H2v-2zm1.15-4.05L4 11.47l.85 1.48l1.3-.75l-.85-1.48H7v-1.5H5.3l.85-1.47L4.85 7L4 8.47L3.15 7l-1.3.75l.85 1.47H1v1.5h1.7l-.85 1.48l1.3.75zm6.7-.75l1.3.75l.85-1.48l.85 1.48l1.3-.75l-.85-1.48H15v-1.5h-1.7l.85-1.47l-1.3-.75L12 8.47L11.15 7l-1.3.75l.85 1.47H9v1.5h1.7l-.85 1.48zM23 9.22h-1.7l.85-1.47l-1.3-.75L20 8.47L19.15 7l-1.3.75l.85 1.47H17v1.5h1.7l-.85 1.48l1.3.75l.85-1.48l.85 1.48l1.3-.75l-.85-1.48H23v-1.5z",
"star": "m12 17.27l4.15 2.51c.76.46 1.69-.22 1.49-1.08l-1.1-4.72l3.67-3.18c.67-.58.31-1.68-.57-1.75l-4.83-.41l-1.89-4.46c-.34-.81-1.5-.81-1.84 0L9.19 8.63l-4.83.41c-.88.07-1.24 1.17-.57 1.75l3.67 3.18l-1.1 4.72c-.2.86.73 1.54 1.49 1.08l4.15-2.5z"
}
13 changes: 6 additions & 7 deletions src/components/Cover/MainCover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<!-- 歌手 -->
<div v-if="item.artists" class="artists">
<n-text v-for="ar in item.artists" :key="ar.id" class="ar">
{{ ar.name }}
{{ ar.name || ar.userName }}
</n-text>
</div>
<!-- 歌曲数量 -->
Expand Down Expand Up @@ -297,8 +297,10 @@ const jumpLink = (data, type) => {
word-break: break-all;
.ar {
display: inline-flex;
color: var(--n-close-icon-color);
transition: color 0.3s;
opacity: 0.6;
transition:
color 0.3s,
opacity 0.3s;
cursor: pointer;
&::after {
content: "/";
Expand All @@ -311,10 +313,7 @@ const jumpLink = (data, type) => {
}
}
&:hover {
color: var(--n-code-text-color);
&::after {
color: var(--n-close-icon-color);
}
opacity: 0.8;
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/components/Global/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ const menuOptions = computed(() => [
key: "like-songs",
icon: renderIcon("favorite-rounded"),
},
{
label: () =>
h(
RouterLink,
{
to: {
name: "like",
},
},
() => ["我的收藏"],
),
key: "like",
icon: renderIcon("star"),
},
{
label: () =>
h(
Expand Down
2 changes: 1 addition & 1 deletion src/components/Global/Playlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</template>
<!-- 提示 -->
<n-alert v-if="playList?.length >= 400" class="alert" :show-icon="false">
因歌单数量过大,无法自动定位,请手动查找
当前歌曲过多,无法自动定位,请手动查找
</n-alert>
<Transition name="fade" mode="out-in">
<n-data-table
Expand Down
2 changes: 1 addition & 1 deletion src/components/Player/PlayerCover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const { playState } = storeToRefs(status);
.cover-loading {
position: absolute;
height: 100%;
margin-bottom: 0;
padding-bottom: 0;
.loading-img {
top: auto;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Player/PrivateFm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<div class="control">
<!-- 播放暂停 -->
<n-button
:loading="playLoading"
:loading="playMode === 'fm' && playLoading"
class="play-control"
color="#efefef"
type="primary"
Expand Down
36 changes: 36 additions & 0 deletions src/router/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,42 @@ const routes = [
},
],
},
// 我的收藏
{
path: "/like",
name: "like",
meta: {
title: "我的收藏",
},
component: () => import("@/views/Like/index.vue"),
beforeEnter: (_, __, next) => {
if (isLogin()) {
next();
} else {
if (typeof $changeLogin !== "undefined") $changeLogin();
$message.error("请登录后使用");
$loadingBar.error();
}
},
redirect: "/like/albums",
children: [
{
path: "albums",
name: "like-albums",
component: () => import("@/views/Like/albums.vue"),
},
{
path: "artists",
name: "like-artists",
component: () => import("@/views/Like/artists.vue"),
},
{
path: "videos",
name: "like-videos",
component: () => import("@/views/Like/videos.vue"),
},
],
},
// 本地歌曲
{
path: "/local",
Expand Down
2 changes: 1 addition & 1 deletion src/stores/siteData.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const useSiteDataStore = defineStore("siteData", {
$message.error("用户喜欢专辑加载失败");
}
},
// 更改用户喜欢歌手
// 更改用户喜欢视频
async setUserLikeMvs() {
try {
if (!isLogin()) return false;
Expand Down
13 changes: 7 additions & 6 deletions src/utils/formatData.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const formatData = (data, type = "playlist", noTracks = false) => {
const imgUrl =
v &&
(v.picUrl ||
v.coverUrl ||
v.coverImgUrl ||
v.cover ||
(v.album && v.album.picUrl) ||
Expand Down Expand Up @@ -97,14 +98,14 @@ const formatData = (data, type = "playlist", noTracks = false) => {
// mv
case "mv":
return {
id: v.id,
name: v.name,
artists: v.artists,
id: v.id || v.vid,
name: v.name || v.title,
artists: v.artists || v.creator,
desc: v.copywriter,
cover,
coverSize: getCoverUrl(v.imgurl16v9 || v.picUrl || v.cover, "464y260"),
duration: v.duration,
playCount: v.playCount,
coverSize: getCoverUrl(cover, "464y260"),
duration: v.duration || v.durationms,
playCount: v.playCount || v.playTime,
};
default:
return null;
Expand Down
31 changes: 31 additions & 0 deletions src/views/Like/albums.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<div class="like-albums">
<Transition name="fade" mode="out-in">
<div v-if="userLikeData.albums?.length" class="list">
<!-- 列表 -->
<MainCover :data="likeAlbumsData" type="album" />
</div>
<n-empty
v-else
description="当前暂无收藏专辑"
class="tip"
style="margin-top: 60px"
size="large"
/>
</Transition>
</div>
</template>

<script setup>
import { storeToRefs } from "pinia";
import { siteData } from "@/stores";
import formatData from "@/utils/formatData";
const data = siteData();
const { userLikeData } = storeToRefs(data);
// 处理专辑数据
const likeAlbumsData = computed(() => {
return formatData(userLikeData.value.albums, "album");
});
</script>
31 changes: 31 additions & 0 deletions src/views/Like/artists.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<div class="like-artists">
<Transition name="fade" mode="out-in">
<div v-if="userLikeData.artists?.length" class="list">
<!-- 列表 -->
<MainCover :data="likeArtistsData" type="artist" columns="3 s:4 m:5 l:6" />
</div>
<n-empty
v-else
description="当前暂无收藏歌手"
class="tip"
style="margin-top: 60px"
size="large"
/>
</Transition>
</div>
</template>

<script setup>
import { storeToRefs } from "pinia";
import { siteData } from "@/stores";
import formatData from "@/utils/formatData";
const data = siteData();
const { userLikeData } = storeToRefs(data);
// 处理歌手数据
const likeArtistsData = computed(() => {
return formatData(userLikeData.value.artists, "artist");
});
</script>
49 changes: 49 additions & 0 deletions src/views/Like/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div class="like">
<n-h1 class="title">我的收藏</n-h1>
<!-- 标签页 -->
<n-tabs v-model:value="tabValue" class="tabs" type="segment" @update:value="tabChange">
<n-tab name="like-albums"> 专辑 </n-tab>
<n-tab name="like-artists"> 歌手 </n-tab>
<n-tab name="like-videos"> 视频 </n-tab>
</n-tabs>
<!-- 路由页面 -->
<router-view v-slot="{ Component }">
<keep-alive>
<Transition name="router" mode="out-in">
<component :is="Component" />
</Transition>
</keep-alive>
</router-view>
</div>
</template>

<script setup>
import { useRouter } from "vue-router";
const router = useRouter();
// 默认选中
const tabValue = ref(router.currentRoute.value?.name ?? "like-albums");
// 标签页切换
const tabChange = (val) => {
const routerPath = val.replace(/^like-/, "");
router.push({
path: `/like/${routerPath}`,
});
};
</script>
<style lang="scss" scoped>
.like {
.title {
margin: 20px 0;
font-size: 36px;
font-weight: bold;
}
.tabs {
margin-bottom: 20px;
}
}
</style>
31 changes: 31 additions & 0 deletions src/views/Like/videos.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<div class="like-videos">
<Transition name="fade" mode="out-in">
<div v-if="userLikeData.mvs?.length" class="list">
<!-- 列表 -->
<MainCover :data="likeVideosData" columns="1 s:2 m:3 l:4 xl:5" type="mv" />
</div>
<n-empty
v-else
description="当前暂无收藏视频"
class="tip"
style="margin-top: 60px"
size="large"
/>
</Transition>
</div>
</template>

<script setup>
import { storeToRefs } from "pinia";
import { siteData } from "@/stores";
import formatData from "@/utils/formatData";
const data = siteData();
const { userLikeData } = storeToRefs(data);
// 处理视频数据
const likeVideosData = computed(() => {
return formatData(userLikeData.value.mvs, "mv");
});
</script>
Loading

0 comments on commit b811b00

Please sign in to comment.