mirror of
https://github.com/imsyy/SPlayer.git
synced 2025-11-25 19:37:35 +08:00
@@ -21,6 +21,7 @@ import { dailyRecommend } from "@/api/rec";
|
|||||||
import { isElectron } from "./helper";
|
import { isElectron } from "./helper";
|
||||||
import { likePlaylist, playlistTracks } from "@/api/playlist";
|
import { likePlaylist, playlistTracks } from "@/api/playlist";
|
||||||
import { likeArtist } from "@/api/artist";
|
import { likeArtist } from "@/api/artist";
|
||||||
|
import { likeAlbum } from "@/api/album";
|
||||||
import { radioSub } from "@/api/radio";
|
import { radioSub } from "@/api/radio";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -236,9 +237,15 @@ export const toLikeSong = debounce(
|
|||||||
{ leading: true, trailing: false },
|
{ leading: true, trailing: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
// 收藏/取消收藏歌单
|
const toLikeSomething =
|
||||||
export const toLikePlaylist = debounce(
|
(
|
||||||
|
actionName: string,
|
||||||
|
thingName: string,
|
||||||
|
request: () => (id: number, t: 1 | 2) => Promise<{ code: number }>,
|
||||||
|
update: () => Promise<void>,
|
||||||
|
) => debounce(
|
||||||
async (id: number, like: boolean) => {
|
async (id: number, like: boolean) => {
|
||||||
|
// 错误情况
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
if (!isLogin()) {
|
if (!isLogin()) {
|
||||||
window.$message.warning("请登录后使用");
|
window.$message.warning("请登录后使用");
|
||||||
@@ -248,13 +255,14 @@ export const toLikePlaylist = debounce(
|
|||||||
window.$message.warning("该登录模式暂不支持该操作");
|
window.$message.warning("该登录模式暂不支持该操作");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { code } = await likePlaylist(id, like ? 1 : 2);
|
// 请求
|
||||||
|
const { code } = await request()(id, like ? 1 : 2);
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
window.$message.success((like ? "收藏" : "取消收藏") + "歌单成功");
|
window.$message.success((like ? "" : "取消") + actionName + thingName + "成功");
|
||||||
// 更新
|
// 更新
|
||||||
await updateUserLikePlaylist();
|
await update();
|
||||||
} else {
|
} else {
|
||||||
window.$message.success((like ? "收藏" : "取消收藏") + "歌单失败,请重试");
|
window.$message.success((like ? "" : "取消") + actionName + thingName + "失败,请重试");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -262,57 +270,17 @@ export const toLikePlaylist = debounce(
|
|||||||
{ leading: true, trailing: false },
|
{ leading: true, trailing: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 收藏/取消收藏歌单
|
||||||
|
export const toLikePlaylist = toLikeSomething("收藏", "歌单", () => likePlaylist, updateUserLikePlaylist)
|
||||||
|
|
||||||
|
// 收藏/取消收藏专辑
|
||||||
|
export const toLikeAlbum = toLikeSomething("收藏", "专辑", () => likeAlbum, updateUserLikeAlbums)
|
||||||
|
|
||||||
// 收藏/取消收藏歌手
|
// 收藏/取消收藏歌手
|
||||||
export const toLikeArtist = debounce(
|
export const toLikeArtist = toLikeSomething("收藏", "歌手", () => likeArtist, updateUserLikeArtists)
|
||||||
async (id: number, like: boolean) => {
|
|
||||||
if (!id) return;
|
|
||||||
if (!isLogin()) {
|
|
||||||
window.$message.warning("请登录后使用");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isLogin() === 2) {
|
|
||||||
window.$message.warning("该登录模式暂不支持该操作");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { code } = await likeArtist(id, like ? 1 : 2);
|
|
||||||
if (code === 200) {
|
|
||||||
window.$message.success((like ? "收藏" : "取消收藏") + "歌手成功");
|
|
||||||
// 更新
|
|
||||||
await updateUserLikeArtists();
|
|
||||||
} else {
|
|
||||||
window.$message.success((like ? "收藏" : "取消收藏") + "歌手失败,请重试");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
300,
|
|
||||||
{ leading: true, trailing: false },
|
|
||||||
);
|
|
||||||
|
|
||||||
// 订阅/取消订阅播客
|
// 订阅/取消订阅播客
|
||||||
export const toSubRadio = debounce(
|
export const toSubRadio = toLikeSomething("订阅", "播客", () => radioSub, updateUserLikeDjs)
|
||||||
async (id: number, like: boolean) => {
|
|
||||||
if (!id) return;
|
|
||||||
if (!isLogin()) {
|
|
||||||
window.$message.warning("请登录后使用");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isLogin() === 2) {
|
|
||||||
window.$message.warning("该登录模式暂不支持该操作");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { code } = await radioSub(id, like ? 1 : 0);
|
|
||||||
if (code === 200) {
|
|
||||||
window.$message.success((like ? "订阅" : "取消订阅") + "播客成功");
|
|
||||||
// 更新
|
|
||||||
await updateUserLikeDjs();
|
|
||||||
} else {
|
|
||||||
window.$message.success((like ? "订阅" : "取消订阅") + "播客失败,请重试");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
300,
|
|
||||||
{ leading: true, trailing: false },
|
|
||||||
);
|
|
||||||
|
|
||||||
// 循环获取用户喜欢数据
|
// 循环获取用户喜欢数据
|
||||||
const setUserLikeDataLoop = async <T>(
|
const setUserLikeDataLoop = async <T>(
|
||||||
|
|||||||
@@ -101,7 +101,13 @@
|
|||||||
</template>
|
</template>
|
||||||
{{ loading ? "加载中..." : "播放" }}
|
{{ loading ? "加载中..." : "播放" }}
|
||||||
</n-button>
|
</n-button>
|
||||||
<n-button :focusable="false" strong secondary round>
|
<n-button
|
||||||
|
:focusable="false"
|
||||||
|
strong
|
||||||
|
secondary
|
||||||
|
round
|
||||||
|
@click="toLikeAlbum(albumId, !isLikeAlbum)"
|
||||||
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<SvgIcon :name="isLikeAlbum ? 'Favorite' : 'FavoriteBorder'" />
|
<SvgIcon :name="isLikeAlbum ? 'Favorite' : 'FavoriteBorder'" />
|
||||||
</template>
|
</template>
|
||||||
@@ -179,6 +185,7 @@ import { debounce } from "lodash-es";
|
|||||||
import { formatTimestamp } from "@/utils/time";
|
import { formatTimestamp } from "@/utils/time";
|
||||||
import { openJumpArtist } from "@/utils/modal";
|
import { openJumpArtist } from "@/utils/modal";
|
||||||
import player from "@/utils/player";
|
import player from "@/utils/player";
|
||||||
|
import { toLikeAlbum } from "@/utils/auth";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const dataStore = useDataStore();
|
const dataStore = useDataStore();
|
||||||
|
|||||||
Reference in New Issue
Block a user