fix: point exp

This commit is contained in:
zzc
2026-02-25 11:02:27 +08:00
parent a6e9c1c9ce
commit 32457aa947
2 changed files with 41 additions and 28 deletions

View File

@@ -332,11 +332,24 @@ const downloadWallpaper = async (item) => {
} }
uni.showLoading({ title: "下载中..." }); uni.showLoading({ title: "下载中..." });
await saveRemoteImageToLocal(item.imageUrl); try {
await saveRecordRequest("", item.id, "wallpaper_download", item.imageUrl); // 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(); // Refresh user assets to show updated points
uni.showToast({ title: "保存成功 消耗 20 积分", icon: "success" }); 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) => {}; const shareWallpaper = (item) => {};

View File

@@ -70,30 +70,30 @@ export const saveViewRequest = async (shareToken, scene, targetId = "") => {
}; };
export const saveRemoteImageToLocal = (imageUrl) => { export const saveRemoteImageToLocal = (imageUrl) => {
uni.downloadFile({ return new Promise((resolve, reject) => {
url: imageUrl, uni.downloadFile({
success: (res) => { url: imageUrl,
if (res.statusCode === 200) { success: (res) => {
uni.saveImageToPhotosAlbum({ if (res.statusCode === 200) {
filePath: res.tempFilePath, uni.saveImageToPhotosAlbum({
success: () => { filePath: res.tempFilePath,
uni.hideLoading(); success: () => {
uni.showToast({ title: "已保存到相册" }); resolve(true);
}, },
fail: () => { fail: (err) => {
uni.hideLoading(); reject(err);
uni.showToast({ title: "保存失败", icon: "none" }); },
}, });
}); } else {
} else { reject(
uni.hideLoading(); new Error("Download failed with status code: " + res.statusCode),
uni.showToast({ title: "下载失败", icon: "none" }); );
} }
}, },
fail: () => { fail: (err) => {
uni.hideLoading(); reject(err);
uni.showToast({ title: "下载失败", icon: "none" }); },
}, });
}); });
}; };