This commit is contained in:
zpc 2026-01-06 21:44:50 +08:00
parent b43786715f
commit 0708675fb5
2 changed files with 37 additions and 6 deletions

View File

@ -878,6 +878,7 @@ export const saveImageToPhotosAlbum = (image) => {
try {
// 创建一个隐藏的 a 标签,触发下载
const link = document.createElement("a");
console.log("下载地址:"+image);
link.href = image;
// 如果 image 是 blob url 或 http url都可以
link.download = "image_" + Date.now()+".jpg"; // 下载文件名
@ -915,6 +916,32 @@ export const saveImageToPhotosAlbum = (image) => {
// #endif
});
};
/**
* 批量保存图片到相册兼容 H5 / App / 小程序
* @param {string[]} images - 图片路径数组
* @param {function} onProgress - 进度回调 (completed, total)
* @returns {Promise<{success: number, failed: number}>} 保存结果统计
*/
export const saveImagesToPhotosAlbum = async (images, onProgress = null) => {
const result = { success: 0, failed: 0 };
for (let i = 0; i < images.length; i++) {
try {
await saveImageToPhotosAlbum(images[i]);
result.success++;
} catch (err) {
console.error(`保存第${i + 1}张图片失败:`, err);
result.failed++;
}
if (onProgress) {
onProgress(i + 1, images.length);
}
}
return result;
};
/**
* 图片转Base64兼容小程序AppH5
* @param {string} filePath - 图片路径小程序临时路径 / H5本地URL / App本地路径

View File

@ -222,6 +222,7 @@ import {
formatDate,
getCachedLogo,
saveImageToPhotosAlbum,
saveImagesToPhotosAlbum,
imageToBase64,
} from "../../common/utils";
import {
@ -910,10 +911,11 @@ const fallbackToV2Upload = async (_remarks, validWorkers) => {
icon: "success",
});
//
//
try {
if (imageSrc.value) {
await saveImageToPhotosAlbum(imageSrc.value);
if (imageList.value.length > 0) {
const watermarkPaths = imageList.value.map(img => img.watermark);
await saveImagesToPhotosAlbum(watermarkPaths);
}
} catch (saveError) {
console.error("保存图片到相册失败:", saveError);
@ -1079,9 +1081,11 @@ const handleSaveAndSubmit = async () => {
}
try {
//
if (imageSrc.value) {
await saveImageToPhotosAlbum(imageSrc.value);
//
if (imageList.value.length > 0) {
const watermarkPaths = imageList.value.map(img => img.watermark);
const saveResult = await saveImagesToPhotosAlbum(watermarkPaths);
console.log(`保存到相册完成: 成功${saveResult.success}张, 失败${saveResult.failed}`);
}
} catch (error) {
console.error("保存图片失败", error);