From 424c1e76f059a97476203472af93e588f4b3d373 Mon Sep 17 00:00:00 2001 From: MoYingJi Date: Sat, 25 Oct 2025 03:36:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A0=BC=E5=BC=8F=20?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=B8=80=E5=B1=82=E5=B5=8C=E5=A5=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/auth.ts | 54 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/utils/auth.ts b/src/utils/auth.ts index 3264f1a..35c33be 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -243,34 +243,32 @@ const toLikeSomething = thingName: string, request: () => (id: number, t: 1 | 2) => Promise<{ code: number }>, update: () => Promise, - ) => { - 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)