优化格式 去掉一层嵌套

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