优化格式 去掉一层嵌套

This commit is contained in:
MoYingJi
2025-10-25 03:36:08 +08:00
parent e854dbb816
commit 424c1e76f0

View File

@@ -243,34 +243,32 @@ const toLikeSomething =
thingName: string,
request: () => (id: number, t: 1 | 2) => Promise<{ code: number }>,
update: () => Promise<void>,
) => {
return debounce(
async (id: number, like: boolean) => {
// 错误情况
if (!id) return;
if (!isLogin()) {
window.$message.warning("请登录后使用");
return;
}
if (isLogin() === 2) {
window.$message.warning("该登录模式暂不支持该操作");
return;
}
// 请求
const { code } = await request()(id, like ? 1 : 2);
if (code === 200) {
window.$message.success((like ? "" : "取消") + actionName + thingName + "成功");
// 更新
await update();
} else {
window.$message.success((like ? "" : "取消") + actionName + thingName + "失败,请重试");
return;
}
},
300,
{ leading: true, trailing: false },
);
};
) => debounce(
async (id: number, like: boolean) => {
// 错误情况
if (!id) return;
if (!isLogin()) {
window.$message.warning("请登录后使用");
return;
}
if (isLogin() === 2) {
window.$message.warning("该登录模式暂不支持该操作");
return;
}
// 请求
const { code } = await request()(id, like ? 1 : 2);
if (code === 200) {
window.$message.success((like ? "" : "取消") + actionName + thingName + "成功");
// 更新
await update();
} else {
window.$message.success((like ? "" : "取消") + actionName + thingName + "失败,请重试");
return;
}
},
300,
{ leading: true, trailing: false },
);
// 收藏/取消收藏歌单
export const toLikePlaylist = toLikeSomething("收藏", "歌单", () => likePlaylist, updateUserLikePlaylist)