fix: point exp
This commit is contained in:
@@ -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),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Refresh user assets to show updated points
|
||||||
await userStore.fetchUserAssets();
|
await userStore.fetchUserAssets();
|
||||||
|
|
||||||
|
uni.hideLoading();
|
||||||
uni.showToast({ title: "保存成功 消耗 20 积分", icon: "success" });
|
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) => {};
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ export const saveViewRequest = async (shareToken, scene, targetId = "") => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const saveRemoteImageToLocal = (imageUrl) => {
|
export const saveRemoteImageToLocal = (imageUrl) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
uni.downloadFile({
|
uni.downloadFile({
|
||||||
url: imageUrl,
|
url: imageUrl,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
@@ -77,24 +78,23 @@ export const saveRemoteImageToLocal = (imageUrl) => {
|
|||||||
uni.saveImageToPhotosAlbum({
|
uni.saveImageToPhotosAlbum({
|
||||||
filePath: res.tempFilePath,
|
filePath: res.tempFilePath,
|
||||||
success: () => {
|
success: () => {
|
||||||
uni.hideLoading();
|
resolve(true);
|
||||||
uni.showToast({ title: "已保存到相册" });
|
|
||||||
},
|
},
|
||||||
fail: () => {
|
fail: (err) => {
|
||||||
uni.hideLoading();
|
reject(err);
|
||||||
uni.showToast({ title: "保存失败", icon: "none" });
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
uni.hideLoading();
|
reject(
|
||||||
uni.showToast({ title: "下载失败", icon: "none" });
|
new Error("Download failed with status code: " + res.statusCode),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: () => {
|
fail: (err) => {
|
||||||
uni.hideLoading();
|
reject(err);
|
||||||
uni.showToast({ title: "下载失败", icon: "none" });
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getShareToken = async (scene, targetId = "") => {
|
export const getShareToken = async (scene, targetId = "") => {
|
||||||
|
|||||||
Reference in New Issue
Block a user