From 32457aa9475d0b0a3704f2576d5c59919bbd1a73 Mon Sep 17 00:00:00 2001 From: zzc <1761997216@qq.com> Date: Wed, 25 Feb 2026 11:02:27 +0800 Subject: [PATCH] fix: point exp --- pages/wallpaper/index.vue | 21 +++++++++++++---- utils/common.js | 48 +++++++++++++++++++-------------------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/pages/wallpaper/index.vue b/pages/wallpaper/index.vue index 5441fd6..62af99a 100644 --- a/pages/wallpaper/index.vue +++ b/pages/wallpaper/index.vue @@ -332,11 +332,24 @@ const downloadWallpaper = async (item) => { } uni.showLoading({ title: "下载中..." }); - await saveRemoteImageToLocal(item.imageUrl); - await saveRecordRequest("", item.id, "wallpaper_download", item.imageUrl); + try { + // Parallelize save record and download + // Wait for saveRecordRequest to ensure backend deducts points + await Promise.all([ + saveRecordRequest("", item.id, "wallpaper_download", item.imageUrl), + saveRemoteImageToLocal(item.imageUrl), + ]); - await userStore.fetchUserAssets(); - uni.showToast({ title: "保存成功 消耗 20 积分", icon: "success" }); + // Refresh user assets to show updated points + await userStore.fetchUserAssets(); + + uni.hideLoading(); + uni.showToast({ title: "保存成功 消耗 20 积分", icon: "success" }); + } catch (e) { + uni.hideLoading(); + console.error("Download failed", e); + uni.showToast({ title: "下载失败", icon: "none" }); + } }; const shareWallpaper = (item) => {}; diff --git a/utils/common.js b/utils/common.js index 27adfc8..90af4f0 100644 --- a/utils/common.js +++ b/utils/common.js @@ -70,30 +70,30 @@ export const saveViewRequest = async (shareToken, scene, targetId = "") => { }; export const saveRemoteImageToLocal = (imageUrl) => { - uni.downloadFile({ - url: imageUrl, - success: (res) => { - if (res.statusCode === 200) { - uni.saveImageToPhotosAlbum({ - filePath: res.tempFilePath, - success: () => { - uni.hideLoading(); - uni.showToast({ title: "已保存到相册" }); - }, - fail: () => { - uni.hideLoading(); - uni.showToast({ title: "保存失败", icon: "none" }); - }, - }); - } else { - uni.hideLoading(); - uni.showToast({ title: "下载失败", icon: "none" }); - } - }, - fail: () => { - uni.hideLoading(); - uni.showToast({ title: "下载失败", icon: "none" }); - }, + return new Promise((resolve, reject) => { + uni.downloadFile({ + url: imageUrl, + success: (res) => { + if (res.statusCode === 200) { + uni.saveImageToPhotosAlbum({ + filePath: res.tempFilePath, + success: () => { + resolve(true); + }, + fail: (err) => { + reject(err); + }, + }); + } else { + reject( + new Error("Download failed with status code: " + res.statusCode), + ); + } + }, + fail: (err) => { + reject(err); + }, + }); }); };