查看大图默认长按保存
function previewImage({ urls, index }) {
uni.previewImage({
urls,
current: index,
});
}
自定义longPressActions
uni.previewImage({
urls,
current: index,
longPressActions: {
itemList: ["保存图片"],
success: async (data) => {
if (data.tapIndex == 0) {
//保存图片
saveImgToLocal(urls[data.index]);
}
},
fail: function (err) {
console.log(err.errMsg);
},
},
});
function saveImgToLocal(url) {
uni.downloadFile({
url, //图片地址
success: (res) => {
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: () => {
uni.showToast({
title: "保存成功到相册",
icon: "none",
});
},
fail: (err) => {
console.log(err);
uni.showToast({
title: "保存失败",
icon: "none",
});
},
});
}
},
fail: (err) => {
console.log(err);
},
});
}
0 个回复